flickraw 0.7 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/flickraw.rb +22 -7
  2. data/rakefile +2 -1
  3. metadata +2 -2
@@ -25,8 +25,14 @@ require 'digest/md5'
25
25
  require 'json'
26
26
  require 'cgi'
27
27
 
28
+ FlickrawOptions = {} if not Object.const_defined? :FlickrawOptions
29
+ if ENV['http_proxy'] and not FlickrawOptions[:proxy_host]
30
+ proxy = URI.parse ENV['http_proxy']
31
+ FlickrawOptions.update(:proxy_host => proxy.host, :proxy_port => proxy.port, :proxy_user => proxy.user, :proxy_password => proxy.password)
32
+ end
33
+
28
34
  module FlickRaw
29
- VERSION='0.7'
35
+ VERSION='0.7.1'
30
36
 
31
37
  FLICKR_HOST='api.flickr.com'.freeze
32
38
 
@@ -148,7 +154,7 @@ module FlickRaw
148
154
  # Raises FailedResponse if the response status is _failed_.
149
155
  def call(req, args={})
150
156
  path = REST_PATH + build_args(args, req).collect { |a, v| "#{a}=#{v}" }.join('&')
151
- http_response = Net::HTTP.start(FLICKR_HOST) { |http| http.get(path, 'User-Agent' => "Flickraw/#{VERSION}") }
157
+ http_response = open_flickr {|http| http.get(path, 'User-Agent' => "Flickraw/#{VERSION}") }
152
158
  parse_response(http_response, req)
153
159
  end
154
160
 
@@ -159,7 +165,7 @@ module FlickRaw
159
165
  # See http://www.flickr.com/services/api/upload.api.html for more information on the arguments.
160
166
  def upload_photo(file, args={})
161
167
  photo = File.open(file, 'rb') { |f| f.read }
162
- boundary = MD5.md5(photo).to_s
168
+ boundary = Digest::MD5.hexdigest(photo)
163
169
 
164
170
  header = {'Content-type' => "multipart/form-data, boundary=#{boundary} ", 'User-Agent' => "Flickraw/#{VERSION}"}
165
171
  query = ''
@@ -178,7 +184,7 @@ module FlickRaw
178
184
  "\r\n" <<
179
185
  "--#{boundary}--"
180
186
 
181
- http_response = Net::HTTP.start(FLICKR_HOST) { |http| http.post(UPLOAD_PATH, query, header) }
187
+ http_response = open_flickr {|http| http.post(UPLOAD_PATH, query, header) }
182
188
  xml = http_response.body
183
189
  if xml[/stat="(\w+)"/, 1] == 'fail'
184
190
  msg = xml[/msg="([^"]+)"/, 1]
@@ -213,6 +219,13 @@ module FlickRaw
213
219
  token_reqs = ['flickr.auth.getToken', 'flickr.auth.getFullToken', 'flickr.auth.checkToken']
214
220
  @token = res.token if token_reqs.include?(req) and res.respond_to?(:token)
215
221
  end
222
+
223
+ def open_flickr
224
+ Net::HTTP::Proxy(FlickrawOptions[:proxy_host], FlickrawOptions[:proxy_port], FlickrawOptions[:proxy_user], FlickrawOptions[:proxy_password]).start(FLICKR_HOST) {|http|
225
+ http.read_timeout = FlickrawOptions[:timeout] if FlickrawOptions[:timeout]
226
+ yield http
227
+ }
228
+ end
216
229
  end
217
230
 
218
231
  class << self
@@ -233,7 +246,7 @@ module FlickRaw
233
246
 
234
247
  # Returns the signature of hsh. This is meant to be passed in the _api_sig_ parameter.
235
248
  def api_sig(hsh)
236
- Digest::MD5.hexdigest(FlickRaw.shared_secret + hsh.sort{|a, b| a[0].to_s <=> b[0].to_s }.flatten.join).to_s
249
+ Digest::MD5.hexdigest(FlickRaw.shared_secret + hsh.sort{|a, b| a[0].to_s <=> b[0].to_s }.flatten.join)
237
250
  end
238
251
  end
239
252
  end
@@ -243,5 +256,7 @@ end
243
256
  #
244
257
  # recent_photos = flickr.photos.getRecent
245
258
  # puts recent_photos[0].title
246
- def flickr; $flickraw end
247
- $flickraw = FlickRaw::Flickr.new
259
+ def flickr; $flickraw ||= FlickRaw::Flickr.new end
260
+
261
+ # Load the methods if the option lazyload is not specified
262
+ flickr if not FlickrawOptions[:lazyload]
data/rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
4
4
  require 'rake/testtask'
5
5
 
6
6
  require 'lib/flickraw'
7
- require 'flickraw_rdoc'
7
+ require 'flickraw_rdoc' if RUBY_VERSION >= "1.9"
8
8
 
9
9
  PKG_FILES = FileList["lib/flickraw.rb", "flickraw_rdoc.rb", "LICENSE", "README.rdoc", "rakefile", "examples/*.rb", "test/*.rb"].to_a
10
10
 
@@ -31,6 +31,7 @@ end
31
31
 
32
32
  Rake::TestTask.new
33
33
 
34
+ desc "Create a gemspec file"
34
35
  task :spec do
35
36
  spec_clone = spec.clone
36
37
  spec_clone.test_files = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickraw
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.7"
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mael Clerambault
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-26 00:00:00 +02:00
12
+ date: 2009-08-08 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15