live_paper 0.0.24 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/live_paper.rb +2 -2
- data/lib/live_paper/base_object.rb +1 -1
- data/lib/live_paper/qr_trigger.rb +0 -4
- data/lib/live_paper/short_trigger.rb +0 -4
- data/lib/live_paper/trigger.rb +4 -0
- data/lib/live_paper/version.rb +1 -1
- data/lib/live_paper/wm_trigger.rb +13 -18
- data/spec/live_paper/trigger_spec.rb +10 -25
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4dfcf2f3b2dc09dd0e30bf6bebadcf716450fb7
|
4
|
+
data.tar.gz: 7cfdbeb94e1a4a456b05da19bbb2656482f1e1ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 646954d3eafc9b73203023364c8caefa78680630c724b1a9654dd5dc44241fe74890a5a4e931370dc43f4e3d19198234d5087ff500a471b28c18b5977f31420b
|
7
|
+
data.tar.gz: 5dbd3caf1e377d15132edba30c8a8f712e0f6434f78ef87a363dcb297bce8a9b60425a4acf1e2216ca024bde74565cf5fd7feafe892dcadd01aef74053b896b5
|
data/README.md
CHANGED
@@ -136,10 +136,10 @@ You can list existing resources with the list operation.
|
|
136
136
|
```ruby
|
137
137
|
image = Image.upload "http://url/to_your_image"
|
138
138
|
|
139
|
-
t=WmTrigger.create(name: 'watermark'
|
139
|
+
t=WmTrigger.create(name: 'watermark')
|
140
140
|
p=Payoff.create(name: 'name', type: Payoff::TYPE[:WEB], url: dest)
|
141
141
|
l=Link.create(payoff_id: p.id, trigger_id: t.id, name: "link")
|
142
|
-
t.download_watermark
|
142
|
+
t.download_watermark(image, {strength: 10, resolution: 75})
|
143
143
|
```
|
144
144
|
|
145
145
|
Alternatively, you can upload an image from your local system by providing the path to the jpg file
|
data/lib/live_paper.rb
CHANGED
@@ -65,11 +65,11 @@ module LivePaper
|
|
65
65
|
def watermark_bytes(dest, image_uri)
|
66
66
|
image = Image.upload image_uri
|
67
67
|
|
68
|
-
t=WmTrigger.create(name: 'watermark'
|
68
|
+
t=WmTrigger.create(name: 'watermark')
|
69
69
|
p=Payoff.create(name: 'name', type: Payoff::TYPE[:WEB], url: dest)
|
70
70
|
l=Link.create(payoff_id: p.id, trigger_id: t.id, name: "link")
|
71
71
|
@remote_resources={link: l, payoff: p, trigger: t}
|
72
|
-
t.download_watermark
|
72
|
+
t.download_watermark(image)
|
73
73
|
rescue Exception => e
|
74
74
|
puts "Exception!"
|
75
75
|
puts e.response
|
@@ -104,7 +104,7 @@ module LivePaper
|
|
104
104
|
headers = {}
|
105
105
|
headers[:authorization] = "Bearer #{$lpp_access_token}"
|
106
106
|
headers[:accept] = options[:accept] || "application/json"
|
107
|
-
headers[:
|
107
|
+
headers[:"X-user-info"] = 'app=rubygem'
|
108
108
|
headers[:content_type] = 'application/json' unless options[:body].nil?
|
109
109
|
|
110
110
|
h = {:method => verb, :url => url.to_s, :headers => headers}
|
data/lib/live_paper/trigger.rb
CHANGED
data/lib/live_paper/version.rb
CHANGED
@@ -2,7 +2,7 @@ require_relative 'base_object'
|
|
2
2
|
|
3
3
|
module LivePaper
|
4
4
|
class WmTrigger < Trigger
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :wm_url
|
6
6
|
WATERMARK_RESOLUTION = 75
|
7
7
|
WATERMARK_STRENGTH = 10
|
8
8
|
DEFAULT_SUBSCRIPTION = :month
|
@@ -14,30 +14,25 @@ module LivePaper
|
|
14
14
|
self
|
15
15
|
end
|
16
16
|
|
17
|
-
def download_watermark
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def download_watermark(image_url, options = {})
|
18
|
+
resolution = options[:resolution] || WATERMARK_RESOLUTION
|
19
|
+
strength = options[:strength] || WATERMARK_STRENGTH
|
20
|
+
url = "#{self.wm_url}?imageUrl=#{CGI.escape(image_url)}&resolution=#{resolution}&strength=#{strength}"
|
21
|
+
begin
|
22
|
+
response = WmTrigger.rest_request( url, :get, accept: "image/jpg" )
|
23
|
+
response.body.empty? ? nil : response.body
|
24
|
+
rescue Exception => e
|
25
|
+
puts 'Exception!\n'
|
26
|
+
puts e.response
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
private
|
26
|
-
def validate_attributes!
|
27
|
-
raise ArgumentError, 'Required Attributes needed: name and watermark.' unless all_present? [@name, @watermark]
|
28
|
-
raise ArgumentError, 'Required Attributes needed: watermark[:strength] and watermark[:imageURL].' unless all_keys_present? @watermark, [:strength, :imageURL]
|
29
|
-
end
|
30
|
-
|
31
31
|
def create_body
|
32
32
|
{
|
33
33
|
trigger: {
|
34
34
|
name: @name,
|
35
|
-
|
36
|
-
outputImageFormat: 'JPEG',
|
37
|
-
resolution: WATERMARK_RESOLUTION,
|
38
|
-
strength: @watermark[:strength],
|
39
|
-
imageURL: @watermark[:imageURL]
|
40
|
-
},
|
35
|
+
type: "watermark",
|
41
36
|
subscription: {
|
42
37
|
package: DEFAULT_SUBSCRIPTION.to_s
|
43
38
|
}
|
@@ -6,14 +6,12 @@ describe LivePaper::WmTrigger do
|
|
6
6
|
before do
|
7
7
|
stub_request(:post, /.*livepaperapi.com\/auth\/token.*/).to_return(:body => lpp_auth_response_json, :status => 200)
|
8
8
|
stub_request(:post, LivePaper::WmTrigger.api_url).to_return(:body => lpp_trigger_response_json, :status => 200)
|
9
|
-
stub_request(:get, 'https://fileapi/id/image').to_return(:body => lpp_watermark_response, :status => 200)
|
10
9
|
stub_request(:get, "#{LivePaper::WmTrigger.api_url}/trigger_id").to_return(:body => lpp_trigger_response_json, :status => 200)
|
11
10
|
stub_request(:get, "#{LivePaper::WmTrigger.api_url}/trigger_not_existent").to_return(:body => '{}', :status => 404)
|
12
11
|
|
13
12
|
@data = {
|
14
13
|
id: 'id',
|
15
14
|
name: 'name',
|
16
|
-
watermark: {strength: 10, imageURL: 'url'},
|
17
15
|
subscription: 'subscription'
|
18
16
|
}
|
19
17
|
end
|
@@ -23,10 +21,6 @@ describe LivePaper::WmTrigger do
|
|
23
21
|
@trigger = LivePaper::WmTrigger.new @data
|
24
22
|
end
|
25
23
|
|
26
|
-
it 'should map the watermark attribute.' do
|
27
|
-
expect(@trigger.watermark).to eq @data[:watermark]
|
28
|
-
end
|
29
|
-
|
30
24
|
it 'should map the subscription attribute.' do
|
31
25
|
expect(@trigger.subscription).to eq @data[:subscription]
|
32
26
|
end
|
@@ -44,12 +38,7 @@ describe LivePaper::WmTrigger do
|
|
44
38
|
assert_requested :post, LivePaper::WmTrigger.api_url, :body => {
|
45
39
|
trigger: {
|
46
40
|
name: 'name',
|
47
|
-
|
48
|
-
outputImageFormat: 'JPEG',
|
49
|
-
resolution: 75,
|
50
|
-
strength: 10,
|
51
|
-
imageURL: 'url'
|
52
|
-
},
|
41
|
+
type: 'watermark',
|
53
42
|
subscription: {package: 'month'}
|
54
43
|
}
|
55
44
|
}.to_json
|
@@ -62,12 +51,6 @@ describe LivePaper::WmTrigger do
|
|
62
51
|
trigger = LivePaper::WmTrigger.new @data
|
63
52
|
expect { trigger.save }.to raise_error
|
64
53
|
end
|
65
|
-
|
66
|
-
it 'should raise exception if the watermark is no provided.' do
|
67
|
-
@data.delete :watermark
|
68
|
-
trigger = LivePaper::WmTrigger.new @data
|
69
|
-
expect { trigger.save }.to raise_error
|
70
|
-
end
|
71
54
|
end
|
72
55
|
end
|
73
56
|
|
@@ -87,10 +70,6 @@ describe LivePaper::WmTrigger do
|
|
87
70
|
expect(@trigger.name).to eq 'name'
|
88
71
|
end
|
89
72
|
|
90
|
-
it 'should map the watermark attribute.' do
|
91
|
-
expect(@trigger.watermark).to eq 'watermark'
|
92
|
-
end
|
93
|
-
|
94
73
|
it 'should map the subscription attribute.' do
|
95
74
|
expect(@trigger.subscription).to eq 'subscription'
|
96
75
|
end
|
@@ -105,7 +84,7 @@ describe LivePaper::WmTrigger do
|
|
105
84
|
it 'should return the requested trigger.' do
|
106
85
|
expect(@trigger.id).to eq 'trigger_id'
|
107
86
|
expect(@trigger.name).to eq 'name'
|
108
|
-
expect(@trigger.
|
87
|
+
expect(@trigger.class).to eq LivePaper::WmTrigger
|
109
88
|
expect(@trigger.subscription).to eq 'subscription'
|
110
89
|
end
|
111
90
|
|
@@ -140,13 +119,19 @@ describe LivePaper::WmTrigger do
|
|
140
119
|
end
|
141
120
|
|
142
121
|
describe '#download_watermark' do
|
122
|
+
let(:image_url) { 'http://lpp_file_storage/image/mine.jpg' }
|
123
|
+
let(:encoded_image_url) { CGI.escape(image_url) }
|
124
|
+
let(:resolution) { LivePaper::WmTrigger::WATERMARK_RESOLUTION }
|
125
|
+
let(:strength) { LivePaper::WmTrigger::WATERMARK_STRENGTH }
|
126
|
+
|
143
127
|
before do
|
128
|
+
stub_request(:get, "https://fileapi/id/image?imageUrl=#{encoded_image_url}&resolution=#{resolution}&strength=#{strength}").to_return(:body => lpp_watermark_response, :status => 200)
|
144
129
|
@trigger = LivePaper::WmTrigger.new @data
|
145
130
|
@trigger.wm_url='https://fileapi/id/image'
|
146
131
|
end
|
147
|
-
|
132
|
+
|
148
133
|
it 'should return the watermark image data.' do
|
149
|
-
expect(@trigger.download_watermark).to eq 'watermark_data'
|
134
|
+
expect(@trigger.download_watermark(image_url)).to eq 'watermark_data'
|
150
135
|
end
|
151
136
|
end
|
152
137
|
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.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Whitmarsh
|
@@ -9,104 +9,104 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.6'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ~>
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.6'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: webmock
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: codeclimate-test-reporter
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - '>='
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: auto_tagger
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - '>='
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - '>='
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
description: Ruby interface to use the Live Paper service by HP for creating watermarked
|
@@ -116,7 +116,7 @@ executables: []
|
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
|
-
-
|
119
|
+
- .gitignore
|
120
120
|
- Gemfile
|
121
121
|
- LICENSE.txt
|
122
122
|
- README.md
|
@@ -150,17 +150,17 @@ require_paths:
|
|
150
150
|
- lib
|
151
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
|
-
- -
|
153
|
+
- - '>='
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: '0'
|
156
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
|
-
- -
|
158
|
+
- - '>='
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.4.5
|
164
164
|
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: Ruby interface to the Live Paper service by HP.
|