Class: MT::DataAPI::Client::Endpoint
- Inherits:
-
Object
- Object
- MT::DataAPI::Client::Endpoint
- Defined in:
- lib/mt/data_api/client/endpoint.rb
Overview
Send request to endpoint.
Class Attribute Summary collapse
-
.api_url ⇒ Object
writeonly
Sets the attribute api_url.
Instance Attribute Summary collapse
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #call(access_token = nil, args = {}) ⇒ Object
-
#initialize(hash) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #request_url(args) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Endpoint
Returns a new instance of Endpoint.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mt/data_api/client/endpoint.rb', line 18 def initialize(hash) raise ArgumentError, 'parameter should be hash' unless hash.is_a? Hash hash = hash.symbolize_keys @id = hash[:id] @route = hash[:route] @version = hash[:version] @verb = hash[:verb] raise ArgumentError, "invalid verb: #{@verb}" unless valid_verb? end |
Class Attribute Details
.api_url=(value) ⇒ Object (writeonly)
Sets the attribute api_url
13 14 15 |
# File 'lib/mt/data_api/client/endpoint.rb', line 13 def api_url=(value) @api_url = value end |
Instance Attribute Details
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
16 17 18 |
# File 'lib/mt/data_api/client/endpoint.rb', line 16 def verb @verb end |
Instance Method Details
#call(access_token = nil, args = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/mt/data_api/client/endpoint.rb', line 30 def call(access_token = nil, args = {}) res = APIRequest.new(self).send(access_token, args) return nil if res.body.nil? JSON.parse(res.body) end |
#request_url(args) ⇒ Object
36 37 38 39 40 |
# File 'lib/mt/data_api/client/endpoint.rb', line 36 def request_url(args) url = self.class.instance_variable_get(:@api_url) + route(args) url += query_string(args) if @verb == 'GET' url end |