live_paper 0.0.9 → 0.0.10
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 +4 -4
- data/lib/live_paper/base_object.rb +6 -2
- data/lib/live_paper/image.rb +0 -1
- data/lib/live_paper/link.rb +5 -10
- data/lib/live_paper/version.rb +1 -1
- data/spec/live_paper/base_object_spec.rb +33 -4
- data/spec/live_paper/link_spec.rb +14 -14
- data/spec/live_paper/payoff_spec.rb +4 -4
- data/spec/live_paper/trigger_spec.rb +4 -4
- data/spec/spec_helpers/lpp_client.rb +50 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54159788ca4d35d52a44ed05de7e2fdfad88998e
|
4
|
+
data.tar.gz: 4f319ab3b4ad6f7380828d0bc68b06ca1979433a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8a4256e05ff2fbf38165b9ed6098673d3602b3a387de482cc4a7f911a82961f148bf118867d7bff796f12a0ed88a3e938a30741a0edd1dcac3a4e5436ae3a33
|
7
|
+
data.tar.gz: c9416a9a5d40f8eabb7d3897b775c390a56346cb2b629e92616a364d2af098d4a124778fef1b6dde36c0868741d059885e6e80bce8597c0a696c0a8630c296a4
|
@@ -4,7 +4,7 @@ require 'json'
|
|
4
4
|
module LivePaper
|
5
5
|
class BaseObject
|
6
6
|
extend HttpClient
|
7
|
-
attr_accessor :id, :name, :date_created, :date_modified
|
7
|
+
attr_accessor :id, :name, :date_created, :date_modified, :link
|
8
8
|
|
9
9
|
def assign_attributes(data)
|
10
10
|
data.each do |key, value|
|
@@ -30,7 +30,7 @@ module LivePaper
|
|
30
30
|
self
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.
|
33
|
+
def self.get(id)
|
34
34
|
request_handling_auth("#{api_url}/#{id}", 'GET') do |request|
|
35
35
|
response = send_request(request, 'application/json')
|
36
36
|
parse response.body
|
@@ -49,6 +49,10 @@ module LivePaper
|
|
49
49
|
raise NotImplementedError
|
50
50
|
end
|
51
51
|
|
52
|
+
def rel(key)
|
53
|
+
link.find { |obj| obj[:rel] == key }[:href] rescue nil
|
54
|
+
end
|
55
|
+
|
52
56
|
protected
|
53
57
|
def all_present?(array)
|
54
58
|
array.all? { |e| present? e } rescue false
|
data/lib/live_paper/image.rb
CHANGED
data/lib/live_paper/link.rb
CHANGED
@@ -2,22 +2,21 @@ require_relative 'base_object'
|
|
2
2
|
|
3
3
|
module LivePaper
|
4
4
|
class Link < BaseObject
|
5
|
-
attr_accessor :payoff_id, :trigger_id
|
5
|
+
attr_accessor :payoff_id, :trigger_id
|
6
6
|
|
7
|
-
def parse(
|
8
|
-
data = JSON.parse(
|
7
|
+
def parse(jsondata)
|
8
|
+
data = JSON.parse(jsondata, symbolize_names: true)[:link]
|
9
9
|
assign_attributes data
|
10
|
-
@analytics = get_link_for data, 'analytics'
|
11
10
|
self
|
12
11
|
end
|
13
12
|
|
14
13
|
def payoff
|
15
|
-
@payoff ||= LivePaper::Payoff.
|
14
|
+
@payoff ||= LivePaper::Payoff.get @payoff_id
|
16
15
|
end
|
17
16
|
|
18
17
|
def trigger
|
19
18
|
#todo: need to get the right object created here!!!
|
20
|
-
@trigger ||= LivePaper::WmTrigger.
|
19
|
+
@trigger ||= LivePaper::WmTrigger.get @trigger_id
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.api_url
|
@@ -38,9 +37,5 @@ module LivePaper
|
|
38
37
|
}
|
39
38
|
}
|
40
39
|
end
|
41
|
-
|
42
|
-
def get_link_for(data, rel)
|
43
|
-
data[:link].find { |obj| obj[:rel] == rel }[:href] rescue ''
|
44
|
-
end
|
45
40
|
end
|
46
41
|
end
|
data/lib/live_paper/version.rb
CHANGED
@@ -101,7 +101,7 @@ describe LivePaper::BaseObject do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe '.
|
104
|
+
describe '.get' do
|
105
105
|
before do
|
106
106
|
allow(LivePaper::BaseObject).to receive(:api_url).and_return(@api_url)
|
107
107
|
@data = '"id": "id", "name": "name"'
|
@@ -112,21 +112,50 @@ describe LivePaper::BaseObject do
|
|
112
112
|
it 'should return the requested base object.' do
|
113
113
|
allow(@data).to receive(:body).and_return(@data)
|
114
114
|
expect(LivePaper::BaseObject).to receive(:parse).with(@data)
|
115
|
-
LivePaper::BaseObject.
|
115
|
+
LivePaper::BaseObject.get('base_object')
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
context 'the requested base object does not exist or some error happened.' do
|
120
120
|
it 'should not raise error.' do
|
121
|
-
expect { LivePaper::BaseObject.
|
121
|
+
expect { LivePaper::BaseObject.get('base_object_not_existent') }.to_not raise_error
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should return nil.' do
|
125
|
-
expect(LivePaper::BaseObject.
|
125
|
+
expect(LivePaper::BaseObject.get('base_object_not_existent')).to eq nil
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
+
describe '#rel' do
|
131
|
+
before do
|
132
|
+
stub_unimplemented_methods
|
133
|
+
@data = {
|
134
|
+
name: 'name',
|
135
|
+
date_created: 'date_created',
|
136
|
+
date_modified: 'date_modified',
|
137
|
+
link: [
|
138
|
+
{ :rel => "self", :href => "/api/v1/payoffs/payoff_id" },
|
139
|
+
{ :rel => "analytics", :href => "/analytics/v1/payoffs/payoff_id" }
|
140
|
+
]
|
141
|
+
}
|
142
|
+
@obj = LivePaper::BaseObject.create @data
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should return href for rel link' do
|
146
|
+
expect(@obj.rel('self')).to eq '/api/v1/payoffs/payoff_id'
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should return nil for unknown rel link' do
|
150
|
+
expect(@obj.rel('invalid')).to be_nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should NOT crash when the link attribute is nil' do
|
154
|
+
@obj.link=nil
|
155
|
+
expect(@obj.rel('self')).to be_nil
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
130
159
|
describe '#all_present?' do
|
131
160
|
before do
|
132
161
|
@all = [1, 2, {k: 'v'}, [1, 2]]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe LivePaper::
|
3
|
+
describe LivePaper::Link do
|
4
4
|
before do
|
5
5
|
stub_request(:post, /.*livepaperapi.com\/auth\/token.*/).to_return(:body => lpp_auth_response_json, :status => 200)
|
6
6
|
stub_request(:post, LivePaper::Link.api_url).to_return(:body => lpp_link_response_json, :status => 200)
|
@@ -10,7 +10,6 @@ describe LivePaper::WmTrigger do
|
|
10
10
|
@data = {
|
11
11
|
id: 'id',
|
12
12
|
name: 'name',
|
13
|
-
analytics: 'analytics',
|
14
13
|
trigger_id: 'trigger_id',
|
15
14
|
payoff_id: 'payoff_id'
|
16
15
|
}
|
@@ -21,10 +20,6 @@ describe LivePaper::WmTrigger do
|
|
21
20
|
@link = LivePaper::Link.new @data
|
22
21
|
end
|
23
22
|
|
24
|
-
it 'should map the analytics attribute.' do
|
25
|
-
expect(@link.analytics).to eq @data[:analytics]
|
26
|
-
end
|
27
|
-
|
28
23
|
it 'should map the trigger_id attribute.' do
|
29
24
|
expect(@link.trigger_id).to eq @data[:trigger_id]
|
30
25
|
end
|
@@ -85,8 +80,13 @@ describe LivePaper::WmTrigger do
|
|
85
80
|
expect(@link.name).to eq 'name'
|
86
81
|
end
|
87
82
|
|
88
|
-
it 'should map the
|
89
|
-
expect(@link.
|
83
|
+
it 'should map the link array attribute.' do
|
84
|
+
expect(@link.link).to be_a Array
|
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"}]
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should map the trigger_id attribute.' do
|
@@ -98,16 +98,17 @@ describe LivePaper::WmTrigger do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe '.
|
101
|
+
describe '.get' do
|
102
102
|
context 'the requested Link exists.' do
|
103
103
|
before do
|
104
|
-
@link = LivePaper::Link.
|
104
|
+
@link = LivePaper::Link.get('link_id')
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'should return the requested link.' do
|
108
108
|
expect(@link.id).to eq 'link_id'
|
109
109
|
expect(@link.name).to eq 'name'
|
110
|
-
expect(@link.
|
110
|
+
expect(@link.link).to be_a Array
|
111
|
+
expect(@link.link.size).to eq 4
|
111
112
|
expect(@link.trigger_id).to eq 'trigger_id'
|
112
113
|
expect(@link.payoff_id).to eq 'payoff_id'
|
113
114
|
end
|
@@ -115,11 +116,11 @@ describe LivePaper::WmTrigger do
|
|
115
116
|
|
116
117
|
context 'the requested link does not exist or some error happened.' do
|
117
118
|
it 'should not raise error.' do
|
118
|
-
expect { LivePaper::Link.
|
119
|
+
expect { LivePaper::Link.get('link_not_existent') }.to_not raise_error
|
119
120
|
end
|
120
121
|
|
121
122
|
it 'should return nil.' do
|
122
|
-
expect(LivePaper::Link.
|
123
|
+
expect(LivePaper::Link.get('link_not_existent')).to eq nil
|
123
124
|
end
|
124
125
|
end
|
125
126
|
end
|
@@ -179,5 +180,4 @@ describe LivePaper::WmTrigger do
|
|
179
180
|
end
|
180
181
|
end
|
181
182
|
end
|
182
|
-
|
183
183
|
end
|
@@ -192,10 +192,10 @@ describe LivePaper::Payoff do
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
-
describe '.
|
195
|
+
describe '.get' do
|
196
196
|
context 'the requested payoff exists.' do
|
197
197
|
before do
|
198
|
-
@payoff = LivePaper::Payoff.
|
198
|
+
@payoff = LivePaper::Payoff.get('payoff_id')
|
199
199
|
end
|
200
200
|
|
201
201
|
it 'should return the requested payoff.' do
|
@@ -208,11 +208,11 @@ describe LivePaper::Payoff do
|
|
208
208
|
|
209
209
|
context 'the requested payoff does not exist or some error happened.' do
|
210
210
|
it 'should not raise error.' do
|
211
|
-
expect { LivePaper::Payoff.
|
211
|
+
expect { LivePaper::Payoff.get('payoff_not_existent') }.to_not raise_error
|
212
212
|
end
|
213
213
|
|
214
214
|
it 'should return nil.' do
|
215
|
-
expect(LivePaper::Payoff.
|
215
|
+
expect(LivePaper::Payoff.get('payoff_not_existent')).to eq nil
|
216
216
|
end
|
217
217
|
end
|
218
218
|
end
|
@@ -96,10 +96,10 @@ describe LivePaper::WmTrigger do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
describe '.
|
99
|
+
describe '.get' do
|
100
100
|
context 'the requested trigger exists.' do
|
101
101
|
before do
|
102
|
-
@trigger = LivePaper::WmTrigger.
|
102
|
+
@trigger = LivePaper::WmTrigger.get('trigger_id')
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should return the requested trigger.' do
|
@@ -112,11 +112,11 @@ describe LivePaper::WmTrigger do
|
|
112
112
|
|
113
113
|
context 'the requested trigger does not exist or some error happened.' do
|
114
114
|
it 'should not raise error.' do
|
115
|
-
expect { LivePaper::WmTrigger.
|
115
|
+
expect { LivePaper::WmTrigger.get('trigger_not_existent') }.to_not raise_error
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'should return nil.' do
|
119
|
-
expect(LivePaper::WmTrigger.
|
119
|
+
expect(LivePaper::WmTrigger.get('trigger_not_existent')).to eq nil
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -27,14 +27,26 @@ def lpp_richpayoff_response_json
|
|
27
27
|
"payoff": {
|
28
28
|
"id": "payoff_id",
|
29
29
|
"name": "name",
|
30
|
+
"dateCreated":"2014-10-07T20:57:01.083+0000",
|
31
|
+
"dateModified":"2014-10-07T20:57:01.083+0000",
|
32
|
+
"link":[
|
33
|
+
{
|
34
|
+
"rel":"self",
|
35
|
+
"href":"/api/v1/payoffs/payoff_id"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"rel":"analytics",
|
39
|
+
"href":"/analytics/v1/payoffs/payoff_id"
|
40
|
+
}
|
41
|
+
],
|
30
42
|
"richPayoff" : {
|
31
43
|
"version": 1,
|
44
|
+
"public": {
|
45
|
+
"url": "url"
|
46
|
+
},
|
32
47
|
"private": {
|
33
48
|
"content-type": "data_type",
|
34
49
|
"data": "#{Base64.encode64('{ "field": 1 }').gsub(/\n/,'')}"
|
35
|
-
},
|
36
|
-
"public": {
|
37
|
-
"url": "url"
|
38
50
|
}
|
39
51
|
}
|
40
52
|
}
|
@@ -62,9 +74,26 @@ def lpp_link_response_json
|
|
62
74
|
"link": {
|
63
75
|
"id": "link_id",
|
64
76
|
"name": "name",
|
65
|
-
"
|
77
|
+
"dateCreated": "2014-04-08T08:16:25.723+0000",
|
78
|
+
"dateModified": "2014-04-08T08:16:25.723+0000",
|
79
|
+
"link": [{
|
80
|
+
"rel": "self",
|
81
|
+
"href": "self_url"
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"rel": "analytics",
|
85
|
+
"href": "analytic_url"
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"rel": "payoff",
|
89
|
+
"href": "payoff_url"
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"rel": "trigger",
|
93
|
+
"href": "trigger_url"
|
94
|
+
}],
|
66
95
|
"payoffId": "payoff_id",
|
67
|
-
"
|
96
|
+
"triggerId": "trigger_id"
|
68
97
|
}
|
69
98
|
}
|
70
99
|
RESPONSE
|
@@ -72,4 +101,20 @@ end
|
|
72
101
|
|
73
102
|
def lpp_watermark_response
|
74
103
|
'watermark_data'
|
104
|
+
end
|
105
|
+
|
106
|
+
def lpp_delete_error_response
|
107
|
+
<<-RESPONSE
|
108
|
+
{ "associatedLinks": "1",
|
109
|
+
"link": [{
|
110
|
+
"rel": "associatedLinks",
|
111
|
+
"href": "https://dev.livepaperapi.com/api/v1/links?trigger=uMTGQ0xoS7exSL3iujHJSA"
|
112
|
+
}],
|
113
|
+
"error": {
|
114
|
+
"title": "409 Conflict",
|
115
|
+
"message": "The trigger to be deleted has associated links. The associated links must be deleted first."
|
116
|
+
}
|
117
|
+
}
|
118
|
+
RESPONSE
|
119
|
+
|
75
120
|
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.10
|
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-
|
12
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|