Class: RakutenWebService::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rakuten_web_service/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_class) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/rakuten_web_service/client.rb', line 10

def initialize(resource_class)
  @resource_class = resource_class
  @url = URI.parse(@resource_class.endpoint)
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/rakuten_web_service/client.rb', line 8

def url
  @url
end

Instance Method Details

#get(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rakuten_web_service/client.rb', line 15

def get(params)
  params = RakutenWebService.configuration.generate_parameters(params)
  response = request(url.path, params)
  body = JSON.parse(response.body)

  if Net::HTTPSuccess === response
    return RakutenWebService::Response.new(@resource_class, body)
  else
    raise RakutenWebService::Error.repository[response.code.to_i], body['error_description']
  end
end