Class: MT::DataAPI::Client::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/mt/data_api/client/endpoint.rb

Overview

Send request to endpoint.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Endpoint

Returns a new instance of Endpoint.

Raises:

  • (ArgumentError)


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

Parameters:

  • value

    the value to set the attribute api_url to.



13
14
15
# File 'lib/mt/data_api/client/endpoint.rb', line 13

def api_url=(value)
  @api_url = value
end

Instance Attribute Details

#verbObject (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)
  raise "#{res.code}: #{res.message}" unless res.code == '200'
  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