passworks 0.0.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 +7 -0
- data/.gitignore +22 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +4 -0
- data/README.md +319 -0
- data/Rakefile +2 -0
- data/lib/passworks.rb +49 -0
- data/lib/passworks/asset_resource.rb +11 -0
- data/lib/passworks/campaign_resource.rb +40 -0
- data/lib/passworks/client.rb +53 -0
- data/lib/passworks/collection_proxy.rb +46 -0
- data/lib/passworks/configuration.rb +58 -0
- data/lib/passworks/exception.rb +5 -0
- data/lib/passworks/exceptions/bad_gateway.rb +8 -0
- data/lib/passworks/exceptions/bad_request.rb +8 -0
- data/lib/passworks/exceptions/enhance_your_calm.rb +9 -0
- data/lib/passworks/exceptions/file_not_found.rb +8 -0
- data/lib/passworks/exceptions/forbidden.rb +8 -0
- data/lib/passworks/exceptions/gateway_timeout.rb +8 -0
- data/lib/passworks/exceptions/internal_server_error.rb +8 -0
- data/lib/passworks/exceptions/method_not_allowed.rb +8 -0
- data/lib/passworks/exceptions/not_found.rb +8 -0
- data/lib/passworks/exceptions/not_implemented.rb +8 -0
- data/lib/passworks/exceptions/payment_required.rb +8 -0
- data/lib/passworks/exceptions/precondition_failed.rb +8 -0
- data/lib/passworks/exceptions/service_unavailable.rb +8 -0
- data/lib/passworks/exceptions/unauthorized.rb +8 -0
- data/lib/passworks/exceptions/unprocessable_entity.rb +8 -0
- data/lib/passworks/faraday/http_exception_middleware.rb +73 -0
- data/lib/passworks/inflector.rb +38 -0
- data/lib/passworks/pass_resource.rb +40 -0
- data/lib/passworks/request.rb +49 -0
- data/lib/passworks/request_proxy.rb +115 -0
- data/lib/passworks/resource.rb +18 -0
- data/lib/passworks/response.rb +56 -0
- data/lib/passworks/version.rb +3 -0
- data/passworks.gemspec +34 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ba2d0f9da5b52d98c7e8d28467ba75e7d7984f1
|
4
|
+
data.tar.gz: 74f29a1668f6560cb74ab045a94d90c9eb756146
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5ddfe8be5badfd3462c239c88f27b9c0d99a2b68a8587f84e57ab455ba86e5bdf41335e5664ad983496d3ca2d27ab3b582674265f73c94315630a387e65703c
|
7
|
+
data.tar.gz: 8ced775e48072afb76a94f1f368b42e111e4498d4ac9d10fde61cac5c2496a8a13b1050859935e83ed9a0dff39f30fa2901ae3d1b03e57538b6b4304ac41a888
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,319 @@
|
|
1
|
+
# passworks-ruby [](https://codeclimate.com/github/passworks/passworks-ruby) [](https://travis-ci.org/passworks/passworks-ruby)
|
2
|
+
|
3
|
+
Ruby bindings for the Passworks API (http://api.passworks.io)
|
4
|
+
|
5
|
+
[API Documentation](https://github.com/passworks/passworks-api)
|
6
|
+
|
7
|
+
Passworks Ruby API client can be installed via rubygems [http://rubygems.org/gems/passworks](http://rubygems.org/gems/passworks).
|
8
|
+
|
9
|
+
|
10
|
+
## Instalation
|
11
|
+
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem install passworks
|
15
|
+
```
|
16
|
+
|
17
|
+
Using bundler
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'passworks'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Basic usage
|
24
|
+
|
25
|
+
### Configuring the client
|
26
|
+
|
27
|
+
|
28
|
+
The Passworks ruby client can be configured at class level or instance level.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# Class level configuration
|
32
|
+
Passworks.configure do |config|
|
33
|
+
config.api_username = "your api username"
|
34
|
+
config.api_secret = "your api secret"
|
35
|
+
end
|
36
|
+
|
37
|
+
client = Passworks.new
|
38
|
+
```
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# Instance level configuration
|
42
|
+
client = Passworks.new({
|
43
|
+
api_username: 'your api username',
|
44
|
+
api_secret: 'your api secret'
|
45
|
+
})
|
46
|
+
```
|
47
|
+
|
48
|
+
## Examples
|
49
|
+
|
50
|
+
### Assets
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
# Upload an asset (icon image)
|
54
|
+
asset_icon = client.assets.create({ file: '/path-to-file/icon-file.png', asset_type: 'icon' })
|
55
|
+
|
56
|
+
# Fetch and iterate through all your assets
|
57
|
+
assets = client.assets.all
|
58
|
+
assets.each do |asset|
|
59
|
+
puts asset
|
60
|
+
end
|
61
|
+
|
62
|
+
# Fetch a specific assets via uuid (uuid=c3d5fc64-3a43-4d3a-a167-473dfeb1edd3)
|
63
|
+
asset = client.assets.find('c3d5fc64-3a43-4d3a-a167-473dfeb1edd3')
|
64
|
+
|
65
|
+
# Delete asset without loading it first
|
66
|
+
client.assets.delete('c3d5fc64-3a43-4d3a-a167-473dfeb1edd3')
|
67
|
+
|
68
|
+
# delete the asset instance (loading first the asset)
|
69
|
+
asset.delete
|
70
|
+
```
|
71
|
+
|
72
|
+
### Coupons
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# Create a coupon campaign
|
76
|
+
coupon_campaign = client.coupons.create({
|
77
|
+
name: "my first coupon campaign",
|
78
|
+
icon_id: "c3d5fc64-3a43-4d3a-a167-473dfeb1edd3"
|
79
|
+
})
|
80
|
+
|
81
|
+
# Add a pass the the coupon campaign
|
82
|
+
# see [Coupon API documentation for details about the valid coupon fields
|
83
|
+
# https://github.com/passworks/passworks-api/blob/master/sections/coupon.md
|
84
|
+
coupon_pass = coupon_campaign.passes.create({
|
85
|
+
primary_fields: [
|
86
|
+
{
|
87
|
+
key: "key1",
|
88
|
+
label: "label1",
|
89
|
+
value: "value1"
|
90
|
+
}
|
91
|
+
]
|
92
|
+
})
|
93
|
+
|
94
|
+
# Fetch and print all passes from the `coupon_campaign` campaign
|
95
|
+
coupon_campaign.passes.all.each do |coupon_pass|
|
96
|
+
puts coupon_pass
|
97
|
+
end
|
98
|
+
|
99
|
+
# send push notification all users of a coupon campaign
|
100
|
+
coupon_campaign.push
|
101
|
+
|
102
|
+
# Send push notification to the users of a given passe of the `coupon_campaign`
|
103
|
+
coupon_campaign.passes.all.first.push
|
104
|
+
|
105
|
+
# Update coupon pass
|
106
|
+
# the `update` method returns the updated PassResource instance
|
107
|
+
coupon_pass = coupon_campaign.passes.all.first
|
108
|
+
updated_coupon_pass = coupon_pass.update({
|
109
|
+
primary_fields: [
|
110
|
+
{
|
111
|
+
key: "key2",
|
112
|
+
label: "label2",
|
113
|
+
value: "value2"
|
114
|
+
}
|
115
|
+
]
|
116
|
+
})
|
117
|
+
```
|
118
|
+
|
119
|
+
### Store Cards
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
# Create a store card campaign
|
123
|
+
coupon_campaign = client.store_cards.create({
|
124
|
+
name: "my first store card campaign",
|
125
|
+
icon_id: "c3d5fc64-3a43-4d3a-a167-473dfeb1edd3"
|
126
|
+
})
|
127
|
+
|
128
|
+
# Add a pass the the store card campaign
|
129
|
+
# see [Store Card API documentation for details about the valid store card fields
|
130
|
+
# https://github.com/passworks/passworks-api/blob/master/sections/store_card.md
|
131
|
+
store_card_pass = store_card_campaign.passes.create({
|
132
|
+
primary_fields: [
|
133
|
+
{
|
134
|
+
key: "key1",
|
135
|
+
label: "label1",
|
136
|
+
value: "value1"
|
137
|
+
}
|
138
|
+
]
|
139
|
+
})
|
140
|
+
|
141
|
+
# Fetch and print all passes from the `store_card_campaign` campaign
|
142
|
+
store_card_campaign.passes.all.each do |store_card_pass|
|
143
|
+
puts store_card_pass
|
144
|
+
end
|
145
|
+
|
146
|
+
# send push notification all users of a store card campaign
|
147
|
+
store_card_campaign.push
|
148
|
+
|
149
|
+
# Send push notification to the users of a given passe of the `store_card_campaign`
|
150
|
+
store_card_campaign.passes.all.first.push
|
151
|
+
|
152
|
+
# Update store card pass
|
153
|
+
# the `update` method returns the updated PassResource instance
|
154
|
+
store_card_pass = store_card_campaign.passes.all.first
|
155
|
+
updated_coupon_pass = store_card_pass.update({
|
156
|
+
primary_fields: [
|
157
|
+
{
|
158
|
+
key: "key2",
|
159
|
+
label: "label2",
|
160
|
+
value: "value2"
|
161
|
+
}
|
162
|
+
]
|
163
|
+
})
|
164
|
+
```
|
165
|
+
|
166
|
+
### Event Tickets
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
# Create a event ticket campaign
|
170
|
+
event_ticket_campaign = client.event_tickets.create({
|
171
|
+
name: "my first event ticket campaign",
|
172
|
+
icon_id: "c3d5fc64-3a43-4d3a-a167-473dfeb1edd3"
|
173
|
+
})
|
174
|
+
|
175
|
+
# Add a pass the the event ticket campaign
|
176
|
+
# see [Event Ticket API documentation for details about the valid event ticket fields
|
177
|
+
# https://github.com/passworks/passworks-api/blob/master/sections/event_ticket.md
|
178
|
+
event_ticket_campaign = event_ticket_campaign.passes.create({
|
179
|
+
primary_fields: [
|
180
|
+
{
|
181
|
+
key: "key1",
|
182
|
+
label: "label1",
|
183
|
+
value: "value1"
|
184
|
+
}
|
185
|
+
]
|
186
|
+
})
|
187
|
+
|
188
|
+
# Fetch and print all passes from the `event_ticket_campaign` campaign
|
189
|
+
event_ticket_campaign.passes.all.each do |event_ticket_pass|
|
190
|
+
puts event_ticket_pass
|
191
|
+
end
|
192
|
+
|
193
|
+
# send push notification all users of a store card campaign
|
194
|
+
event_ticket_campaign.push
|
195
|
+
|
196
|
+
# Send push notification to the users of a given passe of the `event_ticket_campaign`
|
197
|
+
event_ticket_campaign.passes.all.first.push
|
198
|
+
|
199
|
+
# Update event ticket pass
|
200
|
+
# the `update` method returns the updated PassResource instance
|
201
|
+
event_ticket_pass = event_ticket_campaign.passes.all.first
|
202
|
+
updated_event_ticket_pass = event_ticket_pass.update({
|
203
|
+
primary_fields: [
|
204
|
+
{
|
205
|
+
key: "key2",
|
206
|
+
label: "label2",
|
207
|
+
value: "value2"
|
208
|
+
}
|
209
|
+
]
|
210
|
+
})
|
211
|
+
```
|
212
|
+
|
213
|
+
### Bording Passes
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
# Create a boarding pass campaign
|
217
|
+
boarding_pass_campaign = client.boarding_passes.create({
|
218
|
+
name: "my first boarding pass campaign",
|
219
|
+
icon_id: "c3d5fc64-3a43-4d3a-a167-473dfeb1edd3",
|
220
|
+
transit_type: "air"
|
221
|
+
})
|
222
|
+
|
223
|
+
# Add a pass the the boarding pass campaign
|
224
|
+
# see [Boarding Pass API documentation for details about the valid boarding passe fields
|
225
|
+
# https://github.com/passworks/passworks-api/blob/master/sections/boarding_pass.md
|
226
|
+
boarding_pass_pass = boarding_pass_campaign.passes.create({
|
227
|
+
primary_fields: [
|
228
|
+
{
|
229
|
+
key: "key1",
|
230
|
+
label: "label1",
|
231
|
+
value: "value1"
|
232
|
+
}
|
233
|
+
]
|
234
|
+
})
|
235
|
+
|
236
|
+
# Fetch and print all passes from the `boarding_pass_campaign` campaign
|
237
|
+
boarding_pass_campaign.passes.all.each do |boarding_pass|
|
238
|
+
puts boarding_pass
|
239
|
+
end
|
240
|
+
|
241
|
+
# send push notification all users of a boarding pass campaign
|
242
|
+
boarding_pass_campaign.push
|
243
|
+
|
244
|
+
# Send push notification to the users of a given passe of the `boarding_pass_campaign`
|
245
|
+
boarding_pass_campaign.passes.all.first.push
|
246
|
+
|
247
|
+
# Update event ticket pass
|
248
|
+
# the `update` method returns the updated PassResource instance
|
249
|
+
boarding_pass_pass = boarding_pass_campaign.passes.all.first
|
250
|
+
updated_boarding_pass_pass = boarding_pass_pass.update({
|
251
|
+
primary_fields: [
|
252
|
+
{
|
253
|
+
key: "key2",
|
254
|
+
label: "label2",
|
255
|
+
value: "value2"
|
256
|
+
}
|
257
|
+
]
|
258
|
+
})
|
259
|
+
```
|
260
|
+
|
261
|
+
### Generic
|
262
|
+
|
263
|
+
```ruby
|
264
|
+
# Create a generic pass campaign
|
265
|
+
generic_campaign = client.boarding_passes.create({
|
266
|
+
name: "my first generic campaign",
|
267
|
+
icon_id: "c3d5fc64-3a43-4d3a-a167-473dfeb1edd3"
|
268
|
+
})
|
269
|
+
|
270
|
+
# Add a pass the the generic campaign
|
271
|
+
# see [Generic Pass API documentation for details about the valid generic passe fields
|
272
|
+
# https://github.com/passworks/passworks-api/blob/master/sections/generic.md
|
273
|
+
generic_pass = generic_campaign.passes.create({
|
274
|
+
primary_fields: [
|
275
|
+
{
|
276
|
+
key: "key1",
|
277
|
+
label: "label1",
|
278
|
+
value: "value1"
|
279
|
+
}
|
280
|
+
]
|
281
|
+
})
|
282
|
+
|
283
|
+
# Fetch and print all passes from the `generic_campaign` campaign
|
284
|
+
generic_campaign.passes.all.each do |generic_pass|
|
285
|
+
puts generic_pass
|
286
|
+
end
|
287
|
+
|
288
|
+
# send push notification all users of an generic pass campaign
|
289
|
+
generic_campaign.push
|
290
|
+
|
291
|
+
# Send push notification to the users of a given passe of the `generic_campaign`
|
292
|
+
generic_campaign.passes.all.first.push
|
293
|
+
|
294
|
+
# Update event ticket pass
|
295
|
+
# the `update` method returns the updated PassResource instance
|
296
|
+
generic_pass = generic_campaign.passes.all.first
|
297
|
+
updated_generic_pass = generic_pass.update({
|
298
|
+
primary_fields: [
|
299
|
+
{
|
300
|
+
key: "key2",
|
301
|
+
label: "label2",
|
302
|
+
value: "value2"
|
303
|
+
}
|
304
|
+
]
|
305
|
+
})
|
306
|
+
```
|
307
|
+
|
308
|
+
## Documentation
|
309
|
+
|
310
|
+
For more information about the API please please refere to [https://github.com/passworks/passworks-api](https://github.com/passworks/passworks-api)
|
311
|
+
|
312
|
+
For more examples about the Ruby client try browsing the [wiki](https://github.com/passworks/passworks-ruby/wiki)
|
313
|
+
|
314
|
+
|
315
|
+
## Help us make it better
|
316
|
+
|
317
|
+
Please tell us how we can make the Ruby client better. If you have a specific feature request or if you found a bug, please use GitHub issues. Fork these docs and send a pull request with improvements.
|
318
|
+
|
319
|
+
To talk with us and other developers about the API [open a support ticket](https://github.com/passworks/passworks-ruby/issues) or mail us at `api at passworks.io` if you need to talk to us.
|
data/Rakefile
ADDED
data/lib/passworks.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require 'passworks/version'
|
5
|
+
require 'passworks/configuration'
|
6
|
+
require 'passworks/exception'
|
7
|
+
require 'passworks/response'
|
8
|
+
require 'passworks/inflector'
|
9
|
+
require 'passworks/faraday/http_exception_middleware'
|
10
|
+
require 'passworks/request'
|
11
|
+
require 'passworks/request_proxy'
|
12
|
+
require 'passworks/client'
|
13
|
+
require 'passworks/collection_proxy'
|
14
|
+
require 'passworks/resource'
|
15
|
+
require 'passworks/campaign_resource'
|
16
|
+
require 'passworks/asset_resource'
|
17
|
+
require 'passworks/pass_resource'
|
18
|
+
|
19
|
+
# Passworks
|
20
|
+
|
21
|
+
module Passworks
|
22
|
+
extend Configuration
|
23
|
+
|
24
|
+
# Creates an instance of {Passworks::Client} to allow access to Passworks API
|
25
|
+
# @param [Hash] options
|
26
|
+
# @option options [String] :endpoint Defines the API end point (see {Passworks::Configuration::DEFAULT_ENDPOINT} for default endpoint)
|
27
|
+
# @option options [String] :api_username Your API username
|
28
|
+
# @option options [String] :api_secret Your API secret key
|
29
|
+
# @option options [Boolean] :debug Enables debug messages to STDOUT
|
30
|
+
#
|
31
|
+
# @return [Passworks::Client]
|
32
|
+
def self.new(options={})
|
33
|
+
merged_options = self.options.merge(options)
|
34
|
+
@client = Client.new(merged_options) unless defined?(@client) && @client.same_options?(merged_options)
|
35
|
+
@client
|
36
|
+
end
|
37
|
+
|
38
|
+
# @!visibility private
|
39
|
+
def self.respond_to?(method, include_all=false)
|
40
|
+
new.respond_to?(method, include_all) || super
|
41
|
+
end
|
42
|
+
|
43
|
+
# @!visibility private
|
44
|
+
def self.method_missing?(method, *args, &block)
|
45
|
+
return super unless new.respond_to?(method)
|
46
|
+
new.send(method, *args, &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'passworks/resource'
|
2
|
+
|
3
|
+
module Passworks
|
4
|
+
|
5
|
+
# Represents a Campaign of a given type: Coupon, Boarding Pass, Event Ticket, Generic, Store Card
|
6
|
+
#
|
7
|
+
class CampaignResource < Resource
|
8
|
+
|
9
|
+
# @return [RequestProxy]
|
10
|
+
def passes(options={})
|
11
|
+
Passworks::RequestProxy.new(client, collection_name, id, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Deletes the current Campaign
|
15
|
+
# @return [Boolean]
|
16
|
+
def delete
|
17
|
+
client.delete("#{collection_name}/#{id}").ok?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Send push notifications to all customers that have installed passes from this campaign
|
21
|
+
# @return [Boolean]
|
22
|
+
def push
|
23
|
+
client.post("#{collection_name}/#{id}/push").ok?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Updates the {CampaignResource} and returns the updated instance
|
27
|
+
# @return [CampaignResource] Updated instance
|
28
|
+
def update(data, params={})
|
29
|
+
content = {
|
30
|
+
body: {
|
31
|
+
single_name.to_sym => data
|
32
|
+
}.merge(params)
|
33
|
+
}
|
34
|
+
response = client.patch("#{collection_name}/#{id}", content)
|
35
|
+
self.class.new(client, collection_name, response.data)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|