Class: BigcommerceOrderAgent::Client::AbstractClient
- Inherits:
-
Object
- Object
- BigcommerceOrderAgent::Client::AbstractClient
- Defined in:
- lib/client/abstract_client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #index(params = {}) ⇒ Object
-
#initialize(store_hash, client_id, access_token) ⇒ AbstractClient
constructor
A new instance of AbstractClient.
- #uri(params = {}, path = nil) ⇒ Object
- #uri_base ⇒ Object
Constructor Details
#initialize(store_hash, client_id, access_token) ⇒ AbstractClient
Returns a new instance of AbstractClient.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/client/abstract_client.rb', line 8 def initialize(store_hash, client_id, access_token) @endpoint = 'https://api.bigcommerce.com' @headers = { 'X-Auth-Client' => client_id, 'X-Auth-Token' => access_token, 'Content-Type' => 'application/json', 'Accept' => 'application/json' } @store_hash = store_hash end |
Class Method Details
.uri_base ⇒ Object
19 20 21 |
# File 'lib/client/abstract_client.rb', line 19 def self.uri_base @uri_base end |
Instance Method Details
#client ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/client/abstract_client.rb', line 27 def client if !@client @client = Faraday.new({ url: @endpoint, headers: @headers }) do |conn| conn.use Faraday::Response::RaiseError conn.response :logger, nil, { headers: true, bodies: true } conn.response :json, :content_type => 'application/json' conn.adapter Faraday.default_adapter end end return @client end |
#index(params = {}) ⇒ Object
58 59 60 61 |
# File 'lib/client/abstract_client.rb', line 58 def index(params = {}) response = client.get(uri, params) return response.body['data'] end |
#uri(params = {}, path = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/client/abstract_client.rb', line 40 def uri(params = {}, path = nil) params[:api_version] = 'v2' unless params[:api_version].present? u = "/stores/#{@store_hash}/#{uri_base}" if path u = u + "/#{path}" end params.each do |key,val| u = u.gsub(":#{key.to_s}", val.to_s) end # remove params that weren't provided u = u.gsub(/(\/\:[^\/]+)/, '') return u end |
#uri_base ⇒ Object
23 24 25 |
# File 'lib/client/abstract_client.rb', line 23 def uri_base self.class.uri_base end |