Skip to content
Browse files

added parameters to options hash, some were earlier overwritten my me…

…rge!
  • Loading branch information...
1 parent d63a888 commit 9a54dc325a4d7041ea894e7e9794758d909d21e4 @akwiatkowski akwiatkowski committed Feb 26, 2011
Showing with 53 additions and 22 deletions.
  1. +53 −22 lib/panoramio.rb
View
75 lib/panoramio.rb
@@ -2,9 +2,36 @@
require 'json'
#require 'ruby-debug'
+# Utility for getting photos from Panoramio
+# http://www.panoramio.com/api/data/api.html
#
-# http://www.panoramio.com/api/
+# = Options Hash describtion:
#
+# :set:
+# - :public - popular
+# - :full - all
+#
+# :size:
+# - :original
+# - :medium (default value)
+# - :small
+# - :thumbnail
+# - :square
+# - :mini_square
+#
+# :minx, :miny, :maxx, :maxy - minimum longitude, latitude, maximum longitude and latitude, respectively
+#
+# :from, :to - number of photos to be returned
+#
+# Example:
+# Panoramio.photos(
+# :minx => -180,
+# :maxx => 180,
+# :miny => -90,
+# :maxy => 90#,
+# )
+
+
class Panoramio
include Typhoeus
@@ -15,37 +42,41 @@ def url(options = {})
"#{URL}?#{to_uri(options)}"
end
+ # Get photos from Panoramio
+ #
+ # :call-seq:
+ # Panoramio.photos( Hash options ) = > Array of photos
def photos(options = {})
to_photos(get_photos(:params => to_params(options)))
end
protected
- def to_params(options)
- options.merge!({ :order => :popularity,
- :set => :public,
- :size => :thumbnail,
- :from => 0,
- :to => 20 })
- end
-
- def to_uri(options)
- to_params(options).map {|key, val| "#{key}=#{val}" }.join("&")
- end
+ def to_params(options)
+ {:order => :popularity,
+ :set => :public,
+ :size => :thumbnail,
+ :from => 0,
+ :to => 20}.merge(options)
+ end
- def to_photos(json)
- # fix for 'no photos''
- if json['photos'].first.nil?
- return Array.new
- end
+ def to_uri(options)
+ to_params(options).map { |key, val| "#{key}=#{val}" }.join("&")
+ end
- struct = Struct.new('Photo', *json['photos'].first.keys)
- json['photos'].map {|p| struct.new(*p.values) }
+ def to_photos(json)
+ # fix for 'no photos''
+ if json['photos'].first.nil?
+ return Array.new
end
+
+ struct = Struct.new('Photo', *json['photos'].first.keys)
+ json['photos'].map { |p| struct.new(*p.values) }
+ end
end
- remote_defaults :on_success => lambda {|response| JSON.parse(response.body)},
- :on_failure => lambda {|response| raise "Panoramio.com error: #{response.code}. Response #{response.body}"},
+ remote_defaults :on_success => lambda { |response| JSON.parse(response.body) },
+ :on_failure => lambda { |response| raise "Panoramio.com error: #{response.code}. Response #{response.body}" },
:cache_responses => 180
define_remote_method :get_photos, :base_uri => URL
-
+
end

0 comments on commit 9a54dc3

Please sign in to comment.
Something went wrong with that request. Please try again.