Class: Munson::Agent
- Inherits:
-
Object
- Object
- Munson::Agent
- Extended by:
- Forwardable
- Defined in:
- lib/munson/agent.rb
Instance Attribute Summary collapse
-
#connection ⇒ Munson::Connection
Connection that will be used for HTTP requests.
-
#paginator ⇒ Object
Returns the value of attribute paginator.
-
#paginator_options ⇒ Object
Returns the value of attribute paginator_options.
-
#query_builder ⇒ Object
Returns the value of attribute query_builder.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#delete(body: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec DELETE request.
- #find(id, headers: nil, params: nil) ⇒ Object
-
#get(params: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec GET request.
-
#initialize(opts = {}) ⇒ Agent
constructor
Creates a new Munson::Agent.
-
#patch(body: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec PATCH request.
-
#post(body: {}, path: nil, headers: nil, http_method: :post) ⇒ Faraday::Response
JSON API Spec POST request.
-
#put(body: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec PUT request.
-
#query ⇒ Munson::QueryBuilder
Munson::QueryBuilder factory.
Constructor Details
#initialize(opts = {}) ⇒ Agent
Creates a new Munson::Agent
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/munson/agent.rb', line 21 def initialize(opts={}) @connection = opts[:connection] @type = opts[:type] @query_builder = opts[:query_builder].is_a?(Class) ? opts[:query_builder] : Munson::QueryBuilder self.paginator = opts[:paginator] = opts[:paginator_options] end |
Instance Attribute Details
#connection ⇒ Munson::Connection
Connection that will be used for HTTP requests
58 59 60 61 |
# File 'lib/munson/agent.rb', line 58 def connection return @connection if @connection Munson.default_connection end |
#paginator ⇒ Object
Returns the value of attribute paginator.
11 12 13 |
# File 'lib/munson/agent.rb', line 11 def paginator @paginator end |
#paginator_options ⇒ Object
Returns the value of attribute paginator_options.
12 13 14 |
# File 'lib/munson/agent.rb', line 12 def end |
#query_builder ⇒ Object
Returns the value of attribute query_builder.
9 10 11 |
# File 'lib/munson/agent.rb', line 9 def query_builder @query_builder end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/munson/agent.rb', line 8 def type @type end |
Instance Method Details
#delete(body: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec DELETE request
125 126 127 |
# File 'lib/munson/agent.rb', line 125 def delete(body: nil, path: nil, headers: nil) post(body, path: path, headers: headers, http_method: :delete) end |
#find(id, headers: nil, params: nil) ⇒ Object
63 64 65 66 67 |
# File 'lib/munson/agent.rb', line 63 def find(id, headers: nil, params: nil) path = [type, id].join('/') response = get(path: path, headers: headers, params: params) ResponseMapper.new(response).resource end |
#get(params: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec GET request
75 76 77 78 79 80 81 |
# File 'lib/munson/agent.rb', line 75 def get(params: nil, path: nil, headers: nil) connection.get( path: (path || type), params: params, headers: headers ) end |
#patch(body: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec PATCH request
105 106 107 |
# File 'lib/munson/agent.rb', line 105 def patch(body: nil, path: nil, headers: nil) post(body, path: path, headers: headers, http_method: :patch) end |
#post(body: {}, path: nil, headers: nil, http_method: :post) ⇒ Faraday::Response
JSON API Spec POST request
90 91 92 93 94 95 96 97 |
# File 'lib/munson/agent.rb', line 90 def post(body: {}, path: nil, headers: nil, http_method: :post) connection.post( path: (path || type), body: body, headers: headers, http_method: http_method ) end |
#put(body: nil, path: nil, headers: nil) ⇒ Faraday::Response
JSON API Spec PUT request
115 116 117 |
# File 'lib/munson/agent.rb', line 115 def put(body: nil, path: nil, headers: nil) post(body, path: path, headers: headers, http_method: :put) end |
#query ⇒ Munson::QueryBuilder
Munson::QueryBuilder factory
46 47 48 49 50 51 52 53 |
# File 'lib/munson/agent.rb', line 46 def query if paginator query_pager = paginator.new( || {}) @query_builder.new paginator: query_pager, agent: self else @query_builder.new agent: self end end |