Class: Shoplo::Client

Inherits:
Object
  • Object
show all
Includes:
API::Customer, API::Order, API::Product, API::Shop
Defined in:
lib/shoplo/client.rb

Instance Method Summary collapse

Methods included from API::Shop

#get_shop

Methods included from API::Product

#get_products

Methods included from API::Order

#get_orders

Methods included from API::Customer

#get_customers

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

#connectionObject



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

#consumerObject



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

Raises:



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