wegift-ruby-client 1.7.0 → 1.7.1

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: 7e26669ac746a053ceaff3ae76c09064e341e4fc
4
- data.tar.gz: 3bfffee3e75e004ca366c25a4d662b01d9c7129b
3
+ metadata.gz: 8c8d33e34dab238c5e59fb84f6653548713685a2
4
+ data.tar.gz: bb8cd55f5134c27bdde0e978803a711693ceb5b2
5
5
  SHA512:
6
- metadata.gz: b11bbfe7b91be3f83507a8ce7dd5b2b9a49d58b4042091f144e620b4df4bb69eedf33865e50390d8cdb754676e16082b13a14dfcfac01b0a80afd999be23cd0e
7
- data.tar.gz: 03ff16e2c0884a7d2b8cb6bfef2cd6084337ddd6570586928d6f3497614089617e70432e2b55dc3583936ac313905447d897c539aea81617b2cd3f61c5f46fe0
6
+ metadata.gz: e5409f5391c0f2f5a8443bcb85bc11364c94c465be26cb7ca9bf023d85fcfc46abd268c0cbad1d9480065909087378ff624426eb2c333b15efb1978653bad1c5
7
+ data.tar.gz: d46762f2f027ebdb10c6f982bc350c09f769af83ae6c2debde2abb9f80910f305cae652f55996b82cf6653a9f2547b05ba0314d8e0da9ebd90bcdd5297f5c1ec
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.7).
3
+ A simple client for [WeGift.io][wegift] B2B Synchronous API (Document Version 1.7).
4
4
 
5
5
  ## Installation
6
6
 
@@ -24,7 +24,7 @@ $ gem install wegift-ruby-client
24
24
 
25
25
  Simple example for ordering a Digital Card
26
26
  ```ruby
27
- # a simple client
27
+ # a simple client
28
28
  client = Wegift::Client.new(
29
29
  :api_host => 'http://sandbox.wegift.io',
30
30
  :api_path => '/api/b2b-sync/v1',
@@ -34,7 +34,15 @@ client = Wegift::Client.new(
34
34
  )
35
35
 
36
36
  # with all available products
37
- products = client.products
37
+ get_products = client.products
38
+
39
+ if get_products.is_successful?
40
+ # it provides a list of all vouchers
41
+ vouchers = products.all
42
+ else
43
+ # get_products.status => 403
44
+ # get_products.error_details => "Forbidden"
45
+ end
38
46
 
39
47
  # or just a single one
40
48
  product = client.products('PROD-ID')
@@ -51,7 +59,7 @@ order = client.order(
51
59
  :currency_code => 'USD',
52
60
  :amount => '42.00',
53
61
  :delivery_method => 'direct', # default
54
- :delivery_format => 'raw', # default
62
+ :delivery_format => 'raw', # default
55
63
  :external_ref => '123' # optional
56
64
  )
57
65
 
@@ -64,7 +72,7 @@ if order.is_successful?
64
72
  order.pin
65
73
  order.expiry_date
66
74
  order.delivery_url
67
-
75
+
68
76
  end
69
77
  ```
70
78
 
@@ -83,7 +91,7 @@ rspec
83
91
 
84
92
  It will load all tapes found in `spec/tapes`, we are using [VCR][vcr].
85
93
 
86
- To remaster all recordings, you will need a sandbox account.
94
+ To remaster all recordings, you will need a sandbox account.
87
95
  Add an `.env` file to your root:
88
96
 
89
97
  ```bash
@@ -105,4 +113,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/kendri
105
113
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
106
114
 
107
115
  [wegift]: http://WeGift.io
108
- [vcr]: https://github.com/vcr/vcr
116
+ [vcr]: https://github.com/vcr/vcr
@@ -43,13 +43,8 @@ module Wegift
43
43
  # global methods
44
44
 
45
45
  def products()
46
- # initialize endpoint
47
46
  products = Wegift::Products.new()
48
-
49
- # get catalogue with context / current connection
50
47
  products.get(self)
51
-
52
- # TODO: shared error handling
53
48
  end
54
49
 
55
50
  def product(id = nil)
@@ -36,11 +36,11 @@ class Wegift::Order < Wegift::Response
36
36
  # POST /api/b2b-sync/v1/order-digital-card
37
37
  def post(ctx)
38
38
  response = ctx.request(:post, PATH, self.payload)
39
- self.parse(JSON.parse(response.body))
39
+ self.parse(response)
40
40
  end
41
41
 
42
- def parse(data)
43
- super(data)
42
+ def parse(response)
43
+ super(response)
44
44
 
45
45
  # nested status/error object
46
46
  # assuming root "status" is always "SUCCESS" if "e_code" is set
@@ -58,23 +58,23 @@ class Wegift::Order < Wegift::Response
58
58
  #}
59
59
 
60
60
  # override root "status" if set
61
- if data['e_code'] && data['e_code']['status'].eql?(STATUS[:error])
62
- @status = data['e_code']['status']
63
- @error_code = data['e_code']['error_code'] unless data['e_code']['error_code'].blank?
64
- @error_string = data['e_code']['error_string'] unless data['e_code']['error_string'].blank?
65
- @error_details = data['e_code']['error_details'] unless data['e_code']['error_details'].blank?
61
+ if @payload['e_code'] && @payload['e_code']['status'].eql?(STATUS[:error])
62
+ @status = @payload['e_code']['status']
63
+ @error_code = @payload['e_code']['error_code'] unless @payload['e_code']['error_code'].blank?
64
+ @error_string = @payload['e_code']['error_string'] unless @payload['e_code']['error_string'].blank?
65
+ @error_details = @payload['e_code']['error_details'] unless @payload['e_code']['error_details'].blank?
66
66
  end
67
67
 
68
68
  # set valid data
69
- if data['e_code'] && data['e_code']['status'].eql?(STATUS[:success])
70
- @code = data['e_code']['code']
71
- @expiry_date = data['e_code']['expiry_date']
72
- @pin = data['e_code']['pin']
73
- @cvc2 = data['e_code']['cvc2']
74
- @delivery_url = data['e_code']['delivery_url']
69
+ if @payload['e_code'] && @payload['e_code']['status'].eql?(STATUS[:success])
70
+ @code = @payload['e_code']['code']
71
+ @expiry_date = @payload['e_code']['expiry_date']
72
+ @pin = @payload['e_code']['pin']
73
+ @cvc2 = @payload['e_code']['cvc2']
74
+ @delivery_url = @payload['e_code']['delivery_url']
75
75
  end
76
76
 
77
- @order_id = data['order_id']
77
+ @order_id = @payload['order_id']
78
78
 
79
79
  self
80
80
  end
@@ -27,12 +27,12 @@ class Wegift::Product < Wegift::Response
27
27
  # GET /api/b2b-sync/v1/products/ID
28
28
  def get(ctx)
29
29
  response = ctx.request(:get, path)
30
- self.parse(JSON.parse(response.body))
30
+ self.parse(response)
31
31
  end
32
32
 
33
- def parse(data)
34
- super(data)
35
- Wegift::Product.new(data)
33
+ def parse(response)
34
+ super(response)
35
+ Wegift::Product.new(@payload)
36
36
  end
37
37
 
38
38
  end
@@ -2,20 +2,28 @@ class Wegift::Products < Wegift::Response
2
2
 
3
3
  PATH = '/products'
4
4
 
5
+ attr_accessor :all
6
+
5
7
  # Product Details List
6
8
  # GET /api/b2b-sync/v1/products/
7
9
  def get(ctx)
8
10
  response = ctx.request(:get, PATH)
9
- self.parse(JSON.parse(response.body))
11
+ self.parse(response)
10
12
  end
11
13
 
12
- def parse(data)
13
- super(data)
14
+ def parse(response)
15
+ super(response)
14
16
 
15
- # TODO separate?
16
- if data['products']
17
- data['products'].map{|p| Wegift::Product.new(p)}
17
+ if self.is_successful?
18
+ # TODO separate?
19
+ if @payload['products']
20
+ @all = @payload['products'].map{|p| Wegift::Product.new(p)}
21
+ end
22
+ else
23
+ @all = []
18
24
  end
25
+
26
+ self
19
27
  end
20
28
 
21
29
  end
@@ -13,19 +13,29 @@ class Wegift::Response
13
13
  # error_details - Details of the particular error, i.e. Field "delivery" missing from request
14
14
 
15
15
  # global shared body
16
- attr_accessor :status, :error_code, :error_string, :error_details
16
+ attr_accessor :payload, :status, :error_code, :error_string, :error_details
17
17
 
18
18
  def is_successful?
19
19
  @status && @status.eql?(STATUS[:success])
20
20
  end
21
21
 
22
- def parse(data = {})
23
- @status = data['status']
24
- @error_code = data['error_code']
25
- @error_string = data['error_string']
26
- @error_details = data['error_details']
22
+ def parse(response = {})
23
+ # TODO: JSON responses, when requested?
24
+ # let's fix that with a simpel catch all
25
+ if response.success? && response['content-type'].eql?('application/json')
26
+ @payload = JSON.parse(response.body)
27
+ # TODO: @payload['status'] is only returned for orders! (products etc are plain objects)
28
+ @status = @payload['status'] || STATUS[:success]
29
+ @error_code = @payload['error_code']
30
+ @error_string = @payload['error_string']
31
+ @error_details = @payload['error_details']
32
+ else
33
+ @payload = {}
34
+ @status = STATUS[:error]
35
+ @error_code = response.status
36
+ @error_string = response.reason_phrase
37
+ @error_details = response.reason_phrase
38
+ end
27
39
  end
28
40
 
29
- # TODO
30
-
31
- end
41
+ end
@@ -1,4 +1,4 @@
1
1
  module Wegift
2
2
  # api-version.lib-build
3
- VERSION = '1.7.0'
3
+ VERSION = '1.7.1'
4
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: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaas Endrikat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-21 00:00:00.000000000 Z
11
+ date: 2018-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.5.1
203
+ rubygems_version: 2.6.11
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: A simple Ruby client for the WEGIFT API