Class: Vend::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logable
Defined in:
lib/vend/client.rb

Overview

Main access point which allows resources within the Vend gem to make HTTP requests to the Vend API.

Client must be initialized with:

* a store url (e.g. the storeurl portion of http://storeurl.vendhq.com/),
* a valid username and password

Direct Known Subclasses

Oauth2::Client

Constant Summary collapse

DEFAULT_OPTIONS =
{}

Instance Attribute Summary collapse

Attributes included from Logable

#logger

Instance Method Summary collapse

Constructor Details

#initialize(store, username, password, options = {}) ⇒ Client

:nodoc:



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

def initialize(store, username, password, options = {}) #:nodoc:
  @store = store
  @username = username
  @password = password
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/vend/client.rb', line 21

def options
  @options
end

#passwordObject

The store url for this client



20
21
22
# File 'lib/vend/client.rb', line 20

def password
  @password
end

#storeObject

The store url for this client



20
21
22
# File 'lib/vend/client.rb', line 20

def store
  @store
end

#usernameObject

The store url for this client



20
21
22
# File 'lib/vend/client.rb', line 20

def username
  @username
end

Instance Method Details

#base_urlObject

Returns the base API url for the client. E.g. for the store ‘foo’, it returns foo.vendhq.com/api/



68
69
70
# File 'lib/vend/client.rb', line 68

def base_url
  "https://#{@store}.vendhq.com/api/"
end

#CustomerObject

:nodoc:



38
39
40
# File 'lib/vend/client.rb', line 38

def Customer #:nodoc:
  Vend::BaseFactory.new(self, Resource::Customer)
end

#http_clientObject



72
73
74
# File 'lib/vend/client.rb', line 72

def http_client
  @http_client ||= HttpClient.new(http_client_options)
end

#http_client_optionsObject



76
77
78
79
80
# File 'lib/vend/client.rb', line 76

def http_client_options
  options.merge(
    base_url: base_url, username: username, password: password
  )
end

#OutletObject

:nodoc:



34
35
36
# File 'lib/vend/client.rb', line 34

def Outlet #:nodoc:
  Vend::BaseFactory.new(self, Resource::Outlet)
end

#PaymentTypeObject

:nodoc:



42
43
44
# File 'lib/vend/client.rb', line 42

def PaymentType #:nodoc:
  Vend::BaseFactory.new(self, Resource::PaymentType)
end

#ProductObject

:nodoc:



30
31
32
# File 'lib/vend/client.rb', line 30

def Product #:nodoc:
  Vend::BaseFactory.new(self, Resource::Product)
end

#RegisterObject

:nodoc:



46
47
48
# File 'lib/vend/client.rb', line 46

def Register #:nodoc:
  Vend::BaseFactory.new(self, Resource::Register)
end

#RegisterSaleObject

:nodoc:



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

def RegisterSale #:nodoc:
  Vend::BaseFactory.new(self, Resource::RegisterSale)
end

#SupplierObject

:nodoc:



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

def Supplier #:nodoc:
  Vend::BaseFactory.new(self, Resource::Supplier)
end

#TaxObject

:nodoc:



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

def Tax #:nodoc:
  Vend::BaseFactory.new(self, Resource::Tax)
end

#UserObject

:nodoc:



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

def User #:nodoc:
  Vend::BaseFactory.new(self, Resource::User)
end