live_paper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +2 -0
- data/lib/live_paper.rb +179 -0
- data/lib/live_paper/version.rb +3 -0
- data/live_paper.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cdac946c63ee00fa820eb93e33ba775b3cc8bd80
|
4
|
+
data.tar.gz: e30dda90cb7b7e1362e874cfe5c7f9a746f80a7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd833ac68cfdc1c57d2276439fccc6b58e891bcd5b34acc71c773c3a2ae39c4b4381060a48843a53dfdec069a19edaab41733391a8401f257354a1c85057ae46
|
7
|
+
data.tar.gz: f38360db944f969be80ef41d872357230ac1a9a9b6e4491167ee95c3de4f54a106fba014920a0781126022cbd3e20ffccbcec5a838ac0c23ecef068e69633839
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.idea
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# LivePaper
|
2
|
+
|
3
|
+
Provides a ruby interface to the Live Paper service by HP for creating watermarked images, QR codes, and mobile-friendly shortened URLs.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'live_paper'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install live_paper
|
19
|
+
|
20
|
+
## Register with the Live Paper Service
|
21
|
+
|
22
|
+
In order to obtain access credentials register here: https://link.livepaperdeveloper.com
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Authenticate
|
27
|
+
|
28
|
+
Live Paper gem requires an authentication hash with :id and :secret. Obtain your credentials from the registration link above.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
lp = LivePaper.auth id: "your client id", secret: "your client secret"
|
32
|
+
```
|
33
|
+
|
34
|
+
|
35
|
+
### Shortening URLs
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
short_url = lp.shorten('http://www.google.com')
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
### Generating QR Codes
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
qr_bytes = lp.qr_bytes('http://www.amazon.com')
|
46
|
+
File.open("qr.png", "w") { |f| f.write(qr_bytes) }
|
47
|
+
```
|
48
|
+
|
49
|
+
> Note: Version 1 of the API only supports returning QR Code bytes. Version 2 may host publicly accessible QR images.
|
50
|
+
|
51
|
+
### Watermarking Images
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
wm_bytes = lp.watermark_bytes("http://www.hp.com",
|
55
|
+
"https://www.google.com/images/srpr/logo11w.png")
|
56
|
+
File.open("watermark.jpg", "w") { |f| f.write(wm_bytes) }
|
57
|
+
```
|
58
|
+
|
59
|
+
> Note: Version 1 of the API only supports returning image bytes. Version 2 may host publicly accessible images.
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it ( https://github.com/IPGPTP/live_paper/fork )
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/live_paper.rb
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
require "live_paper/version"
|
2
|
+
require 'base64'
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module LivePaper
|
6
|
+
|
7
|
+
LP_API_HOST="https://www.livepaperapi.com"
|
8
|
+
|
9
|
+
def self.auth(auth_hash)
|
10
|
+
LivePaperSession.new(auth_hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
class LivePaperSession
|
14
|
+
def initialize(auth)
|
15
|
+
authorize(auth)
|
16
|
+
end
|
17
|
+
|
18
|
+
def smart_link(dest, image=nil)
|
19
|
+
uber = {}
|
20
|
+
uber[:short] = shorten dest
|
21
|
+
|
22
|
+
qr_data = qr_bytes dest
|
23
|
+
File.open("uber-qr.png", "w") { |f| f.write(qr_data) }
|
24
|
+
uber[:qr] = "./uber-qr.png"
|
25
|
+
|
26
|
+
if image
|
27
|
+
wm_bytes = watermark_bytes(dest, image)
|
28
|
+
File.open("uber-wm.jpg", "w") { |f| f.write(wm_bytes) }
|
29
|
+
uber[:wm] = 'uber-wm.jpg'
|
30
|
+
end
|
31
|
+
uber
|
32
|
+
end
|
33
|
+
|
34
|
+
def shorten(dest)
|
35
|
+
#returns shortened url
|
36
|
+
trig = trigger "shorturl"
|
37
|
+
puts "Trigger: #{trig}"
|
38
|
+
|
39
|
+
payoff = url_payoff dest
|
40
|
+
puts "Payoff: #{payoff}"
|
41
|
+
|
42
|
+
l = link(trig, payoff)
|
43
|
+
puts "Link: #{l}"
|
44
|
+
|
45
|
+
trig["link"].select { |item| item["rel"] == "shortURL" }.first["href"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def qr_bytes(dest)
|
49
|
+
#returns shortened url
|
50
|
+
trig = trigger "qrcode"
|
51
|
+
puts "Trigger: #{trig}"
|
52
|
+
|
53
|
+
payoff = url_payoff dest
|
54
|
+
puts "Destination: #{dest}"
|
55
|
+
|
56
|
+
l = link(trig, payoff)
|
57
|
+
puts "Link: #{l}"
|
58
|
+
|
59
|
+
img_loc = trig["link"].select { |item| item["rel"] == "image" }.first["href"]
|
60
|
+
|
61
|
+
resp = RestClient.get(img_loc, {Authorization: api_headers[:Authorization], Accept: 'image/png'})
|
62
|
+
resp.body
|
63
|
+
end
|
64
|
+
|
65
|
+
def watermark_bytes(dest, image_url)
|
66
|
+
image = upload_image image_url
|
67
|
+
puts "Source Image: #{image}"
|
68
|
+
|
69
|
+
trig = trigger "watermark", watermark: {imageURL: image, resolution: "75", strength: "10"}
|
70
|
+
puts "\nTrigger: #{trig}"
|
71
|
+
|
72
|
+
payoff = url_payoff dest
|
73
|
+
puts "\nDestination: #{dest}"
|
74
|
+
|
75
|
+
l = link(trig, payoff)
|
76
|
+
puts "\nLink: #{l}"
|
77
|
+
|
78
|
+
img_loc = trig["link"].select { |item| item["rel"] == "image" }.first["href"]
|
79
|
+
resp = RestClient.get(img_loc, Authorization: api_headers[:Authorization])
|
80
|
+
resp.body
|
81
|
+
rescue Exception => e
|
82
|
+
puts "Exception!"
|
83
|
+
puts e.response
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def upload_image(img)
|
88
|
+
puts "Upload Image #{img}"
|
89
|
+
uri='https://storage.livepaperapi.com/objects/files'
|
90
|
+
# return the original img uri if it is LPP storage
|
91
|
+
if img.include? uri
|
92
|
+
return img
|
93
|
+
end
|
94
|
+
begin
|
95
|
+
src_image = RestClient.get(img, Accept: 'image/jpg')
|
96
|
+
response = RestClient.post uri,
|
97
|
+
src_image.body,
|
98
|
+
Authorization: api_headers[:Authorization],
|
99
|
+
content_type: 'image/jpg'
|
100
|
+
response.headers[:location]
|
101
|
+
rescue Exception => e
|
102
|
+
puts "Exception! ******\n#{e}"
|
103
|
+
img
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def trigger(type="shorturl", options={})
|
108
|
+
body = {
|
109
|
+
trigger: {
|
110
|
+
name: "foo",
|
111
|
+
type: type,
|
112
|
+
expiryDate: Time.now + (365 * 24 * 60 *60)
|
113
|
+
}.merge(options)
|
114
|
+
}
|
115
|
+
create_resource('trigger', body)
|
116
|
+
end
|
117
|
+
|
118
|
+
def url_payoff(dest)
|
119
|
+
body = {
|
120
|
+
payoff: {
|
121
|
+
name: "foo",
|
122
|
+
URL: dest
|
123
|
+
}
|
124
|
+
}
|
125
|
+
create_resource('payoff', body)
|
126
|
+
end
|
127
|
+
|
128
|
+
def link(trigger, payoff)
|
129
|
+
body = {
|
130
|
+
link: {
|
131
|
+
name: "mud",
|
132
|
+
payoffId: payoff["id"],
|
133
|
+
triggerId: trigger["id"]
|
134
|
+
}
|
135
|
+
}
|
136
|
+
create_resource('link', body)
|
137
|
+
end
|
138
|
+
|
139
|
+
def authorize(auth)
|
140
|
+
uri = "#{LP_API_HOST}/auth/token"
|
141
|
+
body = "grant_type=client_credentials&scope=all"
|
142
|
+
|
143
|
+
basic_auth = Base64.strict_encode64("#{auth['id']}:#{auth['secret']}")
|
144
|
+
|
145
|
+
begin
|
146
|
+
response = RestClient.post uri, body,
|
147
|
+
:content_type => 'application/x-www-form-urlencoded',
|
148
|
+
Accept: 'application/json',
|
149
|
+
Authorization: "Basic #{basic_auth}"
|
150
|
+
rescue Exception => e
|
151
|
+
puts "Exception!"
|
152
|
+
puts e.response
|
153
|
+
end
|
154
|
+
|
155
|
+
body = JSON.parse(response.body)
|
156
|
+
puts "Token: #{body}"
|
157
|
+
@token=body["accessToken"]
|
158
|
+
end
|
159
|
+
|
160
|
+
def api_headers
|
161
|
+
{Authorization: "Bearer #{@token}",
|
162
|
+
content_type: 'application/json',
|
163
|
+
Accept: 'application/json'
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
def create_resource(resource, body)
|
168
|
+
uri= "https://www.livepaperapi.com/api/v1/#{resource}s"
|
169
|
+
response = RestClient.post uri, body.to_json, api_headers
|
170
|
+
JSON.parse(response.body)[resource]
|
171
|
+
rescue Exception => e
|
172
|
+
puts "Exception!"
|
173
|
+
puts e.response
|
174
|
+
nil
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
data/live_paper.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'live_paper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "live_paper"
|
8
|
+
spec.version = LivePaper::VERSION
|
9
|
+
spec.authors = ["Mike Whitmarsh", "William Hertling"]
|
10
|
+
spec.summary = %q{Ruby interface to the Live Paper service by HP.}
|
11
|
+
spec.description = %q{Ruby interface to use the Live Paper service by HP for creating watermarked images, mobile-friendly shortened URLs, and QR codes.}
|
12
|
+
|
13
|
+
spec.homepage = "https://github.com/IPGPTP/live_paper_rubygem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "rest-client"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: live_paper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Whitmarsh
|
8
|
+
- William Hertling
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.6'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.6'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Ruby interface to use the Live Paper service by HP for creating watermarked
|
57
|
+
images, mobile-friendly shortened URLs, and QR codes.
|
58
|
+
email:
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/live_paper.rb
|
69
|
+
- lib/live_paper/version.rb
|
70
|
+
- live_paper.gemspec
|
71
|
+
homepage: https://github.com/IPGPTP/live_paper_rubygem
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Ruby interface to the Live Paper service by HP.
|
95
|
+
test_files: []
|