live_paper 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d8e85b4d1411632bd21583973f51f85b3cf51bd
4
- data.tar.gz: 1745011dfe2dd65fe657dcb8d68148181c754d52
3
+ metadata.gz: b489f0bf261b6914c0c19e4a8a195c29cbab70cc
4
+ data.tar.gz: 02d0367b53900498aeef78b9167f1711950ecf05
5
5
  SHA512:
6
- metadata.gz: 289a6bb4a5f101a53dd76a1720e3bb29ed99559cc99d0f5240d2ca8e7b95b82038690076a828774556a444aed86022312ca3f9a04b7fde671b9a899e4029dde3
7
- data.tar.gz: f26ad8dcdb9c3ed95e97addb6b002e11c837b37bffe5689393cffdbf5dd70cf2dc922f8910ca1b5f58df925872fc831563069513976665d4832b000394faafd1
6
+ metadata.gz: 0940231ff1e32b771bb54fa88338598339a1194650fd433a23ad5d5cb95cadd51d351bfd15fcc495fabe5b7c7d14b6bce8195acec078f8928b23362fa1654434
7
+ data.tar.gz: b3d7a0c30820492c7cdf299f061498ff15526a71ba890daacbb57f738272557c9bc2728c3e2206e67d9d9808c896ab770b15ea377f4d11344bc800ff6c3bbf8d
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ RSpec::Core::RakeTask.new(:spec) do |task|
7
7
  task.rspec_opts = ['--color', '--format', 'documentation']
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task :default => :spec
@@ -24,6 +24,9 @@ module LivePaper
24
24
  def initialize(auth)
25
25
  #todo: tdd, verify hash
26
26
  $lpp_basic_auth = Base64.strict_encode64("#{auth[:id]}:#{auth[:secret]}")
27
+ BaseObject::request_access_token
28
+ BaseObject::request_project_id if $lpp_access_token
29
+
27
30
  @remote_resources={}
28
31
  end
29
32
 
@@ -8,6 +8,7 @@ module LivePaper
8
8
 
9
9
  LP_API_HOST="https://www.livepaperapi.com"
10
10
  AUTH_URL = "#{LP_API_HOST}/auth/token"
11
+ AUTH_VALIDATION_URL = "#{LP_API_HOST}/auth/v1/validate"
11
12
 
12
13
  attr_accessor :id, :name, :date_created, :date_modified, :link
13
14
 
@@ -101,6 +102,7 @@ module LivePaper
101
102
  raise "Method '#{verb}' not supported." unless [:get, :post, :put, :delete].include?(verb)
102
103
 
103
104
  request_access_token unless $lpp_access_token
105
+ request_project_id unless $project_id
104
106
  headers = {}
105
107
  headers[:authorization] = "Bearer #{$lpp_access_token}"
106
108
  headers[:accept] = options[:accept] || "application/json"
@@ -117,6 +119,7 @@ module LivePaper
117
119
  tries += 1
118
120
  if tries < 3
119
121
  request_access_token
122
+ request_project_id
120
123
  headers[:authorization] = "Bearer #{$lpp_access_token}"
121
124
  retry
122
125
  else
@@ -142,6 +145,20 @@ module LivePaper
142
145
  $lpp_access_token = @access_token
143
146
  end
144
147
 
148
+ def self.request_project_id
149
+ project = nil
150
+
151
+ RestClient.proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
152
+ request = {}.to_json
153
+ res = RestClient.post AUTH_VALIDATION_URL, request, { :Authorization => "Bearer #{$lpp_access_token}", :Accept => 'application/json'}
154
+ @project = res.headers[:project_id]
155
+
156
+ if @project.nil?
157
+ raise "Project id not in response header"
158
+ end
159
+
160
+ $project_id = @project
161
+ end
145
162
 
146
163
  def errors
147
164
  begin
@@ -6,7 +6,7 @@ module LivePaper
6
6
 
7
7
  attr_accessor :url
8
8
 
9
- API_URL = 'https://storage.livepaperapi.com/objects/v1/files'
9
+ API_URL = 'https://storage.livepaperapi.com/objects/v2/projects/PROJECTID/files'
10
10
 
11
11
  def self.upload(image_uri)
12
12
  # return the original img uri if it is LivePaper storage
@@ -21,10 +21,16 @@ module LivePaper
21
21
  end
22
22
 
23
23
  BaseObject.request_access_token unless $lpp_access_token
24
- response = RestClient.post API_URL,
25
- image_bytes,
26
- authorization: "Bearer #{$lpp_access_token}",
27
- content_type: 'image/jpg'
24
+ BaseObject.request_project_id unless $project_id
25
+ begin
26
+ response = RestClient.post API_URL.gsub(/PROJECTID/,$project_id),
27
+ image_bytes,
28
+ authorization: "Bearer #{$lpp_access_token}",
29
+ content_type: 'image/jpeg',
30
+ accept: '*/*'
31
+ rescue Exception => e
32
+ puts e.message
33
+ end
28
34
  response.headers[:location]
29
35
 
30
36
  end
@@ -20,7 +20,7 @@ module LivePaper
20
20
  end
21
21
 
22
22
  def self.api_url
23
- "#{LP_API_HOST}/api/v1/links"
23
+ "#{LP_API_HOST}/api/v2/projects/#{$project_id}/links"
24
24
  end
25
25
 
26
26
  def self.list_key
@@ -55,4 +55,4 @@ module LivePaper
55
55
  end
56
56
 
57
57
  end
58
- end
58
+ end
@@ -25,7 +25,7 @@ module LivePaper
25
25
  end
26
26
 
27
27
  def self.api_url
28
- "#{LP_API_HOST}/api/v1/payoffs"
28
+ "#{LP_API_HOST}/api/v2/projects/#{$project_id}/payoffs"
29
29
  end
30
30
 
31
31
  private
@@ -44,7 +44,7 @@ module LivePaper
44
44
 
45
45
  def parse_webpayoff(data)
46
46
  @type = TYPE[:WEB]
47
- @url = data[:URL]
47
+ @url = data[:url]
48
48
  end
49
49
 
50
50
  def update_body
@@ -67,13 +67,15 @@ module LivePaper
67
67
  def create_webpayoff_body
68
68
  {
69
69
  name: @name,
70
- URL: @url
70
+ type: 'url',
71
+ url: @url
71
72
  }
72
73
  end
73
74
 
74
75
  def create_richpayoff_body
75
76
  {
76
77
  name: @name,
78
+ type: 'richPayoff',
77
79
  richPayoff: {
78
80
  version: 1,
79
81
  private: {
@@ -7,7 +7,7 @@ module LivePaper
7
7
  def parse(data)
8
8
  data = JSON.parse(data, symbolize_names: true)[:trigger]
9
9
  assign_attributes data
10
- self.qrcode_url=data[:link].select { |item| item[:rel] == "image" }.first[:href]
10
+ self.qrcode_url=data[:link].select { |item| item[:rel] == "download" }.first[:href]
11
11
  self
12
12
  end
13
13
 
@@ -6,7 +6,7 @@ module LivePaper
6
6
  attr_accessor :state, :start_date, :end_date
7
7
 
8
8
  def self.api_url
9
- "#{LP_API_HOST}/api/v1/triggers"
9
+ "#{LP_API_HOST}/api/v2/projects/#{$project_id}/triggers"
10
10
  end
11
11
 
12
12
  def self.item_key
@@ -55,4 +55,4 @@ module LivePaper
55
55
 
56
56
  end
57
57
 
58
- end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module LivePaper
2
- VERSION = "0.0.28"
2
+ VERSION = "0.0.29"
3
3
  end
@@ -9,14 +9,14 @@ module LivePaper
9
9
  def parse(data)
10
10
  data = JSON.parse(data, symbolize_names: true)[:trigger]
11
11
  assign_attributes data
12
- self.wm_url=data[:link].select { |item| item[:rel] == "image" }.first[:href]
12
+ self.wm_url=data[:link].select { |item| item[:rel] == "download" }.first[:href]
13
13
  self
14
14
  end
15
15
 
16
16
  def download_watermark(image_url, options = {})
17
17
  resolution = options[:resolution] || WATERMARK_RESOLUTION
18
18
  strength = options[:strength] || WATERMARK_STRENGTH
19
- url = "#{self.wm_url}?imageUrl=#{CGI.escape(image_url)}&resolution=#{resolution}&strength=#{strength}"
19
+ url = "#{self.wm_url}?imageURL=#{CGI.escape(image_url)}&resolution=#{resolution}&strength=#{strength}"
20
20
  begin
21
21
  response = WmTrigger.rest_request( url, :get, accept: "image/jpg" )
22
22
  response.body.empty? ? nil : response.body
@@ -22,7 +22,8 @@ describe LivePaper::BaseObject do
22
22
  before do
23
23
  stub_request(:post, /.*livepaperapi.com\/auth\/token.*/).to_return(:body => lpp_auth_response_json, :status => 200)
24
24
  stub_request(:post, api_url).to_return(:body => lpp_richpayoff_response_json, :status => 200)
25
- end
25
+ stub_request(:post, LivePaper::BaseObject::AUTH_VALIDATION_URL).to_return(:status => 201, :body => "", :headers => { project_id: 'pid'})
26
+ end
26
27
 
27
28
  describe '#initialize' do
28
29
  let(:data) {
@@ -373,13 +374,21 @@ describe LivePaper::BaseObject do
373
374
  end
374
375
 
375
376
  describe '.request_access_token' do
376
- it 'should corerectly get the token' do
377
+ it 'should correctly get the token' do
377
378
  $lpp_access_token = nil
378
379
  LivePaper::BaseObject.request_access_token
379
380
  expect($lpp_access_token).to eq 'SECRETTOKEN'
380
381
  end
381
382
  end
382
383
 
384
+ describe '.request_project_id' do
385
+ it 'should correctly get the project id' do
386
+ $project_id = nil
387
+ LivePaper::BaseObject.request_project_id
388
+ expect($project_id).to eq 'pid'
389
+ end
390
+ end
391
+
383
392
  describe 'rest_request' do
384
393
  before do
385
394
 
@@ -395,6 +404,16 @@ describe LivePaper::BaseObject do
395
404
  end
396
405
  end
397
406
 
407
+ context 'when there is no project id' do
408
+ before do
409
+ $project_id = nil
410
+ end
411
+ it 'should request the project_id' do
412
+ expect(LivePaper::BaseObject).to receive(:request_project_id)
413
+ LivePaper::BaseObject.rest_request(api_url, :post)
414
+ end
415
+ end
416
+
398
417
  context 'when there is an access token' do
399
418
  before do
400
419
  $lpp_access_token = 'TOPSECRET'
@@ -407,6 +426,9 @@ describe LivePaper::BaseObject do
407
426
 
408
427
  context 'when the access token is invalid' do
409
428
  before do
429
+ allow(LivePaper::BaseObject).to receive(:request_project_id) do
430
+ @project_id = $project_id = 'pid'
431
+ end
410
432
  $lpp_access_token = 'invalid'
411
433
 
412
434
  @response = double('A mock for a response')
@@ -423,5 +445,37 @@ describe LivePaper::BaseObject do
423
445
  end
424
446
  end
425
447
 
448
+ context 'when there is a project id' do
449
+ before do
450
+ $lpp_access_token = 'TOPSECRET'
451
+ $project_id = 'mypid'
452
+ end
453
+
454
+ it 'should NOT call request_project_id' do
455
+ expect(LivePaper::BaseObject).to receive(:request_project_id).exactly(0).times
456
+ LivePaper::BaseObject.rest_request(api_url, :post)
457
+ end
458
+
459
+ context 'when the access token is invalid' do
460
+ before do
461
+ allow(LivePaper::BaseObject).to receive(:request_project_id) do
462
+ @project_id = $project_id = 'pid'
463
+ end
464
+ $lpp_access_token = 'invalid'
465
+
466
+ @response = double('A mock for a response')
467
+ allow(@response).to receive(:body) { '{ "accessToken" : "valid_access_token" }' }
468
+ @response.stub(:code).and_return(401, 401, 200) #fail first two calls
469
+ RestClient::Request.stub(:execute).and_return(@response)
470
+ end
471
+
472
+ it 'should request a project id' do
473
+ expect(LivePaper::BaseObject).to receive(:request_project_id).exactly(2).times
474
+ LivePaper::BaseObject.rest_request(api_url, :put, body: data.to_json)
475
+ end
476
+
477
+ end
478
+ end
479
+
426
480
  end
427
- end
481
+ end
@@ -6,10 +6,11 @@ describe LivePaper::Image do
6
6
  before do
7
7
  $lpp_access_token = "YouBeenHacked"
8
8
 
9
- stub_request(:post, LivePaper::Image::API_URL).
9
+ stub_request(:post, LivePaper::Image::API_URL.gsub(/PROJECTID/,'pid')).
10
10
  with(:body => "YOURIMAGEBYTES",
11
- :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Authorization'=>'Bearer YouBeenHacked', 'Content-Length'=>'14', 'Content-Type'=>'image/jpg', 'User-Agent'=>'Ruby'}).
11
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Authorization'=>'Bearer YouBeenHacked', 'Content-Length'=>'14', 'Content-Type'=>'image/jpeg', 'User-Agent'=>'Ruby'}).
12
12
  to_return(:status => 201, :body => "", :headers => {location: lpp_img_uri})
13
+ stub_request(:post, LivePaper::BaseObject::AUTH_VALIDATION_URL).to_return(:status => 201, :body => "", :headers => { project_id: 'pid'})
13
14
  end
14
15
 
15
16
  context 'local file' do
@@ -6,6 +6,7 @@ describe LivePaper::Link do
6
6
  stub_request(:post, LivePaper::Link.api_url).to_return(:body => lpp_link_response_json, :status => 200)
7
7
  stub_request(:get, "#{LivePaper::Link.api_url}/link_id").to_return(:body => lpp_link_response_json, :status => 200)
8
8
  stub_request(:get, "#{LivePaper::Link.api_url}/link_not_existent").to_return(:body => '{}', :status => 404)
9
+ stub_request(:post, LivePaper::BaseObject::AUTH_VALIDATION_URL).to_return(:status => 201, :body => "", :headers => { project_id: 'pid'})
9
10
 
10
11
  @data = {
11
12
  id: 'id',
@@ -6,7 +6,8 @@ describe LivePaper::Payoff do
6
6
  stub_request(:post, LivePaper::Payoff.api_url).to_return(:body => lpp_richpayoff_response_json, :status => 200)
7
7
  stub_request(:get, "#{LivePaper::Payoff.api_url}/payoff_id").to_return(:body => lpp_payoff_response_json, :status => 200)
8
8
  stub_request(:get, "#{LivePaper::Payoff.api_url}/payoff_not_existent").to_return(:body => '{}', :status => 404)
9
- end
9
+ stub_request(:post, LivePaper::BaseObject::AUTH_VALIDATION_URL).to_return(:status => 201, :body => "", :headers => { project_id: 'pid'})
10
+ end
10
11
 
11
12
  let(:data) {
12
13
  {
@@ -78,6 +79,7 @@ describe LivePaper::Payoff do
78
79
  assert_requested :post, LivePaper::Payoff.api_url, :body => {
79
80
  payoff: {
80
81
  name: 'name',
82
+ type: 'richPayoff',
81
83
  richPayoff: {
82
84
  version: 1,
83
85
  private: {
@@ -107,7 +109,8 @@ describe LivePaper::Payoff do
107
109
  assert_requested :post, LivePaper::Payoff.api_url, :body => {
108
110
  payoff: {
109
111
  name: data[:name],
110
- URL: data[:url]
112
+ type: 'url',
113
+ url: data[:url]
111
114
  }
112
115
  }.to_json
113
116
  end
@@ -221,4 +224,4 @@ describe LivePaper::Payoff do
221
224
  end
222
225
  end
223
226
 
224
- end
227
+ end
@@ -19,10 +19,11 @@ describe LivePaper::WmTrigger do
19
19
  stub_request(:post, LivePaper::WmTrigger.api_url).to_return(:body => lpp_trigger_response_json, :status => 200)
20
20
  stub_request(:get, "#{LivePaper::WmTrigger.api_url}/trigger_id").to_return(:body => lpp_trigger_response_json, :status => 200)
21
21
  stub_request(:get, "#{LivePaper::WmTrigger.api_url}/trigger_not_existent").to_return(:body => '{}', :status => 404)
22
- end
22
+ stub_request(:post, LivePaper::BaseObject::AUTH_VALIDATION_URL).to_return(:status => 201, :body => "", :headers => { project_id: 'pid'})
23
+ end
23
24
 
24
25
  describe '#initialize without specifying start_date end_date' do
25
- let(:data){
26
+ let(:data){
26
27
  {
27
28
  id: 'id',
28
29
  name: 'name'
@@ -116,7 +117,7 @@ describe LivePaper::WmTrigger do
116
117
  context 'the requested trigger exists.' do
117
118
  let(:lpp_start_date_response_json) { JSON.parse(lpp_trigger_response_json)['trigger']['startDate'] }
118
119
  let(:lpp_end_date_response_json) { JSON.parse(lpp_trigger_response_json)['trigger']['endDate'] }
119
-
120
+
120
121
  before do
121
122
  @trigger = LivePaper::Trigger.get('trigger_id')
122
123
  end
@@ -166,13 +167,13 @@ describe LivePaper::WmTrigger do
166
167
  let(:strength) { LivePaper::WmTrigger::WATERMARK_STRENGTH }
167
168
 
168
169
  before do
169
- stub_request(:get, "https://fileapi/id/image?imageUrl=#{encoded_image_url}&resolution=#{resolution}&strength=#{strength}").to_return(:body => lpp_watermark_response, :status => 200)
170
+ stub_request(:get, "https://fileapi/id/image?imageURL=#{encoded_image_url}&resolution=#{resolution}&strength=#{strength}").to_return(:body => lpp_watermark_response, :status => 200)
170
171
  @trigger = LivePaper::WmTrigger.new data
171
172
  @trigger.wm_url='https://fileapi/id/image'
172
173
  end
173
-
174
+
174
175
  it 'should return the watermark image data.' do
175
176
  expect(@trigger.download_watermark(image_url)).to eq 'watermark_data'
176
177
  end
177
178
  end
178
- end
179
+ end
@@ -15,7 +15,8 @@ def lpp_payoff_response_json
15
15
  "payoff": {
16
16
  "id": "payoff_id",
17
17
  "name": "name",
18
- "URL": "url"
18
+ "type": "url",
19
+ "url": "url"
19
20
  }
20
21
  }
21
22
  RESPONSE
@@ -27,6 +28,7 @@ def lpp_richpayoff_response_json
27
28
  "payoff": {
28
29
  "id": "payoff_id",
29
30
  "name": "name",
31
+ "type": "richPayoff",
30
32
  "dateCreated":"2014-10-07T20:57:01.083+0000",
31
33
  "dateModified":"2014-10-07T20:57:01.083+0000",
32
34
  "link":[
@@ -65,12 +67,11 @@ def lpp_trigger_response_json(type='watermark')
65
67
  "link": [
66
68
  {"rel":"self", "href": "https://www.livepaperapi.com/api/v1/triggers/trigger_id"},
67
69
  {"rel":"analytics", "href": "https://www.livepaperapi.com/analytics/v1/triggers/trigger_id"},
68
- {"rel":"image", "href": "https://fileapi/trigger_id/image"},
70
+ {"rel":"download", "href": "https://fileapi/trigger_id/image"},
69
71
  {"rel":"shortURL", "href": "http://hpgo.co/abc123"}
70
72
  ],
71
73
  "state": "ACTIVE",
72
74
  "type": "#{type}",
73
- "watermark": "watermark",
74
75
  "startDate":"2014-10-08T20:40:26.376+0000",
75
76
  "endDate":"2015-10-09T02:29:12.376+0000"
76
77
  }
@@ -127,4 +128,4 @@ def lpp_delete_error_response
127
128
  }
128
129
  RESPONSE
129
130
 
130
- end
131
+ 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.28
4
+ version: 0.0.29
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-06-25 00:00:00.000000000 Z
12
+ date: 2015-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport