pilbox 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +24 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/bin/console +13 -0
- data/bin/setup +7 -0
- data/lib/pilbox.rb +56 -0
- data/lib/pilbox/version.rb +3 -0
- data/pilbox.gemspec +34 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 12b3de46a2ffae7aab7700e96289f01ae385230b
|
4
|
+
data.tar.gz: 4848979c4b5cfaa7b5428a7637af38253b0b0736
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5bc4e243951a7bd9f5dfe2b8e8e830ecd6f1b2618e2430660c6efc61143863cd6cea606065db0abdf66b5d8d92dffbf254717ccf9a5fd26a682bf0759dc91ef8
|
7
|
+
data.tar.gz: 4bc452d9cd77f72bf671af18e19c1b84f02f54f74f3680a0e5d1d88b9d83181aa81ab537de49e8ef5d8f69ca4b8d2e887e94fec43f8a0a20556ce904d3fd09c2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Justin Workman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
23
|
+
Note that this software is not affiliated with Pilbox, and Pilbox may come with a
|
24
|
+
different license and different authors.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
Pilbox Ruby Gem
|
2
|
+
===============
|
3
|
+
|
4
|
+
This is a Ruby utility for generating request URLs for [Pilbox][0], the image resizing service. This library was made for my personal use and is not affiliated with the Pilbox project.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "pilbox"
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```shell
|
24
|
+
$ gem install pilbox
|
25
|
+
```
|
26
|
+
|
27
|
+
Usage
|
28
|
+
-----
|
29
|
+
|
30
|
+
It's quite straightfoward: simply call `Pilbox.thumb_uri(base_uri, params)`, where the `base_uri` is a string or `URI` pointing to the Pilbox server endpoint, and `params` contains the query params to be passed to the Pilbox request.
|
31
|
+
|
32
|
+
Basic example, generating a thumbnail with a width of 50:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Pilbox.thumb_uri("https://mypilboxserver.example.com", "url" => "https://example.org/funnykittens.jpg", "w" => 50)
|
36
|
+
```
|
37
|
+
|
38
|
+
You will get back a URI suitable for generating a thumbnail on Pilbox. For flexibility, the result will be a `URI` object, which you can easily turn into a string by calling `#to_s` on it.
|
39
|
+
|
40
|
+
You should always pass at least the `"url"` param. If you pass a `client_key` param to `Pilbox#thumb_uri`, a secure signature (compatible with Pilbox) will be generated and added to the resulting URI. The `client_key` param won't be added to the HTTP request, it will remain secret. All other params will pass through to Pilbox. For more information on available params, refer to the documentation on the [Pilbox][0] project.
|
41
|
+
|
42
|
+
The following is a more complete example, which will return a signed URI ready to send as a secure Pilbox request:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
base_uri = ENV["PILBOX_HOST"] # e.g. https://mypilboxserver.example.com
|
46
|
+
thumb_params = {
|
47
|
+
url: "http://www.example.org/happypanda.png",
|
48
|
+
op: "resize,rotate",
|
49
|
+
w: 150,
|
50
|
+
h: 150,
|
51
|
+
deg: "auto",
|
52
|
+
client_name: ENV["PILBOX_CLIENY_NAME"],
|
53
|
+
client_key: ENV["PILBOX_CLIENT_KEY"]
|
54
|
+
}
|
55
|
+
puts Pilbox.thumb_uri(base_uri, thumb_params).to_s
|
56
|
+
```
|
57
|
+
|
58
|
+
If you have an existing URI that already includes Pilbox parameters, and you just want to add the proper signature, you can do that too:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
unsigned_url = "http://mypilboxserver.example.org?url=http%3A%2F%2Fwww.example.com%2Fimage.jpg&w=250&h=80"
|
62
|
+
signed_url = Pilbox.thumb_uri(unsigned_url, client_name: "...", client_key: "...").to_s
|
63
|
+
```
|
64
|
+
|
65
|
+
Care has been taken to make this utility as simple to use as possible. If it behaves unexpectedly for you, please report it on the [issue tracker](https://github.com/xtagon/pilbox-ruby/issues).
|
66
|
+
|
67
|
+
Author
|
68
|
+
------
|
69
|
+
|
70
|
+
[Justin Workman](mailto:xtagon@gmail.com)
|
71
|
+
|
72
|
+
Happy hacking!
|
73
|
+
|
74
|
+
|
75
|
+
[0]: https://github.com/agschwender/pilbox
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pilbox"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
11
|
+
|
12
|
+
#require "irb"
|
13
|
+
#IRB.start
|
data/bin/setup
ADDED
data/lib/pilbox.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "pilbox/version"
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "openssl"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
module Pilbox
|
8
|
+
def self.thumb_uri(base_uri, params = {})
|
9
|
+
# Accept a URI, or a string representing what the URI should be. This
|
10
|
+
# can simple be used as the base host URI.
|
11
|
+
uri = base_uri.is_a?(URI) ? base_uri.dup : URI.parse(base_uri)
|
12
|
+
|
13
|
+
if params.empty?
|
14
|
+
return uri
|
15
|
+
end
|
16
|
+
|
17
|
+
params = if params.is_a?(Hash)
|
18
|
+
params.dup
|
19
|
+
else
|
20
|
+
# CGI.parse results in key/value pairs where the value is an *array*
|
21
|
+
# of values, possibly more than one. We only care about the first, if
|
22
|
+
# there is more than one.
|
23
|
+
CGI.parse(params.to_s).reduce({}) do |hash, (key, value)|
|
24
|
+
hash.merge(key => value.first)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Normalize param keys to strings
|
29
|
+
params = params.reduce({}) do |hash, (key, value)|
|
30
|
+
hash.merge(key.to_s => value)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Client Key is supposed to be a secret...don't let it be merged into
|
34
|
+
# the URI's query params directly.
|
35
|
+
client_key = params.delete("client_key")
|
36
|
+
|
37
|
+
original_params = CGI.parse(uri.query || "")
|
38
|
+
uri.query = URI.encode_www_form(original_params.merge(params))
|
39
|
+
|
40
|
+
if client_key
|
41
|
+
signature = generate_signature(client_key, uri.query)
|
42
|
+
uri.query << "&" << URI.encode_www_form({"sig" => signature})
|
43
|
+
end
|
44
|
+
|
45
|
+
return uri
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def self.generate_signature(client_key, query_string)
|
51
|
+
OpenSSL::HMAC.hexdigest(
|
52
|
+
OpenSSL::Digest.new("sha1"),
|
53
|
+
client_key, query_string
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
data/pilbox.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "pilbox/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pilbox"
|
8
|
+
spec.version = Pilbox::VERSION
|
9
|
+
spec.authors = ["Justin Workman"]
|
10
|
+
spec.email = ["xtagon@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "An URL-signing utility for Pilbox, the image resizing service."
|
13
|
+
#spec.description = ""
|
14
|
+
#spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
#
|
20
|
+
#if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
#else
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
#end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = %w(lib)
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pilbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Workman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- xtagon@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".ruby-version"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/pilbox.rb
|
73
|
+
- lib/pilbox/version.rb
|
74
|
+
- pilbox.gemspec
|
75
|
+
homepage:
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: An URL-signing utility for Pilbox, the image resizing service.
|
99
|
+
test_files: []
|
100
|
+
has_rdoc:
|