voucherify 0.8.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/voucherify.rb CHANGED
@@ -1,181 +1,11 @@
1
- require "voucherify/version"
2
- require "net/http"
3
- require "uri"
4
- require "rest-client"
5
- require "json"
6
-
7
- class Voucherify
8
- def initialize(options)
9
- @backend_url = "https://api.voucherify.io/v1"
10
- @options = options
11
- @headers = {
12
- "X-App-Id" => @options["applicationId"],
13
- "X-App-Token" => @options["clientSecretKey"],
14
- "X-Voucherify-Channel" => "Ruby-SDK",
15
- :accept => :json
16
- }
17
- end
18
-
19
- def get(code)
20
- url = @backend_url + "/vouchers/" + URI.encode(code)
21
- response = RestClient.get(url, @headers)
22
- JSON.parse(response.body)
23
- end
24
-
25
- # List vouchers. Query parameters:
26
- # - code_query
27
- # - limit (default 10)
28
- # - skip (default 0)
29
- # - category
30
- # - campaign
31
- # - customer
32
- # Sample query: { limit: 100, skip: 200, category: "Loyalty" }
33
- def list(query)
34
- url = @backend_url + "/vouchers/"
35
- response = RestClient.get(url, @headers.merge({ :params => query }))
36
- JSON.parse(response.body)
37
- end
38
-
39
- def redemption(code)
40
- url = @backend_url + "/vouchers/" + URI.encode(code) + "/redemption"
41
- response = RestClient.get(url, @headers)
42
- JSON.parse(response.body)
43
- end
44
-
45
- # List redemptions. Sample query (1000 successful redemptions from April 2016):
46
- # {
47
- # limit: 1000,
48
- # page: 0,
49
- # start_date: "2016-04-01T00:00:00",
50
- # end_date: "2016-04-30T23:59:59",
51
- # result: "Success"
52
- # }
53
- def redemptions(query)
54
- url = @backend_url + "/redemptions/"
55
- response = RestClient.get(url, @headers.merge({ :params => query }))
56
- JSON.parse(response.body)
57
- end
58
-
59
- # Sample context:
60
- # {
61
- # tracking_id: "john@lemon.com",
62
- # customer: {
63
- # id: "cust_07sVjVsr71Ewot9lVZSrIVLH",
64
- # source_id: "john@lemon.com",
65
- # name: "John Lemon"
66
- # },
67
- # order: {
68
- # amount: 1000
69
- # }
70
- # }
71
- def validate(code, context = {})
72
- url = @backend_url + "/vouchers/" + URI.encode(code) + "/validate"
73
-
74
- response = RestClient.post(url, context.to_json, @headers.merge({ :content_type => :json }))
75
- JSON.parse(response.body)
76
- end
77
-
78
- def redeem(code, tracking_id = nil)
79
- payload = {}
80
-
81
- if code.is_a? Hash
82
- payload = code
83
- code = payload["voucher"] || payload[:voucher]
84
- payload.delete "voucher"
85
- payload.delete :voucher
86
- end
87
-
88
- url = @backend_url + "/vouchers/" + URI.encode(code) + "/redemption"
89
- url += ("?tracking_id=" + URI.encode(tracking_id)) if tracking_id
90
-
91
- response = RestClient.post(url, payload.to_json, @headers.merge({ :content_type => :json }))
92
- JSON.parse(response.body)
93
- end
94
-
95
- def publish(campaign_name)
96
- url = @backend_url + "/vouchers/publish"
97
- payload = {}
98
-
99
- if campaign_name.is_a? String
100
- url += "?campaign=" + URI.encode(campaign_name)
101
- elsif campaign_name.is_a? Hash
102
- payload = campaign_name
103
- end
104
-
105
- response = RestClient.post(url, payload.to_json, @headers.merge({ :content_type => :json }))
106
- JSON.parse(response.body)
107
- end
108
-
109
- # `code` is optional - will be generated if absent.
110
- # Sample `options` object:
111
- # {
112
- # category: "New Customers",
113
- # type: "DISCOUNT_VOUCHER",
114
- # discount: {
115
- # percent_off: 10.0,
116
- # type: "PERCENT"
117
- # },
118
- # start_date: "2016-01-01T00:00:00Z",
119
- # expiration_date: "2016-12-31T23:59:59Z",
120
- # redemption: {
121
- # quantity: 100
122
- # }
123
- # }
124
- def create(code, options = {})
125
- url = @backend_url + "/vouchers/"
126
- url += URI.encode(code) if code
127
- response = RestClient.post(url, options.to_json, @headers.merge({ :content_type => :json }))
128
- JSON.parse(response.body)
129
- end
130
-
131
- def update(voucher_update)
132
- url = @backend_url + "/vouchers/" + URI.encode(voucher_update["code"])
133
- response = RestClient.put(url, voucher_update.to_json, @headers.merge({ :content_type => :json }))
134
- JSON.parse(response.body)
135
- end
136
-
137
- def enable(code)
138
- url = @backend_url + "/vouchers/" + URI.encode(code) + "/enable"
139
- response = RestClient.post(url, nil, @headers.merge({ :content_type => :json }))
140
- nil
141
- end
142
-
143
- def disable(code)
144
- url = @backend_url + "/vouchers/" + URI.encode(code) + "/disable"
145
- response = RestClient.post(url, nil, @headers.merge({ :content_type => :json }))
146
- nil
147
- end
148
-
149
- def rollback(redemption_id, tracking_id=nil, reason=nil)
150
- url = @backend_url + "/redemptions/" + URI.encode(redemption_id) + "/rollback"
151
- if tracking_id || reason
152
- url += "?" + URI.encode_www_form(:tracking_id => tracking_id, :reason => reason)
153
- end
154
- response = RestClient.post(url, nil, @headers.merge({ :content_type => :json }))
155
- JSON.parse(response.body)
156
- end
157
-
158
- def create_customer(customer)
159
- url = @backend_url + "/customers/"
160
- response = RestClient.post(url, customer.to_json, @headers.merge({ :content_type => :json }))
161
- JSON.parse(response.body)
162
- end
163
-
164
- def get_customer(customer_id)
165
- url = @backend_url + "/customers/" + customer_id
166
- response = RestClient.get(url, @headers)
167
- JSON.parse(response.body)
168
- end
169
-
170
- def update_customer(customer)
171
- url = @backend_url + "/customers/" + (customer["id"] || customer[:id])
172
- response = RestClient.put(url, customer.to_json, @headers.merge({ :content_type => :json }))
173
- JSON.parse(response.body)
174
- end
175
-
176
- def delete_customer(customer_id)
177
- url = @backend_url + "/customers/" + customer_id
178
- response = RestClient.delete(url, @headers)
179
- nil
180
- end
181
- end
1
+ require 'voucherify/version'
2
+ require 'voucherify/client'
3
+ require 'voucherify/service/customers'
4
+ require 'voucherify/service/distributions'
5
+ require 'voucherify/service/redemptions'
6
+ require 'voucherify/service/validations'
7
+ require 'voucherify/service/vouchers'
8
+ require 'voucherify/utils'
9
+
10
+ module Voucherify
11
+ end
Binary file
data/voucherify.gemspec CHANGED
@@ -4,25 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'voucherify/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "voucherify"
7
+ spec.name = 'voucherify'
8
8
  spec.version = Voucherify::VERSION
9
- spec.authors = ["pawelrychlik"]
10
- spec.email = ["pawel.rychlik@rspective.pl"]
9
+ spec.authors = ['pawelrychlik']
10
+ spec.email = ['pawel.rychlik@rspective.pl']
11
11
 
12
12
  spec.summary = %q{Ruby SDK for Voucherify. More info on http://www.voucherify.io}
13
- spec.homepage = "https://github.com/rspective/voucherify-ruby-sdk/"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/rspective/voucherify-ruby-sdk/'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
17
+ spec.bindir = 'exe'
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
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"
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
24
 
25
- spec.add_dependency "rest-client", "~> 1.8"
25
+ spec.add_dependency 'rest-client', '~> 2.0'
26
26
 
27
27
  spec.required_ruby_version = '>= 1.9.3'
28
28
  end
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: 0.8.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawelrychlik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '1.8'
61
+ version: '2.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '1.8'
68
+ version: '2.0'
69
69
  description:
70
70
  email:
71
71
  - pawel.rychlik@rspective.pl
@@ -80,12 +80,19 @@ files:
80
80
  - Rakefile
81
81
  - bin/console
82
82
  - bin/setup
83
- - examples/customer.rb
83
+ - examples/customers.rb
84
84
  - examples/utils.rb
85
- - examples/validate.rb
85
+ - examples/vouchers.rb
86
86
  - lib/voucherify.rb
87
+ - lib/voucherify/client.rb
88
+ - lib/voucherify/service/customers.rb
89
+ - lib/voucherify/service/distributions.rb
90
+ - lib/voucherify/service/redemptions.rb
91
+ - lib/voucherify/service/validations.rb
92
+ - lib/voucherify/service/vouchers.rb
87
93
  - lib/voucherify/utils.rb
88
94
  - lib/voucherify/version.rb
95
+ - voucherify-ruby-sdk.png
89
96
  - voucherify.gemspec
90
97
  homepage: https://github.com/rspective/voucherify-ruby-sdk/
91
98
  licenses:
data/examples/customer.rb DELETED
@@ -1,29 +0,0 @@
1
- require 'voucherify'
2
-
3
- voucherify = Voucherify.new({
4
- "applicationId" => "c70a6f00-cf91-4756-9df5-47628850002b",
5
- "clientSecretKey" => "3266b9f8-e246-4f79-bdf0-833929b1380c"
6
- })
7
-
8
- new_customer = voucherify.create_customer({
9
- name: "John Doe",
10
- email: "john@email.com",
11
- description: "Sample description about customer",
12
- metadata: {
13
- lang: "en"
14
- }
15
- })
16
-
17
- print(new_customer)
18
-
19
- customer = voucherify.get_customer(new_customer["id"])
20
-
21
- print(customer)
22
-
23
- customer[:description] = "Sample description of customer with updates"
24
-
25
- updated_customer = voucherify.update_customer(customer)
26
-
27
- print(updated_customer)
28
-
29
- voucherify.delete_customer(updated_customer["id"])
data/examples/validate.rb DELETED
@@ -1,15 +0,0 @@
1
- require '../lib/voucherify'
2
-
3
- voucherify = Voucherify.new({
4
- "applicationId" => "c70a6f00-cf91-4756-9df5-47628850002b",
5
- "clientSecretKey" => "3266b9f8-e246-4f79-bdf0-833929b1380c"
6
- })
7
-
8
- validation_result = voucherify.validate("91Ft4U", {
9
- tracking_id: "john@lemon.com",
10
- order: {
11
- amount: 1000
12
- }
13
- })
14
-
15
- print(validation_result);