class Wegift::Client

Attributes

api_host[RW]
api_key[RW]
api_path[RW]
api_secret[RW]
connection[RW]

Public Class Methods

new(options = {}) click to toggle source

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

# File lib/wegift/client.rb, line 16
def initialize(options = {})
  @api_host = options[:api_host] || 'https://playground.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
    unless options[:proxy].nil?
      c.options[:proxy] = {
        uri: URI(options[:proxy])
      }
    end
  end
end

Public Instance Methods

order(options) click to toggle source
# File lib/wegift/client.rb, line 57
def order(options)
  order = Wegift::Order.new(options)
  order.post(self)
end
product(id = nil) click to toggle source
# File lib/wegift/client.rb, line 52
def product(id = nil)
  products = Wegift::Product.new(product_code: id)
  products.get(self)
end
products() click to toggle source

global methods

# File lib/wegift/client.rb, line 47
def products
  products = Wegift::Products.new
  products.get(self)
end
request(method, path, payload = {}) click to toggle source
# File lib/wegift/client.rb, line 33
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