Class: Wegift::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wegift/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

supported: basic-http-auth - see: sandbox.wegift.io



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wegift/client.rb', line 11

def initialize(options = {})
  @api_host = options[:api_host] || 'https://api-sandbox.wegift.io'
  @api_path = options[:api_path] || '/api/b2b-sync/v1'
  @api_key = options[:api_key].to_s
  @api_secret = options[:api_secret]

  @connection = Faraday.new(:url => @api_host) do |c|
    c.basic_auth(@api_key, @api_secret)
    c.adapter Faraday.default_adapter
    c.options[:proxy] = {
        :uri => URI(options[:proxy])
    } unless options[:proxy].nil?
  end
end

Instance Attribute Details

#api_hostObject

Returns the value of attribute api_host.



7
8
9
# File 'lib/wegift/client.rb', line 7

def api_host
  @api_host
end

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/wegift/client.rb', line 7

def api_key
  @api_key
end

#api_pathObject

Returns the value of attribute api_path.



7
8
9
# File 'lib/wegift/client.rb', line 7

def api_path
  @api_path
end

#api_secretObject

Returns the value of attribute api_secret.



7
8
9
# File 'lib/wegift/client.rb', line 7

def api_secret
  @api_secret
end

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/wegift/client.rb', line 7

def connection
  @connection
end

Instance Method Details

#order(options) ⇒ Object



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

def order(options)
  order = Wegift::Order.new(options)
  order.post(self)
end

#product(id = nil) ⇒ Object



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

def product(id = nil)
  products = Wegift::Product.new(:product_code => id)
  products.get(self)
end

#productsObject

global methods



40
41
42
43
44
45
46
47
48
# File 'lib/wegift/client.rb', line 40

def products()
  # initialize endpoint
  products = Wegift::Products.new()

  # get catalogue with context / current connection
  products.get(self)

  # TODO: shared error handling
end

#request(method, path, payload = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/wegift/client.rb', line 26

def request(method, path, payload = {})
  @connection.send(method) do |req|
    req.url [@api_path, path].join('')
    req.headers['Content-Type'] = 'application/json'
    req.body = payload.to_json if method.to_sym.eql?(:post)
    req.params = payload if method.to_sym.eql?(:get)
  end
end