voucherify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +419 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/voucherify.rb +109 -0
- data/lib/voucherify/version.rb +3 -0
- data/voucherify.gemspec +29 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c55ee00e0d7f7eac4ddc7c1af5a22f5f86c8f123
|
4
|
+
data.tar.gz: 567e26d05a69d3f16f04168000192b3f7dc0e3a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1f68cce9487f59ea25600870dbcd345e5b1d1f544d1a437cf8b19cfa7431045df8c75458b158e1f11e167744e03319d5017c1128e3fdbce269d92e41c6dc257
|
7
|
+
data.tar.gz: e13b130625ed45c3ab0e8bb20f49ff694e7d12a634a9102604ee3f24b885a93774e303011f7c635b2828fb82d9c9768b6f18ada03c0f73c25e36d80908444a6f
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
Gemfile.lock
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 rspective P.Rychlik sp.j.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,419 @@
|
|
1
|
+
## Voucherify Ruby SDK
|
2
|
+
|
3
|
+
[Voucherify](http://voucherify.io?utm_source=inbound&utm_medium=github&utm_campaign=voucherify-ruby-sdk) has a new platform that will help your team automate voucher campaigns. It does this by providing composable API and the marketer-friendly interface that increases teams' productivity:
|
4
|
+
|
5
|
+
- **roll-out thousands** of vouchers **in minutes** instead of weeks,
|
6
|
+
- **check status** or disable **every single** promo code in real time,
|
7
|
+
- **track redemption** history and build reports on the fly.
|
8
|
+
|
9
|
+
Here you can find a library that makes it easier to integrate Voucherify with your Ruby server.
|
10
|
+
|
11
|
+
Full documentation is located at [voucherify.readme.io](https://voucherify.readme.io).
|
12
|
+
|
13
|
+
### Usage
|
14
|
+
|
15
|
+
#### Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'voucherify'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install voucherify
|
30
|
+
|
31
|
+
#### Authentication
|
32
|
+
|
33
|
+
[Log-in](http://app.voucherify.io/#/login) to Voucherify web interface and obtain your Application Keys from [Configuration](https://app.voucherify.io/#/app/configuration):
|
34
|
+
|
35
|
+
![](https://www.filepicker.io/api/file/WKYkl2bSAWKHccEN9tEG)
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require "voucherify"
|
39
|
+
|
40
|
+
voucherify = Voucherify.new({
|
41
|
+
"applicationId" => "YOUR-APPLICATION-ID-OBTAINED-FROM-CONFIGURATION",
|
42
|
+
"clientSecretKey" => "YOUR-CLIENT-SECRET-KEY-OBTAINED-FROM-CONFIGURATION"
|
43
|
+
})
|
44
|
+
```
|
45
|
+
|
46
|
+
#### Error handling
|
47
|
+
|
48
|
+
This voucherify gem uses [rest-client](https://github.com/rest-client/rest-client) under the hood for handling HTTP calls. In case of an HTTP 4xx or 5xx error, a RestClient exception is thrown. The server's specific response is available in `.response` of the exception object.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
begin
|
52
|
+
voucherify.publish("test")
|
53
|
+
rescue => e
|
54
|
+
JSON.parse(e.response)
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
```json
|
59
|
+
{
|
60
|
+
"code": 400,
|
61
|
+
"message": "Couldn't find any voucher suitable for publication."
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
Please refer to [rest-client documentation](https://github.com/rest-client/rest-client#exceptions-see-httpwwww3orgprotocolsrfc2616rfc2616-sec10html) for more detailed information.
|
66
|
+
|
67
|
+
#### Listing vouchers
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
voucherify.list({ limit: 10, skip: 20, category: "API Test" })
|
71
|
+
```
|
72
|
+
|
73
|
+
Result:
|
74
|
+
```json
|
75
|
+
[{
|
76
|
+
"code": "9mYBpIk",
|
77
|
+
"campaign": null,
|
78
|
+
"category": "API Test",
|
79
|
+
"discount": {
|
80
|
+
"type": "AMOUNT",
|
81
|
+
"amount_off": 400
|
82
|
+
},
|
83
|
+
"start_date": "2016-03-01T12:00:00Z",
|
84
|
+
"expiration_date": null,
|
85
|
+
"redemption": {
|
86
|
+
"quantity": 1,
|
87
|
+
"redeemed_quantity": 0,
|
88
|
+
"redemption_entries": []
|
89
|
+
},
|
90
|
+
"active": true,
|
91
|
+
"additional_info": null,
|
92
|
+
"metadata": null
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"code": "AzTsIH",
|
96
|
+
"campaign": null,
|
97
|
+
"category": "API Test",
|
98
|
+
"discount": {
|
99
|
+
"type": "AMOUNT",
|
100
|
+
"amount_off": 400
|
101
|
+
},
|
102
|
+
"start_date": "2016-03-01T10:00:00Z",
|
103
|
+
"expiration_date": null,
|
104
|
+
"redemption": {
|
105
|
+
"quantity": 1,
|
106
|
+
"redeemed_quantity": 0,
|
107
|
+
"redemption_entries": []
|
108
|
+
},
|
109
|
+
"active": true,
|
110
|
+
"additional_info": null,
|
111
|
+
"metadata": null
|
112
|
+
},
|
113
|
+
...
|
114
|
+
]
|
115
|
+
```
|
116
|
+
|
117
|
+
#### Getting voucher details
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
voucherify.get("v1GiJYuuS")
|
121
|
+
```
|
122
|
+
|
123
|
+
Result:
|
124
|
+
```json
|
125
|
+
{
|
126
|
+
"code": "v1GiJYuuS",
|
127
|
+
"campaign": "vip",
|
128
|
+
"discount": {
|
129
|
+
"percent_off": 10.0,
|
130
|
+
"type": "PERCENT"
|
131
|
+
},
|
132
|
+
"expiration_date": "2015-12-31T23:59:59Z",
|
133
|
+
"redemption": {
|
134
|
+
"quantity": 3,
|
135
|
+
"redeemed_quantity": 1,
|
136
|
+
"redemption_entries": [
|
137
|
+
{
|
138
|
+
"date": "2015-09-24T06:03:35Z",
|
139
|
+
"tracking_id": "GENERATED-OR-PROVIDED-TRACKING-ID"
|
140
|
+
}
|
141
|
+
]
|
142
|
+
},
|
143
|
+
"additional_info": ""
|
144
|
+
}
|
145
|
+
```
|
146
|
+
|
147
|
+
#### Getting voucher redemption
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
voucherify.redemption("v1GiJYuuS")
|
151
|
+
```
|
152
|
+
|
153
|
+
Result:
|
154
|
+
```json
|
155
|
+
{
|
156
|
+
"quantity": 3,
|
157
|
+
"redeemed_quantity": 1,
|
158
|
+
"redemption_entries": [
|
159
|
+
{
|
160
|
+
"date": "2015-09-24T06:03:35Z",
|
161
|
+
"tracking_id": "GENERATED-OR-PROVIDED-TRACKING-ID"
|
162
|
+
}
|
163
|
+
]
|
164
|
+
}
|
165
|
+
```
|
166
|
+
|
167
|
+
#### Publishing voucher
|
168
|
+
|
169
|
+
This method selects active, unpublished voucher from the specific campaign and returns it to client.
|
170
|
+
In effect, this voucher is marked as published and it will not be announced once again to customer.
|
171
|
+
|
172
|
+
Example:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
voucherify.publish("First Ride")
|
176
|
+
```
|
177
|
+
|
178
|
+
Positive result:
|
179
|
+
|
180
|
+
```json
|
181
|
+
{
|
182
|
+
"code": "FR-zT-u9I7zG",
|
183
|
+
"campaign": "First Ride",
|
184
|
+
"category": null,
|
185
|
+
"discount": {
|
186
|
+
"type": "PERCENT",
|
187
|
+
"amount_off": 50
|
188
|
+
},
|
189
|
+
"start_date": "2015-01-01T00:00:00Z",
|
190
|
+
"expiration_date": "2016-12-31T23:59:59Z",
|
191
|
+
"redemption": {
|
192
|
+
"quantity": 1,
|
193
|
+
"redeemed_quantity": 0,
|
194
|
+
"redemption_entries": []
|
195
|
+
},
|
196
|
+
"active": true,
|
197
|
+
"additional_info": null,
|
198
|
+
"metadata": {
|
199
|
+
"published": "2016-01-22T09:25:07Z"
|
200
|
+
}
|
201
|
+
}
|
202
|
+
```
|
203
|
+
|
204
|
+
Possible error:
|
205
|
+
|
206
|
+
```json
|
207
|
+
{
|
208
|
+
"code": 400,
|
209
|
+
"message": "Couldn't find any voucher suitable for publication."
|
210
|
+
}
|
211
|
+
```
|
212
|
+
|
213
|
+
#### Redeeming voucher
|
214
|
+
|
215
|
+
##### 1. Just by code
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
voucherify.redeem("v1GiJYuuS")
|
219
|
+
```
|
220
|
+
|
221
|
+
Result (voucher details after redemption):
|
222
|
+
|
223
|
+
```json
|
224
|
+
{
|
225
|
+
"code": "v1GiJYuuS",
|
226
|
+
"campaign": "vip",
|
227
|
+
"discount": {
|
228
|
+
"percent_off": 10.0,
|
229
|
+
"type": "PERCENT"
|
230
|
+
},
|
231
|
+
"expiration_date": "2015-12-31T23:59:59Z",
|
232
|
+
"redemption": {
|
233
|
+
"quantity": 3,
|
234
|
+
"redeemed_quantity": 2,
|
235
|
+
"redemption_entries": [
|
236
|
+
{
|
237
|
+
"date": "2015-09-24T06:03:35Z",
|
238
|
+
"tracking_id": "(tracking_id not set)"
|
239
|
+
},
|
240
|
+
{
|
241
|
+
"date": "2015-09-25T10:34:57Z",
|
242
|
+
"tracking_id": "(tracking_id not set)"
|
243
|
+
},
|
244
|
+
]
|
245
|
+
},
|
246
|
+
"additional_info": ""
|
247
|
+
}
|
248
|
+
```
|
249
|
+
|
250
|
+
Error:
|
251
|
+
```json
|
252
|
+
{
|
253
|
+
"code": 400,
|
254
|
+
"message": "voucher expired or quantity exceeded",
|
255
|
+
"details": "v1GiJYuuS"
|
256
|
+
}
|
257
|
+
```
|
258
|
+
|
259
|
+
##### 2. With tracking id
|
260
|
+
|
261
|
+
You can provide a tracking id (e.g. your customer's login or a generated id) to the voucher redemption request.
|
262
|
+
|
263
|
+
```ruby
|
264
|
+
voucherify.redeem("v1GiJYuuS", "alice.morgan")
|
265
|
+
```
|
266
|
+
|
267
|
+
Result:
|
268
|
+
```json
|
269
|
+
{
|
270
|
+
"code": "v1GiJYuuS",
|
271
|
+
"campaign": "vip",
|
272
|
+
"discount": {
|
273
|
+
"percent_off": 10.0,
|
274
|
+
"type": "PERCENT"
|
275
|
+
},
|
276
|
+
"expiration_date": "2015-12-31T23:59:59Z",
|
277
|
+
"redemption": {
|
278
|
+
"quantity": 3,
|
279
|
+
"redeemed_quantity": 3,
|
280
|
+
"redemption_entries": [
|
281
|
+
{
|
282
|
+
"date": "2015-09-24T06:03:35Z",
|
283
|
+
"tracking_id": "(tracking_id not set)"
|
284
|
+
},
|
285
|
+
{
|
286
|
+
"date": "2015-09-25T10:34:57Z",
|
287
|
+
"tracking_id": "(tracking_id not set)"
|
288
|
+
},
|
289
|
+
{
|
290
|
+
"date": "2015-09-25T12:04:08Z",
|
291
|
+
"tracking_id": "alice.morgan"
|
292
|
+
},
|
293
|
+
]
|
294
|
+
},
|
295
|
+
"additional_info": ""
|
296
|
+
}
|
297
|
+
```
|
298
|
+
|
299
|
+
##### 3. With customer profile
|
300
|
+
|
301
|
+
You can record a detailed customer profile consisting of an `id` (obligatory), `name`, `email`, `description` and a `metadata` section that can include any data you wish.
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
voucherify.redeem({
|
305
|
+
voucher: "v1GiJYuuS",
|
306
|
+
customer: {
|
307
|
+
id: "alice.morgan",
|
308
|
+
name: "Alice Morgan",
|
309
|
+
email: "alice@morgan.com",
|
310
|
+
description: "",
|
311
|
+
metadata: {
|
312
|
+
locale: "en-GB",
|
313
|
+
shoeSize: 5,
|
314
|
+
favourite_brands: ["Armani", "L’Autre Chose", "Voucherify"]
|
315
|
+
}
|
316
|
+
})
|
317
|
+
```
|
318
|
+
|
319
|
+
### Listing redemptions
|
320
|
+
|
321
|
+
Use `voucherify.redemptions(filter)` to get a filtered list of redemptions.
|
322
|
+
|
323
|
+
Example - 1000 successful redemptions from April 2016:
|
324
|
+
|
325
|
+
```ruby
|
326
|
+
filter = {
|
327
|
+
limit: 1000,
|
328
|
+
page: 0,
|
329
|
+
start_date: "2016-04-01T00:00:00",
|
330
|
+
end_date: "2016-04-30T23:59:59",
|
331
|
+
result: "Success"
|
332
|
+
}
|
333
|
+
|
334
|
+
voucherify.redemptions(filter)
|
335
|
+
```
|
336
|
+
|
337
|
+
#### Creating vouchers
|
338
|
+
|
339
|
+
Use `voucherify.create(code, options)` to create new vouchers.
|
340
|
+
|
341
|
+
```ruby
|
342
|
+
code = "EASTER-2016" # use given voucher code
|
343
|
+
code = nil # for an automatically generated string
|
344
|
+
|
345
|
+
# single-use voucher with 10% off discount that is valid throughout the whole 2016
|
346
|
+
opts = {
|
347
|
+
category: "New Customers",
|
348
|
+
discount: {
|
349
|
+
percent_off: 10.0,
|
350
|
+
type: "PERCENT"
|
351
|
+
},
|
352
|
+
start_date: "2016-01-01T00:00:00Z",
|
353
|
+
expiration_date: "2016-12-31T23:59:59Z",
|
354
|
+
redemption: {
|
355
|
+
quantity: 1
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
voucherify.create(code, opts)
|
360
|
+
```
|
361
|
+
|
362
|
+
Result (voucher details):
|
363
|
+
```json
|
364
|
+
{
|
365
|
+
"code": "9Yi5g",
|
366
|
+
"campaign": null,
|
367
|
+
"category": "New Customers",
|
368
|
+
"discount": {
|
369
|
+
"type": "PERCENT",
|
370
|
+
"percent_off": 10.0
|
371
|
+
},
|
372
|
+
"start_date": "2016-01-01T00:00:00Z",
|
373
|
+
"expiration_date": "2016-12-31T23:59:59Z",
|
374
|
+
"redemption": {
|
375
|
+
"quantity": 1,
|
376
|
+
"redeemed_quantity": 0,
|
377
|
+
"redemption_entries": []
|
378
|
+
},
|
379
|
+
"active": true,
|
380
|
+
"additional_info": null,
|
381
|
+
"metadata": null
|
382
|
+
}
|
383
|
+
```
|
384
|
+
|
385
|
+
### Disable a voucher
|
386
|
+
|
387
|
+
```ruby
|
388
|
+
voucherify.disable("EASTER-2016")
|
389
|
+
```
|
390
|
+
|
391
|
+
The response has empty body.
|
392
|
+
|
393
|
+
### Enable a voucher
|
394
|
+
|
395
|
+
```ruby
|
396
|
+
voucherify.enable("EASTER-2016")
|
397
|
+
```
|
398
|
+
|
399
|
+
The response has empty body.
|
400
|
+
|
401
|
+
## Development
|
402
|
+
|
403
|
+
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.
|
404
|
+
|
405
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
406
|
+
|
407
|
+
## Contributing
|
408
|
+
|
409
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rspective/voucherify-ruby-sdk.
|
410
|
+
|
411
|
+
## Changelog
|
412
|
+
- **2016-04-11** - `0.1.0` - First version:
|
413
|
+
- Authentication
|
414
|
+
- Voucher information: *retrieve voucher*, *list vouchers*, *retrieve redemptions*, *list redemptions*
|
415
|
+
- Voucher operations: *redeem voucher*, *publish voucher*, *create voucher*, *enable/disable voucher*
|
416
|
+
|
417
|
+
## License
|
418
|
+
|
419
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "voucherify"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start
|
data/bin/setup
ADDED
data/lib/voucherify.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require "voucherify/version"
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
4
|
+
require "rest-client"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
require "pry"
|
8
|
+
|
9
|
+
|
10
|
+
class Voucherify
|
11
|
+
def initialize(options)
|
12
|
+
@backend_url = "https://api.voucherify.io/v1"
|
13
|
+
@options = options
|
14
|
+
@headers = {
|
15
|
+
"X-App-Id" => @options["applicationId"],
|
16
|
+
"X-App-Token" => @options["clientSecretKey"],
|
17
|
+
"X-Voucherify-Channel" => "Ruby-SDK",
|
18
|
+
:accept => :json
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(code)
|
23
|
+
url = @backend_url + "/vouchers/" + URI.encode(code)
|
24
|
+
response = RestClient.get(url, @headers)
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
# List vouchers. Sample query: { limit: 100, skip: 200, category: "Loyalty" }
|
29
|
+
def list(query)
|
30
|
+
url = @backend_url + "/vouchers/"
|
31
|
+
response = RestClient.get(url, @headers.merge({ :params => query }))
|
32
|
+
JSON.parse(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def redemption(code)
|
36
|
+
url = @backend_url + "/vouchers/" + URI.encode(code) + "/redemption"
|
37
|
+
response = RestClient.get(url, @headers)
|
38
|
+
JSON.parse(response.body)
|
39
|
+
end
|
40
|
+
|
41
|
+
# List redemptions. Sample query (1000 successful redemptions from April 2016):
|
42
|
+
# {
|
43
|
+
# limit: 1000,
|
44
|
+
# page: 0,
|
45
|
+
# start_date: "2016-04-01T00:00:00",
|
46
|
+
# end_date: "2016-04-30T23:59:59",
|
47
|
+
# result: "Success"
|
48
|
+
# }
|
49
|
+
def redemptions(query)
|
50
|
+
url = @backend_url + "/redemptions/"
|
51
|
+
response = RestClient.get(url, @headers.merge({ :params => query }))
|
52
|
+
JSON.parse(response.body)
|
53
|
+
end
|
54
|
+
|
55
|
+
def redeem(code, tracking_id = nil)
|
56
|
+
payload = {}
|
57
|
+
|
58
|
+
if code.is_a? Hash
|
59
|
+
payload = code
|
60
|
+
code = payload["voucher"]
|
61
|
+
payload.delete "voucher"
|
62
|
+
end
|
63
|
+
|
64
|
+
url = @backend_url + "/vouchers/" + URI.encode(code) + "/redemption"
|
65
|
+
url += ("?tracking_id=" + URI.encode(tracking_id)) if tracking_id
|
66
|
+
|
67
|
+
response = RestClient.post(url, payload.to_json, @headers.merge({ :content_type => :json }))
|
68
|
+
JSON.parse(response.body)
|
69
|
+
end
|
70
|
+
|
71
|
+
def publish(campaign_name)
|
72
|
+
url = @backend_url + "/vouchers/publish?campaign=" + URI.encode(campaign_name)
|
73
|
+
response = RestClient.post(url, nil, @headers.merge({ :content_type => :json }))
|
74
|
+
JSON.parse(response.body)
|
75
|
+
end
|
76
|
+
|
77
|
+
# `code` is optional - will be generated if absent.
|
78
|
+
# Sample `options` object:
|
79
|
+
# {
|
80
|
+
# category: "New Customers",
|
81
|
+
# discount: {
|
82
|
+
# percent_off: 10.0,
|
83
|
+
# type: "PERCENT"
|
84
|
+
# },
|
85
|
+
# start_date: "2016-01-01T00:00:00Z",
|
86
|
+
# expiration_date: "2016-12-31T23:59:59Z",
|
87
|
+
# redemption: {
|
88
|
+
# quantity: 100
|
89
|
+
# }
|
90
|
+
# }
|
91
|
+
def create(code, options = {})
|
92
|
+
url = @backend_url + "/vouchers/"
|
93
|
+
url += URI.encode(code) if code
|
94
|
+
response = RestClient.post(url, options.to_json, @headers.merge({ :content_type => :json }))
|
95
|
+
JSON.parse(response.body)
|
96
|
+
end
|
97
|
+
|
98
|
+
def enable(code)
|
99
|
+
url = @backend_url + "/vouchers/" + URI.encode(code) + "/enable"
|
100
|
+
response = RestClient.post(url, nil, @headers.merge({ :content_type => :json }))
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
|
104
|
+
def disable(code)
|
105
|
+
url = @backend_url + "/vouchers/" + URI.encode(code) + "/disable"
|
106
|
+
response = RestClient.post(url, nil, @headers.merge({ :content_type => :json }))
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
end
|
data/voucherify.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'voucherify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "voucherify"
|
8
|
+
spec.version = Voucherify::VERSION
|
9
|
+
spec.authors = ["pawelrychlik"]
|
10
|
+
spec.email = ["pawel.rychlik@rspective.pl"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby SDK for Voucherify}
|
13
|
+
spec.homepage = "http://www.voucherify.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
25
|
+
|
26
|
+
spec.add_dependency "rest-client", "~> 1.8"
|
27
|
+
|
28
|
+
spec.required_ruby_version = '>= 1.9.3'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voucherify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pawelrychlik
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- pawel.rychlik@rspective.pl
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/voucherify.rb
|
98
|
+
- lib/voucherify/version.rb
|
99
|
+
- voucherify.gemspec
|
100
|
+
homepage: http://www.voucherify.io
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 1.9.3
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.0.14.1
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Ruby SDK for Voucherify
|
124
|
+
test_files: []
|