Class: Nuorder::Client

Inherits:
Object
  • Object
show all
Includes:
Oauth, Configurable
Defined in:
lib/nuorder/client.rb,
lib/nuorder/client/oauth.rb

Defined Under Namespace

Modules: Oauth

Constant Summary

Constants included from Oauth

Oauth::SIGNATURE_METHOD, Oauth::VERSION

Instance Method Summary collapse

Methods included from Oauth

#oauth_headers

Methods included from Configurable

#configure, keys, #options, #reset!

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



12
13
14
15
# File 'lib/nuorder/client.rb', line 12

def initialize(options = {})
  options = Nuorder::Default.options.merge(options)
  set_instance_variables(options)
end

Instance Method Details

#api_initiateObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/nuorder/client.rb', line 21

def api_initiate
  addons = { 'application_name' => @app_name, 'oauth_callback' => @oauth_callback }
  headers = oauth_headers('GET', '/api/initiate', addons)
  response = connection.get '/api/initiate', {}, headers

  @oauth_token = response.body['oauth_token']
  @oauth_token_secret = response.body['oauth_token_secret']

  response
end

#get(url, params: nil) ⇒ Object



44
45
46
47
48
# File 'lib/nuorder/client.rb', line 44

def get(url, params: nil)
  headers = oauth_headers('GET', url)
  response = connection.get url, params, headers
  validate_response(response)
end

#get_oauth_token(oauth_verifier) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nuorder/client.rb', line 32

def get_oauth_token(oauth_verifier)
  fail 'No oauth_verifier' unless oauth_verifier

  headers = oauth_headers('GET', '/api/token', { 'oauth_verifier' => oauth_verifier })
  response = connection.get '/api/token', {}, headers

  @oauth_token = response.body['oauth_token']
  @oauth_token_secret = response.body['oauth_token_secret']

  response
end

#orders(status:) ⇒ Object



50
51
52
# File 'lib/nuorder/client.rb', line 50

def orders(status:)
  get("/api/orders/#{status}/detail").body
end

#orders_with_product_details(status:) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/nuorder/client.rb', line 58

def orders_with_product_details(status:)
  orders = orders(status: status)
  orders.map! do |order|
    add_product_details!(line_items: order['line_items'])
    order
  end
end

#product(id:) ⇒ Object



54
55
56
# File 'lib/nuorder/client.rb', line 54

def product(id:)
  get("/api/product/#{id}").body
end

#same_options?(opts) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/nuorder/client.rb', line 17

def same_options?(opts)
  opts.hash == options.hash
end