filestack 2.3.0 → 2.4.0

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: c102fe7fb533cf82413791d4b49e8dd9a76926e0
4
- data.tar.gz: 64dd9ae18a850ce6f5fa06b81fab6933973582d3
3
+ metadata.gz: 07dcc17274c65c4740665bb4fc382cd44e8af337
4
+ data.tar.gz: 866e63f55957c74c0f374698c8a5c79b400fec2d
5
5
  SHA512:
6
- metadata.gz: c616fd86fe99d2473f2135af8ad062a35ebbc8e2e1cb658c2dc17784f1d27aae056f6842f5495147e108f037b6a8fb133ae4c8e1fbf789bded36a6386216aaf5
7
- data.tar.gz: 2873772fa6e71ea7d8fab34caa6e366a15c3ee829c83b05197f894bcbf78d97d894003fb33255165d75843a9deb4886e803db0f8383be364a60dfb78ba4de37b
6
+ metadata.gz: a19cfe346bda3974b11a315139f4a51c2108397c21cf55d3848facabbbb12f455d273735806874d51d0e2238cff2324b80de8a75f3a9af73bc38888eaafab145
7
+ data.tar.gz: 82a7b00a7772903cd892d48e6c691324a88c4b322d38f2269b882fca18aac3c67703b0fe55ddc80a7bff26f2b8497230045188ebfd5c64078bf46de67d5fdd67
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Filestack-Ruby Changelog
2
2
 
3
+ ## 2.4.0 (August 27, 2018)
4
+ - FS-3813 Convert security options hash with string keys to symbols
5
+ - FS-3903 Add parsing the response body before reading it
6
+
3
7
  ## 2.3.0 (July 26, 2018)
4
8
  - FS-3437 Change Unirest library to Typhoeus, and fix warning in rspecs
5
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4.0
data/lib/filestack.rb CHANGED
@@ -3,3 +3,4 @@ require 'filestack/models/filestack_client'
3
3
  require 'filestack/models/filestack_security'
4
4
  require 'filestack/utils/utils'
5
5
  require 'filestack/models/filestack_transform'
6
+ require 'filestack/core_ext/hash/keys'
@@ -0,0 +1,20 @@
1
+ module Filestack
2
+ # A helper class for the purpose of implementing a symbolize_keys method
3
+ # similar to ActiveSupport's symbolize_keys.
4
+ class Hash
5
+
6
+ # Convert a hash to use symbolized keys.
7
+ #
8
+ # @param [Hash] to_symbolize The hash which contains the keys to be
9
+ # symbolized
10
+ #
11
+ # @return [Hash]
12
+ def self.symbolize_keys(to_symbolize)
13
+ symbolized = {}
14
+ to_symbolize.each_key do |key|
15
+ symbolized[key.to_sym] = to_symbolize[key]
16
+ end
17
+ symbolized
18
+ end
19
+ end
20
+ end
@@ -2,6 +2,7 @@ require 'filestack/config'
2
2
  require 'filestack/utils/utils'
3
3
  require 'filestack/utils/multipart_upload_utils'
4
4
  require 'mimemagic'
5
+ require 'json'
5
6
 
6
7
  # Module is mixin for common functionalities that all Filestack
7
8
  # objects can call.
@@ -88,7 +89,8 @@ module FilestackCommon
88
89
  signature = security.signature
89
90
  url = "#{FilestackConfig::CDN_URL}/#{task}/"\
90
91
  "security=signature:#{signature},policy:#{policy}/#{handle}"
91
- UploadUtils.make_call(url, 'get').body[task]
92
+ response = UploadUtils.make_call(url, 'get')
93
+ JSON.parse(response.body)[task]
92
94
  end
93
95
 
94
96
  def send_metadata(handle, security = nil, params)
@@ -102,7 +104,7 @@ module FilestackCommon
102
104
  response = UploadUtils.make_call(url, 'get', parameters: params)
103
105
 
104
106
  if response.code == 200
105
- return response.body
107
+ return JSON.parse(response.body)
106
108
  end
107
109
  raise response.body
108
110
  end
@@ -73,7 +73,7 @@ class FilestackFilelink
73
73
 
74
74
  # Return metadata for file handle
75
75
  #
76
- # @return [Typhoeus::Response]
76
+ # @return [Hash]
77
77
  def metadata(params = {})
78
78
  send_metadata(@handle, @security, params)
79
79
  end
@@ -81,7 +81,7 @@ class FilestackFilelink
81
81
  # Return true (SFW) or false (NSFW)
82
82
  #
83
83
  # @return [Bool]
84
- def sfw
84
+ def sfw
85
85
  send_tags('sfw', @handle, @security)
86
86
  end
87
87
 
@@ -1,5 +1,6 @@
1
1
  require 'filestack/models/filelink'
2
2
  require 'filestack/utils/utils'
3
+ require 'json'
3
4
 
4
5
  # Class for AV objects -- allows to check status
5
6
  # and upgrade to filelink once completed
@@ -18,8 +19,9 @@ class AV
18
19
  # @return [Filestack::FilestackFilelink]
19
20
  def to_filelink
20
21
  return 'Video conversion incomplete' unless status == 'completed'
21
- response = UploadUtils.make_call(@url, 'get').body
22
- handle = response['data']['url'].split('/').last
22
+ response = UploadUtils.make_call(@url, 'get')
23
+ response_body = JSON.parse(response.body)
24
+ handle = response_body['data']['url'].split('/').last
23
25
  FilestackFilelink.new(handle, apikey: @apikey, security: @security)
24
26
  end
25
27
 
@@ -27,6 +29,8 @@ class AV
27
29
  #
28
30
  # @return [String]
29
31
  def status
30
- UploadUtils.make_call(@url, 'get').body['status']
32
+ response = UploadUtils.make_call(@url, 'get')
33
+ response_body = JSON.parse(response.body)
34
+ response_body['status']
31
35
  end
32
36
  end
@@ -43,7 +43,7 @@ class FilestackSecurity
43
43
  # @param [String] secret Your filestack security secret
44
44
  # @param [Hash] options Hash of options - see constructor
45
45
  def generate(secret, options)
46
- policy_json = create_policy_string(options)
46
+ policy_json = create_policy_string(Filestack::Hash.symbolize_keys(options))
47
47
  @policy = Base64.urlsafe_encode64(policy_json)
48
48
  @signature = OpenSSL::HMAC.hexdigest('sha256', secret, policy)
49
49
  end
@@ -62,6 +62,7 @@ class FilestackSecurity
62
62
  #
63
63
  # Manage options and convert hash to json string
64
64
  #
65
+
65
66
  def create_policy_string(options)
66
67
  options[:expiry] = expiry_timestamp(options)
67
68
  options.to_json
@@ -1,5 +1,6 @@
1
1
  require 'filestack/config'
2
2
  require 'filestack/models/filestack_av'
3
+ require 'json'
3
4
 
4
5
  # Class for creating transformation chains and storing them to Filestack
5
6
  class Transform
@@ -64,12 +65,13 @@ class Transform
64
65
 
65
66
  # Add debug parameter to get information on transformation image
66
67
  #
67
- # @return [Typhoeus::Response]
68
+ # @return [Hash]
68
69
  def debug
69
70
  @transform_tasks.push(
70
71
  add_transform_task('debug')
71
72
  )
72
- UploadUtils.make_call(url, 'get').body
73
+ response = UploadUtils.make_call(url, 'get')
74
+ JSON.parse(response.body)
73
75
  end
74
76
 
75
77
  # Stores a transformation URL and returns a filelink
@@ -80,7 +82,8 @@ class Transform
80
82
  add_transform_task('store', {})
81
83
  )
82
84
  response = UploadUtils.make_call(url, 'get')
83
- handle = response.body['url'].split('/').last
85
+ response_body = JSON.parse(response.body)
86
+ handle = response_body['url'].split('/').last
84
87
  FilestackFilelink.new(handle, apikey: @apikey, security: @security)
85
88
  end
86
89
 
@@ -1,5 +1,5 @@
1
1
  module Filestack
2
2
  module Ruby
3
- VERSION = '2.3.0'.freeze
3
+ VERSION = '2.4.0'.freeze
4
4
  end
5
5
  end
@@ -234,7 +234,7 @@ module MultipartUploadUtils
234
234
  # @param [Hash] options User-defined options for
235
235
  # multipart uploads
236
236
  #
237
- # @return [Typhoeus::Response]
237
+ # @return [Hash]
238
238
  def multipart_upload(apikey, filepath, security, options, timeout, intelligent: false)
239
239
  filename, filesize, mimetype = get_file_info(filepath)
240
240
  start_response = multipart_start(
@@ -272,6 +272,6 @@ module MultipartUploadUtils
272
272
  rescue
273
273
  raise "Upload timed out upon completion. Please try again later"
274
274
  end
275
- response_complete.body
275
+ JSON.parse(response_complete.body)
276
276
  end
277
277
  end
@@ -73,7 +73,7 @@ module UploadUtils
73
73
  # multipart uploads
74
74
  # @param [String] storage Storage destination
75
75
  # (s3, rackspace, etc)
76
- # @return [Typhoeus::Response]
76
+ # @return [Hash]
77
77
  def send_upload(apikey, filepath: nil, external_url: nil, security: nil, options: nil, storage: 'S3')
78
78
  data = if filepath
79
79
  { fileUpload: File.open(filepath) }
@@ -93,7 +93,8 @@ module UploadUtils
93
93
 
94
94
  response = make_call(base, 'post', parameters: data)
95
95
  if response.code == 200
96
- handle = response.body['url'].split('/').last
96
+ response_body = JSON.parse(response.body)
97
+ handle = response_body['url'].split('/').last
97
98
  return { 'handle' => handle }
98
99
  end
99
100
  raise response.body
@@ -390,7 +391,7 @@ module IntelligentUtils
390
391
  rescue
391
392
  raise 'BACKEND_NETWORK'
392
393
  end
393
- fs_response = fs_response.body
394
+ fs_response = JSON.parse(fs_response.body)
394
395
 
395
396
  # PUT to S3
396
397
  begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filestack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filestack
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-26 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -180,6 +180,7 @@ files:
180
180
  - filestack-ruby.gemspec
181
181
  - lib/filestack.rb
182
182
  - lib/filestack/config.rb
183
+ - lib/filestack/core_ext/hash/keys.rb
183
184
  - lib/filestack/mixins/filestack_common.rb
184
185
  - lib/filestack/models/filelink.rb
185
186
  - lib/filestack/models/filestack_av.rb