Module: RmsApi::Helper
- Included in:
- Item
- Defined in:
- lib/rms_api/helper.rb
Constant Summary collapse
- ENDPOINT_BASE =
'https://api.rms.rakuten.co.jp/es/1.0/'.freeze
Instance Method Summary collapse
- #connection(service:, method:) ⇒ Object
- #convert_xml_into_json(xml) ⇒ Object
- #handler(response) ⇒ Object
Instance Method Details
#connection(service:, method:) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/rms_api/helper.rb', line 5 def connection(service:, method:) Faraday.new(url: ENDPOINT_BASE + "#{service}/#{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_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 |
# File 'lib/rms_api/helper.rb', line 16 def handler(response) rexml = REXML::Document.new(response.body) define_singleton_method(:all) { convert_xml_into_json(response.body) } check_system_status(rexml) status_parser(response_code: get_response_code(rexml), error_messages: (rexml)) get_response_parser(rexml) if response.env.method == :get self end |