live_paper 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +38 -0
- data/lib/live_paper/payoff.rb +5 -6
- data/lib/live_paper/version.rb +1 -1
- data/spec/live_paper/base_object_spec.rb +95 -107
- data/spec/live_paper/payoff_spec.rb +99 -95
- metadata +3 -5
- data/spec/live_paper_session_spec.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae8ade5ac1bf301f3f4ad667d85c8e56bd39feb1
|
4
|
+
data.tar.gz: 5b68905a2265416d44675488978834a62a6ce577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55789d46658c47bd8f0d5456c413657970078532345efb05299f253e6648eafbcc0a07b1e44f22c3e655e806fc69ff65e21b664195f253dfd2c0c896d68f5624
|
7
|
+
data.tar.gz: fbfbdf7bb295bcd07efaff8d919290b7110be3e0740df7d3726510d6febcdddb6768006a9bbeea3c3b95d7a600430aa68e04b0ae536869f1418b3c012ba89b67
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -142,6 +142,44 @@ You can list existing resources with the list operation.
|
|
142
142
|
t.download_watermark
|
143
143
|
```
|
144
144
|
|
145
|
+
Alternatively, you can upload an image from your local system by providing the path to the jpg file
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
image = Image.upload "/Users/mike/images/your_image.jpg"
|
149
|
+
```
|
150
|
+
|
151
|
+
### RichPayoff Example - Alternate for Watermarked or QR Code Payoff
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
rich_data = {
|
155
|
+
"type":"content action layout",
|
156
|
+
"version":1,
|
157
|
+
"data":{
|
158
|
+
"content":{
|
159
|
+
"type":"image",
|
160
|
+
"label":"Movember!",
|
161
|
+
"data":{"URL":"http://static.movember.com/uploads/2014/profiles/ef4/ef48a53fb031669fe86e741164d56972-546b9b5c56e15-hero.jpg"}
|
162
|
+
},
|
163
|
+
"actions":[
|
164
|
+
{
|
165
|
+
"type":"webpage",
|
166
|
+
"label":"Donate!",
|
167
|
+
"icon":{"id":"533"},
|
168
|
+
"data":{"URL":"http://MOBRO.CO/oamike"}
|
169
|
+
},
|
170
|
+
{
|
171
|
+
"type":"share",
|
172
|
+
"label":"Share!",
|
173
|
+
"icon":{"id":"527"},
|
174
|
+
"data":{"URL":"Help Mike get the prize of most donations on his team! MOBRO.CO/oamike"}
|
175
|
+
}
|
176
|
+
]
|
177
|
+
}
|
178
|
+
}
|
179
|
+
p=Payoff.create(name: 'name', type: Payoff::TYPE[:RICH], url: dest, data: rich_data)
|
180
|
+
l=Link.create(payoff_id: p.id, trigger_id: t.id, name: "link")
|
181
|
+
t.download_watermark
|
182
|
+
```
|
145
183
|
|
146
184
|
## Contributing
|
147
185
|
|
data/lib/live_paper/payoff.rb
CHANGED
@@ -2,7 +2,7 @@ require_relative 'base_object'
|
|
2
2
|
|
3
3
|
module LivePaper
|
4
4
|
class Payoff < BaseObject
|
5
|
-
attr_accessor :type, :url, :
|
5
|
+
attr_accessor :type, :url, :data
|
6
6
|
|
7
7
|
TYPE = {
|
8
8
|
WEB: 'WEB_PAYOFF',
|
@@ -30,16 +30,15 @@ module LivePaper
|
|
30
30
|
|
31
31
|
private
|
32
32
|
def validate_attributes!
|
33
|
-
raise ArgumentError, 'Required Attributes needed: name, type
|
34
|
-
raise ArgumentError, 'Required
|
33
|
+
raise ArgumentError, 'Required Attributes needed: name, type' unless all_present? [@name, @type]
|
34
|
+
raise ArgumentError, 'Required Attribute needed: url.' if @type == TYPE[:WEB] and !present? @url
|
35
|
+
raise ArgumentError, 'Required Attribute needed: data.' if @type == TYPE[:RICH] and !present? @data
|
35
36
|
end
|
36
37
|
|
37
38
|
def parse_richpayoff(data)
|
38
39
|
data = data[:richPayoff]
|
39
|
-
|
40
40
|
@type = TYPE[:RICH]
|
41
41
|
@url = data[:public][:url]
|
42
|
-
@data_type = data[:private][:'content-type']
|
43
42
|
@data = JSON.parse(Base64.decode64(data[:private][:data]), symbolize_names: true) rescue nil
|
44
43
|
end
|
45
44
|
|
@@ -78,7 +77,7 @@ module LivePaper
|
|
78
77
|
richPayoff: {
|
79
78
|
version: 1,
|
80
79
|
private: {
|
81
|
-
:'content-type' =>
|
80
|
+
:'content-type' => 'custom-base64',
|
82
81
|
:data => Base64.encode64(@data.to_json)
|
83
82
|
},
|
84
83
|
public: {url: @url}
|
data/lib/live_paper/version.rb
CHANGED
@@ -3,123 +3,121 @@ require 'json'
|
|
3
3
|
|
4
4
|
def stub_unimplemented_methods
|
5
5
|
allow_any_instance_of(LivePaper::BaseObject).to receive(:validate_attributes!)
|
6
|
-
allow_any_instance_of(LivePaper::BaseObject).to receive(:create_body).and_return(
|
6
|
+
allow_any_instance_of(LivePaper::BaseObject).to receive(:create_body).and_return(data)
|
7
7
|
allow_any_instance_of(LivePaper::BaseObject).to receive(:parse) { |data| data }
|
8
|
-
allow(LivePaper::BaseObject).to receive(:api_url).and_return(
|
8
|
+
allow(LivePaper::BaseObject).to receive(:api_url).and_return(api_url)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe LivePaper::BaseObject do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
stub_request(:post, @api_url).to_return(:body => lpp_richpayoff_response_json, :status => 200)
|
16
|
-
|
17
|
-
@data = {
|
12
|
+
let(:api_url) { "#{LivePaper::LP_API_HOST}/v99/objects" }
|
13
|
+
let(:data) {
|
14
|
+
{
|
18
15
|
name: 'name',
|
19
16
|
date_created: 'date_created',
|
20
17
|
date_modified: 'date_modified'
|
21
18
|
}
|
19
|
+
}
|
20
|
+
let(:object) { LivePaper::BaseObject.new data }
|
22
21
|
|
22
|
+
before do
|
23
|
+
stub_request(:post, /.*livepaperapi.com\/auth\/token.*/).to_return(:body => lpp_auth_response_json, :status => 200)
|
24
|
+
stub_request(:post, api_url).to_return(:body => lpp_richpayoff_response_json, :status => 200)
|
23
25
|
end
|
24
26
|
|
25
27
|
describe '#initialize' do
|
26
|
-
|
27
|
-
|
28
|
+
let(:data) {
|
29
|
+
{
|
28
30
|
id: 'id',
|
29
31
|
name: 'name',
|
30
32
|
date_created: 'date_created',
|
31
33
|
date_modified: 'date_modified'
|
32
34
|
}
|
33
|
-
|
34
|
-
end
|
35
|
+
}
|
35
36
|
|
36
37
|
it 'should map the id attribute.' do
|
37
|
-
expect(
|
38
|
+
expect(object.id).to eq data[:id]
|
38
39
|
end
|
39
40
|
|
40
41
|
it 'should map the name attribute.' do
|
41
|
-
expect(
|
42
|
+
expect(object.name).to eq data[:name]
|
42
43
|
end
|
43
44
|
|
44
45
|
it 'should map the date_created attribute.' do
|
45
|
-
expect(
|
46
|
+
expect(object.date_created).to eq data[:date_created]
|
46
47
|
end
|
47
48
|
|
48
49
|
it 'should map the date_modified attribute.' do
|
49
|
-
expect(
|
50
|
+
expect(object.date_modified).to eq data[:date_modified]
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
54
|
describe '#save' do
|
54
55
|
before do
|
55
56
|
stub_unimplemented_methods
|
56
|
-
@data = {
|
57
|
-
name: 'name',
|
58
|
-
date_created: 'date_created',
|
59
|
-
date_modified: 'date_modified'
|
60
|
-
}
|
61
|
-
@obj = LivePaper::BaseObject.new @data
|
62
57
|
end
|
63
58
|
|
64
59
|
it 'should not make a POST if the object has already an id.' do
|
65
|
-
|
66
|
-
|
67
|
-
assert_not_requested :post,
|
60
|
+
object.id = 'id'
|
61
|
+
object.save
|
62
|
+
assert_not_requested :post, api_url
|
68
63
|
end
|
69
64
|
|
70
65
|
it 'should re-assign the current object attributes.' do
|
71
|
-
|
72
|
-
expect(
|
73
|
-
expect(
|
74
|
-
expect(
|
66
|
+
object.save
|
67
|
+
expect(object.name).to eq data[:name]
|
68
|
+
expect(object.date_created).to eq data[:date_created]
|
69
|
+
expect(object.date_modified).to eq data[:date_modified]
|
75
70
|
end
|
76
71
|
|
77
72
|
it 'should return the object instance.' do
|
78
|
-
obj =
|
79
|
-
expect(obj).to eq
|
73
|
+
obj = object.save
|
74
|
+
expect(obj).to eq object
|
80
75
|
end
|
81
76
|
|
82
77
|
it 'should make a POST to the api_url with the body provided.' do
|
83
|
-
|
84
|
-
assert_requested :post,
|
78
|
+
object.save
|
79
|
+
assert_requested :post, api_url, :body => data.to_json
|
85
80
|
end
|
86
81
|
end
|
87
82
|
|
88
83
|
describe '.create' do
|
84
|
+
let(:object) { LivePaper::BaseObject.create data }
|
89
85
|
before do
|
90
86
|
stub_unimplemented_methods
|
91
|
-
@obj = LivePaper::BaseObject.create @data
|
92
87
|
end
|
93
88
|
|
94
89
|
it 'should return a object instance.' do
|
95
|
-
expect(
|
90
|
+
expect(object.class).to eq LivePaper::BaseObject
|
96
91
|
end
|
97
92
|
|
98
93
|
it 'should return the object instance with the provided + updated data.' do
|
99
|
-
expect(
|
100
|
-
expect(
|
101
|
-
expect(
|
94
|
+
expect(object.name).to eq data[:name]
|
95
|
+
expect(object.date_created).to eq data[:date_created]
|
96
|
+
expect(object.date_modified).to eq data[:date_modified]
|
102
97
|
end
|
103
98
|
end
|
104
99
|
|
105
100
|
describe '.list' do
|
101
|
+
let(:data) {
|
102
|
+
{lists: [{id: 1, name: 'first'},
|
103
|
+
{id: 2, name: 'second'},
|
104
|
+
{id: 3, name: 'third'}
|
105
|
+
]}
|
106
|
+
}
|
106
107
|
before do
|
107
|
-
allow(LivePaper::BaseObject).to receive(:api_url).and_return(
|
108
|
+
allow(LivePaper::BaseObject).to receive(:api_url).and_return(api_url)
|
108
109
|
allow(LivePaper::BaseObject).to receive(:list_key).and_return(:lists)
|
109
110
|
allow(LivePaper::BaseObject).to receive(:item_key).and_return(:list)
|
110
|
-
|
111
|
-
{id: 2, name: 'second'},
|
112
|
-
{id: 3, name: 'third'}
|
113
|
-
]}
|
114
|
-
stub_request(:get, "#{@api_url}").to_return(:body => @data.to_json, :status => 200)
|
111
|
+
stub_request(:get, "#{api_url}").to_return(:body => data.to_json, :status => 200)
|
115
112
|
end
|
113
|
+
|
116
114
|
it 'should return array of parsed objects' do
|
117
|
-
allow(
|
118
|
-
|
115
|
+
allow(data).to receive(:body).and_return(data)
|
116
|
+
data[:lists].each do |datum|
|
119
117
|
expect(LivePaper::BaseObject).to receive(:parse).with({:list => datum}.to_json) { datum[:id] }
|
120
118
|
end
|
121
119
|
result = LivePaper::BaseObject.list
|
122
|
-
expect(result.count).to eq
|
120
|
+
expect(result.count).to eq data[:lists].size
|
123
121
|
result.each_with_index do |res, i|
|
124
122
|
expect(res).to eq i+1
|
125
123
|
end
|
@@ -128,15 +126,15 @@ describe LivePaper::BaseObject do
|
|
128
126
|
|
129
127
|
describe '.get' do
|
130
128
|
before do
|
131
|
-
allow(LivePaper::BaseObject).to receive(:api_url).and_return(
|
132
|
-
@
|
133
|
-
stub_request(:get, "#{
|
134
|
-
stub_request(:get, "#{
|
129
|
+
allow(LivePaper::BaseObject).to receive(:api_url).and_return(api_url)
|
130
|
+
@body = '"id": "id", "name": "name"'
|
131
|
+
stub_request(:get, "#{api_url}/base_object").to_return(:body => @body, :status => 200)
|
132
|
+
stub_request(:get, "#{api_url}/base_object_not_existent").to_return(:body => '{}', :status => 404)
|
135
133
|
end
|
136
134
|
context 'the requested base_object exists.' do
|
137
135
|
it 'should return the requested base object.' do
|
138
|
-
allow(@
|
139
|
-
expect(LivePaper::BaseObject).to receive(:parse).with(@
|
136
|
+
allow(@body).to receive(:body).and_return(@body)
|
137
|
+
expect(LivePaper::BaseObject).to receive(:parse).with(@body)
|
140
138
|
LivePaper::BaseObject.get('base_object')
|
141
139
|
end
|
142
140
|
end
|
@@ -155,10 +153,10 @@ describe LivePaper::BaseObject do
|
|
155
153
|
describe '.update' do
|
156
154
|
let(:obj_id) { 12345 }
|
157
155
|
let(:update_json) { {name: 'new_name'}.to_json }
|
158
|
-
let (:
|
159
|
-
|
160
|
-
|
161
|
-
|
156
|
+
let (:data) { {name: 'name',
|
157
|
+
id: obj_id,
|
158
|
+
date_created: 'date_created',
|
159
|
+
date_modified: 'date_modified'} }
|
162
160
|
let(:resp_body) {}
|
163
161
|
|
164
162
|
before do
|
@@ -173,72 +171,59 @@ describe LivePaper::BaseObject do
|
|
173
171
|
date_modified: 'new_date_modified'}} }
|
174
172
|
let(:new_name) { 'my_valid_name_change' }
|
175
173
|
before do
|
176
|
-
|
177
|
-
stub_request(:put, "#{@api_url}/#{obj_id}").to_return(:body => resp_body.to_json, :status => 200)
|
178
|
-
@obj=LivePaper::BaseObject.new data1
|
179
|
-
@obj.name = new_name
|
174
|
+
stub_request(:put, "#{api_url}/#{obj_id}").to_return(:body => resp_body.to_json, :status => 200)
|
180
175
|
end
|
181
176
|
it 'should return success' do
|
182
|
-
|
183
|
-
|
177
|
+
object.name = new_name
|
178
|
+
ret_val = object.update
|
179
|
+
assert_requested :put, "#{api_url}/#{obj_id}"
|
184
180
|
expect(ret_val).to eq '200 OK'
|
185
181
|
end
|
186
|
-
xit 'should reflect the updated object' do
|
187
|
-
allow(@response).to receive(:body).and_return(@response[:object])
|
188
|
-
allow(@obj).to receive(:parse) { |data| data }
|
189
|
-
@obj.update
|
190
|
-
assert_requested :put, "#{@api_url}/#{obj_id}"
|
191
|
-
expect(@obj).to receive(:parse).with(resp_body)
|
192
|
-
|
193
|
-
expect(@obj.name).to eq new_name
|
194
|
-
expect(@obj.date_modified).to eq 'new_date_modified'
|
195
|
-
end
|
196
|
-
|
197
182
|
end
|
198
183
|
|
199
184
|
context 'with invalid data' do
|
200
185
|
before do
|
201
|
-
stub_request(:put, "#{
|
202
|
-
|
203
|
-
@obj.name = 'my_new_name'
|
186
|
+
stub_request(:put, "#{api_url}/#{obj_id}").to_return(:body => resp_body, :status => 400)
|
187
|
+
object.name = 'my_new_name'
|
204
188
|
end
|
189
|
+
|
205
190
|
it 'should return the error details' do
|
206
|
-
ret_val =
|
207
|
-
assert_requested :put, "#{
|
191
|
+
ret_val = object.update
|
192
|
+
assert_requested :put, "#{api_url}/#{obj_id}"
|
208
193
|
expect(ret_val).to eq 'Bad Request'
|
209
194
|
end
|
210
195
|
it 'should preserve the invalid object attributes' do
|
211
|
-
|
212
|
-
assert_requested :put, "#{
|
213
|
-
expect(
|
196
|
+
object.update
|
197
|
+
assert_requested :put, "#{api_url}/#{obj_id}"
|
198
|
+
expect(object.name).to eq 'my_new_name'
|
214
199
|
end
|
215
200
|
end
|
216
201
|
|
217
202
|
context 'remote object has been deleted' do
|
218
203
|
before do
|
219
|
-
stub_request(:put, "#{
|
204
|
+
stub_request(:put, "#{api_url}/#{obj_id}").to_return(:body => resp_body, :status => 404)
|
220
205
|
end
|
206
|
+
|
221
207
|
it 'should return an error' do
|
222
|
-
|
223
|
-
|
224
|
-
assert_requested :put, "#{@api_url}/#{obj_id}"
|
208
|
+
ret_val = object.update
|
209
|
+
assert_requested :put, "#{api_url}/#{obj_id}"
|
225
210
|
expect(ret_val).to eq 'Object Invalid'
|
226
211
|
end
|
227
212
|
end
|
228
213
|
|
229
214
|
context 'remote object was never saved.' do
|
215
|
+
let(:obj_id) { nil }
|
230
216
|
it 'should return an error' do
|
231
|
-
|
232
|
-
ret_val =
|
217
|
+
obj = LivePaper::BaseObject.new data
|
218
|
+
ret_val = obj.update
|
233
219
|
expect(ret_val).to eq 'Object Invalid'
|
234
220
|
end
|
235
221
|
end
|
236
222
|
end
|
237
223
|
|
238
224
|
describe '.delete' do
|
239
|
-
|
240
|
-
|
241
|
-
@data = {
|
225
|
+
let(:data) {
|
226
|
+
{
|
242
227
|
name: 'name',
|
243
228
|
id: 'obj_id',
|
244
229
|
date_created: 'date_created',
|
@@ -248,38 +233,41 @@ describe LivePaper::BaseObject do
|
|
248
233
|
{:rel => "analytics", :href => "/analytics/v1/objects/obj_id"}
|
249
234
|
]
|
250
235
|
}
|
251
|
-
|
252
|
-
|
236
|
+
}
|
237
|
+
let(:self_link) { "#{api_url}/#{object.id}" }
|
238
|
+
|
239
|
+
before do
|
240
|
+
stub_unimplemented_methods
|
253
241
|
end
|
254
242
|
|
255
243
|
it 'should not DELETE if the object does not have an id.' do
|
256
|
-
|
257
|
-
ret_val =
|
258
|
-
assert_not_requested :delete,
|
244
|
+
object.id = nil
|
245
|
+
ret_val = object.delete
|
246
|
+
assert_not_requested :delete, self_link
|
259
247
|
expect(ret_val).to eq 'Object Invalid'
|
260
248
|
end
|
261
249
|
|
262
250
|
context 'successful delete' do
|
263
251
|
before do
|
264
|
-
stub_request(:delete,
|
252
|
+
stub_request(:delete, self_link).to_return(:status => 200, :body => "")
|
265
253
|
end
|
266
254
|
it 'should DELETE when there is an ID' do
|
267
|
-
result
|
268
|
-
assert_requested :delete,
|
255
|
+
result=object.delete
|
256
|
+
assert_requested :delete, self_link
|
269
257
|
expect(result).to eq '200 OK'
|
270
258
|
end
|
271
259
|
end
|
272
260
|
|
273
261
|
context 'when link points to object' do
|
274
262
|
before do
|
275
|
-
@
|
276
|
-
stub_request(:delete,
|
263
|
+
@body = lpp_delete_error_response
|
264
|
+
stub_request(:delete, self_link).to_return(:status => 409, :body => @body)
|
277
265
|
end
|
278
266
|
it 'should fail' do
|
279
|
-
result
|
280
|
-
assert_requested :delete,
|
267
|
+
result=object.delete
|
268
|
+
assert_requested :delete, self_link
|
281
269
|
expect(result).to eq 'Conflict'
|
282
|
-
expect(
|
270
|
+
expect(object.errors).to eq JSON.parse(@body)
|
283
271
|
end
|
284
272
|
end
|
285
273
|
end
|
@@ -403,7 +391,7 @@ describe LivePaper::BaseObject do
|
|
403
391
|
end
|
404
392
|
it 'should request the access token' do
|
405
393
|
expect(LivePaper::BaseObject).to receive(:request_access_token)
|
406
|
-
LivePaper::BaseObject.rest_request(
|
394
|
+
LivePaper::BaseObject.rest_request(api_url, :post)
|
407
395
|
end
|
408
396
|
end
|
409
397
|
|
@@ -414,7 +402,7 @@ describe LivePaper::BaseObject do
|
|
414
402
|
|
415
403
|
it 'should NOT call request_access_token' do
|
416
404
|
expect(LivePaper::BaseObject).to receive(:request_access_token).exactly(0).times
|
417
|
-
LivePaper::BaseObject.rest_request(
|
405
|
+
LivePaper::BaseObject.rest_request(api_url, :post)
|
418
406
|
end
|
419
407
|
|
420
408
|
context 'when the access token is invalid' do
|
@@ -429,7 +417,7 @@ describe LivePaper::BaseObject do
|
|
429
417
|
|
430
418
|
it 'should request access an token' do
|
431
419
|
expect(LivePaper::BaseObject).to receive(:request_access_token).exactly(2).times
|
432
|
-
LivePaper::BaseObject.rest_request(
|
420
|
+
LivePaper::BaseObject.rest_request(api_url, :put, body: data.to_json)
|
433
421
|
end
|
434
422
|
|
435
423
|
end
|
@@ -8,200 +8,204 @@ describe LivePaper::Payoff do
|
|
8
8
|
stub_request(:get, "#{LivePaper::Payoff.api_url}/payoff_not_existent").to_return(:body => '{}', :status => 404)
|
9
9
|
end
|
10
10
|
|
11
|
+
let(:data) {
|
12
|
+
{
|
13
|
+
id: 'id',
|
14
|
+
name: 'name',
|
15
|
+
type: 'type',
|
16
|
+
url: 'url',
|
17
|
+
data: 'data'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
let(:payoff) { LivePaper::Payoff.new data }
|
21
|
+
|
11
22
|
describe '#initialize' do
|
12
|
-
before do
|
13
|
-
@data = {
|
14
|
-
id: 'id',
|
15
|
-
name: 'name',
|
16
|
-
type: 'type',
|
17
|
-
url: 'url',
|
18
|
-
data_type: 'data_type',
|
19
|
-
data: 'data'
|
20
|
-
}
|
21
|
-
@payoff = LivePaper::Payoff.new @data
|
22
|
-
end
|
23
23
|
|
24
24
|
it 'should map the type attribute.' do
|
25
|
-
expect(
|
25
|
+
expect(payoff.type).to eq data[:type]
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should map the url attribute.' do
|
29
|
-
expect(
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should map the data_type attribute.' do
|
33
|
-
expect(@payoff.data_type).to eq @data[:data_type]
|
29
|
+
expect(payoff.url).to eq data[:url]
|
34
30
|
end
|
35
31
|
|
36
32
|
it 'should map the data attribute.' do
|
37
|
-
expect(
|
33
|
+
expect(payoff.data).to eq data[:data]
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
37
|
describe '#save' do
|
42
38
|
context 'all needed attributes are provided.' do
|
43
39
|
context 'payoff type is RICH_PAYOFF.' do
|
44
|
-
|
45
|
-
|
40
|
+
let(:rich_data) {
|
41
|
+
{
|
42
|
+
type: "content action layout",
|
43
|
+
version: 1,
|
44
|
+
data: {
|
45
|
+
content: {
|
46
|
+
type: "image",
|
47
|
+
label: "Movember!",
|
48
|
+
data: {URL: "http://static.movember.com/uploads/2014/profiles/ef4/ef48a53fb031669fe86e741164d56972-546b9b5c56e15-hero.jpg"}
|
49
|
+
},
|
50
|
+
actions: [
|
51
|
+
{
|
52
|
+
type: "webpage",
|
53
|
+
label: "Donate!",
|
54
|
+
icon: {id: "533"},
|
55
|
+
data: {URL: "http://MOBRO.CO/oamike"}
|
56
|
+
},
|
57
|
+
{
|
58
|
+
type: "share",
|
59
|
+
label: "Share!",
|
60
|
+
icon: {id: "527"},
|
61
|
+
data: {URL: "Help Mike get the prize of most donations on his team! MOBRO.CO/oamike"}
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
let(:data) {
|
68
|
+
{
|
46
69
|
name: 'name',
|
47
70
|
type: LivePaper::Payoff::TYPE[:RICH],
|
48
71
|
url: 'url',
|
49
|
-
|
50
|
-
data: 'data'
|
72
|
+
data: rich_data
|
51
73
|
}
|
52
|
-
|
53
|
-
end
|
74
|
+
}
|
54
75
|
|
55
76
|
it 'should make a POST to the payoff URL with the richpayoff options hash.' do
|
56
|
-
|
77
|
+
payoff.save
|
57
78
|
assert_requested :post, LivePaper::Payoff.api_url, :body => {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
payoff: {
|
80
|
+
name: 'name',
|
81
|
+
richPayoff: {
|
82
|
+
version: 1,
|
83
|
+
private: {
|
84
|
+
:'content-type' => 'custom-base64',
|
85
|
+
:data => Base64.encode64(rich_data.to_json)
|
86
|
+
},
|
87
|
+
public: {
|
88
|
+
url: 'url'
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}.to_json
|
72
93
|
end
|
73
94
|
end
|
74
95
|
|
75
96
|
context 'payoff type is WEB_PAYOFF.' do
|
76
|
-
|
77
|
-
|
97
|
+
let(:data) {
|
98
|
+
{
|
78
99
|
name: 'name',
|
79
100
|
type: LivePaper::Payoff::TYPE[:WEB],
|
80
101
|
url: 'url'
|
81
102
|
}
|
82
|
-
|
83
|
-
end
|
103
|
+
}
|
84
104
|
|
85
105
|
it 'should make a POST to the payoff URL with the webpayoff options hash.' do
|
86
|
-
|
106
|
+
payoff.save
|
87
107
|
assert_requested :post, LivePaper::Payoff.api_url, :body => {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
108
|
+
payoff: {
|
109
|
+
name: data[:name],
|
110
|
+
URL: data[:url]
|
111
|
+
}
|
112
|
+
}.to_json
|
93
113
|
end
|
94
114
|
end
|
95
115
|
|
96
116
|
end
|
97
117
|
|
98
118
|
context 'when we do not have all needed data.' do
|
99
|
-
|
100
|
-
|
119
|
+
let(:data) {
|
120
|
+
{
|
101
121
|
name: 'name',
|
102
122
|
type: LivePaper::Payoff::TYPE[:WEB],
|
103
123
|
url: 'url'
|
104
124
|
}
|
105
|
-
|
106
|
-
end
|
107
|
-
|
125
|
+
}
|
108
126
|
it 'should raise an exception if the name was not provided.' do
|
109
|
-
|
110
|
-
expect {
|
127
|
+
payoff.name = nil
|
128
|
+
expect { payoff.save }.to raise_error ArgumentError
|
111
129
|
end
|
112
130
|
|
113
131
|
it 'should raise an exception if the type was not provided.' do
|
114
|
-
|
115
|
-
expect {
|
132
|
+
payoff.type = nil
|
133
|
+
expect { payoff.save }.to raise_error ArgumentError
|
116
134
|
end
|
117
135
|
|
118
136
|
it 'should raise an exception a unsupported type was provided.' do
|
119
|
-
|
120
|
-
expect {
|
137
|
+
payoff.type = 'unsupported type'
|
138
|
+
expect { payoff.save }.to raise_error ArgumentError
|
121
139
|
end
|
122
140
|
|
123
141
|
it 'should raise an exception if the url was not provided.' do
|
124
|
-
|
125
|
-
expect {
|
142
|
+
payoff.url = nil
|
143
|
+
expect { payoff.save }.to raise_error ArgumentError
|
126
144
|
end
|
127
145
|
|
128
146
|
context 'payoff type is RICH_PAYOFF.' do
|
129
|
-
|
130
|
-
|
147
|
+
let(:data) {
|
148
|
+
{
|
131
149
|
name: 'name',
|
132
150
|
type: LivePaper::Payoff::TYPE[:RICH],
|
133
151
|
url: 'url',
|
134
|
-
data_type: 'data_type',
|
135
152
|
data: 'data'
|
136
153
|
}
|
137
|
-
|
138
|
-
|
139
|
-
it 'should raise an exception if the data_type was not provided.' do
|
140
|
-
@payoff.data_type = nil
|
141
|
-
expect { @payoff.save }.to raise_error ArgumentError
|
142
|
-
end
|
154
|
+
}
|
155
|
+
|
143
156
|
it 'should raise an exception if the data was not provided.' do
|
144
|
-
|
145
|
-
expect {
|
157
|
+
payoff.data = nil
|
158
|
+
expect { payoff.save }.to raise_error ArgumentError
|
146
159
|
end
|
147
160
|
end
|
148
161
|
end
|
149
162
|
end
|
150
163
|
|
151
164
|
describe '#parse' do
|
152
|
-
|
153
|
-
@payoff = LivePaper::Payoff.parse(lpp_payoff_response_json)
|
154
|
-
end
|
165
|
+
let(:payoff) { LivePaper::Payoff.parse(lpp_payoff_response_json) }
|
155
166
|
|
156
167
|
it 'should return a Payoff object.' do
|
157
|
-
expect(
|
168
|
+
expect(payoff.class).to eq LivePaper::Payoff
|
158
169
|
end
|
159
170
|
|
160
171
|
it 'should map the id attribute.' do
|
161
|
-
expect(
|
172
|
+
expect(payoff.id).to eq 'payoff_id'
|
162
173
|
end
|
163
174
|
it 'should map the name attribute.' do
|
164
|
-
expect(
|
175
|
+
expect(payoff.name).to eq 'name'
|
165
176
|
end
|
166
177
|
|
167
178
|
it 'should map the url attribute.' do
|
168
|
-
expect(
|
179
|
+
expect(payoff.url).to eq 'url'
|
169
180
|
end
|
170
181
|
|
171
182
|
context 'when the data is from a web payoff.' do
|
172
183
|
it 'should map the payoff type attribute.' do
|
173
|
-
expect(
|
184
|
+
expect(payoff.type).to eq LivePaper::Payoff::TYPE[:WEB]
|
174
185
|
end
|
175
186
|
end
|
176
187
|
|
177
188
|
context 'when the data is from a rich payoff.' do
|
178
|
-
|
179
|
-
@payoff = LivePaper::Payoff.parse(lpp_richpayoff_response_json)
|
180
|
-
end
|
189
|
+
let(:payoff) { LivePaper::Payoff.parse(lpp_richpayoff_response_json) }
|
181
190
|
|
182
191
|
it 'should map the payoff type attribute.' do
|
183
|
-
expect(
|
192
|
+
expect(payoff.type).to eq LivePaper::Payoff::TYPE[:RICH]
|
184
193
|
end
|
185
194
|
|
186
|
-
it 'should map the data_type attribute.' do
|
187
|
-
expect(@payoff.data_type).to eq 'data_type'
|
188
|
-
end
|
189
195
|
it 'should map the data attribute.' do
|
190
|
-
expect(
|
196
|
+
expect(payoff.data).to eq ({field: 1})
|
191
197
|
end
|
192
198
|
end
|
193
199
|
end
|
194
200
|
|
195
201
|
describe '.get' do
|
196
202
|
context 'the requested payoff exists.' do
|
197
|
-
|
198
|
-
@payoff = LivePaper::Payoff.get('payoff_id')
|
199
|
-
end
|
203
|
+
let(:payoff) { LivePaper::Payoff.get('payoff_id') }
|
200
204
|
|
201
205
|
it 'should return the requested payoff.' do
|
202
|
-
expect(
|
203
|
-
expect(
|
204
|
-
expect(
|
206
|
+
expect(payoff.id).to eq 'payoff_id'
|
207
|
+
expect(payoff.name).to eq 'name'
|
208
|
+
expect(payoff.url).to eq 'url'
|
205
209
|
end
|
206
210
|
|
207
211
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: live_paper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Whitmarsh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -109,7 +109,6 @@ files:
|
|
109
109
|
- spec/live_paper/link_spec.rb
|
110
110
|
- spec/live_paper/payoff_spec.rb
|
111
111
|
- spec/live_paper/trigger_spec.rb
|
112
|
-
- spec/live_paper_session_spec.rb
|
113
112
|
- spec/spec_helper.rb
|
114
113
|
- spec/spec_helpers/lpp_client.rb
|
115
114
|
homepage: https://github.com/IPGPTP/live_paper_rubygem
|
@@ -132,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
131
|
version: '0'
|
133
132
|
requirements: []
|
134
133
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.0.14
|
136
135
|
signing_key:
|
137
136
|
specification_version: 4
|
138
137
|
summary: Ruby interface to the Live Paper service by HP.
|
@@ -142,6 +141,5 @@ test_files:
|
|
142
141
|
- spec/live_paper/link_spec.rb
|
143
142
|
- spec/live_paper/payoff_spec.rb
|
144
143
|
- spec/live_paper/trigger_spec.rb
|
145
|
-
- spec/live_paper_session_spec.rb
|
146
144
|
- spec/spec_helper.rb
|
147
145
|
- spec/spec_helpers/lpp_client.rb
|