imager 0.0.3 → 0.0.4

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: d30bc7d9057f78efe90d633324e31852c4c5ca60
4
- data.tar.gz: e7dbe1bf69a88703cde2c1e672c396543ba48ba7
3
+ metadata.gz: b207cc06a420c94e94e3dba7ba472d951071f02d
4
+ data.tar.gz: 6ce99f02a7183309cd0631debf8229caf1562f1a
5
5
  SHA512:
6
- metadata.gz: e2d3700bf32ccbc0d3e930b8b9472f586b8a909652eff5d5f3f5dd327faf335dcc87bf47243facd0f783595da51210af4b3437da777c03b2ac7aee18ba88c06b
7
- data.tar.gz: 2f5a859eb4cb534df31357ddf22510f8e8001f5d6735ef7010bb882851359224862843a731d14c3a02c027971054bc04152c31a25219625a46fff92de4e1f976
6
+ metadata.gz: 8e60bf378182a02855a9efd9b413b2df993c35f988a18858cbd4dfc4b358c180f7158787c3fb8b0313afbd68c1fcbc25ffd306ed10c6d71fbe169339b1ef609d
7
+ data.tar.gz: f290efc196700897687f378bce2c20171817d2d3a58a86334ed4a36fe5c3a62c02fad672e77f6d6d2947899fc13c1c0de87bbc494c45a75633443eacbcdc70f2
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ script: bundle exec rspec spec
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx-19mode
data/README.md CHANGED
@@ -4,6 +4,9 @@ Use with [ImagerServer](https://github.com/guilherme-otran/ImagerServer), a stor
4
4
  Check the test directory for know how the server works.
5
5
  You can save your images in other domain running ImagerServer.
6
6
 
7
+ [![Build Status](https://travis-ci.org/guilherme-otran/Imager.png?branch=master)](https://travis-ci.org/guilherme-otran/Imager)
8
+ [![Dependency Status](https://gemnasium.com/guilherme-otran/Imager.png)](https://gemnasium.com/guilherme-otran/Imager)
9
+
7
10
  ## Please contribute!
8
11
  A lot of the features are not implemented yet (except for the server)
9
12
 
@@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "vcr"
26
+ spec.add_development_dependency "turn"
24
27
  spec.add_dependency "httmultiparty", "~> 0.3.10"
25
28
  spec.add_dependency "json"
26
29
  end
@@ -1,5 +1,7 @@
1
1
  require 'httmultiparty'
2
2
 
3
- class ServerClient
4
- include HTTMultiParty
3
+ module Imager
4
+ class ServerClient
5
+ include HTTMultiParty
6
+ end
5
7
  end
@@ -28,10 +28,10 @@ module Imager
28
28
  end
29
29
 
30
30
  def self.client
31
- unless ServerClient.base_uri
32
- ServerClient.base_uri Imager.base_uri + '/' + Imager.manager_path
31
+ unless Imager::ServerClient.base_uri
32
+ Imager::ServerClient.base_uri Imager.base_uri + '/' + Imager.manager_path
33
33
  end
34
- ServerClient
34
+ Imager::ServerClient
35
35
  end
36
36
 
37
37
  private
@@ -1,3 +1,3 @@
1
1
  module Imager
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.local/imagerserver/manager/post.php
6
+ body:
7
+ encoding: ASCII-8BIT
8
+ string: !binary |-
9
+ BAhbClsHSSIPY29sbGVjdGlvbgY6BkVGSSIABjsAVFsHSSIKYWxidW0GOwBG
10
+ SSIABjsAVFsHSSIXc2l6ZXNbc2l6ZV1bd2lkdGhdBjsARmlpWwdJIglmaWxl
11
+ BjsARm86EUZha2VVcGxvYWRJTwg6F0BvcmlnaW5hbF9maWxlbmFtZUkiDmlt
12
+ YWdlLmpwZwY7AFQ6EkBjb250ZW50X3R5cGVJIh1hcHBsaWNhdGlvbi9vY3Rl
13
+ dC1zdHJlYW0GOwBUOgpAYm9keUkiApwB/9j/4AAQSkZJRgABAQEASABIAAD/
14
+ 2wBDAAEBAQEBAQEBAQEBAQECAgMCAgICAgQDAwIDBQQFBQUEBAQFBgcGBQUH
15
+ BgQEBgkGBwgICAgIBQYJCgkICgcICAj/2wBDAQEBAQICAgQCAgQIBQQFCAgI
16
+ CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
17
+ CAj/wAARCAMABAADASIAAhEBAxEB/8QAHwAAAAYDAQEBAAAAAAAAAAAABAUG
18
+ BwgJAgMKAQAL/8QAThAAAQMCBQIEAwYEBAQFAgENAQIDBAURAAYHEiETMQgi
19
+ QVEUYXEJFSMygZFCUqGxFjNiwQokctEXQ4Lh8JLxJTRTY6IYJrInNURzwqP/
20
+ xAAcAQABBQEBAQAAAAAAAAAAAAAFAQIDBAYABwj/xAA5EQABAwMDAgUCBQME
21
+ AwEBAQEBAgMRAAQhBRIxQVEGEyJhcYGRFDKhscHR4fAVI0LxBxZSMyQlQ//a
22
+ AAwDAQACEQMRAD8A468keHnMOpGaP/BvIFWydXM4VgY6DWVuY29kaW5nIgpD
23
+ UDg1MFsHSSIJYXV0aAY7AEYiJTYzY2IxNDE5YjlkNmNlNTVkNmFmNDEwMmRi
24
+ OGQzNjc5
25
+ headers:
26
+ Content-Type:
27
+ - multipart/form-data; boundary=-----------RubyMultipartPost
28
+ Content-Length:
29
+ - '382016'
30
+ response:
31
+ status:
32
+ code: 400
33
+ message: Bad Request
34
+ headers:
35
+ Date:
36
+ - Mon, 03 Jun 2013 03:28:24 GMT
37
+ Server:
38
+ - Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.13
39
+ X-Powered-By:
40
+ - PHP/5.4.13
41
+ Connection:
42
+ - close
43
+ Content-Type:
44
+ - text/html; charset=UTF-8
45
+ Content-Length:
46
+ - '18'
47
+ body:
48
+ encoding: UTF-8
49
+ string: Invalid collection
50
+ http_version:
51
+ recorded_at: Mon, 03 Jun 2013 03:28:24 GMT
52
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,32 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.local/imagerserver/manager/delete.php
6
+ body:
7
+ encoding: UTF-8
8
+ string: collection=test&album=1&file_id=non_existing_image&auth=89a623c5f2557f09332c90cfddc4725a
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 400
13
+ message: Bad Request
14
+ headers:
15
+ Date:
16
+ - Mon, 03 Jun 2013 03:08:22 GMT
17
+ Server:
18
+ - Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.13
19
+ X-Powered-By:
20
+ - PHP/5.4.13
21
+ Connection:
22
+ - close
23
+ Content-Type:
24
+ - text/html; charset=UTF-8
25
+ Content-Length:
26
+ - '16'
27
+ body:
28
+ encoding: UTF-8
29
+ string: Invalid file_id.
30
+ http_version:
31
+ recorded_at: Mon, 03 Jun 2013 03:08:22 GMT
32
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.local/imagerserver/manager/delete.php
6
+ body:
7
+ encoding: UTF-8
8
+ string: collection=test&album=1&file_id=image&auth=3ce2c42fcd1ad5ae91e58586fa49aed3
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 204
13
+ message: No Content
14
+ headers:
15
+ Date:
16
+ - Mon, 03 Jun 2013 03:28:24 GMT
17
+ Server:
18
+ - Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.13
19
+ X-Powered-By:
20
+ - PHP/5.4.13
21
+ Content-Type:
22
+ - text/html; charset=UTF-8
23
+ Content-Length:
24
+ - '0'
25
+ body:
26
+ encoding: UTF-8
27
+ string: ''
28
+ http_version:
29
+ recorded_at: Mon, 03 Jun 2013 03:28:24 GMT
30
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://dev.local/imagerserver/manager/post.php
6
+ body:
7
+ encoding: ASCII-8BIT
8
+ string: !binary |-
9
+ BAhbClsHSSIPY29sbGVjdGlvbgY6BkVGSSIJdGVzdAY7AFRbB0kiCmFsYnVt
10
+ BjsARkkiBjEGOwBUWwdJIhhzaXplc1tzbWFsbF1bd2lkdGhdBjsARmlpWwdJ
11
+ IglmaWxlBjsARm86EUZha2VVcGxvYWRJTwg6F0BvcmlnaW5hbF9maWxlbmFt
12
+ ZUkiDmltYWdlLmpwZwY7AFQ6EkBjb250ZW50X3R5cGVJIh1hcHBsaWNhdGlv
13
+ bi9vY3RldC1zdHJlYW0GOwBUOgpAYm9keUkiApwB/9j/4AAQSkZJRgABAQEA
14
+ SABIAAD/2wBDAAEBAQEBAQEBAQEBAQECAgMCAgICAgQDAwIDBQQFBQUEBAQF
15
+ BgcGBQUHBgQEBgkGBwgICAgIBQYJCgkICgcICAj/2wBDAQEBAQICAgQCAgQI
16
+ BQQFCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
17
+ CAgICAgICAj/wAARCAMABAADASIAAhEBAxEB/8QAHwAAAAYDAQEBAAAAAAAA
18
+ AAAABAUGBwgJAgMKAQAL/8QAThAAAQMCBQIEAwYEBAQFAgENAQIDBAURAAYH
19
+ EiETMQgiQVEUYXEJFSMygZFCUqGxFjNiwQokctEXQ4Lh8JLxJTRTY6IYJrIn
20
+ NURzwqP/xAAcAQABBQEBAQAAAAAAAAAAAAAFAQIDBAYABwj/xAA5EQABAwMD
21
+ AgUCBQMEAwEBAQEBAgMRAAQhBRIxQVEGEyJhcYGRFDKhscHR4fAVI0LxBxZS
22
+ MyQlQ//aAAwDAQACEQMRAD8A468keHnMOpGaP/BvIFWydXM4VgY6DWVuY29k
23
+ aW5nIgpDUDg1MFsHSSIJYXV0aAY7AEYiJTQwZDk3MDM4OWIyMzA5NDdkNTlm
24
+ OWExZTZlOTBhNzQ0
25
+ headers:
26
+ Content-Type:
27
+ - multipart/form-data; boundary=-----------RubyMultipartPost
28
+ Content-Length:
29
+ - '382022'
30
+ response:
31
+ status:
32
+ code: 200
33
+ message: OK
34
+ headers:
35
+ Date:
36
+ - Mon, 03 Jun 2013 03:28:23 GMT
37
+ Server:
38
+ - Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.13
39
+ X-Powered-By:
40
+ - PHP/5.4.13
41
+ Content-Type:
42
+ - text/html; charset=UTF-8
43
+ Content-Length:
44
+ - '165'
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"collection":"test","album":"1","file_id":"image","accepted_sizes":["small"],"URIs":{"small":"http:\/\/dev.local\/imagerserver\/images\/test\/1\/image\/small.jpg"}}'
48
+ http_version:
49
+ recorded_at: Mon, 03 Jun 2013 03:28:24 GMT
50
+ recorded_with: VCR 2.5.0
@@ -1,37 +1,56 @@
1
1
  require 'spec_helper'
2
- require 'debugger'
2
+
3
3
  describe Imager::ServerInterface do
4
4
  describe ".post" do
5
5
 
6
6
  context "when params are valid" do
7
7
  it "returns true" do
8
- described_class.post("test", "1", "spec/image.jpg", small: { width: 100 }).should be_true
8
+ VCR.use_cassette('valid_post') do
9
+ described_class.post("test", "1", "spec/image.jpg", small: { width: 100 }).should be_true
10
+ end
9
11
  end
10
12
  end
11
13
 
12
- context "when some param is not correct" do
14
+ context "when no image" do
13
15
  it "raises an error" do
16
+ # No request made here, because has no image
14
17
  expect {
15
18
  described_class.post("", "", "", size: { width: 100 })
16
19
  }.to raise_error Imager::ImagerError
17
20
  end
18
21
  end
22
+
23
+ context "when other params are wrong" do
24
+ it "raises an error" do
25
+ VCR.use_cassette('invalid_album_and_collection_post') do
26
+ expect {
27
+ described_class.post("", "", "spec/image.jpg", size: { width: 100 })
28
+ }.to raise_error Imager::ImagerError
29
+ end
30
+ end
31
+ end
19
32
  end
20
33
 
21
34
  describe ".delete" do
22
35
  context "valid params and existing image" do
23
36
 
24
37
  it "returns true" do
25
- described_class.post("test", "1", "spec/image.jpg", small: { width: 100 })
26
- described_class.delete("test", "1", "image").should be_true
38
+ VCR.use_cassette('valid_post') do
39
+ described_class.post("test", "1", "spec/image.jpg", small: { width: 100 })
40
+ end
41
+ VCR.use_cassette('valid_delete') do
42
+ described_class.delete("test", "1", "image").should be_true
43
+ end
27
44
  end
28
45
  end
29
46
 
30
47
  context "some invalid param" do
31
48
  it "raises an error" do
32
- expect {
33
- described_class.delete("test", "1", "non_existing_image")
34
- }.to raise_error Imager::ImagerError
49
+ VCR.use_cassette('no_image_delete') do
50
+ expect {
51
+ described_class.delete("test", "1", "non_existing_image")
52
+ }.to raise_error Imager::ImagerError
53
+ end
35
54
  end
36
55
  end
37
56
  end
@@ -1,12 +1,36 @@
1
1
  require 'imager'
2
2
 
3
+ #dependencies
4
+ require 'minitest/autorun'
5
+ require 'webmock/minitest'
6
+ require 'vcr'
7
+ require 'turn'
8
+
9
+ # Hack for HTTMultiParty And VCR
10
+ require 'support/httmultiparty'
11
+
3
12
  RSpec.configure do |c|
4
13
  c.before do
5
14
  Imager.configure do |c|
6
15
  c.base_uri = "http://dev.local/imagerserver"
7
- c.auth_code = "f8cecac2459d83eb9c8c703663e349ddbeb82a76230c7ca5ffc8434cfaab"
16
+ c.auth_code = "ABCDE"
8
17
  c.collection_path = "images"
9
18
  c.manager_path = "manager"
10
19
  end
11
20
  end
21
+ end
22
+
23
+ Turn.config do |c|
24
+ # :outline - turn's original case/test outline mode [default]
25
+ c.format = :outline
26
+ # turn on invoke/execute tracing, enable full backtrace
27
+ c.trace = true
28
+ # use humanized test names (works only with :outline format)
29
+ c.natural = true
30
+ end
31
+
32
+ #VCR config
33
+ VCR.configure do |c|
34
+ c.cassette_library_dir = 'spec/fixtures/imagerserver_cassettes'
35
+ c.hook_into :webmock
12
36
  end
@@ -0,0 +1,82 @@
1
+ require 'webmock'
2
+ require 'httmultiparty'
3
+
4
+ class FakeUploadIO
5
+
6
+ attr_accessor :original_filename, :content_type, :body
7
+
8
+ def initialize(io)
9
+ io.rewind # make sure....
10
+
11
+ self.original_filename = io.original_filename || File.basename(io.local_path)
12
+ self.content_type = io.content_type
13
+ self.body = io.read
14
+
15
+ io.rewind # ...we don't mess up with the io
16
+ end
17
+
18
+ end
19
+
20
+ module WebMock
21
+ module NetHTTPUtility
22
+
23
+ def self.request_signature_from_request(net_http, request, body = nil)
24
+ protocol = net_http.use_ssl? ? "https" : "http"
25
+
26
+ path = request.path
27
+ path = WebMock::Util::URI.heuristic_parse(request.path).request_uri if request.path =~ /^http/
28
+
29
+ if request["authorization"] =~ /^Basic /
30
+ userinfo = WebMock::Util::Headers.decode_userinfo_from_header(request["authorization"])
31
+ userinfo = WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo) + "@"
32
+ else
33
+ userinfo = ""
34
+ end
35
+
36
+ uri = "#{protocol}://#{userinfo}#{net_http.address}:#{net_http.port}#{path}"
37
+ method = request.method.downcase.to_sym
38
+
39
+ headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}]
40
+
41
+ headers.reject! {|k,v| k =~ /[Aa]uthorization/ && v.first =~ /^Basic / } #we added it to url userinfo
42
+
43
+ # changes happen here
44
+ if body != nil && body.respond_to?(:read)
45
+ request.set_body_internal body.read
46
+ else
47
+ request.set_body_internal body
48
+ end
49
+
50
+ _body = request.respond_to?(:body_footprint) ? request.body_footprint : request.body
51
+
52
+ WebMock::RequestSignature.new(method, uri, :body => _body, :headers => headers)
53
+ end
54
+ end
55
+ end
56
+
57
+ module HTTMultiParty::Multipartable::Webmock
58
+
59
+ def body_footprint
60
+ return self.body if (!@_body.is_a? Array) && @_body.blank?
61
+
62
+ Marshal.dump(@_body.map do |key, _value|
63
+ _value = FakeUploadIO.new(_value) if _value.is_a?(UploadIO)
64
+ [key, _value]
65
+ end)
66
+ end
67
+
68
+ def body=(value)
69
+ if value.is_a?(Array)
70
+ @_body = value.dup # save it for later
71
+ super(value)
72
+ else
73
+ # does this case exist for real ? Never observed so far
74
+ puts "[httmultiparty] not an array !!! #{value.class}."
75
+ raise 'STOP'
76
+ end
77
+ end
78
+ end
79
+
80
+ class HTTMultiParty::MultipartPost < Net::HTTP::Post
81
+ include HTTMultiParty::Multipartable::Webmock
82
+ 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.3
4
+ version: 0.0.4
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-06-02 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: turn
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: httmultiparty
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +130,7 @@ extensions: []
88
130
  extra_rdoc_files: []
89
131
  files:
90
132
  - .gitignore
133
+ - .travis.yml
91
134
  - Gemfile
92
135
  - LICENSE.txt
93
136
  - README.md
@@ -99,11 +142,16 @@ files:
99
142
  - lib/imager/server_client.rb
100
143
  - lib/imager/server_interface.rb
101
144
  - lib/imager/version.rb
145
+ - spec/fixtures/imagerserver_cassettes/invalid_album_and_collection_post.yml
146
+ - spec/fixtures/imagerserver_cassettes/no_image_delete.yml
147
+ - spec/fixtures/imagerserver_cassettes/valid_delete.yml
148
+ - spec/fixtures/imagerserver_cassettes/valid_post.yml
102
149
  - spec/image.jpg
103
150
  - spec/imager/link_helper_spec.rb
104
151
  - spec/imager/server_interface_spec.rb
105
152
  - spec/imager_spec.rb
106
153
  - spec/spec_helper.rb
154
+ - spec/support/httmultiparty.rb
107
155
  homepage: https://github.com/guilherme-otran/Imager
108
156
  licenses:
109
157
  - MIT
@@ -129,8 +177,13 @@ signing_key:
129
177
  specification_version: 4
130
178
  summary: Imager Client API
131
179
  test_files:
180
+ - spec/fixtures/imagerserver_cassettes/invalid_album_and_collection_post.yml
181
+ - spec/fixtures/imagerserver_cassettes/no_image_delete.yml
182
+ - spec/fixtures/imagerserver_cassettes/valid_delete.yml
183
+ - spec/fixtures/imagerserver_cassettes/valid_post.yml
132
184
  - spec/image.jpg
133
185
  - spec/imager/link_helper_spec.rb
134
186
  - spec/imager/server_interface_spec.rb
135
187
  - spec/imager_spec.rb
136
188
  - spec/spec_helper.rb
189
+ - spec/support/httmultiparty.rb