cdnconnect-api 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/cdnconnect_api.rb +19 -10
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c769230e6585f7cf8e4a9cb4693c3d2f4cde3c13
4
- data.tar.gz: 030324b9ac21ba79b319885bce287c4326abd3bc
3
+ metadata.gz: cd6b1fa74023415fa1b4a66f45f23563295dad9a
4
+ data.tar.gz: 1a849ee61d2d9903faefa7b3ba43deb575b0cfae
5
5
  SHA512:
6
- metadata.gz: c996b2f72c90dd2b0233ba26caac1b8c99ab46505323f8ad8447769a5420417117f8bfd51a5538320601a62d30ae12f4d96938c4431c3f2dd08fb3863434d478
7
- data.tar.gz: 5d783487d3aa20eed0831e930fd265b377411812dbf8f79ab5bc33e397d68a88c93db4b3f64a4f07c8ff370f8b532bb2b4b758cc277f185e4e3daed24280e205
6
+ metadata.gz: fd2d29668600520d2db891d053b6757ff855b305b18f6f37b05eb52b72b21345fe9e9742986d907d6da66efe3a0450467ea6bf2967640a4a84df236f3b42eab4
7
+ data.tar.gz: 51305c08c62822d81f60e6f4ba3c21aa897261d1e7f5bfce7c5476c055a90f3d1b8e531828a2a5a77e526b8fc1adcfbc3e1ae5b06eec882d417afdd81137c161
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CDN Connect API Ruby Client, v0.3.1
1
+ # CDN Connect API Ruby Client, v0.3.2
2
2
 
3
3
  CDN Connect makes it easier to manage production assets for teams of developers and designers, all while serving files from a fast content delivery network. Features include image optimization, resizing, cropping, filters, changing output formats, convert to WebP image format, etc. The CDN Connect API Ruby Client makes it easier to upload files and interact with the API with only a few lines of code.
4
4
 
@@ -13,7 +13,6 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require 'faraday'
16
- require 'faraday/utils'
17
16
  require 'signet/oauth_2/client'
18
17
  require 'cdnconnect_api/response'
19
18
  require 'logger'
@@ -26,7 +25,7 @@ module CDNConnect
26
25
  class APIClient
27
26
 
28
27
  @@application_name = 'cdnconnect-api-ruby'
29
- @@application_version = '0.3.1'
28
+ @@application_version = '0.3.2'
30
29
  @@user_agent = @@application_name + ' v' + @@application_version
31
30
  @@api_host = 'https://api.cdnconnect.com'
32
31
  @@api_version = 'v1'
@@ -206,7 +205,8 @@ module CDNConnect
206
205
  return upload_url_response
207
206
  end
208
207
  upload_url = upload_url_response.get_result('upload_url')
209
- @logger.debug("Received new upload url")
208
+ upload_id = upload_url_response.get_result('upload_id')
209
+ @logger.debug("Received new upload url, #{upload_id}")
210
210
  else
211
211
  @logger.debug("Use prefetched upload url")
212
212
  end
@@ -262,8 +262,13 @@ module CDNConnect
262
262
 
263
263
  # an upload response also contains a new upload url.
264
264
  # Save it for the next upload to the same destination.
265
- set_prefetched_upload_url(destination_path,
266
- upload_response.get_result('upload_url'))
265
+ new_upload_url = upload_response.get_result('upload_url')
266
+ new_upload_id = upload_response.get_result('upload_url_upload_id')
267
+ if new_upload_url != nil
268
+ @logger.debug("Received upload url in upload response, #{new_upload_id}")
269
+ set_prefetched_upload_url(destination_path,
270
+ new_upload_url)
271
+ end
267
272
  end
268
273
 
269
274
  end
@@ -597,7 +602,7 @@ module CDNConnect
597
602
  if destination_path == "/"
598
603
  destination_path = ""
599
604
  end
600
- upload_id = Random.new.rand(1_000_000..9_999_999)
605
+ upload_id = ((9_999_999 - 1_000_000) * rand + 1_000_000).to_i
601
606
  api_path = "#{destination_path}/upload-#{upload_id}.json"
602
607
 
603
608
  @logger.debug("get_upload_url: #{api_path}")
@@ -890,10 +895,14 @@ module CDNConnect
890
895
  end
891
896
 
892
897
  def human_file_size(bytes)
893
- units = %w{B KB MB GB TB}
894
- e = (Math.log(bytes)/Math.log(1024)).floor
895
- s = "%.2f" % (bytes.to_f / 1024**e)
896
- s.sub(/\.?0*$/, units[e])
898
+ begin
899
+ units = %w{B KB MB GB TB}
900
+ e = (Math.log(bytes)/Math.log(1024)).floor
901
+ s = "%.2f" % (bytes.to_f / 1024**e)
902
+ s.sub(/\.?0*$/, units[e])
903
+ rescue
904
+ bytes
905
+ end
897
906
  end
898
907
 
899
908
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdnconnect-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bradley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-22 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday