resizing 0.3.2 → 0.5.3

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
  SHA256:
3
- metadata.gz: a68f3747dc45de527ea32a40bb2586783a0ea14d76717bd85186aae178ef18bd
4
- data.tar.gz: 5ecebffc8b0eb31c22e3bb408eea3d99db21b90bcdba5178e74f1f0704261ed5
3
+ metadata.gz: df0aac4e125b7c1c3b293001f2de5fa8846758918b5c7016aeb137fec06fc51f
4
+ data.tar.gz: 4564dbc3de047efbf559a188395fb666c2ad781c32daddf8f057449757497175
5
5
  SHA512:
6
- metadata.gz: 233c87e03b19be35e89d373a4456aa81cdd82c110eea4cff47f2d8498a852ed203c0443567f0afb8b6d85bd419da49b6accb5e52038e823beddf40d88f84e94d
7
- data.tar.gz: 66f18b1648e93a2cbdf73a2a457b9e2591262b795dfbebd232cd0388ca7787a755068a85c84f763f1c28fa7e10c61a4169915aff35184d1f602c6498cca8f63e
6
+ metadata.gz: 673b324144203b4d8020d93dbf725bf9faf799dc4eac563a400d53c83ca439764ecc27fb4fb9481e5262f77fe694025b8cd890e7cdb7190b0d580ca1fa23c8f5
7
+ data.tar.gz: 5a984d738fdb21036b35c47987e5d50f01cc9cab7275052cfa88c01d180a9441f017e7071ac5ca26d3b2c87740b7e25ed78f7fc7c0da3d4eb23866bba677f62c
@@ -0,0 +1,141 @@
1
+ # Changelog
2
+
3
+ ## [v0.5.2](https://github.com/jksy/resizing-gem/tree/v0.5.2) (2020-10-11)
4
+
5
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.5.1...v0.5.2)
6
+
7
+ ## [v0.5.1](https://github.com/jksy/resizing-gem/tree/v0.5.1) (2020-10-11)
8
+
9
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.5.0...v0.5.1)
10
+
11
+ ## [v0.5.0](https://github.com/jksy/resizing-gem/tree/v0.5.0) (2020-10-11)
12
+
13
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.4.2...v0.5.0)
14
+
15
+ ## [v0.4.2](https://github.com/jksy/resizing-gem/tree/v0.4.2) (2020-10-01)
16
+
17
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.4.1...v0.4.2)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - fix raise error if tempfile is assinged [\#38](https://github.com/jksy/resizing-gem/pull/38) ([jksy](https://github.com/jksy))
22
+
23
+ ## [v0.4.1](https://github.com/jksy/resizing-gem/tree/v0.4.1) (2020-10-01)
24
+
25
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.2.1...v0.4.1)
26
+
27
+ **Closed issues:**
28
+
29
+ - pass original filename into Resizing [\#36](https://github.com/jksy/resizing-gem/issues/36)
30
+ - columnがnilの時はdefault\_urlを返す [\#33](https://github.com/jksy/resizing-gem/issues/33)
31
+
32
+ **Merged pull requests:**
33
+
34
+ - save original filename [\#37](https://github.com/jksy/resizing-gem/pull/37) ([jksy](https://github.com/jksy))
35
+ - columnがnilの時はdefault\_urlを返す \#33 [\#34](https://github.com/jksy/resizing-gem/pull/34) ([jksy](https://github.com/jksy))
36
+
37
+ ## [v0.2.1](https://github.com/jksy/resizing-gem/tree/v0.2.1) (2020-09-29)
38
+
39
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.4.0...v0.2.1)
40
+
41
+ ## [v0.4.0](https://github.com/jksy/resizing-gem/tree/v0.4.0) (2020-09-28)
42
+
43
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.3.2...v0.4.0)
44
+
45
+ **Merged pull requests:**
46
+
47
+ - change version string when put request with mockclient [\#32](https://github.com/jksy/resizing-gem/pull/32) ([jksy](https://github.com/jksy))
48
+ - add delete method [\#31](https://github.com/jksy/resizing-gem/pull/31) ([jksy](https://github.com/jksy))
49
+ - Feature/add identifier to public [\#30](https://github.com/jksy/resizing-gem/pull/30) ([jksy](https://github.com/jksy))
50
+ - add identifier [\#29](https://github.com/jksy/resizing-gem/pull/29) ([jksy](https://github.com/jksy))
51
+ - Feature/refactor public [\#28](https://github.com/jksy/resizing-gem/pull/28) ([jksy](https://github.com/jksy))
52
+ - divide to PublicId class [\#27](https://github.com/jksy/resizing-gem/pull/27) ([jksy](https://github.com/jksy))
53
+ - fix some bug & errors [\#26](https://github.com/jksy/resizing-gem/pull/26) ([jksy](https://github.com/jksy))
54
+ - fix mockclient [\#25](https://github.com/jksy/resizing-gem/pull/25) ([jksy](https://github.com/jksy))
55
+ - fix raise no method presented, no cotent type is presented [\#24](https://github.com/jksy/resizing-gem/pull/24) ([jksy](https://github.com/jksy))
56
+
57
+ ## [v0.3.2](https://github.com/jksy/resizing-gem/tree/v0.3.2) (2020-09-11)
58
+
59
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.3.1...v0.3.2)
60
+
61
+ **Merged pull requests:**
62
+
63
+ - fix raise error when call remove! with nil column [\#23](https://github.com/jksy/resizing-gem/pull/23) ([jksy](https://github.com/jksy))
64
+
65
+ ## [v0.3.1](https://github.com/jksy/resizing-gem/tree/v0.3.1) (2020-09-11)
66
+
67
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.3.0...v0.3.1)
68
+
69
+ ## [v0.3.0](https://github.com/jksy/resizing-gem/tree/v0.3.0) (2020-08-21)
70
+
71
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.2.0...v0.3.0)
72
+
73
+ **Merged pull requests:**
74
+
75
+ - Feature/fix mock client [\#22](https://github.com/jksy/resizing-gem/pull/22) ([jksy](https://github.com/jksy))
76
+
77
+ ## [v0.2.0](https://github.com/jksy/resizing-gem/tree/v0.2.0) (2020-08-12)
78
+
79
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.1.4...v0.2.0)
80
+
81
+ **Merged pull requests:**
82
+
83
+ - version 0.2.0 [\#21](https://github.com/jksy/resizing-gem/pull/21) ([jksy](https://github.com/jksy))
84
+ - support f\_auto, q\_auto parameter [\#20](https://github.com/jksy/resizing-gem/pull/20) ([jksy](https://github.com/jksy))
85
+
86
+ ## [v0.1.4](https://github.com/jksy/resizing-gem/tree/v0.1.4) (2020-08-08)
87
+
88
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.1.3...v0.1.4)
89
+
90
+ **Merged pull requests:**
91
+
92
+ - Feature/update gems and change default hostname [\#19](https://github.com/jksy/resizing-gem/pull/19) ([jksy](https://github.com/jksy))
93
+
94
+ ## [v0.1.3](https://github.com/jksy/resizing-gem/tree/v0.1.3) (2020-06-12)
95
+
96
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.1.2...v0.1.3)
97
+
98
+ **Merged pull requests:**
99
+
100
+ - fix error when record is not found [\#18](https://github.com/jksy/resizing-gem/pull/18) ([jksy](https://github.com/jksy))
101
+
102
+ ## [v0.1.2](https://github.com/jksy/resizing-gem/tree/v0.1.2) (2020-06-12)
103
+
104
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.1.1...v0.1.2)
105
+
106
+ **Merged pull requests:**
107
+
108
+ - ignore response if delete method is received 404 status code [\#17](https://github.com/jksy/resizing-gem/pull/17) ([jksy](https://github.com/jksy))
109
+
110
+ ## [v0.1.1](https://github.com/jksy/resizing-gem/tree/v0.1.1) (2020-06-12)
111
+
112
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/v0.1.0...v0.1.1)
113
+
114
+ **Merged pull requests:**
115
+
116
+ - Feature/fix raise error [\#16](https://github.com/jksy/resizing-gem/pull/16) ([jksy](https://github.com/jksy))
117
+ - fix empty url when model is reload [\#10](https://github.com/jksy/resizing-gem/pull/10) ([jksy](https://github.com/jksy))
118
+
119
+ ## [v0.1.0](https://github.com/jksy/resizing-gem/tree/v0.1.0) (2020-06-07)
120
+
121
+ [Full Changelog](https://github.com/jksy/resizing-gem/compare/e817d9b883425ddae3e42439ccd1a9d2e270c363...v0.1.0)
122
+
123
+ **Merged pull requests:**
124
+
125
+ - add mock client for test environments [\#14](https://github.com/jksy/resizing-gem/pull/14) ([jksy](https://github.com/jksy))
126
+ - Feature/add test test for remove xxx [\#13](https://github.com/jksy/resizing-gem/pull/13) ([jksy](https://github.com/jksy))
127
+ - add rubocop & fix some tests [\#12](https://github.com/jksy/resizing-gem/pull/12) ([jksy](https://github.com/jksy))
128
+ - fix the column cant be update by null value [\#11](https://github.com/jksy/resizing-gem/pull/11) ([jksy](https://github.com/jksy))
129
+ - change mysql port on docker-compose [\#9](https://github.com/jksy/resizing-gem/pull/9) ([jksy](https://github.com/jksy))
130
+ - fix return invalid url when model is reloaded [\#8](https://github.com/jksy/resizing-gem/pull/8) ([jksy](https://github.com/jksy))
131
+ - add circleci [\#7](https://github.com/jksy/resizing-gem/pull/7) ([jksy](https://github.com/jksy))
132
+ - divide some classes and add tests [\#6](https://github.com/jksy/resizing-gem/pull/6) ([jksy](https://github.com/jksy))
133
+ - fix connect host [\#5](https://github.com/jksy/resizing-gem/pull/5) ([jksy](https://github.com/jksy))
134
+ - Feature/carrier wave [\#4](https://github.com/jksy/resizing-gem/pull/4) ([jksy](https://github.com/jksy))
135
+ - faraday version is down. and some fix bugs [\#3](https://github.com/jksy/resizing-gem/pull/3) ([jksy](https://github.com/jksy))
136
+ - Feature/add default host [\#2](https://github.com/jksy/resizing-gem/pull/2) ([jksy](https://github.com/jksy))
137
+ - first implementation [\#1](https://github.com/jksy/resizing-gem/pull/1) ([jksy](https://github.com/jksy))
138
+
139
+
140
+
141
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/bash
2
+
3
+ github_changelog_generator -u jksy -p resizing-gem
@@ -9,6 +9,7 @@ module Resizing
9
9
  autoload :MockClient, 'resizing/mock_client'
10
10
  autoload :Configuration, 'resizing/configuration'
11
11
  autoload :CarrierWave, 'resizing/carrier_wave'
12
+ autoload :PublicId, 'resizing/public_id'
12
13
 
13
14
  class Error < StandardError; end
14
15
  class ConfigurationError < Error; end
@@ -41,6 +42,14 @@ module Resizing
41
42
  self.client.put name, file_or_binary, options
42
43
  end
43
44
 
45
+ def self.delete(name)
46
+ self.client.delete name
47
+ end
48
+
49
+ def self.metadata(name, options)
50
+ self.client.metadata name, options
51
+ end
52
+
44
53
  # TODO: refactoring
45
54
  #
46
55
  # identifier:
@@ -54,7 +63,7 @@ module Resizing
54
63
  end
55
64
 
56
65
  def self.separate_public_id public_id
57
- public_id.match('/projects/(?<project_id>[0-9a-f-]+)/upload/images/(?<image_id>[0-9a-f-]+)(/v(?<version>[^/]+))?')
66
+ public_id.match('/projects/(?<project_id>[0-9a-f-]+)/upload/images/(?<image_id>[^/]+)(/v(?<version>[^/]+))?')
58
67
  end
59
68
 
60
69
  def self.client
@@ -25,23 +25,35 @@ module Resizing
25
25
  base.extend ClassMethods
26
26
  end
27
27
 
28
+ def initialize(*args)
29
+ @requested_format = nil
30
+ @default_format = nil
31
+ super
32
+ end
33
+
28
34
  def url(*args)
29
- return nil unless read_column.present?
35
+ return default_url unless read_column.present?
30
36
 
31
- transforms = [transform_string]
37
+ transforms = args.map do |version|
38
+ version = version.intern
39
+ raise "No version is found: #{version}, #{versions.keys} are exists." unless versions.has_key? version
40
+ versions[version].transform_string
41
+ end.compact
32
42
 
33
- while (version = args.pop)
34
- transforms << versions[version].transform_string
35
- end
36
- "#{default_url}/#{transforms.join('/')}"
43
+ "#{build_url}/#{transforms.join('/')}"
37
44
  end
38
45
 
39
46
  def read_column
40
- model.read_attribute(mounted_as)
47
+ model.read_attribute(serialization_column)
41
48
  end
42
49
 
50
+ def build_url
51
+ "#{Resizing.configure.host}#{model.read_attribute(serialization_column)}"
52
+ end
53
+
54
+ # need override this. if you want to return some url when target_column is nil
43
55
  def default_url
44
- "#{Resizing.configure.host}#{model.read_attribute(mounted_as)}"
56
+ nil
45
57
  end
46
58
 
47
59
  def transform_string
@@ -79,16 +91,21 @@ module Resizing
79
91
  # save to resizing directly
80
92
  # @cache_id = file.public_id
81
93
 
82
- @filename = file.public_id
94
+ @filename = file.public_id.to_s
83
95
  @file = file
84
96
  end
85
97
 
98
+ def filename
99
+ read_column
100
+ end
101
+
86
102
  def store!
87
103
  # DO NOTHING
88
104
  super
89
105
  end
90
106
 
91
- module ClassMethods
107
+ def serialization_column
108
+ model.send(:_mounter, mounted_as).send(:serialization_column)
92
109
  end
93
110
 
94
111
  # store_versions! is called after store!
@@ -105,6 +122,23 @@ module Resizing
105
122
  # NOP
106
123
  end
107
124
 
125
+ def requested_format
126
+ # TODO
127
+ # The request with uploading format parameter is not working on the Resizing until 2020/09/25
128
+ @requested_format
129
+ end
130
+
131
+ def default_format
132
+ @default_format
133
+ end
134
+
135
+ def format
136
+ requested_format || default_format
137
+ end
138
+
139
+ module ClassMethods
140
+ end
141
+
108
142
  private
109
143
 
110
144
  # rubocop:disable Metrics/AbcSize
@@ -8,10 +8,13 @@ module Resizing
8
8
 
9
9
  def initialize(uploader, identifier = nil)
10
10
  @uploader = uploader
11
+ @file = nil
11
12
  @content_type = nil
12
- @identifier = identifier
13
+ @public_id = Resizing::PublicId.new identifier
13
14
  end
14
15
 
16
+ attr_reader :public_id
17
+
15
18
  def attributes
16
19
  file.attributes
17
20
  end
@@ -24,24 +27,18 @@ module Resizing
24
27
  @content_type || file.try(:content_type)
25
28
  end
26
29
 
27
- attr_writer :content_type
28
-
29
30
  def delete
30
- public_id = model.send :read_attribute, serialization_column
31
- return if public_id.nil? # do nothing
32
-
33
- # TODO:
34
- # refactoring
35
- separted = Resizing.separate_public_id(public_id)
36
- image_id = separted[:image_id]
37
- resp = client.delete(image_id)
31
+ @public_id = Resizing::PublicId.new(model.send :read_attribute, serialization_column)
32
+ return if @public_id.empty? # do nothing
33
+
34
+ resp = client.delete(@public_id.image_id)
38
35
  if resp['error'] == 'ActiveRecord::RecordNotFound' # 404 not found
39
- model.send :write_attribute, serialization_column, nil
36
+ model.send :write_attribute, serialization_column, nil unless model.destroyed?
40
37
  return
41
38
  end
42
39
 
43
- if public_id == resp['public_id']
44
- model.send :write_attribute, serialization_column, nil
40
+ if @public_id.image_id == resp['id']
41
+ model.send :write_attribute, serialization_column, nil unless model.destroyed?
45
42
  return
46
43
  end
47
44
 
@@ -80,15 +77,41 @@ module Resizing
80
77
  !!file
81
78
  end
82
79
 
80
+ def current_path
81
+ @current_path = model.send :read_attribute, serialization_column
82
+ end
83
+ alias path current_path
84
+
83
85
  def store(new_file)
84
86
  if new_file.is_a?(self.class)
85
87
  # new_file.copy_to(path)
86
88
  raise NotImplementedError, 'new file is required duplicating'
87
89
  end
88
90
 
89
- @content_type ||= new_file.content_type
90
- @response = Resizing.put(identifier, new_file.read, { content_type: @content_type })
91
- @public_id = @response['public_id']
91
+ if new_file.respond_to? :content_type
92
+ @content_type ||= new_file.content_type
93
+ else
94
+ # guess content-type from extension
95
+ @content_type ||= MIME::Types.type_for(new_file.path).first.content_type
96
+ end
97
+
98
+ original_filename = new_file.try(:original_filename) || new_file.try(:filename) || new_file.try(:path)
99
+ if original_filename.present?
100
+ original_filename = ::File.basename(original_filename)
101
+ end
102
+
103
+ content = if new_file.respond_to?(:to_io)
104
+ new_file.to_io.tap(&:rewind)
105
+ elsif new_file.respond_to?(:read) && new_file.respond_to?(:rewind)
106
+ new_file.read.tap do
107
+ new_file.rewind
108
+ end
109
+ else
110
+ new_file
111
+ end
112
+
113
+ @response = Resizing.post(content, { content_type: @content_type, filename: original_filename })
114
+ @public_id = Resizing::PublicId.new(@response['public_id'])
92
115
 
93
116
  # force update column
94
117
  # model_class
@@ -96,26 +119,14 @@ module Resizing
96
119
  # .update_all(serialization_column=>@public_id)
97
120
 
98
121
  # save new value to model class
99
- model.send :write_attribute, serialization_column, @public_id
122
+ model.send :write_attribute, serialization_column, @public_id.to_s
100
123
 
101
124
  true
102
125
  end
103
126
 
104
- attr_reader :public_id
105
-
106
- def identifier
107
- if public_id.present?
108
- public_id
109
- else
110
- @identifier = SecureRandom.uuid
111
- end
112
- end
113
-
114
- def filename(options = {})
115
- file_url = url(options)
116
- return unless file_url
117
-
118
- CGI.unescape(file_url.split('?').first).gsub(%r{.*/(.*?$)}, '\1')
127
+ def name(options = {})
128
+ @public_id = PublicId.new(model.send :read_attribute, serialization_column)
129
+ CGI.unescape(@public_id.filename)
119
130
  end
120
131
 
121
132
  # def copy_to(new_path)
@@ -179,12 +190,6 @@ module Resizing
179
190
  parameters.count == 2 && parameters[1].include?(:options)
180
191
  end
181
192
 
182
- # def store! sanitized_file
183
- # puts sanitized_file.inspect
184
- # client = Resizing::Client.new
185
- # @store_response = client.post(sanitized_file.to_file, {content_type: sanitized_file.content_type})
186
- # end
187
-
188
193
  def retrieve!(identifier)
189
194
  raise NotImplementedError, "retrieve! #{identifier}"
190
195
  end
@@ -9,7 +9,14 @@ module Resizing
9
9
  def store!(file)
10
10
  f = Resizing::CarrierWave::Storage::File.new(uploader)
11
11
  f.store(file)
12
- @filename = f.public_id
12
+ @filename = f.public_id.to_s
13
+ f
14
+ end
15
+
16
+ def remove!(file)
17
+ f = Resizing::CarrierWave::Storage::File.new(uploader)
18
+ f.delete(file)
19
+ @filename = f.public_id.to_s
13
20
  f
14
21
  end
15
22
 
@@ -41,7 +41,7 @@ module Resizing
41
41
  end
42
42
  end
43
43
 
44
- def get(name)
44
+ def get(image_id)
45
45
  raise NotImplementedError
46
46
  end
47
47
 
@@ -50,9 +50,11 @@ module Resizing
50
50
 
51
51
  url = build_post_url
52
52
 
53
+ filename = gather_filename file_or_binary, options
54
+
53
55
  body = to_io(file_or_binary)
54
56
  params = {
55
- image: Faraday::UploadIO.new(body, options[:content_type])
57
+ image: Faraday::UploadIO.new(body, options[:content_type], filename)
56
58
  }
57
59
 
58
60
  response = http_client.post(url, params) do |request|
@@ -63,14 +65,16 @@ module Resizing
63
65
  result
64
66
  end
65
67
 
66
- def put(name, file_or_binary, options)
68
+ def put(image_id, file_or_binary, options)
67
69
  ensure_content_type(options)
68
70
 
69
- url = build_put_url(name)
71
+ url = build_put_url(image_id)
72
+
73
+ filename = gather_filename file_or_binary, options
70
74
 
71
75
  body = to_io(file_or_binary)
72
76
  params = {
73
- image: Faraday::UploadIO.new(body, options[:content_type])
77
+ image: Faraday::UploadIO.new(body, options[:content_type], filename)
74
78
  }
75
79
 
76
80
  response = http_client.put(url, params) do |request|
@@ -81,8 +85,8 @@ module Resizing
81
85
  result
82
86
  end
83
87
 
84
- def delete(name)
85
- url = build_delete_url(name)
88
+ def delete(image_id)
89
+ url = build_delete_url(image_id)
86
90
 
87
91
  response = http_client.delete(url) do |request|
88
92
  request.headers['X-ResizingToken'] = config.generate_auth_header
@@ -92,22 +96,42 @@ module Resizing
92
96
  result
93
97
  end
94
98
 
99
+ def metadata(image_id, options = {})
100
+ url = build_metadata_url(image_id)
101
+
102
+ response = http_client.get(url) do |request|
103
+ request.headers['X-ResizingToken'] = config.generate_auth_header
104
+ end
105
+
106
+ result = handle_metadata_response(response)
107
+ result
108
+ end
109
+
95
110
  private
96
111
 
97
- def build_get_url(name)
98
- "#{config.host}/projects/#{config.project_id}/upload/images/#{name}"
112
+ def build_get_url(image_id)
113
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}"
99
114
  end
100
115
 
101
116
  def build_post_url
102
117
  "#{config.host}/projects/#{config.project_id}/upload/images/"
103
118
  end
104
119
 
105
- def build_put_url(name)
106
- "#{config.host}/projects/#{config.project_id}/upload/images/#{name}"
120
+ def gather_filename file_or_binary, options
121
+ filename = options[:filename]
122
+ filename ||= file_or_binary.respond_to?(:path) ? File.basename(file_or_binary.path) : nil
107
123
  end
108
124
 
109
- def build_delete_url(name)
110
- "#{config.host}/projects/#{config.project_id}/upload/images/#{name}"
125
+ def build_put_url(image_id)
126
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}"
127
+ end
128
+
129
+ def build_delete_url(image_id)
130
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}"
131
+ end
132
+
133
+ def build_metadata_url(image_id)
134
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}/metadata"
111
135
  end
112
136
 
113
137
  def http_client
@@ -121,13 +145,13 @@ module Resizing
121
145
  end
122
146
 
123
147
  def to_io(data)
148
+ return data.to_io if data.respond_to? :to_io
149
+
124
150
  case data
125
- when IO
126
- data
127
151
  when String
128
152
  StringIO.new(data)
129
153
  else
130
- raise ArgumentError, 'file_or_binary is required IO class or String'
154
+ raise ArgumentError, "file_or_binary is required IO class or String:#{data.class}"
131
155
  end
132
156
  end
133
157
 
@@ -150,7 +174,18 @@ module Resizing
150
174
  raise APIError, "no response is returned" if response.nil?
151
175
 
152
176
  case response.status
153
- when HTTP_STATUS_OK, HTTP_STATUS_CREATED, HTTP_STATUS_NOT_FOUND
177
+ when HTTP_STATUS_OK, HTTP_STATUS_NOT_FOUND
178
+ JSON.parse(response.body)
179
+ else
180
+ raise APIError, "invalid http status code #{response.status}"
181
+ end
182
+ end
183
+
184
+ def handle_metadata_response(response)
185
+ raise APIError, "no response is returned" if response.nil?
186
+
187
+ case response.status
188
+ when HTTP_STATUS_OK, HTTP_STATUS_NOT_FOUND
154
189
  JSON.parse(response.body)
155
190
  else
156
191
  raise APIError, "invalid http status code #{response.status}"