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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56ce5179ec4ee910013a72451b268ee141a7bb07
4
- data.tar.gz: 62092eb90e5d9d6ab5e3675ec9aeabcc4de44889
3
+ metadata.gz: ef11a3f46f143082a1a0f76416edf5fdb8a17d72
4
+ data.tar.gz: 540cb3e2fa09528f711339ed4ba55dec8e6ba9a7
5
5
  SHA512:
6
- metadata.gz: 26ebfba5221636a4bbb8ea45334d568a441fcd0e85f6aed87354ca8ab838cee7a7e4bcf6173b870101efac83627d141fe471fe226632611919ef5cab02a886e9
7
- data.tar.gz: c584666fbacb84d2ba4e39c806bc29f35537cf6261749e0731e3f3859a5a09f71402d053c289b901de0ff3e4405d8e31f74b70cee6f8ecd0573a7b1b3b161eaf
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
@@ -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", File.new("test/test_image.png"), small: { width: 100})
44
-
45
- ### Removing the images
46
- Not yet.
47
-
48
- ### Using the images
49
- Imager::LinkHelper.link_for("Collection", "Album", :small)
50
- Will return:
51
- "http://files.myserver.com/images/collection/album/test_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/test_image/small.jpg"
56
- Just save as:
57
- Imager::ServerInterface.post("product", "1", File.new("test/test_image.png"), small: { width: 100})
58
-
59
- ## Notes about saving and sizes
60
- Saving first as `"product", "1", File.new("test/test_image.png"), small: { width: 100})` and after `"product", "1", File.new("test/other_image.png"), small: { width: 90})` don't changes the size of test_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
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
@@ -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
@@ -1,15 +1,16 @@
1
- require "imager/version"
2
- require "imager/server_client"
3
- require "imager/server_interface"
4
-
5
- module Imager
6
-
7
- class << self
8
- attr_accessor :manager_path, :collection_path, :auth_code, :base_uri
9
-
10
- def configure
11
- yield self
12
- end
13
- end
14
-
15
- end
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
@@ -0,0 +1,8 @@
1
+ module Imager
2
+ class LinkHelper
3
+ def self.link_for(collection, album, image, size)
4
+ size = size.to_s
5
+ "#{Imager.base_uri}#{Imager.collection_path}/#{collection}/#{album}/#{image}/#{size}.jpg"
6
+ end
7
+ end
8
+ end
@@ -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 'debugger'
2
- require 'openssl'
3
- require 'cgi'
4
-
5
- module Imager
6
- class ServerInterface
7
- def self.post(collection, album, file, sizes)
8
- query = {}
9
- query[:collection] = collection
10
- query[:album] = album
11
- query[:sizes] = sizes
12
-
13
- auth = auth_token(query, file)
14
- query[:file] = File.new(file)
15
- query[:auth] = auth
16
-
17
- return parse(client.post('/post.php', { query: query }))
18
- end
19
-
20
- def self.delete(collection, album, file_id)
21
- query = {}
22
- query[:collection] = collection
23
- query[:album] = album
24
- query[:file_id] = file_id
25
- query[:auth] = auth_token(query)
26
-
27
- return parse(client.post('/delete.php', { query: query }))
28
- end
29
-
30
- def self.client
31
- unless ServerClient.base_uri
32
- ServerClient.base_uri Imager.base_uri + '/' + Imager.manager_path
33
- end
34
- ServerClient
35
- end
36
-
37
- private
38
-
39
- def self.parse(response)
40
- case response.code
41
- when 200..299
42
- return true
43
- when 400
44
- raise ArgumentError, response.body, caller
45
- when 401
46
- raise Error, "Authentication failed."
47
- else
48
- raise Error, "The server returned an error."
49
- end
50
- end
51
-
52
- def self.auth_token(query, file=nil)
53
- query_hash = query.clone
54
- if file
55
- query_hash[:file_md5] = Digest::MD5.file(file)
56
- query_hash[:file_sha1] = Digest::SHA1.file(file)
57
- query_hash[:file_name] = File.basename(file)
58
- end
59
-
60
- query_hash = to_query(query_hash)
61
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('md5'), Imager.auth_code, query_hash)
62
- end
63
-
64
- def self.to_query(hash, namespace=false)
65
- if(hash.is_a? Hash)
66
- hash.collect do |k, v|
67
- to_query(v, namespace ? "#{namespace}[#{k}]" : k)
68
- end.join '&'
69
- else
70
- CGI.escape(namespace.to_s) + "=" + CGI.escape(hash.to_s)
71
- end
72
- end
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
@@ -1,3 +1,3 @@
1
- module Imager
2
- VERSION = "0.0.1"
3
- end
1
+ module Imager
2
+ VERSION = "0.0.2"
3
+ end
@@ -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://localhost/projects/imager_server"; end;
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("", "", File.new("test/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
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.1
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-05-30 00:00:00.000000000 Z
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