Class: Newegg::Client
Overview
API Client
Constant Summary collapse
- DEFAULT_ENDPOINT =
'https://api.newegg.cn'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
Instance Method Summary collapse
-
#connection_options ⇒ Hash
Connection options for faraday.
-
#delete(path, params = {}) ⇒ Object
Perform an HTTP DELETE request.
- #endpoint ⇒ String
-
#get(path, params = {}) ⇒ Object
Perform an HTTP GET request.
-
#initialize(options) ⇒ Client
constructor
Initializes a new Client object.
- #middleware ⇒ Faraday::RackBuilder
-
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request.
-
#put(path, params = {}) ⇒ Object
Perform an HTTP PUT request.
- #user_agent ⇒ String
Methods included from Orders
#cancel_order, #fetch_orders, #order_details, #ship_order
Constructor Details
#initialize(options) ⇒ Client
Initializes a new Client object
20 21 22 23 24 |
# File 'lib/newegg/client.rb', line 20 def initialize() @app_key = .fetch(:app_key) @access_token = .fetch(:access_token) @endpoint = [:endpoint] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
13 14 15 |
# File 'lib/newegg/client.rb', line 13 def access_token @access_token end |
#app_key ⇒ Object (readonly)
Returns the value of attribute app_key.
13 14 15 |
# File 'lib/newegg/client.rb', line 13 def app_key @app_key end |
Instance Method Details
#connection_options ⇒ Hash
Connection options for faraday
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/newegg/client.rb', line 39 def { builder: middleware, headers: { accept: 'application/json', user_agent: user_agent, Authorization: "#{app_key}&#{access_token}" }, request: { open_timeout: 10, timeout: 30 } } end |
#delete(path, params = {}) ⇒ Object
Perform an HTTP DELETE request
84 85 86 |
# File 'lib/newegg/client.rb', line 84 def delete(path, params = {}) request(:delete, path, params) end |
#endpoint ⇒ String
27 28 29 |
# File 'lib/newegg/client.rb', line 27 def endpoint @endpoint ||= DEFAULT_ENDPOINT end |
#get(path, params = {}) ⇒ Object
Perform an HTTP GET request
69 70 71 |
# File 'lib/newegg/client.rb', line 69 def get(path, params = {}) request(:get, path, params) end |
#middleware ⇒ Faraday::RackBuilder
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/newegg/client.rb', line 55 def middleware Faraday::RackBuilder.new do |faraday| # Checks for files in the payload, otherwise leaves everything untouched faraday.request :multipart # Encodes as "application/x-www-form-urlencoded" if not already encoded faraday.request :url_encoded # Parse JSON response bodies faraday.response :parse_json # Set default HTTP adapter faraday.adapter :net_http end end |
#post(path, params = {}) ⇒ Object
Perform an HTTP POST request
74 75 76 |
# File 'lib/newegg/client.rb', line 74 def post(path, params = {}) request(:post, path, params) end |
#put(path, params = {}) ⇒ Object
Perform an HTTP PUT request
79 80 81 |
# File 'lib/newegg/client.rb', line 79 def put(path, params = {}) request(:put, path, params) end |