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.



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

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

Instance Method Details

#api_initiateObject



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

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



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

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



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

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



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

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

#orders_with_product_details(status:) ⇒ Object



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

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



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

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

#same_options?(opts) ⇒ Boolean

Returns:

  • (Boolean)


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

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