Class: Wegift::Client
- Inherits:
-
Object
- Object
- Wegift::Client
- Defined in:
- lib/wegift/client.rb
Instance Attribute Summary collapse
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_path ⇒ Object
Returns the value of attribute api_path.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
supported: basic-http-auth - see: playground.wegift.io.
- #order(options) ⇒ Object
- #product(id = nil) ⇒ Object
-
#products ⇒ Object
global methods.
- #request(method, path, payload = {}) ⇒ Object
- #stock(id) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
supported: basic-http-auth - see: playground.wegift.io
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wegift/client.rb', line 17 def initialize( = {}) @api_host = [:api_host] || 'https://playground.wegift.io' @api_path = [:api_path] || '/api/b2b-sync/v1' @api_key = [:api_key].to_s @api_secret = [:api_secret] @connection = Faraday.new(url: @api_host) do |c| c.basic_auth(@api_key, @api_secret) c.adapter Faraday.default_adapter unless [:proxy].nil? c.[:proxy] = { uri: URI([:proxy]) } end end end |
Instance Attribute Details
#api_host ⇒ Object
Returns the value of attribute api_host.
13 14 15 |
# File 'lib/wegift/client.rb', line 13 def api_host @api_host end |
#api_key ⇒ Object
Returns the value of attribute api_key.
13 14 15 |
# File 'lib/wegift/client.rb', line 13 def api_key @api_key end |
#api_path ⇒ Object
Returns the value of attribute api_path.
13 14 15 |
# File 'lib/wegift/client.rb', line 13 def api_path @api_path end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
13 14 15 |
# File 'lib/wegift/client.rb', line 13 def api_secret @api_secret end |
#connection ⇒ Object
Returns the value of attribute connection.
13 14 15 |
# File 'lib/wegift/client.rb', line 13 def connection @connection end |
Instance Method Details
#order(options) ⇒ Object
58 59 60 61 |
# File 'lib/wegift/client.rb', line 58 def order() order = Wegift::Order.new() order.post(self) end |
#product(id = nil) ⇒ Object
53 54 55 56 |
# File 'lib/wegift/client.rb', line 53 def product(id = nil) products = Wegift::Product.new(product_code: id) products.get(self) end |
#products ⇒ Object
global methods
48 49 50 51 |
# File 'lib/wegift/client.rb', line 48 def products products = Wegift::Products.new products.get(self) end |
#request(method, path, payload = {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/wegift/client.rb', line 34 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 |
#stock(id) ⇒ Object
63 64 65 66 |
# File 'lib/wegift/client.rb', line 63 def stock(id) stock = Wegift::Stock.new(product_code: id) stock.get(self) end |