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(endpoint) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
# File 'lib/rakuten_web_service/client.rb', line 14

def initialize(endpoint)
  url = URI.parse(endpoint)
  @url = "#{url.scheme}://#{url.host}"
  @path = url.path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#get(query) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rakuten_web_service/client.rb', line 20

def get(query)
  query = RakutenWebService.configuration.generate_parameters.merge(query)
  query = convert_snake_key_to_camel_key(query)
  response = connection.get(path, query)
  case response.status
  when 200
    return response
  when 400
    raise WrongParameter, response.body['error_description']
  when 404
    raise NotFound, response.body['error_description']
  when 429
    raise TooManyRequests, response.body['error_description']
  when 500
    raise SystemError, response.body['error_description']
  when 503
    raise ServiceUnavailable, response.body['error_description']
  end
end