image_server 0.4.0 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4e2dabc23df77549e15530494663bfe8debb848
4
- data.tar.gz: 8fb675eecb59d6c280a451945cc21dd12dcdf9dd
3
+ metadata.gz: 9147befb6357ed6c9e3b160794ebc46b535a4ee2
4
+ data.tar.gz: 8be91bbfa024ee310ce5286129b9c07275491eb7
5
5
  SHA512:
6
- metadata.gz: 72cf34e5d620b3bfa83d86ec4bcb019af5458d4f0750820f9a8366d7e9570de2eea36a1769e5e67a36d04a4cf4a5c11103993d038ce677d59a725d6118e8345e
7
- data.tar.gz: dcf61e940894e44c2bcd94c46bad7579890600489103ae5c5b1df5b6d6556311ed305e0c8a306b3dbd577568c58cbf5bfc85e1007a245391c6080734131d41d9
6
+ metadata.gz: f13101ae69fc6dbc1c2d80cc608d37ef38d79f901b0cce96fdb2bcd2f86f415585df3c094d75f68d08c38b747594c4d288117e0aadf1ed0b0961c99b87bbbb95
7
+ data.tar.gz: 62d26cd64e71734efa59f17201e2fc9ff55439c8ef8be5871e3b66a5616c235f3b0b35ed7bd087f5324c7f213dc8b7f24577bfe8cc967af9d4ceb69b3c683cb5
@@ -1,14 +1,15 @@
1
1
  module ImageServer
2
2
  module ActiveRecord
3
- def image_server(column, namespace: 'img', versions: nil, processing_formats: [:jpg], default_size: 'full_size', default_format: 'jpg', sharded_cdn_template: nil)
4
- sizes = versions.values.sort.uniq
3
+ def image_server(column, namespace: 'img', versions: nil, processing: nil, processing_formats: [:jpg], default_size: 'full_size', default_format: 'jpg', sharded_cdn_template: nil)
5
4
  keys = versions.keys.sort.uniq
6
5
  processing_formats = processing_formats.map(&:to_s).sort.uniq
7
- outputs = sizes.flat_map { |s| processing_formats.map { |f| "#{s}.#{f}" } }
6
+ processing_versions = processing[:versions].sort.uniq if processing
7
+ processing_versions ||= versions.values.sort.uniq
8
+ outputs = processing_versions.flat_map { |s| processing_formats.map { |f| "#{s}.#{f}" } }
8
9
  outputs_str = outputs.join(',')
9
-
10
10
  namespace_constant = "#{column.to_s.upcase}_NAMESPACE"
11
11
  outputs_constant = "#{column.to_s.upcase}_OUTPUTS_STR"
12
+ processing_versions_constant = "#{column.to_s.upcase}_PROCESSING_VERSIONS"
12
13
  keys_constant = "#{column.to_s.upcase}_KEYS"
13
14
 
14
15
  sharded_cdn_template_constant = "#{column.to_s.upcase}_SHARDED_CDN_TEMPLATE"
@@ -18,6 +19,7 @@ module ImageServer
18
19
  #{namespace_constant} = '#{namespace}'
19
20
  #{outputs_constant} = '#{outputs_str}'
20
21
  #{keys_constant} = #{keys}
22
+ #{processing_versions_constant} = #{processing_versions}
21
23
  #{sharded_cdn_template_constant} = #{sharded_cdn_template}
22
24
 
23
25
  def remote_#{column}_url=(url)
@@ -27,12 +29,11 @@ module ImageServer
27
29
  end
28
30
 
29
31
  def #{column}(options={})
30
- processing = #{column}_hash.blank?
31
32
  default_options = { protocol: #{column}_cdn_protocol,
32
33
  domain: #{column}_cdn_domain,
33
34
  default_size: '#{default_size}',
34
35
  format: '#{default_format}',
35
- processing: processing,
36
+ processing: #{column}_processing?,
36
37
  object: self }
37
38
  ImageServer::Image.new(#{namespace_constant}, #{column}_hash, default_options.merge(options))
38
39
  end
@@ -48,12 +49,16 @@ module ImageServer
48
49
 
49
50
  private
50
51
 
52
+ def #{column}_processing?
53
+ #{column}_hash == nil || #{column}_hash == ''
54
+ end
55
+
51
56
  def #{column}_cdn_protocol
52
57
  ImageServer.configuration.cdn_protocol
53
58
  end
54
59
 
55
60
  def #{column}_cdn_domain
56
- return #{column}_host if #{column}_hash.blank?
61
+ return #{column}_host if #{column}_processing?
57
62
  return #{column}_host unless #{sharded_cdn_template_constant}
58
63
  shard = #{column}_hash[0].hex % #{column}_sharded_host_count
59
64
  #{sharded_cdn_template_constant} % shard
@@ -18,9 +18,10 @@ module ImageServer
18
18
  logger.info "ImageServer::Adapters::Http --> uploading to image server: [#{upload_uri}]"
19
19
 
20
20
  response = Net::HTTP.start(upload_uri.host, upload_uri.port) do |http|
21
-
22
- http.read_timeout = 60
23
- body = if source_is_url?
21
+ request = Net::HTTP::Post.new(upload_uri.request_uri)
22
+ request['Accept'] = "application/json"
23
+ request['Content-Type'] = "application/json"
24
+ request.body = if source_is_url?
24
25
  '{}' # blank body
25
26
  elsif @source.is_a?(File)
26
27
  @source
@@ -30,7 +31,8 @@ module ImageServer
30
31
  raise('Not supported')
31
32
  end
32
33
 
33
- http.post("#{upload_uri.path}?#{upload_uri.query}", body)
34
+ http.read_timeout = 60
35
+ http.request(request)
34
36
  end
35
37
 
36
38
  ErrorHandler.new(response).handle_errors!
@@ -37,7 +37,7 @@ module ImageServer
37
37
  end
38
38
 
39
39
  def current_version
40
- '1.16.1'
40
+ '1.17.0'
41
41
  end
42
42
 
43
43
  def executable_name
@@ -1,3 +1,3 @@
1
1
  module ImageServer
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Millan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-12 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry