Module: RmsItemApi::Helper

Included in:
Client, Item
Defined in:
lib/rms_item_api/helper.rb

Constant Summary collapse

ENDPOINT =
'https://api.rms.rakuten.co.jp/es/1.0/item/'.freeze

Instance Method Summary collapse

Instance Method Details

#connection(method) ⇒ Object



5
6
7
8
9
10
# File 'lib/rms_item_api/helper.rb', line 5

def connection(method)
  Faraday.new(url: ENDPOINT + method) do |conn|
    conn.adapter(Faraday.default_adapter)
    conn.headers['Authorization'] = encoded_key
  end
end

#convert_xml_into_json(xml) ⇒ Object



12
13
14
# File 'lib/rms_item_api/helper.rb', line 12

def convert_xml_into_json(xml)
  Hash.from_xml(xml)
end

#handler(response) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rms_item_api/helper.rb', line 16

def handler(response)
  rexml = REXML::Document.new(response.body)
  self.define_singleton_method(:all) { convert_xml_into_json(response.body) }

  if rexml.elements["result/status/systemStatus"].text == "NG"
    raise rexml.elements["result/status/message"].text
  end

  status_parser(rexml)
  case response.env.method
  when :get
    get_response_parser(rexml)
  # when :post
  #   post_response_parser(rexml)
  end

  self
end