imager 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -17
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +79 -79
- data/Rakefile +8 -8
- data/imager.gemspec +24 -24
- data/lib/imager.rb +16 -15
- data/lib/imager/link_helper.rb +8 -0
- data/lib/imager/server_client.rb +4 -4
- data/lib/imager/server_interface.rb +72 -73
- data/lib/imager/version.rb +3 -3
- data/test/test_imager.rb +117 -103
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef11a3f46f143082a1a0f76416edf5fdb8a17d72
|
4
|
+
data.tar.gz: 540cb3e2fa09528f711339ed4ba55dec8e6ba9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fec4251a3c3f023ed8a5eb1c48396b293843025c7175680807b9d3d9c0b1acb885d2e2c450ae95839652bf565277d46fff3d9b5d09cec569899360f7ef8ceb10
|
7
|
+
data.tar.gz: aa98a48c0d0d5d328b057dd3fe34bbdd48b1b320f42499b05e64750b6716562a0bc1ebba6fdd5c5a343437daf9a6916e3779c7693731bdb3bd6343ab678d0173
|
data/.gitignore
CHANGED
@@ -1,17 +1,17 @@
|
|
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
|
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
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in Imager.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in Imager.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2013 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.
|
1
|
+
Copyright (c) 2013 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
CHANGED
@@ -1,80 +1,80 @@
|
|
1
|
-
# Imager
|
2
|
-
|
3
|
-
Use with [ImagerServer](https://github.com/guilherme-otran/ImagerServer), a storange and resizer server for images.
|
4
|
-
Check the test directory for know how the server works.
|
5
|
-
You can save your images in other domain running ImagerServer.
|
6
|
-
|
7
|
-
## Please contribute!
|
8
|
-
A lot of the features are not implemented yet (except for the server)
|
9
|
-
|
10
|
-
1. Fork it
|
11
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
12
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
13
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
14
|
-
5. Create new Pull Request
|
15
|
-
|
16
|
-
## Installation
|
17
|
-
|
18
|
-
Add this line to your application's Gemfile:
|
19
|
-
|
20
|
-
gem 'Imager'
|
21
|
-
|
22
|
-
And then execute:
|
23
|
-
|
24
|
-
$ bundle
|
25
|
-
|
26
|
-
Or install it yourself as:
|
27
|
-
|
28
|
-
$ gem install Imager
|
29
|
-
|
30
|
-
## Usage
|
31
|
-
|
32
|
-
Imager.configure do |c|
|
33
|
-
c.base_uri = "http://files.myserver.com"
|
34
|
-
c.manager_path = "manager"
|
35
|
-
c.collections_path = "images"
|
36
|
-
c.auth_code = ""
|
37
|
-
end
|
38
|
-
|
39
|
-
c.auth_code is the `$YOUR_AUTH_CODE = '';` you setted in the [server] (https://github.com/guilherme-otran/ImagerServer).
|
40
|
-
This is for post and delete authentication (manager).
|
41
|
-
|
42
|
-
### Sending the images
|
43
|
-
Imager::ServerInterface.post("Collection", "Album",
|
44
|
-
|
45
|
-
### Removing the images
|
46
|
-
|
47
|
-
|
48
|
-
### Using the images
|
49
|
-
Imager::LinkHelper.link_for("Collection", "Album", :small)
|
50
|
-
Will return:
|
51
|
-
"http://files.myserver.com/images/collection/album/
|
52
|
-
Since the server ALWAYS save the images as jpg.
|
53
|
-
|
54
|
-
You can use Collection as model name(product) and album as id(1) and get the result:
|
55
|
-
"http://files.myserver.com/images/product/1/
|
56
|
-
Just save as:
|
57
|
-
Imager::ServerInterface.post("product", "1",
|
58
|
-
|
59
|
-
## Notes about saving and sizes
|
60
|
-
Saving first as `"product", "1",
|
61
|
-
|
62
|
-
### Sizes Explain:
|
63
|
-
The server accepts the following combinations:
|
64
|
-
```
|
65
|
-
YourSizeName: { width: 100 } # Will resize (maintein main aspect) the image for 100px of width
|
66
|
-
YourSizeName: { height: 100 } # Will resize (maintein main aspect) the image for 100px of height
|
67
|
-
YourSizeName: { width: 100, height: 150 } # Will resize to fit in 100x150 px
|
68
|
-
YourSizeName: { original: true } # Will save the original size. Don't worry. The server compress to 50% of quality.
|
69
|
-
```
|
70
|
-
You can have many sizes when posting a image:
|
71
|
-
```
|
72
|
-
sizes = [
|
73
|
-
small: { width: 100 }
|
74
|
-
gallery: { height: 300 }
|
75
|
-
mini-home: { width: 50, height: 50 }
|
76
|
-
original: true
|
77
|
-
]
|
78
|
-
```
|
79
|
-
### Compression
|
1
|
+
# Imager
|
2
|
+
|
3
|
+
Use with [ImagerServer](https://github.com/guilherme-otran/ImagerServer), a storange and resizer server for images.
|
4
|
+
Check the test directory for know how the server works.
|
5
|
+
You can save your images in other domain running ImagerServer.
|
6
|
+
|
7
|
+
## Please contribute!
|
8
|
+
A lot of the features are not implemented yet (except for the server)
|
9
|
+
|
10
|
+
1. Fork it
|
11
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
12
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
13
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
14
|
+
5. Create new Pull Request
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'Imager'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install Imager
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Imager.configure do |c|
|
33
|
+
c.base_uri = "http://files.myserver.com"
|
34
|
+
c.manager_path = "manager"
|
35
|
+
c.collections_path = "images"
|
36
|
+
c.auth_code = ""
|
37
|
+
end
|
38
|
+
|
39
|
+
c.auth_code is the `$YOUR_AUTH_CODE = '';` you setted in the [server] (https://github.com/guilherme-otran/ImagerServer).
|
40
|
+
This is for post and delete authentication (manager).
|
41
|
+
|
42
|
+
### Sending the images
|
43
|
+
Imager::ServerInterface.post("Collection", "Album", "test/image.png", small: { width: 100 })
|
44
|
+
|
45
|
+
### Removing the images
|
46
|
+
Imager::ServerInterface.delete("Collection", "Album", "image")
|
47
|
+
|
48
|
+
### Using the images
|
49
|
+
Imager::LinkHelper.link_for("Collection", "Album", "image", :small)
|
50
|
+
Will return:
|
51
|
+
"http://files.myserver.com/images/collection/album/image/small.jpg"
|
52
|
+
Since the server ALWAYS save the images as jpg.
|
53
|
+
|
54
|
+
You can use Collection as model name(product) and album as id(1) and get the result:
|
55
|
+
"http://files.myserver.com/images/product/1/image/small.jpg"
|
56
|
+
Just save as:
|
57
|
+
Imager::ServerInterface.post("product", "1", "test/image.png", small: { width: 100 })
|
58
|
+
|
59
|
+
## Notes about saving and sizes
|
60
|
+
Saving first as `"product", "1", "test/image.png", small: { width: 100 })` and after `"product", "1", "test/otherimage.png", small: { width: 90 })` don't changes the size of image. Beware!
|
61
|
+
|
62
|
+
### Sizes Explain:
|
63
|
+
The server accepts the following combinations:
|
64
|
+
```
|
65
|
+
YourSizeName: { width: 100 } # Will resize (maintein main aspect) the image for 100px of width
|
66
|
+
YourSizeName: { height: 100 } # Will resize (maintein main aspect) the image for 100px of height
|
67
|
+
YourSizeName: { width: 100, height: 150 } # Will resize to fit in 100x150 px
|
68
|
+
YourSizeName: { original: true } # Will save the original size. Don't worry. The server compress to 50% of quality.
|
69
|
+
```
|
70
|
+
You can have many sizes when posting a image:
|
71
|
+
```
|
72
|
+
sizes = [
|
73
|
+
small: { width: 100 }
|
74
|
+
gallery: { height: 300 }
|
75
|
+
mini-home: { width: 50, height: 50 }
|
76
|
+
original: true
|
77
|
+
]
|
78
|
+
```
|
79
|
+
### Compression
|
80
80
|
The images always are compressed to 70%. Except for the original size (50%).
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require 'rake/testtask'
|
3
|
-
|
4
|
-
Rake::TestTask.new do |t|
|
5
|
-
t.libs << 'test'
|
6
|
-
end
|
7
|
-
|
8
|
-
desc "Run tests"
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Run tests"
|
9
9
|
task :default => :test
|
data/imager.gemspec
CHANGED
@@ -1,24 +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 'imager/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "imager"
|
8
|
-
spec.version = Imager::VERSION
|
9
|
-
spec.authors = ["Guilherme Otranto"]
|
10
|
-
spec.email = ["guilherme_otran@hotmail.com"]
|
11
|
-
spec.description = %q{A remote storange and resizer client for images.}
|
12
|
-
spec.summary = %q{Imager Client API}
|
13
|
-
spec.homepage = "https://github.com/guilherme-otran/Imager"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
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 "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
spec.add_dependency "httmultiparty"
|
24
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'imager/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "imager"
|
8
|
+
spec.version = Imager::VERSION
|
9
|
+
spec.authors = ["Guilherme Otranto"]
|
10
|
+
spec.email = ["guilherme_otran@hotmail.com"]
|
11
|
+
spec.description = %q{A remote storange and resizer client for images.}
|
12
|
+
spec.summary = %q{Imager Client API}
|
13
|
+
spec.homepage = "https://github.com/guilherme-otran/Imager"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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 "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "httmultiparty"
|
24
|
+
end
|
data/lib/imager.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
require "imager/version"
|
2
|
-
require "imager/server_client"
|
3
|
-
require "imager/server_interface"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
require "imager/version"
|
2
|
+
require "imager/server_client"
|
3
|
+
require "imager/server_interface"
|
4
|
+
require "imager/link_helper"
|
5
|
+
|
6
|
+
module Imager
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :manager_path, :collection_path, :auth_code, :base_uri
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/imager/server_client.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'httmultiparty'
|
2
|
-
|
3
|
-
class ServerClient
|
4
|
-
include HTTMultiParty
|
1
|
+
require 'httmultiparty'
|
2
|
+
|
3
|
+
class ServerClient
|
4
|
+
include HTTMultiParty
|
5
5
|
end
|
@@ -1,74 +1,73 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
query =
|
9
|
-
query[:
|
10
|
-
query[:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
query[:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
query =
|
22
|
-
query[:
|
23
|
-
query[:
|
24
|
-
query[:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
query_hash[:
|
56
|
-
query_hash[:
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
1
|
+
require 'openssl'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Imager
|
5
|
+
class ServerInterface
|
6
|
+
def self.post(collection, album, file, sizes)
|
7
|
+
query = {}
|
8
|
+
query[:collection] = collection
|
9
|
+
query[:album] = album
|
10
|
+
query[:sizes] = sizes
|
11
|
+
|
12
|
+
auth = auth_token(query, file)
|
13
|
+
query[:file] = File.new(file)
|
14
|
+
query[:auth] = auth
|
15
|
+
|
16
|
+
return parse(client.post('/post.php', { query: query }))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.delete(collection, album, file_id)
|
20
|
+
query = {}
|
21
|
+
query[:collection] = collection
|
22
|
+
query[:album] = album
|
23
|
+
query[:file_id] = file_id
|
24
|
+
query[:auth] = auth_token(query)
|
25
|
+
|
26
|
+
return parse(client.post('/delete.php', { query: query }))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.client
|
30
|
+
unless ServerClient.base_uri
|
31
|
+
ServerClient.base_uri Imager.base_uri + '/' + Imager.manager_path
|
32
|
+
end
|
33
|
+
ServerClient
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def self.parse(response)
|
39
|
+
case response.code
|
40
|
+
when 200..299
|
41
|
+
return true
|
42
|
+
when 400
|
43
|
+
raise ArgumentError, response.body, caller
|
44
|
+
when 401
|
45
|
+
raise Error, "Authentication failed."
|
46
|
+
else
|
47
|
+
raise Error, "The server returned an error."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.auth_token(query, file=nil)
|
52
|
+
query_hash = query.clone
|
53
|
+
if file
|
54
|
+
query_hash[:file_md5] = Digest::MD5.file(file)
|
55
|
+
query_hash[:file_sha1] = Digest::SHA1.file(file)
|
56
|
+
query_hash[:file_name] = File.basename(file)
|
57
|
+
end
|
58
|
+
|
59
|
+
query_hash = to_query(query_hash)
|
60
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('md5'), Imager.auth_code, query_hash)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.to_query(hash, namespace=false)
|
64
|
+
if(hash.is_a? Hash)
|
65
|
+
hash.collect do |k, v|
|
66
|
+
to_query(v, namespace ? "#{namespace}[#{k}]" : k)
|
67
|
+
end.join '&'
|
68
|
+
else
|
69
|
+
CGI.escape(namespace.to_s) + "=" + CGI.escape(hash.to_s)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
74
73
|
end
|
data/lib/imager/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Imager
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
1
|
+
module Imager
|
2
|
+
VERSION = "0.0.2"
|
3
|
+
end
|
data/test/test_imager.rb
CHANGED
@@ -1,104 +1,118 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'imager'
|
3
|
-
|
4
|
-
|
5
|
-
class ImagerTest < Test::Unit::TestCase
|
6
|
-
def your_base_uri; "http://
|
7
|
-
def your_manager_path; "manager"; end;
|
8
|
-
def your_collections_path; "images"; end;
|
9
|
-
def your_auth_code; ""; end;
|
10
|
-
|
11
|
-
def test_configure
|
12
|
-
Imager.configure do |c|
|
13
|
-
assert_equal c, Imager
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_set_server_uri
|
18
|
-
Imager.configure do |c|
|
19
|
-
c.base_uri = your_base_uri
|
20
|
-
end
|
21
|
-
|
22
|
-
assert_equal your_base_uri, Imager.base_uri
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_set_manager_path
|
26
|
-
Imager.configure do |c|
|
27
|
-
c.manager_path = your_manager_path
|
28
|
-
end
|
29
|
-
|
30
|
-
assert_equal your_manager_path, Imager.manager_path
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_set_collection_path
|
34
|
-
Imager.configure do |c|
|
35
|
-
c.collection_path = your_collections_path
|
36
|
-
end
|
37
|
-
|
38
|
-
assert_equal your_collections_path, Imager.collection_path
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_set_auth_code
|
42
|
-
Imager.configure do |c|
|
43
|
-
c.auth_code = your_auth_code
|
44
|
-
end
|
45
|
-
|
46
|
-
assert_equal your_auth_code, Imager.auth_code
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_valid_post_image
|
50
|
-
Imager.configure do |c|
|
51
|
-
c.base_uri = your_base_uri
|
52
|
-
c.auth_code = your_auth_code
|
53
|
-
c.collection_path = your_collections_path
|
54
|
-
c.manager_path = your_manager_path
|
55
|
-
end
|
56
|
-
|
57
|
-
response = Imager::ServerInterface.post("testcollection", "1", "test/image.jpg", small: { width: 100})
|
58
|
-
assert_equal true, response
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_invalid_post_image
|
62
|
-
response = true
|
63
|
-
begin
|
64
|
-
Imager.configure do |c|
|
65
|
-
c.base_uri = your_base_uri
|
66
|
-
c.auth_code = your_auth_code
|
67
|
-
c.collection_path = your_collections_path
|
68
|
-
c.manager_path = your_manager_path
|
69
|
-
end
|
70
|
-
Imager::ServerInterface.post("", "",
|
71
|
-
rescue
|
72
|
-
response = false
|
73
|
-
end
|
74
|
-
assert_equal false, response
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_valid_delete_image
|
78
|
-
Imager.configure do |c|
|
79
|
-
c.base_uri = your_base_uri
|
80
|
-
c.auth_code = your_auth_code
|
81
|
-
c.collection_path = your_collections_path
|
82
|
-
c.manager_path = your_manager_path
|
83
|
-
end
|
84
|
-
|
85
|
-
response = Imager::ServerInterface.delete("testcollection", "1", "image")
|
86
|
-
assert_equal true, response
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_invalid_delete_image
|
90
|
-
response = true
|
91
|
-
begin
|
92
|
-
Imager.configure do |c|
|
93
|
-
c.base_uri = your_base_uri
|
94
|
-
c.auth_code = your_auth_code
|
95
|
-
c.collection_path = your_collections_path
|
96
|
-
c.manager_path = your_manager_path
|
97
|
-
end
|
98
|
-
Imager::ServerInterface.delete("testcollection", "1", "non_existing_image")
|
99
|
-
rescue
|
100
|
-
response = false
|
101
|
-
end
|
102
|
-
assert_equal false, response
|
103
|
-
end
|
1
|
+
require 'test/unit'
|
2
|
+
require 'imager'
|
3
|
+
|
4
|
+
|
5
|
+
class ImagerTest < Test::Unit::TestCase
|
6
|
+
def your_base_uri; "http://dev.local/imagerserver/"; end;
|
7
|
+
def your_manager_path; "manager"; end;
|
8
|
+
def your_collections_path; "images"; end;
|
9
|
+
def your_auth_code; "f8cecac2459d83eb9c8c703663e349ddbeb82a76230c7ca5ffc8434cfaab"; end;
|
10
|
+
|
11
|
+
def test_configure
|
12
|
+
Imager.configure do |c|
|
13
|
+
assert_equal c, Imager
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_set_server_uri
|
18
|
+
Imager.configure do |c|
|
19
|
+
c.base_uri = your_base_uri
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal your_base_uri, Imager.base_uri
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_set_manager_path
|
26
|
+
Imager.configure do |c|
|
27
|
+
c.manager_path = your_manager_path
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_equal your_manager_path, Imager.manager_path
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_set_collection_path
|
34
|
+
Imager.configure do |c|
|
35
|
+
c.collection_path = your_collections_path
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal your_collections_path, Imager.collection_path
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_set_auth_code
|
42
|
+
Imager.configure do |c|
|
43
|
+
c.auth_code = your_auth_code
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_equal your_auth_code, Imager.auth_code
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_valid_post_image
|
50
|
+
Imager.configure do |c|
|
51
|
+
c.base_uri = your_base_uri
|
52
|
+
c.auth_code = your_auth_code
|
53
|
+
c.collection_path = your_collections_path
|
54
|
+
c.manager_path = your_manager_path
|
55
|
+
end
|
56
|
+
|
57
|
+
response = Imager::ServerInterface.post("testcollection", "1", "test/image.jpg", small: { width: 100 })
|
58
|
+
assert_equal true, response
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_invalid_post_image
|
62
|
+
response = true
|
63
|
+
begin
|
64
|
+
Imager.configure do |c|
|
65
|
+
c.base_uri = your_base_uri
|
66
|
+
c.auth_code = your_auth_code
|
67
|
+
c.collection_path = your_collections_path
|
68
|
+
c.manager_path = your_manager_path
|
69
|
+
end
|
70
|
+
Imager::ServerInterface.post("", "", "test/image.jpg", small: { width: 100 })
|
71
|
+
rescue
|
72
|
+
response = false
|
73
|
+
end
|
74
|
+
assert_equal false, response
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_valid_delete_image
|
78
|
+
Imager.configure do |c|
|
79
|
+
c.base_uri = your_base_uri
|
80
|
+
c.auth_code = your_auth_code
|
81
|
+
c.collection_path = your_collections_path
|
82
|
+
c.manager_path = your_manager_path
|
83
|
+
end
|
84
|
+
|
85
|
+
response = Imager::ServerInterface.delete("testcollection", "1", "image")
|
86
|
+
assert_equal true, response
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_invalid_delete_image
|
90
|
+
response = true
|
91
|
+
begin
|
92
|
+
Imager.configure do |c|
|
93
|
+
c.base_uri = your_base_uri
|
94
|
+
c.auth_code = your_auth_code
|
95
|
+
c.collection_path = your_collections_path
|
96
|
+
c.manager_path = your_manager_path
|
97
|
+
end
|
98
|
+
Imager::ServerInterface.delete("testcollection", "1", "non_existing_image")
|
99
|
+
rescue
|
100
|
+
response = false
|
101
|
+
end
|
102
|
+
assert_equal false, response
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_link_helper
|
106
|
+
Imager.configure do |c|
|
107
|
+
c.base_uri = your_base_uri
|
108
|
+
c.auth_code = your_auth_code
|
109
|
+
c.collection_path = your_collections_path
|
110
|
+
c.manager_path = your_manager_path
|
111
|
+
end
|
112
|
+
|
113
|
+
result = Imager::LinkHelper.link_for("testcollection", "1", "image", :small)
|
114
|
+
should_be = "#{your_base_uri}#{your_collections_path}/testcollection/1/image/small.jpg"
|
115
|
+
|
116
|
+
assert_equal should_be, result
|
117
|
+
end
|
104
118
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Otranto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- imager.gemspec
|
68
68
|
- lib/imager.rb
|
69
|
+
- lib/imager/link_helper.rb
|
69
70
|
- lib/imager/server_client.rb
|
70
71
|
- lib/imager/server_interface.rb
|
71
72
|
- lib/imager/version.rb
|