voucherify 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -11
- data/examples/vouchers.rb +9 -4
- data/lib/voucherify/client.rb +47 -16
- data/lib/voucherify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93236863fb4ac7cae0378cb4c8287bf04686b651
|
4
|
+
data.tar.gz: 8819259dbfbaa0411336f5a7bcbeead247f67f49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bf377abdcd3bb07477ed748a179836fc5c5c4033ace42f9feb490fe9c8eba7572ee4fa8ae269d31ee291082a5ab3a40da95372c151a53c26473dcb122f45387
|
7
|
+
data.tar.gz: f43536f00e1f4eece69096286742742a7d51d251fe2067412907edc838dbecfcbb293b54fc4d6b6fdaf1fee9409294ebcb8fdb9e4d89ec2abbafda5e6ddd295d
|
data/README.md
CHANGED
@@ -344,24 +344,34 @@ with their namespaced equivalent.
|
|
344
344
|
|
345
345
|
## Error handling
|
346
346
|
|
347
|
-
|
347
|
+
When the Voucherify API responds with an error (HTTP status code is 4xx or 5xx) then the client raises a `VoucherifyError`.
|
348
|
+
It contains following properties:
|
349
|
+
- `code` - HTTP status code
|
350
|
+
- `message` - a human-readable message providing short description about the error.
|
351
|
+
- `details` - a human-readable message providing more details about the error, usually includes a hint on how to fix the error
|
352
|
+
- `key` - a short string describing the kind of error that occurred.
|
353
|
+
|
354
|
+
Example:
|
348
355
|
|
349
356
|
```ruby
|
350
357
|
begin
|
351
358
|
voucherify.distributions.publish('test')
|
352
|
-
rescue => e
|
353
|
-
|
359
|
+
rescue Voucherify::VoucherifyError => e
|
360
|
+
puts e.code
|
361
|
+
puts e.message
|
362
|
+
puts e.details
|
363
|
+
puts e.key
|
354
364
|
end
|
355
365
|
```
|
356
366
|
|
357
|
-
|
358
|
-
{
|
359
|
-
"code": 400,
|
360
|
-
"message": "Couldn't find any voucher suitable for publication."
|
361
|
-
}
|
362
|
-
```
|
367
|
+
The ouput may be:
|
363
368
|
|
364
|
-
|
369
|
+
```
|
370
|
+
400
|
371
|
+
Couldn't find any voucher suitable for publication.
|
372
|
+
Use auto-update campaigns if you want Voucherify to generate vouchers automatically.
|
373
|
+
no_voucher_suitable_for_publication
|
374
|
+
```
|
365
375
|
|
366
376
|
## Development
|
367
377
|
|
@@ -374,7 +384,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
374
384
|
Bug reports and pull requests are welcome on GitHub at https://github.com/rspective/voucherify-ruby-sdk.
|
375
385
|
|
376
386
|
## Changelog
|
377
|
-
- **
|
387
|
+
- **2017-03-22** - `1.3.0` - improved error handling
|
388
|
+
- **2017-01-04** - `1.2.0` - added [import vouchers](#import-vouchers) method.
|
378
389
|
- **2016-12-29** - `1.1.0` - introduced [campaigns api](#campaigns-api) and [products api](#products-api).
|
379
390
|
- **2016-12-15** - `1.0.0` - introduced namespaces, unified method names, updated README. Migration from versions 0.x required [migration from version 0.x](#migration-from-0x)
|
380
391
|
- **2016-12-02** - `0.8.2` - support gift vouchers in utils, fix price and discount calculations for amount discounts
|
@@ -406,6 +417,7 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
406
417
|
[List Vouchers]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-vouchers
|
407
418
|
[Enable Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#enable-voucher
|
408
419
|
[Disable Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#disable-voucher
|
420
|
+
[Import Vouchers]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#import-vouchers-1
|
409
421
|
|
410
422
|
[Create Campaign]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-campaign
|
411
423
|
[Get Campaign]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-campaign
|
@@ -436,3 +448,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
436
448
|
[Update SKU]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-sku
|
437
449
|
[Delete SKU]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-sku
|
438
450
|
[List all product SKUs]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-skus
|
451
|
+
|
data/examples/vouchers.rb
CHANGED
@@ -4,13 +4,18 @@ voucherify = Voucherify::Client.new({
|
|
4
4
|
:applicationId => 'c70a6f00-cf91-4756-9df5-47628850002b',
|
5
5
|
:clientSecretKey => '3266b9f8-e246-4f79-bdf0-833929b1380c'
|
6
6
|
})
|
7
|
-
|
8
|
-
puts voucherify.
|
7
|
+
begin
|
8
|
+
puts voucherify.validations.validate_voucher('91Ft4U', {
|
9
9
|
tracking_id: 'john@lemon.com',
|
10
10
|
order: {
|
11
|
-
|
11
|
+
amount: 1000
|
12
12
|
}
|
13
|
-
})
|
13
|
+
})
|
14
|
+
rescue Voucherify::VoucherifyError => e
|
15
|
+
puts e.message
|
16
|
+
puts e.details
|
17
|
+
puts e.key
|
18
|
+
end
|
14
19
|
|
15
20
|
query = {limit: 10, skip: 20, category: 'API Test'}
|
16
21
|
puts voucherify.vouchers.list(query)
|
data/lib/voucherify/client.rb
CHANGED
@@ -47,32 +47,63 @@ module Voucherify
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def get(path, params = {})
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
begin
|
51
|
+
url = @backend_url + path
|
52
|
+
response = RestClient.get(url, @headers.merge({:params => params}))
|
53
|
+
JSON.parse(response.body)
|
54
|
+
rescue RestClient::Exception => e
|
55
|
+
raise VoucherifyError.new(e)
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
59
|
def put(path, body, params = {})
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
begin
|
61
|
+
url = @backend_url + path
|
62
|
+
response = RestClient.put(url, body, @headers.merge({:params => params, :content_type => :json}))
|
63
|
+
JSON.parse(response.body)
|
64
|
+
rescue RestClient::Exception => e
|
65
|
+
raise VoucherifyError.new(e)
|
66
|
+
end
|
59
67
|
end
|
60
68
|
|
61
69
|
def post(path, body, params = {})
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
begin
|
71
|
+
url = @backend_url + path
|
72
|
+
response = RestClient.post(url, body, @headers.merge({:params => params, :content_type => :json}))
|
73
|
+
if !response.body.empty?
|
74
|
+
JSON.parse(response.body)
|
75
|
+
else
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
rescue RestClient::Exception => e
|
79
|
+
raise VoucherifyError.new(e)
|
68
80
|
end
|
69
|
-
|
70
81
|
end
|
71
82
|
|
72
83
|
def delete(path, params = {})
|
73
|
-
|
74
|
-
|
75
|
-
|
84
|
+
begin
|
85
|
+
url = @backend_url + path
|
86
|
+
RestClient.delete(url, @headers.merge({:params => params}))
|
87
|
+
nil
|
88
|
+
rescue RestClient::Exception => e
|
89
|
+
raise VoucherifyError.new(e)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class VoucherifyError < RuntimeError
|
95
|
+
attr_reader :response
|
96
|
+
attr_reader :code
|
97
|
+
attr_reader :details
|
98
|
+
attr_reader :key
|
99
|
+
|
100
|
+
def initialize (restClientError)
|
101
|
+
@response = restClientError.response
|
102
|
+
parsedResponse = JSON.parse(@response)
|
103
|
+
@code = parsedResponse['code']
|
104
|
+
@details = parsedResponse['details']
|
105
|
+
@key = parsedResponse['key']
|
106
|
+
super(parsedResponse['message'])
|
76
107
|
end
|
77
108
|
end
|
78
109
|
|
data/lib/voucherify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voucherify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawelrychlik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|