wegift-ruby-client 0.1.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78e0ef24b5481fd31e4bf96d82f486d48bae2d10
4
- data.tar.gz: e90efcb5f259200f4e0f52f556b21259d757b5b4
3
+ metadata.gz: 5fcd237e45bbafd74525b6521aeb8a9ff7df0645
4
+ data.tar.gz: 6064d9bb7825783312a0f48fb83b057aae0c0545
5
5
  SHA512:
6
- metadata.gz: 8031c492f87e7bbd660abd16111064c3494680cfdf74a4c1c0988a6a0c67807d94f11f3e21148c2be9f9f449ecadbe4378204f219de1e8806520bed96067e9eb
7
- data.tar.gz: 56e5eaf9f1fdbd766783f86af2953178217816d455af2a86fcf36045403834f70b43ec028510b0f9e88feab0095f2f586a6d2602154c4127710e5546a9e1ad3c
6
+ metadata.gz: 8b5d6db5ad8960ed3a39cd78352f4461066521b6932e872bae099a97752a8eab8da4de03ed6df442032854dce04685b112b02c587dc673705d160a613d19f9fd
7
+ data.tar.gz: eeb495aaa807a095f4c62cc7c928ae40d5db74e8c247c7b106703627019fd7a46e2941cc18abf393b828530441bb9cf633ce1065982c9b61c2410beed491615f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # WeGift Ruby Client
2
2
 
3
- A simple client for [WeGift.io][wegift] B2B Synchronous API (Document Version 1.2).
3
+ A simple client for [WeGift.io][wegift] B2B Synchronous API (Document Version 1.4).
4
4
 
5
5
  ## Installation
6
6
 
@@ -27,25 +27,25 @@ Simple example for ordering a Digital Card
27
27
  # a simple client
28
28
  client = Wegift::Client.new(
29
29
  :api_host => 'http://sandbox.wegift.io',
30
- :api_path => '/api/b2b-sync/v1/auth',
30
+ :api_path => '/api/b2b-sync/v1',
31
31
  :api_key => ENV['AUTH_NAME'],
32
32
  :api_secret => ENV['AUTH_PASS'],
33
33
  :proxy => ENV['PROXY']
34
34
  )
35
35
 
36
- # and a simple request
37
- order = Wegift::Order.new(
38
- :product_code => 'tTV',
36
+ # with all available products
37
+ products = client.products
38
+
39
+ # post a simple order
40
+ order = client.order(
41
+ :product_code => products.first.code,
39
42
  :delivery => 'direct',
40
43
  :amount => '42.00',
41
44
  :currency_code => 'USD',
42
45
  :external_ref => '123'
43
46
  )
44
47
 
45
- # executes the POST (TODO: shared/singleton client?)
46
- order.post(client)
47
-
48
- # and returns
48
+ # which returns
49
49
  if order.is_successful?
50
50
 
51
51
  # some nice data
@@ -56,8 +56,6 @@ if order.is_successful?
56
56
  end
57
57
  ```
58
58
 
59
- _See official docs for Product Codes (http://sandbox.wegift.io/product-codes)_
60
-
61
59
  ## Development
62
60
 
63
61
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -73,13 +71,14 @@ rspec
73
71
 
74
72
  It will load all tapes found in `spec/tapes`, we are using [VCR][vcr].
75
73
 
76
- Optional - If you want/need to remaster all the recordings, you will need a sandbox account.
74
+ To remaster all recordings, you will need a sandbox account.
77
75
  Add an `.env` file to your root:
78
76
 
79
77
  ```bash
80
78
  # .env
81
79
  AUTH_NAME='sandbox_username'
82
80
  AUTH_PASS='sandbox_password'
81
+ PROXY='proxy_uri'
83
82
  ```
84
83
 
85
84
  Start the VCR with `rspec` - this should add all Tapes to `spec/tapes`.
data/lib/wegift.rb CHANGED
@@ -1,5 +1,3 @@
1
- require_relative 'wegift/models/order'
2
-
3
1
  module Wegift
4
2
 
5
3
  end
data/lib/wegift/client.rb CHANGED
@@ -9,7 +9,7 @@ module Wegift
9
9
  # supported: basic-http-auth - see: http://sandbox.wegift.io
10
10
 
11
11
  def initialize(options = {})
12
- @api_host = options[:api_host] || 'http://sandbox.wegift.io'
12
+ @api_host = options[:api_host] || 'https://api-sandbox.wegift.io'
13
13
  @api_path = options[:api_path] || '/api/b2b-sync/v1'
14
14
  @api_key = options[:api_key].to_s
15
15
  @api_secret = options[:api_secret]
@@ -19,22 +19,44 @@ module Wegift
19
19
  c.adapter Faraday.default_adapter
20
20
  c.options[:proxy] = {
21
21
  :uri => URI(options[:proxy])
22
- } unless options[:proxy].blank?
22
+ } unless options[:proxy].nil?
23
23
  end
24
24
  end
25
25
 
26
- # KISS since we have only one call!
27
- def post(path, payload = {})
28
- @connection.post do |req|
26
+ def request(method, path, payload = {})
27
+ @connection.send(method) do |req|
29
28
  req.url [@api_path, path].join('')
30
29
  req.headers['Content-Type'] = 'application/json'
31
- req.body = payload.to_json
30
+ req.body = payload.to_json if method.to_sym.eql?(:post)
31
+ req.params = payload if method.to_sym.eql?(:get)
32
32
  end
33
33
  end
34
34
 
35
35
  # TODO: shared context/connection for all calls
36
36
  # keep client => https://github.com/lostisland/faraday#basic-use
37
37
 
38
+ # global methods
39
+
40
+ def products()
41
+ # initialize endpoint
42
+ products = Wegift::Products.new()
43
+
44
+ # get catalogue with context / current connection
45
+ products.get(self)
46
+
47
+ # TODO: shared error handling
48
+ end
49
+
50
+ def product(id = nil)
51
+ products = Wegift::Product.new(:product_code => id)
52
+ products.get(self)
53
+ end
54
+
55
+ def order(options)
56
+ order = Wegift::Order.new(options)
57
+ order.post(self)
58
+ end
59
+
38
60
  end
39
61
 
40
62
  end
@@ -0,0 +1,8 @@
1
+ module Initializable
2
+ def initialize(params = {})
3
+ params.each do |key, value|
4
+ setter = "#{key}="
5
+ send(setter, value) if respond_to?(setter.to_sym, false)
6
+ end
7
+ end
8
+ end
@@ -4,28 +4,32 @@ class Wegift::Order < Wegift::Response
4
4
 
5
5
  PATH = '/order-digital-card'
6
6
 
7
- DELIVERY_TYPE = {:direct => 'direct', :email => 'email'}
7
+ DELIVERY_METHODS = {:direct => 'direct', :email => 'email'}
8
+ DELIVERY_FORMATS = {:code => 'raw', :url => 'url-instant'}
8
9
 
9
10
  # request/payload
10
- attr_accessor :product_code, :delivery, :amount, :currency_code, :external_ref
11
+ attr_accessor :product_code, :currency_code, :amount, :delivery_method, :delivery_format,
12
+ :notification_email, :delivery_email, :external_ref
11
13
 
12
14
  # response/success
13
15
  attr_accessor :code, :expiry_date, :pin
14
16
 
15
- def initialize(options = {})
16
- @product_code = options[:product_code]
17
- @delivery = options[:delivery].eql?(DELIVERY_TYPE[:email]) ? options[:delivery] : DELIVERY_TYPE[:direct]
18
- @amount = options[:amount]
19
- @currency_code = options[:currency_code]
20
- @external_ref = options[:external_ref]
17
+ def initialize(params = {})
18
+ super(params)
19
+ # default/fallback: 'direct'/'raw'
20
+ @delivery_method = params[:delivery_method] || DELIVERY_METHODS[:direct]
21
+ @delivery_format = params[:delivery_format] || DELIVERY_FORMATS[:code]
21
22
  end
22
23
 
23
24
  def payload
24
25
  {
25
26
  :product_code => @product_code,
26
- :delivery => @delivery,
27
- :amount => @amount,
28
27
  :currency_code => @currency_code,
28
+ :amount => @amount,
29
+ :delivery_method => @delivery_method,
30
+ :delivery_format => delivery_format,
31
+ :notification_email => @notification_email,
32
+ :delivery_email => @delivery_email,
29
33
  :external_ref => @external_ref,
30
34
  }
31
35
  end
@@ -33,7 +37,7 @@ class Wegift::Order < Wegift::Response
33
37
  # Order Digital Card
34
38
  # POST /api/b2b-sync/v1/order-digital-card
35
39
  def post(ctx)
36
- response = ctx.post(PATH, self.payload)
40
+ response = ctx.request(:post, PATH, self.payload)
37
41
  self.parse(JSON.parse(response.body))
38
42
  end
39
43
 
@@ -0,0 +1,35 @@
1
+ require_relative 'response'
2
+
3
+ class Wegift::Product < Wegift::Response
4
+
5
+ PATH = '/products'
6
+
7
+ # request/payload
8
+ attr_accessor :product_code
9
+
10
+ # response/success
11
+ attr_accessor :code, :name, :description, :currency_code, :availability,
12
+ :denomination_type, :minimum_value, :maximum_value,
13
+ :card_image_url, :terms_and_conditions_url, :expiry_date_policy
14
+
15
+ def initialize(params = {})
16
+ super
17
+ end
18
+
19
+ def path
20
+ [PATH, @product_code.to_s].join('/')
21
+ end
22
+
23
+ # Product Details List
24
+ # GET /api/b2b-sync/v1/products/ID
25
+ def get(ctx)
26
+ response = ctx.request(:get, path)
27
+ self.parse(JSON.parse(response.body))
28
+ end
29
+
30
+ def parse(data)
31
+ super(data)
32
+ Wegift::Product.new(data)
33
+ end
34
+
35
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'response'
2
+
3
+ class Wegift::Products < Wegift::Response
4
+
5
+ PATH = '/products'
6
+
7
+ # Product Details List
8
+ # GET /api/b2b-sync/v1/products/
9
+ def get(ctx)
10
+ response = ctx.request(:get, PATH)
11
+ self.parse(JSON.parse(response.body))
12
+ end
13
+
14
+ def parse(data)
15
+ super(data)
16
+
17
+ # TODO separate?
18
+ if data['products']
19
+ data['products'].map{|p| Wegift::Product.new(p)}
20
+ end
21
+ end
22
+
23
+ end
@@ -1,4 +1,7 @@
1
+ require_relative 'initializable'
2
+
1
3
  class Wegift::Response
4
+ include Initializable
2
5
 
3
6
  STATUS = {:success => 'SUCCESS', :error => 'ERROR'}
4
7
 
@@ -1,3 +1,4 @@
1
1
  module Wegift
2
- VERSION = '0.1.1'
2
+ # api-version.lib-build
3
+ VERSION = '1.4.0'
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wegift-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaas Endrikat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-16 00:00:00.000000000 Z
11
+ date: 2017-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -173,7 +173,10 @@ files:
173
173
  - bin/setup
174
174
  - lib/wegift.rb
175
175
  - lib/wegift/client.rb
176
+ - lib/wegift/models/initializable.rb
176
177
  - lib/wegift/models/order.rb
178
+ - lib/wegift/models/product.rb
179
+ - lib/wegift/models/products.rb
177
180
  - lib/wegift/models/response.rb
178
181
  - lib/wegift/version.rb
179
182
  - wegift-ruby-client.gemspec