resizor 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/resizor/asset.rb +1 -1
- data/lib/resizor/connection.rb +4 -3
- data/lib/resizor/resizor.rb +1 -1
- data/lib/resizor/version.rb +1 -1
- data/test/asset_test.rb +7 -7
- data/test/integration_test.rb +5 -5
- data/test/resizor_test.rb +18 -10
- metadata +4 -4
data/lib/resizor/asset.rb
CHANGED
@@ -8,7 +8,7 @@ module Resizor
|
|
8
8
|
|
9
9
|
def url(options={})
|
10
10
|
options = {:size => '200', :format => 'jpg'}.merge(options)
|
11
|
-
"#{Resizor.api_url}/assets/#{id}.#{options[:format]}?size=#{options[:size]}&token=#{resize_token_for(options)}"
|
11
|
+
"#{Resizor.api_url(true)}/assets/#{id}.#{options[:format]}?size=#{options[:size]}&token=#{resize_token_for(options)}"
|
12
12
|
end
|
13
13
|
|
14
14
|
def resize_token_for(options={})
|
data/lib/resizor/connection.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
module Resizor
|
3
3
|
class Connection
|
4
|
-
attr_accessor :api_host, :api_port, :api_key
|
4
|
+
attr_accessor :api_host, :api_port, :api_key, :use_ssl
|
5
5
|
|
6
6
|
def initialize(options={})
|
7
7
|
@api_host = options[:api_host] || options['api_host'] || 'resizor.com'
|
8
8
|
@api_port = options[:api_port] || options['api_port'] || 80
|
9
9
|
@api_key = options[:api_key] || options['api_key']
|
10
|
+
@use_ssl = options[:use_ssl] || options['use_ssl'] || true
|
10
11
|
end
|
11
12
|
|
12
13
|
def get(request_uri, params={}, append_api_key=true)
|
@@ -32,8 +33,8 @@ module Resizor
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
def api_url
|
36
|
-
@api_url ||= "http://#{@api_host}:#{@api_port}"
|
36
|
+
def api_url(force_http = false)
|
37
|
+
@api_url ||= "#{(@use_ssl == true && force_http == false) ? 'https' : 'http'}://#{@api_host}:#{@api_port}"
|
37
38
|
end
|
38
39
|
|
39
40
|
protected
|
data/lib/resizor/resizor.rb
CHANGED
@@ -6,7 +6,7 @@ module Resizor
|
|
6
6
|
extend self
|
7
7
|
extend Forwardable
|
8
8
|
attr_reader :connection
|
9
|
-
def_delegators :connection, :get, :post, :delete, :api_url, :api_key
|
9
|
+
def_delegators :connection, :get, :post, :delete, :api_url, :api_key, :use_ssl
|
10
10
|
|
11
11
|
def configure
|
12
12
|
yield @connection = Connection.new
|
data/lib/resizor/version.rb
CHANGED
data/test/asset_test.rb
CHANGED
@@ -41,7 +41,7 @@ class AssetTest < Test::Unit::TestCase
|
|
41
41
|
|
42
42
|
context 'on success' do
|
43
43
|
setup do
|
44
|
-
stub_http_request(:post, "resizor.test/assets.json").
|
44
|
+
stub_http_request(:post, "https://resizor.test:80/assets.json").
|
45
45
|
with { |request|
|
46
46
|
request.body.include?("Content-Disposition: form-data; name=\"file\"; filename=\"image.jpg")
|
47
47
|
}.
|
@@ -51,7 +51,7 @@ class AssetTest < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
should 'make create call to Resizor on save with file' do
|
54
|
-
assert_requested(:post, "resizor.test/assets.json",
|
54
|
+
assert_requested(:post, "https://resizor.test:80/assets.json",
|
55
55
|
:times => 1) { |request|
|
56
56
|
request.body.include?("Content-Disposition: form-data; name=\"file\"; filename=\"image.jpg")
|
57
57
|
}
|
@@ -69,7 +69,7 @@ class AssetTest < Test::Unit::TestCase
|
|
69
69
|
|
70
70
|
context 'on failure' do
|
71
71
|
should 'return false' do
|
72
|
-
stub_http_request(:post, "resizor.test/assets.json").to_return(:status => 422)
|
72
|
+
stub_http_request(:post, "https://resizor.test:80/assets.json").to_return(:status => 422)
|
73
73
|
assert !@asset.save_to_resizor
|
74
74
|
end
|
75
75
|
end
|
@@ -77,18 +77,18 @@ class AssetTest < Test::Unit::TestCase
|
|
77
77
|
|
78
78
|
context 'when destroying an asset' do
|
79
79
|
should 'make delete call to Resizor on destroy' do
|
80
|
-
stub_http_request(:delete, "resizor.test/assets/10.json?api_key=test-api-key").to_return(:status => 200)
|
80
|
+
stub_http_request(:delete, "https://resizor.test:80/assets/10.json?api_key=test-api-key").to_return(:status => 200)
|
81
81
|
@asset.destroy
|
82
|
-
assert_requested :delete, "resizor.test/assets/10.json?api_key=test-api-key", :times => 1
|
82
|
+
assert_requested :delete, "https://resizor.test:80/assets/10.json?api_key=test-api-key", :times => 1
|
83
83
|
end
|
84
84
|
|
85
85
|
should 'return true on success' do
|
86
|
-
stub_http_request(:delete, "resizor.test/assets/10.json?api_key=test-api-key").to_return(:status => 200)
|
86
|
+
stub_http_request(:delete, "https://resizor.test:80/assets/10.json?api_key=test-api-key").to_return(:status => 200)
|
87
87
|
assert @asset.destroy
|
88
88
|
end
|
89
89
|
|
90
90
|
should 'return false on failure' do
|
91
|
-
stub_http_request(:delete, "resizor.test/assets/10.json?api_key=test-api-key").to_return(:status => 404)
|
91
|
+
stub_http_request(:delete, "https://resizor.test:80/assets/10.json?api_key=test-api-key").to_return(:status => 404)
|
92
92
|
assert !@asset.destroy
|
93
93
|
end
|
94
94
|
end
|
data/test/integration_test.rb
CHANGED
@@ -24,17 +24,17 @@ class IntegrationTest < Test::Unit::TestCase
|
|
24
24
|
File.open(@image_fixture_path, 'w') {|f| f.write('JPEG data') }
|
25
25
|
@file = File.new(@image_fixture_path, 'rb')
|
26
26
|
@item.image = @file
|
27
|
-
stub_http_request(:post, "resizor.test/assets.json").
|
27
|
+
stub_http_request(:post, "https://resizor.test:80/assets.json").
|
28
28
|
with { |request| request.body.include?("Content-Disposition: form-data; name=\"file\"; filename=\"image.jpg") }.
|
29
29
|
to_return(:status => 201, :body => '{"asset": { "id":1, "name":"i", "extension":"jpg", "mime_type":"image/jpeg", "height":7, "width":8, "file_size":9, "created_at":"2010-10-23T13:07:25Z"}}')
|
30
|
-
stub_http_request(:delete, "resizor.test/assets/1.json?api_key=test-api-key").to_return(:status => 200)
|
30
|
+
stub_http_request(:delete, "https://resizor.test:80/assets/1.json?api_key=test-api-key").to_return(:status => 200)
|
31
31
|
end
|
32
32
|
|
33
33
|
teardown { File.unlink(@image_fixture_path) }
|
34
34
|
|
35
35
|
should 'save attached asset to Resizor on save' do
|
36
36
|
assert @item.save
|
37
|
-
assert_requested(:post, "resizor.test/assets.json", :times => 1) do |request|
|
37
|
+
assert_requested(:post, "https://resizor.test:80/assets.json", :times => 1) do |request|
|
38
38
|
request.body.include?("Content-Disposition: form-data; name=\"file\"; filename=\"image.jpg")
|
39
39
|
end
|
40
40
|
end
|
@@ -75,14 +75,14 @@ class IntegrationTest < Test::Unit::TestCase
|
|
75
75
|
[:image_resizor_id, :image_name, :image_mime_type, :image_size, :image_width, :image_height].each do |_attr|
|
76
76
|
assert_nil @item.send(_attr)
|
77
77
|
end
|
78
|
-
assert_requested :delete, "resizor.test/assets/1.json?api_key=test-api-key", :times => 1
|
78
|
+
assert_requested :delete, "https://resizor.test:80/assets/1.json?api_key=test-api-key", :times => 1
|
79
79
|
end
|
80
80
|
|
81
81
|
should 'delete resizor asset when model instance is deleted' do
|
82
82
|
@item.save
|
83
83
|
@item.reload
|
84
84
|
assert @item.destroy
|
85
|
-
assert_requested :delete, "resizor.test/assets/1.json?api_key=test-api-key", :times => 1
|
85
|
+
assert_requested :delete, "https://resizor.test:80/assets/1.json?api_key=test-api-key", :times => 1
|
86
86
|
end
|
87
87
|
|
88
88
|
end
|
data/test/resizor_test.rb
CHANGED
@@ -16,12 +16,20 @@ class ResizorTest < Test::Unit::TestCase
|
|
16
16
|
|
17
17
|
context 'When Resizor gem has been setup it' do
|
18
18
|
setup { setup_resizor }
|
19
|
-
should '
|
19
|
+
should 'default to use ssl' do
|
20
|
+
assert Resizor.use_ssl
|
21
|
+
end
|
22
|
+
should 'return a API https url when use_ssl is set to true' do
|
23
|
+
assert_equal 'https://resizor.test:80', Resizor.api_url
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'return a API http url when use_ssl is set to false' do
|
27
|
+
Resizor.connection.use_ssl = false
|
20
28
|
assert_equal 'http://resizor.test:80', Resizor.api_url
|
21
29
|
end
|
22
30
|
|
23
31
|
should 'make a GET request to Resizor server with API key' do
|
24
|
-
stub_http_request(:get, "resizor.test:80/assets.json?api_key=test-api-key").to_return(:body => '{"a": "123"}')
|
32
|
+
stub_http_request(:get, "https://resizor.test:80/assets.json?api_key=test-api-key").to_return(:body => '{"a": "123"}')
|
25
33
|
Resizor.get('/assets.json').tap do |r|
|
26
34
|
assert_equal 200, r.code
|
27
35
|
assert_equal Hash['a', '123'], r.body
|
@@ -29,7 +37,7 @@ class ResizorTest < Test::Unit::TestCase
|
|
29
37
|
end
|
30
38
|
|
31
39
|
should 'make a POST request to Resizor server with API key' do
|
32
|
-
stub_http_request(:post, "resizor.test:80/assets.json").with(:body => 'api_key=test-api-key').to_return(:body => '{"a": "123"}', :status => 201)
|
40
|
+
stub_http_request(:post, "https://resizor.test:80/assets.json").with(:body => 'api_key=test-api-key').to_return(:body => '{"a": "123"}', :status => 201)
|
33
41
|
Resizor.post('/assets.json').tap do |r|
|
34
42
|
assert_equal 201, r.code
|
35
43
|
assert_equal Hash['a', '123'], r.body
|
@@ -37,7 +45,7 @@ class ResizorTest < Test::Unit::TestCase
|
|
37
45
|
end
|
38
46
|
|
39
47
|
should 'make a DELETE request to Resizor server with API key' do
|
40
|
-
stub_http_request(:delete, "resizor.test:80/assets/1.json?api_key=test-api-key")
|
48
|
+
stub_http_request(:delete, "https://resizor.test:80/assets/1.json?api_key=test-api-key")
|
41
49
|
Resizor.delete('/assets/1.json').tap do |r|
|
42
50
|
assert_equal 200, r.code
|
43
51
|
assert_equal nil, r.body
|
@@ -45,21 +53,21 @@ class ResizorTest < Test::Unit::TestCase
|
|
45
53
|
end
|
46
54
|
|
47
55
|
should 'add params along with API key when generating GET URL' do
|
48
|
-
stub_http_request(:get, "resizor.test:80/assets.json?api_key=test-api-key&id=1")
|
56
|
+
stub_http_request(:get, "https://resizor.test:80/assets.json?api_key=test-api-key&id=1")
|
49
57
|
Resizor.get('/assets.json', :id => 1)
|
50
|
-
assert_requested :get, "resizor.test:80/assets.json?api_key=test-api-key&id=1"
|
58
|
+
assert_requested :get, "https://resizor.test:80/assets.json?api_key=test-api-key&id=1"
|
51
59
|
end
|
52
60
|
|
53
61
|
should 'add params along with API key when generating POST URL' do
|
54
|
-
stub_http_request(:post, "resizor.test:80/assets.json").with(:body => 'api_key=test-api-key&id=1')
|
62
|
+
stub_http_request(:post, "https://resizor.test:80/assets.json").with(:body => 'api_key=test-api-key&id=1')
|
55
63
|
Resizor.post('/assets.json', :id => 1)
|
56
|
-
assert_requested :post, "resizor.test:80/assets.json"
|
64
|
+
assert_requested :post, "https://resizor.test:80/assets.json"
|
57
65
|
end
|
58
66
|
|
59
67
|
should 'add params along with API key when generating DELETE URL' do
|
60
|
-
stub_http_request(:delete, "resizor.test:80/assets.json?api_key=test-api-key&id=1")
|
68
|
+
stub_http_request(:delete, "https://resizor.test:80/assets.json?api_key=test-api-key&id=1")
|
61
69
|
Resizor.delete('/assets.json', :id => 1)
|
62
|
-
assert_requested :delete, "resizor.test:80/assets.json?api_key=test-api-key&id=1"
|
70
|
+
assert_requested :delete, "https://resizor.test:80/assets.json?api_key=test-api-key&id=1"
|
63
71
|
end
|
64
72
|
|
65
73
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resizor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Winston Design
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-22 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|