Class: RakutenProductApi::Client
- Inherits:
-
Object
- Object
- RakutenProductApi::Client
- Extended by:
- Forwardable
- Defined in:
- lib/rakuten_product_api/client.rb
Constant Summary collapse
- REFRESH_TOKEN_LEEWAY =
Ten minutes prior to expiry we should refresh token
60 * 10
Instance Attribute Summary collapse
-
#authenticate ⇒ Object
Returns the value of attribute authenticate.
-
#password ⇒ Object
Returns the value of attribute password.
-
#sid ⇒ Object
Returns the value of attribute sid.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #api_request(payload, path) ⇒ Object
-
#initialize(sid: RakutenProductApi.sid, endpoint: RakutenProductApi.endpoint, access_token: nil, access_token_expires_at: nil) ⇒ Client
constructor
A new instance of Client.
- #search(**options) ⇒ Object
Constructor Details
#initialize(sid: RakutenProductApi.sid, endpoint: RakutenProductApi.endpoint, access_token: nil, access_token_expires_at: nil) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rakuten_product_api/client.rb', line 15 def initialize(sid: RakutenProductApi.sid, endpoint: RakutenProductApi.endpoint, access_token: nil, access_token_expires_at: nil) @sid = sid @endpoint = endpoint @authenticate = Authenticate.new(sid: sid, access_token: access_token, access_token_expires_at: access_token_expires_at) end |
Instance Attribute Details
#authenticate ⇒ Object
Returns the value of attribute authenticate.
13 14 15 |
# File 'lib/rakuten_product_api/client.rb', line 13 def authenticate @authenticate end |
#password ⇒ Object
Returns the value of attribute password.
13 14 15 |
# File 'lib/rakuten_product_api/client.rb', line 13 def password @password end |
#sid ⇒ Object
Returns the value of attribute sid.
13 14 15 |
# File 'lib/rakuten_product_api/client.rb', line 13 def sid @sid end |
#username ⇒ Object
Returns the value of attribute username.
13 14 15 |
# File 'lib/rakuten_product_api/client.rb', line 13 def username @username end |
Instance Method Details
#api_request(payload, path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rakuten_product_api/client.rb', line 35 def api_request(payload, path) params = payload.map { |k, v| "#{k}=#{v}" }.join("&") uri = URI("#{@endpoint}#{path}?#{params}") res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| req = Net::HTTP::Get.new(uri) req["Authorization"] = @authenticate.auth_header req["Accept"] = "application/xml" http.request(req) end puts "RESPONSE CODE #{res.code} received" if res.code != "200" res end |