Class: Whitehouse::Client

Inherits:
Object
  • Object
show all
Includes:
Authentication, Catalog, Order, Webhook, Configurable
Defined in:
lib/whitehouse/client.rb,
lib/whitehouse/client/order.rb,
lib/whitehouse/client/catalog.rb,
lib/whitehouse/client/webhook.rb

Overview

Client for the WHCC API

Defined Under Namespace

Modules: Catalog, Order, Webhook

Constant Summary

Constants included from Order

Order::BOUNDARY

Instance Attribute Summary

Attributes included from Configurable

#access_token, #api_endpoint, #connection_options, #consumer_key, #consumer_secret, #default_media_type, #user_agent

Instance Method Summary collapse

Methods included from Webhook

#create_webhook, #verify_webhook

Methods included from Order

#confirm_order, #submit_order

Methods included from Catalog

#request_catalog

Methods included from Configurable

#configure, keys, #reset!

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



23
24
25
26
27
# File 'lib/whitehouse/client.rb', line 23

def initialize(options = {})
  Whitehouse::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Whitehouse.instance_variable_get(:"@#{key}"))
  end
end

Instance Method Details

#connectionObject



29
30
31
# File 'lib/whitehouse/client.rb', line 29

def connection
  @connection || init_connection(:oauth2)
end

#get(*args) ⇒ Object



58
59
60
# File 'lib/whitehouse/client.rb', line 58

def get(*args)
  request :get, *args
end

#inspectString

Text representation of the client, masking tokens

Returns:

  • (String)


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/whitehouse/client.rb', line 44

def inspect
  inspected = super

  # Only show last 4 of token, secret
  if @access_token
    inspected = inspected.gsub! @access_token, "#{'*'*8}#{@access_token[8..-1]}"
  end
  if @consumer_secret
    inspected = inspected.gsub! @consumer_secret, "#{'*'*8}#{@consumer_secret[8..-1]}"
  end

  inspected
end

#post(*args) ⇒ Object



62
63
64
# File 'lib/whitehouse/client.rb', line 62

def post(*args)
  request :post, *args
end

#same_options?(opts) ⇒ Boolean

Compares client options to a Hash of requested options

Parameters:

  • opts (Hash)

    Options to compare with current client options

Returns:

  • (Boolean)


37
38
39
# File 'lib/whitehouse/client.rb', line 37

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