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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 090fca8974a9aaec09e17d67fbba8b6cb2c06527
4
- data.tar.gz: 280161344f75ca01fdb2e552d7a4bb1c894f7e66
3
+ metadata.gz: c4dfcf2f3b2dc09dd0e30bf6bebadcf716450fb7
4
+ data.tar.gz: 7cfdbeb94e1a4a456b05da19bbb2656482f1e1ab
5
5
  SHA512:
6
- metadata.gz: 0632fd85530b8d2626ceb2ad0ee25198237f6edc280e001da54411016965550757df8ba9cff3b2a86f268f6d035e311227de0f6d5ad3514f4ef171234e882d65
7
- data.tar.gz: a14b7647ec398b7f958be6f107de75b710f66df1f8ed3276a90ba8e9d1796d46eb9b335df603381c1b6a0b18445b05b85fc9dadd197ae2013e5b1fe431bc6d6f
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', watermark: {strength: 10, resolution: 75, imageURL: image})
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', watermark: {strength: 10, resolution: 75, imageURL: image})
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[:x_user_info] = 'app=rubygem' unless options[:skip] == :user_info #watermark download fails if set
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}
@@ -19,10 +19,6 @@ module LivePaper
19
19
  end
20
20
 
21
21
  private
22
- def validate_attributes!
23
- raise ArgumentError, 'Required Attributes needed: name' unless all_present? [@name]
24
- end
25
-
26
22
  def create_body
27
23
  {
28
24
  trigger: {
@@ -14,10 +14,6 @@ module LivePaper
14
14
  end
15
15
 
16
16
  private
17
- def validate_attributes!
18
- raise ArgumentError, 'Required Attributes needed: name' unless all_present? [@name]
19
- end
20
-
21
17
  def create_body
22
18
  {
23
19
  trigger: {
@@ -32,6 +32,10 @@ module LivePaper
32
32
  end
33
33
 
34
34
  private
35
+ def validate_attributes!
36
+ raise ArgumentError, 'Required Attributes needed: name' unless all_present? [@name]
37
+ end
38
+
35
39
  def update_body
36
40
  {
37
41
  trigger: {
@@ -1,3 +1,3 @@
1
1
  module LivePaper
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.26"
3
3
  end
@@ -2,7 +2,7 @@ require_relative 'base_object'
2
2
 
3
3
  module LivePaper
4
4
  class WmTrigger < Trigger
5
- attr_accessor :watermark, :wm_url
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
- response = WmTrigger.rest_request( self.wm_url, :get, accept: "image/jpg", skip: :x_user_info )
19
- response.body.empty? ? nil : response.body
20
- rescue Exception => e
21
- puts 'Exception!\n'
22
- puts e.response
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
- watermark: {
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
- watermark: {
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.watermark).to eq 'watermark'
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.24
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-04-30 00:00:00.000000000 Z
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
- - ".gitignore"
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.2.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.