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 +4 -4
- data/README.md +11 -12
- data/lib/wegift.rb +0 -2
- data/lib/wegift/client.rb +28 -6
- data/lib/wegift/models/initializable.rb +8 -0
- data/lib/wegift/models/order.rb +15 -11
- data/lib/wegift/models/product.rb +35 -0
- data/lib/wegift/models/products.rb +23 -0
- data/lib/wegift/models/response.rb +3 -0
- data/lib/wegift/version.rb +2 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fcd237e45bbafd74525b6521aeb8a9ff7df0645
|
4
|
+
data.tar.gz: 6064d9bb7825783312a0f48fb83b057aae0c0545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
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
|
-
#
|
37
|
-
|
38
|
-
|
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
|
-
#
|
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
|
-
|
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
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] || '
|
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].
|
22
|
+
} unless options[:proxy].nil?
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
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
|
data/lib/wegift/models/order.rb
CHANGED
@@ -4,28 +4,32 @@ class Wegift::Order < Wegift::Response
|
|
4
4
|
|
5
5
|
PATH = '/order-digital-card'
|
6
6
|
|
7
|
-
|
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, :
|
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(
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
@
|
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
|
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
|
data/lib/wegift/version.rb
CHANGED
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:
|
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-
|
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
|