live_paper 0.0.26 → 0.0.27

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: c4dfcf2f3b2dc09dd0e30bf6bebadcf716450fb7
4
- data.tar.gz: 7cfdbeb94e1a4a456b05da19bbb2656482f1e1ab
3
+ metadata.gz: a8e506ee521e614012d2e33d930f8d399623cdb7
4
+ data.tar.gz: 81a129d47d16a138d10542fe04c7f6ce78773b2a
5
5
  SHA512:
6
- metadata.gz: 646954d3eafc9b73203023364c8caefa78680630c724b1a9654dd5dc44241fe74890a5a4e931370dc43f4e3d19198234d5087ff500a471b28c18b5977f31420b
7
- data.tar.gz: 5dbd3caf1e377d15132edba30c8a8f712e0f6434f78ef87a363dcb297bce8a9b60425a4acf1e2216ca024bde74565cf5fd7feafe892dcadd01aef74053b896b5
6
+ metadata.gz: edffcf5ba57cd5430bab1bb5c9e1283b9cde187e1f2f2807a0f47526bb4cee99284917a006f819d7763957eac0f4b2fb7b1d3625833d28744f726d88ef175458
7
+ data.tar.gz: bf363c81984efdc320c8c63633ec660b24fefdfc8aa2dd592da6302c86fe9803cd5c05d2b01a46d9625e66515d7533614ad7ae6d2f5ac7d60c2c73635db85783
@@ -4,8 +4,6 @@ module LivePaper
4
4
  class QrTrigger < Trigger
5
5
  attr_accessor :qrcode_url
6
6
 
7
- DEFAULT_SUBSCRIPTION = :month
8
-
9
7
  def parse(data)
10
8
  data = JSON.parse(data, symbolize_names: true)[:trigger]
11
9
  assign_attributes data
@@ -24,9 +22,8 @@ module LivePaper
24
22
  trigger: {
25
23
  name: @name,
26
24
  type: "qrcode",
27
- subscription: {
28
- package: DEFAULT_SUBSCRIPTION.to_s
29
- }
25
+ startDate: @start_date || default_start_date,
26
+ endDate: @end_date || default_end_date
30
27
  }
31
28
  }
32
29
  end
@@ -4,8 +4,6 @@ module LivePaper
4
4
  class ShortTrigger < Trigger
5
5
  attr_accessor :short_url
6
6
 
7
- DEFAULT_SUBSCRIPTION = :month
8
-
9
7
  def parse(data)
10
8
  data = JSON.parse(data, symbolize_names: true)[:trigger]
11
9
  assign_attributes data
@@ -19,9 +17,8 @@ module LivePaper
19
17
  trigger: {
20
18
  name: @name,
21
19
  type: "shorturl",
22
- subscription: {
23
- package: DEFAULT_SUBSCRIPTION.to_s
24
- }
20
+ startDate: @start_date || default_start_date,
21
+ endDate: @end_date || default_end_date
25
22
  }
26
23
  }
27
24
  end
@@ -1,8 +1,9 @@
1
1
  require_relative 'base_object'
2
+ require 'active_support/time'
2
3
 
3
4
  module LivePaper
4
5
  class Trigger < BaseObject
5
- attr_accessor :subscription, :state
6
+ attr_accessor :state, :start_date, :end_date
6
7
 
7
8
  def self.api_url
8
9
  "#{LP_API_HOST}/api/v1/triggers"
@@ -31,6 +32,14 @@ module LivePaper
31
32
  trigger_class.new.parse(data_in)
32
33
  end
33
34
 
35
+ def default_start_date
36
+ Time.now.iso8601
37
+ end
38
+
39
+ def default_end_date
40
+ Time.now.advance(years: 1).iso8601
41
+ end
42
+
34
43
  private
35
44
  def validate_attributes!
36
45
  raise ArgumentError, 'Required Attributes needed: name' unless all_present? [@name]
@@ -43,6 +52,7 @@ module LivePaper
43
52
  }
44
53
  }
45
54
  end
55
+
46
56
  end
47
57
 
48
58
  end
@@ -1,3 +1,3 @@
1
1
  module LivePaper
2
- VERSION = "0.0.26"
2
+ VERSION = "0.0.27"
3
3
  end
@@ -5,7 +5,6 @@ module LivePaper
5
5
  attr_accessor :wm_url
6
6
  WATERMARK_RESOLUTION = 75
7
7
  WATERMARK_STRENGTH = 10
8
- DEFAULT_SUBSCRIPTION = :month
9
8
 
10
9
  def parse(data)
11
10
  data = JSON.parse(data, symbolize_names: true)[:trigger]
@@ -33,9 +32,8 @@ module LivePaper
33
32
  trigger: {
34
33
  name: @name,
35
34
  type: "watermark",
36
- subscription: {
37
- package: DEFAULT_SUBSCRIPTION.to_s
38
- }
35
+ startDate: @start_date || default_start_date,
36
+ endDate: @end_date || default_end_date
39
37
  }
40
38
  }
41
39
  end
data/live_paper.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "activesupport"
21
22
  spec.add_runtime_dependency "rest-client"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -3,34 +3,64 @@ require 'spec_helper'
3
3
  DOWNLOAD_URL = "https://watermark.livepaperapi.com/watermark/v1/triggers"
4
4
 
5
5
  describe LivePaper::WmTrigger do
6
+ let(:start_date) { "my_start_date" }
7
+ let(:end_date) { "my_end_date" }
8
+ let(:data) {
9
+ {
10
+ id: 'id',
11
+ name: 'name',
12
+ start_date: start_date,
13
+ end_date: end_date
14
+ }
15
+ }
16
+
6
17
  before do
7
18
  stub_request(:post, /.*livepaperapi.com\/auth\/token.*/).to_return(:body => lpp_auth_response_json, :status => 200)
8
19
  stub_request(:post, LivePaper::WmTrigger.api_url).to_return(:body => lpp_trigger_response_json, :status => 200)
9
20
  stub_request(:get, "#{LivePaper::WmTrigger.api_url}/trigger_id").to_return(:body => lpp_trigger_response_json, :status => 200)
10
21
  stub_request(:get, "#{LivePaper::WmTrigger.api_url}/trigger_not_existent").to_return(:body => '{}', :status => 404)
22
+ end
11
23
 
12
- @data = {
13
- id: 'id',
14
- name: 'name',
15
- subscription: 'subscription'
24
+ describe '#initialize without specifying start_date end_date' do
25
+ let(:data){
26
+ {
27
+ id: 'id',
28
+ name: 'name'
29
+ }
16
30
  }
31
+ before do
32
+ @trigger = LivePaper::WmTrigger.new data
33
+ end
34
+
35
+ it 'should set startDate attribute to nil by default.' do
36
+ expect(@trigger.start_date).to be_nil
37
+ end
38
+
39
+ it 'should set endDate attribute to nil by default.' do
40
+ expect(@trigger.end_date).to be_nil
41
+ end
42
+
17
43
  end
18
44
 
19
- describe '#initialize' do
45
+ describe '#initialize with specifying start_date and end_date' do
20
46
  before do
21
- @trigger = LivePaper::WmTrigger.new @data
47
+ @trigger = LivePaper::WmTrigger.new data
22
48
  end
23
49
 
24
- it 'should map the subscription attribute.' do
25
- expect(@trigger.subscription).to eq @data[:subscription]
50
+ it 'should set startDate attribute.' do
51
+ expect(@trigger.start_date).to eq(start_date)
52
+ end
53
+
54
+ it 'should set endDate attribute.' do
55
+ expect(@trigger.end_date).to eq(end_date)
26
56
  end
27
57
  end
28
58
 
29
59
  describe '#save' do
30
60
  context 'when all needed attributes are provided,' do
31
61
  before do
32
- @data.delete :id
33
- @trigger = LivePaper::WmTrigger.new @data
62
+ data.delete :id
63
+ @trigger = LivePaper::WmTrigger.new data
34
64
  end
35
65
 
36
66
  it 'should make a POST to the trigger URL with body.' do
@@ -39,7 +69,8 @@ describe LivePaper::WmTrigger do
39
69
  trigger: {
40
70
  name: 'name',
41
71
  type: 'watermark',
42
- subscription: {package: 'month'}
72
+ startDate: start_date,
73
+ endDate: end_date
43
74
  }
44
75
  }.to_json
45
76
  end
@@ -47,14 +78,16 @@ describe LivePaper::WmTrigger do
47
78
 
48
79
  context 'when we do not have all needed data,' do
49
80
  it 'should raise exception if the name is no provided.' do
50
- @data.delete :name
51
- trigger = LivePaper::WmTrigger.new @data
81
+ data.delete :name
82
+ trigger = LivePaper::WmTrigger.new data
52
83
  expect { trigger.save }.to raise_error
53
84
  end
54
85
  end
55
86
  end
56
87
 
57
88
  describe '#parse' do
89
+ let(:lpp_start_date_response_json) { JSON.parse(lpp_trigger_response_json)['trigger']['startDate'] }
90
+ let(:lpp_end_date_response_json) { JSON.parse(lpp_trigger_response_json)['trigger']['endDate'] }
58
91
  before do
59
92
  @trigger = LivePaper::WmTrigger.parse(lpp_trigger_response_json)
60
93
  end
@@ -70,13 +103,20 @@ describe LivePaper::WmTrigger do
70
103
  expect(@trigger.name).to eq 'name'
71
104
  end
72
105
 
73
- it 'should map the subscription attribute.' do
74
- expect(@trigger.subscription).to eq 'subscription'
106
+ it 'should map the start_date attribute.' do
107
+ expect(@trigger.start_date).to eq lpp_start_date_response_json
108
+ end
109
+
110
+ it 'should map the end_date attribute.' do
111
+ expect(@trigger.end_date).to eq lpp_end_date_response_json
75
112
  end
76
113
  end
77
114
 
78
115
  describe '.get' do
79
116
  context 'the requested trigger exists.' do
117
+ let(:lpp_start_date_response_json) { JSON.parse(lpp_trigger_response_json)['trigger']['startDate'] }
118
+ let(:lpp_end_date_response_json) { JSON.parse(lpp_trigger_response_json)['trigger']['endDate'] }
119
+
80
120
  before do
81
121
  @trigger = LivePaper::Trigger.get('trigger_id')
82
122
  end
@@ -85,7 +125,8 @@ describe LivePaper::WmTrigger do
85
125
  expect(@trigger.id).to eq 'trigger_id'
86
126
  expect(@trigger.name).to eq 'name'
87
127
  expect(@trigger.class).to eq LivePaper::WmTrigger
88
- expect(@trigger.subscription).to eq 'subscription'
128
+ expect(@trigger.start_date).to eq lpp_start_date_response_json
129
+ expect(@trigger.end_date).to eq lpp_end_date_response_json
89
130
  end
90
131
 
91
132
  context 'qr trigger' do
@@ -126,7 +167,7 @@ describe LivePaper::WmTrigger do
126
167
 
127
168
  before do
128
169
  stub_request(:get, "https://fileapi/id/image?imageUrl=#{encoded_image_url}&resolution=#{resolution}&strength=#{strength}").to_return(:body => lpp_watermark_response, :status => 200)
129
- @trigger = LivePaper::WmTrigger.new @data
170
+ @trigger = LivePaper::WmTrigger.new data
130
171
  @trigger.wm_url='https://fileapi/id/image'
131
172
  end
132
173
 
@@ -71,7 +71,8 @@ def lpp_trigger_response_json(type='watermark')
71
71
  "state": "ACTIVE",
72
72
  "type": "#{type}",
73
73
  "watermark": "watermark",
74
- "subscription": "subscription"
74
+ "startDate":"2014-10-08T20:40:26.376+0000",
75
+ "endDate":"2015-10-09T02:29:12.376+0000"
75
76
  }
76
77
  }
77
78
  RESPONSE
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.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Whitmarsh
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-17 00:00:00.000000000 Z
12
+ date: 2015-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: rest-client
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -160,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
174
  version: '0'
161
175
  requirements: []
162
176
  rubyforge_project:
163
- rubygems_version: 2.4.5
177
+ rubygems_version: 2.4.6
164
178
  signing_key:
165
179
  specification_version: 4
166
180
  summary: Ruby interface to the Live Paper service by HP.