Class: Rakuten::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rakuten/request.rb

Constant Summary collapse

URL =
"http://webservice.rakuten.de/merchants"
FORMAT =
"json"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
# File 'lib/rakuten/request.rb', line 11

def initialize *args
  @params = args.extract_options!
  @group, @method, @version = args.map(&:to_s)

  @method = @method.camelize(:lower)
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



9
10
11
# File 'lib/rakuten/request.rb', line 9

def group
  @group
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/rakuten/request.rb', line 9

def method
  @method
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/rakuten/request.rb', line 9

def version
  @version
end

Instance Method Details

#getObject



22
23
24
# File 'lib/rakuten/request.rb', line 22

def get
  resource.get params: params
end

#paramsObject



34
35
36
# File 'lib/rakuten/request.rb', line 34

def params
  @params.merge format: FORMAT
end

#postObject



26
27
28
# File 'lib/rakuten/request.rb', line 26

def post
  resource.post params
end

#resourceObject



30
31
32
# File 'lib/rakuten/request.rb', line 30

def resource
  @resource ||= RestClient::Resource.new(url, timeout: -1, open_timeout: 120)
end

#urlObject



18
19
20
# File 'lib/rakuten/request.rb', line 18

def url
  @url ||= [URL, group, method, version].compact * '/'
end