Class: Munson::Agent
- Inherits:
-
Object
- Object
- Munson::Agent
- Defined in:
- lib/munson/agent.rb
Instance Method Summary collapse
-
#connection ⇒ Munson::Connection
Connection that will be used for HTTP requests.
-
#delete(body: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec DELETE request.
-
#get(params: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec GET request.
-
#initialize(path, connection: nil) ⇒ Agent
constructor
Creates a new Munson::Agent.
- #negotiate_path(path = nil, id = nil) ⇒ Object
-
#patch(body: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec PATCH request.
-
#post(body: {}, path: nil, headers: nil, http_method: :post, id: nil) ⇒ Faraday::Response
JSON API Spec POST request.
-
#put(body: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec PUT request.
Constructor Details
#initialize(path, connection: nil) ⇒ Agent
Creates a new Munson::Agent
7 8 9 10 |
# File 'lib/munson/agent.rb', line 7 def initialize(path, connection: nil) @path = path @connection = connection end |
Instance Method Details
#connection ⇒ Munson::Connection
Connection that will be used for HTTP requests
15 16 17 18 |
# File 'lib/munson/agent.rb', line 15 def connection return @connection if @connection Munson.default_connection end |
#delete(body: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec DELETE request
91 92 93 |
# File 'lib/munson/agent.rb', line 91 def delete(body: nil, path: nil, headers: nil, id: nil) post(body: body, path: path, headers: headers, http_method: :delete, id: id) end |
#get(params: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec GET request
27 28 29 30 31 32 33 |
# File 'lib/munson/agent.rb', line 27 def get(params: nil, path: nil, headers: nil, id: nil) connection.get( path: negotiate_path(path, id), params: params, headers: headers ) end |
#negotiate_path(path = nil, id = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/munson/agent.rb', line 35 def negotiate_path(path = nil, id = nil) if path path elsif id [@path, id].join('/') else @path end end |
#patch(body: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec PATCH request
69 70 71 |
# File 'lib/munson/agent.rb', line 69 def patch(body: nil, path: nil, headers: nil, id: nil) post(body: body, path: path, headers: headers, http_method: :patch, id: id) end |
#post(body: {}, path: nil, headers: nil, http_method: :post, id: nil) ⇒ Faraday::Response
JSON API Spec POST request
53 54 55 56 57 58 59 60 |
# File 'lib/munson/agent.rb', line 53 def post(body: {}, path: nil, headers: nil, http_method: :post, id: nil) connection.post( path: negotiate_path(path, id), body: body, headers: headers, http_method: http_method ) end |
#put(body: nil, path: nil, headers: nil, id: nil) ⇒ Faraday::Response
JSON API Spec PUT request
80 81 82 |
# File 'lib/munson/agent.rb', line 80 def put(body: nil, path: nil, headers: nil, id: nil) post(body: body, path: path, headers: headers, http_method: :put, id: id) end |