live_paper 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/live_paper.rb +1 -0
- data/lib/live_paper/base_object.rb +51 -0
- data/lib/live_paper/http_client.rb +3 -0
- data/lib/live_paper/link.rb +19 -1
- data/lib/live_paper/payoff.rb +14 -2
- data/lib/live_paper/qr_trigger.rb +2 -6
- data/lib/live_paper/short_trigger.rb +2 -6
- data/lib/live_paper/trigger.rb +44 -0
- data/lib/live_paper/version.rb +1 -1
- data/lib/live_paper/wm_trigger.rb +2 -6
- data/spec/live_paper/base_object_spec.rb +112 -4
- data/spec/live_paper/link_spec.rb +29 -4
- data/spec/live_paper/payoff_spec.rb +1 -1
- data/spec/live_paper/trigger_spec.rb +21 -3
- data/spec/spec_helpers/lpp_client.rb +13 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c8909429faeddd085edf073d104a1ad717b67c6
|
4
|
+
data.tar.gz: af646c3ccc94ac5f67e9e27b8b9e8c27542096aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbf2eb746d0325c2e4b1ba2860969b7b20a04df9ffd1c3b558f170470c20b0825d2b7d1dfca1f379614fb31a3c82ae6eb3aa2a0c13464dfed1e3a755c7b464bc
|
7
|
+
data.tar.gz: 30f24581fe65c6120f7e42ffc63bced8b59d0438db7225db153b549332ef8a8c31a1097f0709239a5616daaf833d53aaae63e6e3435fe3631833b55498aeca5c
|
data/lib/live_paper.rb
CHANGED
@@ -37,6 +37,45 @@ module LivePaper
|
|
37
37
|
end rescue nil
|
38
38
|
end
|
39
39
|
|
40
|
+
def self.list
|
41
|
+
objects=[]
|
42
|
+
request_handling_auth("#{api_url}", 'GET') do |request|
|
43
|
+
response = send_request(request, content_type: 'application/json')
|
44
|
+
JSON.parse(response.body, symbolize_names: true)[list_key].each do |linkdata|
|
45
|
+
objects << self.parse({item_key => linkdata}.to_json)
|
46
|
+
end
|
47
|
+
end #rescue nil
|
48
|
+
objects
|
49
|
+
end
|
50
|
+
|
51
|
+
def update
|
52
|
+
puts 'update called'
|
53
|
+
response_code = 'Object Invalid'
|
54
|
+
if self.id
|
55
|
+
BaseObject.request_handling_auth("#{self.class.api_url}/#{id}", 'PUT') do |request|
|
56
|
+
response = BaseObject.send_request(request,
|
57
|
+
content_type: 'application/json',
|
58
|
+
body: update_body.to_json,
|
59
|
+
allow_codes: [200, 400, 404, 409])
|
60
|
+
response_code = case response.code.to_i
|
61
|
+
when 200
|
62
|
+
puts "update response 200"
|
63
|
+
parse(response.body)
|
64
|
+
'OK'
|
65
|
+
when 400
|
66
|
+
@errors=response.body
|
67
|
+
'Bad Request'
|
68
|
+
when 409
|
69
|
+
@errors=response.body
|
70
|
+
'Conflict'
|
71
|
+
else
|
72
|
+
'Object Invalid'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
response_code
|
77
|
+
end
|
78
|
+
|
40
79
|
def delete
|
41
80
|
response_code = nil
|
42
81
|
if self.id
|
@@ -76,6 +115,14 @@ module LivePaper
|
|
76
115
|
raise NotImplementedError
|
77
116
|
end
|
78
117
|
|
118
|
+
def self.list_key
|
119
|
+
raise NotImplementedError
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.item_key
|
123
|
+
raise NotImplementedError
|
124
|
+
end
|
125
|
+
|
79
126
|
def rel(key)
|
80
127
|
link.find { |obj| obj[:rel] == key }[:href] rescue nil
|
81
128
|
end
|
@@ -109,5 +156,9 @@ module LivePaper
|
|
109
156
|
def create_body
|
110
157
|
raise NotImplementedError
|
111
158
|
end
|
159
|
+
|
160
|
+
def update_body
|
161
|
+
raise NotImplementedError
|
162
|
+
end
|
112
163
|
end
|
113
164
|
end
|
@@ -32,6 +32,7 @@ module LivePaper
|
|
32
32
|
request_access_token unless @access_token
|
33
33
|
request = http_request(url, method)
|
34
34
|
request['Authorization'] = "Bearer #{@access_token}"
|
35
|
+
request['Accept'] = "application/json"
|
35
36
|
yield request
|
36
37
|
rescue NotAuthenticatedError => e
|
37
38
|
tries += 1
|
@@ -63,6 +64,8 @@ module LivePaper
|
|
63
64
|
Net::HTTP::Post.new(uri.request_uri)
|
64
65
|
when 'GET'
|
65
66
|
Net::HTTP::Get.new(uri.request_uri)
|
67
|
+
when 'PUT'
|
68
|
+
Net::HTTP::Put.new(uri.request_uri)
|
66
69
|
when 'DELETE'
|
67
70
|
Net::HTTP::Delete.new(uri.request_uri)
|
68
71
|
else
|
data/lib/live_paper/link.rb
CHANGED
@@ -5,7 +5,8 @@ module LivePaper
|
|
5
5
|
attr_accessor :payoff_id, :trigger_id
|
6
6
|
|
7
7
|
def parse(jsondata)
|
8
|
-
data
|
8
|
+
puts "parsing data and it is #{jsondata}"
|
9
|
+
data = JSON.parse(jsondata, symbolize_names: true)[self.class.item_key]
|
9
10
|
assign_attributes data
|
10
11
|
self
|
11
12
|
end
|
@@ -23,6 +24,14 @@ module LivePaper
|
|
23
24
|
"#{LP_API_HOST}/api/v1/links"
|
24
25
|
end
|
25
26
|
|
27
|
+
def self.list_key
|
28
|
+
:links
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.item_key
|
32
|
+
:link
|
33
|
+
end
|
34
|
+
|
26
35
|
private
|
27
36
|
def validate_attributes!
|
28
37
|
raise ArgumentError, 'Required Attributes needed: name, payoff_id and trigger_id.' unless all_present? [@name, @payoff_id, @trigger_id]
|
@@ -37,5 +46,14 @@ module LivePaper
|
|
37
46
|
}
|
38
47
|
}
|
39
48
|
end
|
49
|
+
|
50
|
+
def update_body
|
51
|
+
{
|
52
|
+
link: {
|
53
|
+
name: @name
|
54
|
+
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
40
58
|
end
|
41
59
|
end
|
data/lib/live_paper/payoff.rb
CHANGED
@@ -10,12 +10,20 @@ module LivePaper
|
|
10
10
|
}
|
11
11
|
|
12
12
|
def parse(data)
|
13
|
-
data = JSON.parse(data, symbolize_names: true)[
|
13
|
+
data = JSON.parse(data, symbolize_names: true)[self.class.item_key]
|
14
14
|
assign_attributes(data)
|
15
15
|
send(present?(data[:richPayoff]) ? :parse_richpayoff : :parse_webpayoff, data)
|
16
16
|
self
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.list_key
|
20
|
+
:payoffs
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.item_key
|
24
|
+
:payoff
|
25
|
+
end
|
26
|
+
|
19
27
|
def self.api_url
|
20
28
|
"#{LP_API_HOST}/api/v1/payoffs"
|
21
29
|
end
|
@@ -40,6 +48,10 @@ module LivePaper
|
|
40
48
|
@url = data[:URL]
|
41
49
|
end
|
42
50
|
|
51
|
+
def update_body
|
52
|
+
create_body
|
53
|
+
end
|
54
|
+
|
43
55
|
def create_body
|
44
56
|
{
|
45
57
|
payoff: case @type
|
@@ -67,7 +79,7 @@ module LivePaper
|
|
67
79
|
version: 1,
|
68
80
|
private: {
|
69
81
|
:'content-type' => @data_type,
|
70
|
-
:data => @data
|
82
|
+
:data => Base64.encode64(@data.to_json)
|
71
83
|
},
|
72
84
|
public: {url: @url}
|
73
85
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative 'base_object'
|
2
2
|
|
3
3
|
module LivePaper
|
4
|
-
class QrTrigger <
|
5
|
-
attr_accessor :
|
4
|
+
class QrTrigger < Trigger
|
5
|
+
attr_accessor :qrcode_url
|
6
6
|
|
7
7
|
DEFAULT_SUBSCRIPTION = :month
|
8
8
|
|
@@ -13,10 +13,6 @@ module LivePaper
|
|
13
13
|
self
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.api_url
|
17
|
-
"#{LP_API_HOST}/api/v1/triggers"
|
18
|
-
end
|
19
|
-
|
20
16
|
def download_qrcode
|
21
17
|
QrTrigger.request_handling_auth(self.qrcode_url, 'GET') do |request|
|
22
18
|
response = QrTrigger.send_request(request)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative 'base_object'
|
2
2
|
|
3
3
|
module LivePaper
|
4
|
-
class ShortTrigger <
|
5
|
-
attr_accessor :
|
4
|
+
class ShortTrigger < Trigger
|
5
|
+
attr_accessor :short_url
|
6
6
|
|
7
7
|
DEFAULT_SUBSCRIPTION = :month
|
8
8
|
|
@@ -13,10 +13,6 @@ module LivePaper
|
|
13
13
|
self
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.api_url
|
17
|
-
"#{LP_API_HOST}/api/v1/triggers"
|
18
|
-
end
|
19
|
-
|
20
16
|
private
|
21
17
|
def validate_attributes!
|
22
18
|
raise ArgumentError, 'Required Attributes needed: name' unless all_present? [@name]
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'base_object'
|
2
|
+
|
3
|
+
module LivePaper
|
4
|
+
class Trigger < BaseObject
|
5
|
+
attr_accessor :subscription, :state
|
6
|
+
|
7
|
+
def self.api_url
|
8
|
+
"#{LP_API_HOST}/api/v1/triggers"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.item_key
|
12
|
+
:trigger
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.list_key
|
16
|
+
:triggers
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.parse(data_in)
|
20
|
+
data = JSON.parse(data_in, symbolize_names: true)[item_key]
|
21
|
+
trigger_class = case data[:type]
|
22
|
+
when "shorturl"
|
23
|
+
ShortTrigger
|
24
|
+
when "qrcode"
|
25
|
+
QrTrigger
|
26
|
+
when "watermark"
|
27
|
+
WmTrigger
|
28
|
+
else
|
29
|
+
raise "UnsupportedTriggerType"
|
30
|
+
end
|
31
|
+
trigger_class.new.parse(data_in)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def update_body
|
36
|
+
{
|
37
|
+
trigger: {
|
38
|
+
name: @name
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/live_paper/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative 'base_object'
|
2
2
|
|
3
3
|
module LivePaper
|
4
|
-
class WmTrigger <
|
5
|
-
attr_accessor :watermark, :
|
4
|
+
class WmTrigger < Trigger
|
5
|
+
attr_accessor :watermark, :wm_url
|
6
6
|
WATERMARK_RESOLUTION = 75
|
7
7
|
WATERMARK_STRENGTH = 10
|
8
8
|
DEFAULT_SUBSCRIPTION = :month
|
@@ -14,10 +14,6 @@ module LivePaper
|
|
14
14
|
self
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.api_url
|
18
|
-
"#{LP_API_HOST}/api/v1/triggers"
|
19
|
-
end
|
20
|
-
|
21
17
|
def download_watermark
|
22
18
|
WmTrigger.request_handling_auth(self.wm_url, 'GET') do |request|
|
23
19
|
response = WmTrigger.send_request(request)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
def stub_unimplemented_methods
|
4
5
|
allow_any_instance_of(LivePaper::BaseObject).to receive(:validate_attributes!)
|
@@ -101,6 +102,30 @@ describe LivePaper::BaseObject do
|
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
105
|
+
describe '.list' do
|
106
|
+
before do
|
107
|
+
allow(LivePaper::BaseObject).to receive(:api_url).and_return(@api_url)
|
108
|
+
allow(LivePaper::BaseObject).to receive(:list_key).and_return(:lists)
|
109
|
+
allow(LivePaper::BaseObject).to receive(:item_key).and_return(:list)
|
110
|
+
@data = {lists: [{id: 1, name: 'first'},
|
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)
|
115
|
+
end
|
116
|
+
it 'should return array of parsed objects' do
|
117
|
+
allow(@data).to receive(:body).and_return(@data)
|
118
|
+
@data[:lists].each do |datum|
|
119
|
+
expect(LivePaper::BaseObject).to receive(:parse).with({:list => datum}.to_json) { datum[:id] }
|
120
|
+
end
|
121
|
+
result = LivePaper::BaseObject.list
|
122
|
+
expect(result.count).to eq @data[:lists].size
|
123
|
+
result.each_with_index do |res, i|
|
124
|
+
expect(res).to eq i+1
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
104
129
|
describe '.get' do
|
105
130
|
before do
|
106
131
|
allow(LivePaper::BaseObject).to receive(:api_url).and_return(@api_url)
|
@@ -127,6 +152,89 @@ describe LivePaper::BaseObject do
|
|
127
152
|
end
|
128
153
|
end
|
129
154
|
|
155
|
+
describe '.update' do
|
156
|
+
let(:obj_id) { 12345 }
|
157
|
+
let(:update_json) { {name: 'new_name'}.to_json }
|
158
|
+
let (:data1) { {name: 'name',
|
159
|
+
id: obj_id,
|
160
|
+
date_created: 'date_created',
|
161
|
+
date_modified: 'date_modified'} }
|
162
|
+
let(:resp_body) { }
|
163
|
+
|
164
|
+
before do
|
165
|
+
stub_unimplemented_methods
|
166
|
+
allow_any_instance_of(LivePaper::BaseObject).to receive(:update_body).and_return(update_json)
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'with valid data' do
|
170
|
+
let(:resp_body) { { object: {name: new_name,
|
171
|
+
id: obj_id,
|
172
|
+
date_created: 'date_created',
|
173
|
+
date_modified: 'new_date_modified'}} }
|
174
|
+
let(:new_name) { 'my_valid_name_change' }
|
175
|
+
before do
|
176
|
+
@response = resp_body
|
177
|
+
stub_request(:put, "#{@api_url}/#{obj_id}").to_return(:body => @response, :status => 200)
|
178
|
+
@obj=LivePaper::BaseObject.new data1
|
179
|
+
@obj.name = new_name
|
180
|
+
end
|
181
|
+
it 'should return success' do
|
182
|
+
ret_val = @obj.update
|
183
|
+
assert_requested :put, "#{@api_url}/#{obj_id}"
|
184
|
+
expect(ret_val).to eq 'OK'
|
185
|
+
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
|
+
end
|
198
|
+
|
199
|
+
context 'with invalid data' do
|
200
|
+
before do
|
201
|
+
stub_request(:put, "#{@api_url}/#{obj_id}").to_return(:body => resp_body, :status => 400)
|
202
|
+
@obj=LivePaper::BaseObject.new data1
|
203
|
+
@obj.name = 'my_new_name'
|
204
|
+
end
|
205
|
+
it 'should return the error details' do
|
206
|
+
ret_val = @obj.update
|
207
|
+
assert_requested :put, "#{@api_url}/#{obj_id}"
|
208
|
+
expect(ret_val).to eq 'Bad Request'
|
209
|
+
end
|
210
|
+
it 'should preserve the invalid object attributes' do
|
211
|
+
@obj.update
|
212
|
+
assert_requested :put, "#{@api_url}/#{obj_id}"
|
213
|
+
expect(@obj.name).to eq 'my_new_name'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'remote object has been deleted' do
|
218
|
+
before do
|
219
|
+
stub_request(:put, "#{@api_url}/#{obj_id}").to_return(:body => resp_body, :status => 404)
|
220
|
+
end
|
221
|
+
it 'should return an error' do
|
222
|
+
@obj=LivePaper::BaseObject.new data1
|
223
|
+
ret_val = @obj.update
|
224
|
+
assert_requested :put, "#{@api_url}/#{obj_id}"
|
225
|
+
expect(ret_val).to eq 'Object Invalid'
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'remote object was never saved.' do
|
230
|
+
it 'should return an error' do
|
231
|
+
@obj = LivePaper::BaseObject.new @data
|
232
|
+
ret_val = @obj.update
|
233
|
+
expect(ret_val).to eq 'Object Invalid'
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
130
238
|
describe '.delete' do
|
131
239
|
before do
|
132
240
|
stub_unimplemented_methods
|
@@ -136,8 +244,8 @@ describe LivePaper::BaseObject do
|
|
136
244
|
date_created: 'date_created',
|
137
245
|
date_modified: 'date_modified',
|
138
246
|
link: [
|
139
|
-
{
|
140
|
-
{
|
247
|
+
{:rel => "self", :href => "/api/v1/objects/obj_id"},
|
248
|
+
{:rel => "analytics", :href => "/analytics/v1/objects/obj_id"}
|
141
249
|
]
|
142
250
|
}
|
143
251
|
@obj = LivePaper::BaseObject.create @data
|
@@ -184,8 +292,8 @@ describe LivePaper::BaseObject do
|
|
184
292
|
date_created: 'date_created',
|
185
293
|
date_modified: 'date_modified',
|
186
294
|
link: [
|
187
|
-
{
|
188
|
-
{
|
295
|
+
{:rel => "self", :href => "/api/v1/payoffs/payoff_id"},
|
296
|
+
{:rel => "analytics", :href => "/analytics/v1/payoffs/payoff_id"}
|
189
297
|
]
|
190
298
|
}
|
191
299
|
@obj = LivePaper::BaseObject.create @data
|
@@ -83,10 +83,10 @@ describe LivePaper::Link do
|
|
83
83
|
it 'should map the link array attribute.' do
|
84
84
|
expect(@link.link).to be_a Array
|
85
85
|
expect(@link.link.size).to eq 4
|
86
|
-
expect(@link.link).to eq [{:rel=>"self", :href=>"self_url"},
|
87
|
-
{:rel=>"analytics", :href=>"analytic_url"},
|
88
|
-
{:rel=>"payoff", :href=>"payoff_url"},
|
89
|
-
{:rel=>"trigger", :href=>"trigger_url"}]
|
86
|
+
expect(@link.link).to eq [{:rel => "self", :href => "self_url"},
|
87
|
+
{:rel => "analytics", :href => "analytic_url"},
|
88
|
+
{:rel => "payoff", :href => "payoff_url"},
|
89
|
+
{:rel => "trigger", :href => "trigger_url"}]
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should map the trigger_id attribute.' do
|
@@ -125,6 +125,31 @@ describe LivePaper::Link do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
describe '.update' do
|
129
|
+
let(:newname) { 'my_new_name' }
|
130
|
+
before do
|
131
|
+
@link = LivePaper::Link.new @data
|
132
|
+
stub_request(:put, "#{LivePaper::Link.api_url}/#{@data[:id]}").to_return(:body => lpp_link_response_json(newname), :status => 200)
|
133
|
+
@link.name = newname
|
134
|
+
@link.update
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should make a PUT to the link URL with the parse body.' do
|
138
|
+
assert_requested :put, "#{LivePaper::Link.api_url}/#{@data[:id]}", :body => {
|
139
|
+
link: {
|
140
|
+
name: newname
|
141
|
+
}
|
142
|
+
}.to_json
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should reflect the data returned' do
|
146
|
+
expect(@link.name).to eq newname
|
147
|
+
expect(@link.date_modified).to eq '2014-04-08T08:16:25.723+0000'
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
end
|
152
|
+
|
128
153
|
describe '#trigger' do
|
129
154
|
before do
|
130
155
|
stub_request(:get, "#{LivePaper::WmTrigger.api_url}/trigger_id").to_return(:body => lpp_trigger_response_json, :status => 200)
|
@@ -99,7 +99,7 @@ describe LivePaper::WmTrigger do
|
|
99
99
|
describe '.get' do
|
100
100
|
context 'the requested trigger exists.' do
|
101
101
|
before do
|
102
|
-
@trigger = LivePaper::
|
102
|
+
@trigger = LivePaper::Trigger.get('trigger_id')
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should return the requested trigger.' do
|
@@ -108,15 +108,33 @@ describe LivePaper::WmTrigger do
|
|
108
108
|
expect(@trigger.watermark).to eq 'watermark'
|
109
109
|
expect(@trigger.subscription).to eq 'subscription'
|
110
110
|
end
|
111
|
+
|
112
|
+
context 'qr trigger' do
|
113
|
+
before do
|
114
|
+
stub_request(:get, "#{LivePaper::Trigger.api_url}/qr_trigger_id").to_return(:body => lpp_trigger_response_json('qrcode'), :status => 200)
|
115
|
+
end
|
116
|
+
it 'should create a QrTrigger' do
|
117
|
+
qr_trigger = LivePaper::Trigger.get('qr_trigger_id')
|
118
|
+
expect(qr_trigger).to be_a LivePaper::QrTrigger
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'short trigger' do
|
123
|
+
it 'should return a ShortTrigger' do
|
124
|
+
stub_request(:get, "#{LivePaper::Trigger.api_url}/short_trigger_id").to_return(:body => lpp_trigger_response_json('shorturl'), :status => 200)
|
125
|
+
my_trigger = LivePaper::Trigger.get('short_trigger_id')
|
126
|
+
expect(my_trigger).to be_a LivePaper::ShortTrigger
|
127
|
+
end
|
128
|
+
end
|
111
129
|
end
|
112
130
|
|
113
131
|
context 'the requested trigger does not exist or some error happened.' do
|
114
132
|
it 'should not raise error.' do
|
115
|
-
expect { LivePaper::
|
133
|
+
expect { LivePaper::Trigger.get('trigger_not_existent') }.to_not raise_error
|
116
134
|
end
|
117
135
|
|
118
136
|
it 'should return nil.' do
|
119
|
-
expect(LivePaper::
|
137
|
+
expect(LivePaper::Trigger.get('trigger_not_existent')).to eq nil
|
120
138
|
end
|
121
139
|
end
|
122
140
|
end
|
@@ -54,26 +54,35 @@ def lpp_richpayoff_response_json
|
|
54
54
|
RESPONSE
|
55
55
|
end
|
56
56
|
|
57
|
-
def lpp_trigger_response_json
|
57
|
+
def lpp_trigger_response_json(type='watermark')
|
58
58
|
<<-RESPONSE
|
59
59
|
{
|
60
60
|
"trigger": {
|
61
61
|
"id": "trigger_id",
|
62
62
|
"name": "name",
|
63
|
+
"dateCreated": "2014-10-08T22:06:28.518+0000",
|
64
|
+
"dateModified": "2014-10-08T22:06:28.518+0000",
|
65
|
+
"link": [
|
66
|
+
{"rel":"self", "href": "https://www.livepaperapi.com/api/v1/triggers/trigger_id"},
|
67
|
+
{"rel":"analytics", "href": "https://www.livepaperapi.com/analytics/v1/triggers/trigger_id"},
|
68
|
+
{"rel":"image", "href": "https://fileapi/trigger_id/image"},
|
69
|
+
{"rel":"shortURL", "href": "http://hpgo.co/abc123"}
|
70
|
+
],
|
71
|
+
"state": "ACTIVE",
|
72
|
+
"type": "#{type}",
|
63
73
|
"watermark": "watermark",
|
64
|
-
"link": [{"rel":"image", "href": "https://fileapi/id/image"}],
|
65
74
|
"subscription": "subscription"
|
66
75
|
}
|
67
76
|
}
|
68
77
|
RESPONSE
|
69
78
|
end
|
70
79
|
|
71
|
-
def lpp_link_response_json
|
80
|
+
def lpp_link_response_json(name='name')
|
72
81
|
<<-RESPONSE
|
73
82
|
{
|
74
83
|
"link": {
|
75
84
|
"id": "link_id",
|
76
|
-
"name": "name",
|
85
|
+
"name": "#{name}",
|
77
86
|
"dateCreated": "2014-04-08T08:16:25.723+0000",
|
78
87
|
"dateModified": "2014-04-08T08:16:25.723+0000",
|
79
88
|
"link": [{
|
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.12
|
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: 2014-11-
|
12
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/live_paper/payoff.rb
|
102
102
|
- lib/live_paper/qr_trigger.rb
|
103
103
|
- lib/live_paper/short_trigger.rb
|
104
|
+
- lib/live_paper/trigger.rb
|
104
105
|
- lib/live_paper/version.rb
|
105
106
|
- lib/live_paper/wm_trigger.rb
|
106
107
|
- live_paper.gemspec
|