Class: Shoplo::Client
- Inherits:
-
Object
- Object
- Shoplo::Client
- Includes:
- API::Customer, API::Order, API::Product, API::Shop
- Defined in:
- lib/shoplo/client.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #connection=(new_connection) ⇒ Object
- #consumer ⇒ Object
- #get_content(type, params = {}) ⇒ Object
-
#initialize(access_token, token_secret) ⇒ Client
constructor
A new instance of Client.
Methods included from API::Shop
Methods included from API::Product
Methods included from API::Order
Methods included from API::Customer
Constructor Details
#initialize(access_token, token_secret) ⇒ Client
Returns a new instance of Client.
17 18 19 |
# File 'lib/shoplo/client.rb', line 17 def initialize(access_token, token_secret) @access_token, @token_secret = access_token, token_secret end |
Instance Method Details
#connection ⇒ Object
27 28 29 |
# File 'lib/shoplo/client.rb', line 27 def connection @connection ||= OAuth::AccessToken.new(consumer, @access_token, @token_secret) end |
#connection=(new_connection) ⇒ Object
31 32 33 |
# File 'lib/shoplo/client.rb', line 31 def connection=(new_connection) @connection = new_connection end |
#consumer ⇒ Object
21 22 23 24 25 |
# File 'lib/shoplo/client.rb', line 21 def consumer @consumer ||= OAuth::Consumer.new(Shoplo.api_key, Shoplo.secret, { site: 'http://api.shoplo.com/services' } ) end |
#get_content(type, params = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shoplo/client.rb', line 35 def get_content(type, params = {}) id = params.delete(:id).to_i id = '' if id <= 0 _uri = "/#{type}" _uri += "/#{id}" unless id.to_s.empty? _params = URI.encode_www_form(params) _uri += "?#{_params}" unless params.to_s.empty? response = connection.get(_uri) json = Oj.load(response.body, mode: :compat) raise HTTPUnauthorized.new(json['error_msg']) unless json['error'].nil? json.values.first end |