giddy 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- giddy (0.0.4)
4
+ giddy (0.0.5)
5
5
  httparty (>= 0.11.0)
6
6
  json (>= 1.8.0)
7
7
 
data/README.md CHANGED
@@ -46,6 +46,14 @@ Download request:
46
46
  puts image.download_largest
47
47
  ```
48
48
 
49
+ To get the available sizes, and then the URL of the download for the smallest:
50
+ ```ruby
51
+ image = client.search(:image_id => "136094606")
52
+ # image.sizes is ordered by file size, smallest to largest
53
+ smallest = image.sizes.first
54
+ puts image.download(smallest).url_attachment
55
+ ```
56
+
49
57
  It's also possible to cache session information so that you don't have to reauthenticate on each client creation. For instance:
50
58
  ```ruby
51
59
  client = Giddy::Client.new("username", "password")
@@ -4,6 +4,12 @@ module Giddy
4
4
  super mediator, "download", true
5
5
  end
6
6
 
7
+ def get_image_download_authorizations(image_id, sizes)
8
+ images = sizes.map { |s| { :ImageId => image_id, :SizeKey => s } }
9
+ result = gettyup :GetImageDownloadAuthorizations, { :ImageSizes => images }
10
+ result["Images"].inject({}) { |h,i| h[i["SizeKey"]] = Utils.rubified_hash(i); h }
11
+ end
12
+
7
13
  def get_largest_image_download_authorizations(ids)
8
14
  ids = [ids].flatten.map { |id| { :ImageId => id } }
9
15
  result = gettyup :GetLargestImageDownloadAuthorizations, { :Images => ids }
@@ -13,6 +13,17 @@ module Giddy
13
13
  @downloader ||= Download.new(@mediator)
14
14
  end
15
15
 
16
+ # return sorted sizes, smallest to largest
17
+ def sizes
18
+ sizes_downloadable_images.sort { |a,b| a[:file_size_in_bytes] <=> b[:file_size_in_bytes] }
19
+ end
20
+
21
+ def download(size)
22
+ sizekey = size[:size_key]
23
+ result = downloader.get_image_download_authorizations(@attrs[:image_id], [sizekey])
24
+ download_request result[sizekey][:authorizations].first[:download_token]
25
+ end
26
+
16
27
  def largest_available
17
28
  result = downloader.get_largest_image_download_authorizations(@attrs[:image_id])
18
29
  result[@attrs[:image_id]]
@@ -1,3 +1,3 @@
1
1
  module Giddy
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: giddy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Muller
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-10-04 00:00:00 Z
13
+ date: 2013-10-07 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
- hash: -4275994823671579037
100
+ hash: 990344511966185404
101
101
  segments:
102
102
  - 0
103
103
  version: "0"
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- hash: -4275994823671579037
109
+ hash: 990344511966185404
110
110
  segments:
111
111
  - 0
112
112
  version: "0"