Sha256: b6554ae5a34aceb9fc5c6cbc3ba12e2b7a8c542aa042e330ad20cf7408d588c5
Contents?: true
Size: 943 Bytes
Versions: 2
Compression:
Stored size: 943 Bytes
Contents
require 'faraday' require 'faraday_middleware' module RakutenWebService class Client attr_reader :url, :path def initialize(endpoint) url = URI.parse(endpoint) @url = "#{url.scheme}://#{url.host}" @path = url.path end def get(query) query = RakutenWebService.configuration.generate_parameters.merge(query) query = convert_snake_key_to_camel_key(query) connection.get(path, query) end private def connection return @connection if @connection @connection = Faraday.new(:url => url) do |conn| conn.request :url_encoded conn.response :json conn.adapter Faraday.default_adapter end end def convert_snake_key_to_camel_key(params) converted = {} params.each do |k, v| k = k.to_s.gsub(/([a-z]+)_([a-z]+)/) { "#{$1}#{$2.capitalize}" } converted[k] = v end return converted end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rakuten_web_service-0.1.0 | lib/rakuten_web_service/client.rb |
rakuten_web_service-0.0.1 | lib/rakuten_web_service/client.rb |