Class: RmsWebService::Client::Item

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

Constant Summary collapse

Endpoint =
"https://api.rms.rakuten.co.jp/es/1.0/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Item

Returns a new instance of Item.



11
12
13
14
# File 'lib/rms_web_service/client/item.rb', line 11

def initialize(args={})
  @configuration = ::RmsWebService::Configuration.new(args)
  @endpoint = args[:endpoint]
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



9
10
11
# File 'lib/rms_web_service/client/item.rb', line 9

def configuration
  @configuration
end

Instance Method Details

#connection(method) ⇒ Object



16
17
18
19
20
21
# File 'lib/rms_web_service/client/item.rb', line 16

def connection(method)
  connection = Faraday.new(:url => endpoint(method)) do |c|
    c.adapter Faraday.default_adapter
    c.headers['Authorization'] = self.configuration.encoded_keys
  end
end

#delete(item_url) ⇒ Object



44
45
46
47
48
# File 'lib/rms_web_service/client/item.rb', line 44

def delete(item_url)
  xml = {:itemDeleteRequest => {:item => {:itemUrl => item_url}}}.to_xml(:root => 'request', :camelize => :lower, :skip_types => true)
  request = connection("item/delete").post {|req| req.body = xml}
  return ::RWS::Response::Item::Delete.new(request.body)
end

#endpoint(method) ⇒ Object



23
24
25
# File 'lib/rms_web_service/client/item.rb', line 23

def endpoint(method)
  @endpoint || Endpoint + method
end

#get(item_url) ⇒ Object



27
28
29
30
# File 'lib/rms_web_service/client/item.rb', line 27

def get(item_url)
  request = connection('item/get').get {|req| req.params['itemUrl'] = item_url }
  return ::RWS::Response::Item::Get.new(request.body)
end

#insert(args) ⇒ Object



32
33
34
35
36
# File 'lib/rms_web_service/client/item.rb', line 32

def insert(args)
  xml = {:itemInsertRequest => {:item => args}}.to_xml(:root => 'request', :camelize => :lower, :skip_types => true)
  request = connection("item/insert").post {|req| req.body = xml}
  return ::RWS::Response::Item::Insert.new(request.body)
end

#items_update(args) ⇒ Object



57
58
59
60
61
# File 'lib/rms_web_service/client/item.rb', line 57

def items_update(args)
  xml = {:itemsUpdateRequest => {:items => args}}.to_xml(:root => 'request', :camelize => :lower, :skip_types => true)
  request = connection("items/update").post {|req| req.body = xml}
  return ::RWS::Response::Item::ItemsUpdate.new(request.body)
end

#search(args) ⇒ Object



50
51
52
53
54
55
# File 'lib/rms_web_service/client/item.rb', line 50

def search(args)
  request = connection("item/search").get do |req|
    args.each {|key, value| req.params["#{key.to_s.camelize(:lower)}"] = args[:"#{key}"]}
  end
  return ::RWS::Response::Item::Search.new(request.body)
end

#update(args) ⇒ Object



38
39
40
41
42
# File 'lib/rms_web_service/client/item.rb', line 38

def update(args)
  xml = {:itemUpdateRequest => {:item => args}}.to_xml(:root => 'request', :camelize => :lower, :skip_types => true)
  request = connection("item/update").post {|req| req.body = xml}
  return ::RWS::Response::Item::Update.new(request.body)
end