Skip to content
Browse files

first commit

  • Loading branch information...
1 parent 5712c7f commit 3b16fec0bf9ee58c1e515f596608a2123dfb7be9 @christianhellsten committed Oct 6, 2009
Showing with 325 additions and 0 deletions.
  1. +5 −0 .document
  2. +8 −0 .gitignore
  3. +20 −0 LICENSE
  4. +18 −0 README.rdoc
  5. +59 −0 Rakefile
  6. +1 −0 VERSION
  7. +46 −0 lib/panoramio.rb
  8. +58 −0 panoramio.gemspec
  9. +1 −0 ruby-panoramio
  10. +55 −0 ruby-panoramio.gemspec
  11. +43 −0 test/panoramio_test.rb
  12. +11 −0 test/test_helper.rb
View
5 .document
@@ -0,0 +1,5 @@
+README.rdoc
+lib/**/*.rb
+bin/*
+features/**/*.feature
+LICENSE
View
8 .gitignore
@@ -0,0 +1,8 @@
+*.sw?
+.DS_Store
+coverage
+tmp/*
+pkg/*
+**/*.log
+rdoc
+pkg
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Christian Hellsten
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
18 README.rdoc
@@ -0,0 +1,18 @@
+= ruby-panoramio-api
+
+Description goes here.
+
+== Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a
+ future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+ (if you want to have your own version, that is fine but
+ bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+== Copyright
+
+Copyright (c) 2009 Christian Hellsten. See LICENSE for details.
View
59 Rakefile
@@ -0,0 +1,59 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "panoramio"
+ gem.summary = %Q{Simple Panoramio API client written in Ruby}
+ gem.description = %Q{Simple Panoramio API client written in Ruby}
+ gem.email = "christian.hellsten@gmail.com"
+ gem.homepage = "http://github.com/christian.hellsten/ruby-panoramio"
+ gem.authors = ["Christian Hellsten"]
+ gem.add_dependency "pauldix-typhoeus"
+ gem.add_dependency "json"
+ gem.add_development_dependency "thoughtbot-shoulda"
+ gem.add_development_dependency "jeremymcanally-matchy"
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/*_test.rb'
+ test.verbose = true
+end
+
+begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/*_test.rb'
+ test.verbose = true
+ end
+rescue LoadError
+ task :rcov do
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
+ end
+end
+
+task :test => :check_dependencies
+
+task :default => :test
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ if File.exist?('VERSION')
+ version = File.read('VERSION')
+ else
+ version = ""
+ end
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "panoramio #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
1 VERSION
@@ -0,0 +1 @@
+0.0.1
View
46 lib/panoramio.rb
@@ -0,0 +1,46 @@
+require 'typhoeus'
+require 'json'
+#require 'ruby-debug'
+
+#
+# http://www.panoramio.com/api/
+#
+class Panoramio
+ include Typhoeus
+
+ URL = 'http://www.panoramio.com/map/get_panoramas.php'
+
+ class << self
+ def url(options = {})
+ "#{URL}?#{to_uri(options)}"
+ end
+
+ 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_photos(json)
+ 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 "Error: #{response.code}. Body #{response.body}"},
+ :cache_responses => 180
+ define_remote_method :get_photos, :base_uri => URL
+
+end
View
58 panoramio.gemspec
@@ -0,0 +1,58 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE
+# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{panoramio}
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Christian Hellsten"]
+ s.date = %q{2009-10-03}
+ s.description = %q{Simple Panoramio API client written in Ruby}
+ s.email = %q{christian.hellsten@gmail.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/panoramio.rb",
+ "test/panoramio_test.rb",
+ "test/test_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/christian.hellsten/ruby-panoramio}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{Simple Panoramio API client written in Ruby}
+ s.test_files = [
+ "test/panoramio_test.rb",
+ "test/test_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<pauldix-typhoeus>, [">= 0"])
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ s.add_development_dependency(%q<jeremymcanally-matchy>, [">= 0"])
+ else
+ s.add_dependency(%q<pauldix-typhoeus>, [">= 0"])
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ s.add_dependency(%q<jeremymcanally-matchy>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<pauldix-typhoeus>, [">= 0"])
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ s.add_dependency(%q<jeremymcanally-matchy>, [">= 0"])
+ end
+end
1 ruby-panoramio
@@ -0,0 +1 @@
+Subproject commit e0d65de7b9bbb460c0272d63d7e505f5ba18fef6
View
55 ruby-panoramio.gemspec
@@ -0,0 +1,55 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE
+# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{ruby-panoramio}
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Christian Hellsten"]
+ s.date = %q{2009-10-03}
+ s.description = %q{Simple Panoramio API client written in Ruby}
+ s.email = %q{christian.hellsten@gmail.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/panoramio.rb",
+ "test/panoramio_test.rb",
+ "test/test_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/christian.hellsten/ruby-panoramio}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{Simple Panoramio API client written in Ruby}
+ s.test_files = [
+ "test/panoramio_test.rb",
+ "test/test_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ s.add_development_dependency(%q<jeremymcanally-matchy>, [">= 0"])
+ else
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ s.add_dependency(%q<jeremymcanally-matchy>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ s.add_dependency(%q<jeremymcanally-matchy>, [">= 0"])
+ end
+end
View
43 test/panoramio_test.rb
@@ -0,0 +1,43 @@
+require 'test_helper'
+require 'uri'
+
+class PanoramioTest < Test::Unit::TestCase
+ should "generate Panoramio API URLs" do
+ url = Panoramio.url(:order => :popularity,
+ :set => :public,
+ :from => 0,
+ :to => 10,
+ :minx => 60,
+ :maxx => 70,
+ :miny => 10,
+ :maxy => 20,
+ :size => :medium)
+ expected = "http://www.panoramio.com/map/get_panoramas.php?order=popularity&maxx=70&miny=10&set=public&maxy=20&from=0&size=thumbnail&to=20&minx=60"
+ url.should == expected
+ URI.parse(url).to_s.should == expected
+ end
+
+ should "generate Panoramio API URLs with default parameters" do
+ url = Panoramio.url(:minx => 60,
+ :maxx => 70,
+ :miny => 10,
+ :maxy => 20)
+ expected = "http://www.panoramio.com/map/get_panoramas.php?order=popularity&maxx=70&miny=10&set=public&maxy=20&from=0&size=thumbnail&to=20&minx=60"
+ url.should == expected
+ URI.parse(url).to_s.should == expected
+ end
+
+ context "support Panoramio REST API" do
+ should "GET /get_panoramas.php" do
+ photos = Panoramio.photos(:minx => 60,
+ :maxx => 70,
+ :miny => 10,
+ :maxy => 20)
+
+ photos.size.should == 20
+ photos.first.photo_title.should_not == nil
+ photos.first.latitude.should_not == nil
+ photos.first.longitude.should_not == nil
+ end
+ end
+end
View
11 test/test_helper.rb
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'test/unit'
+require 'shoulda'
+require 'matchy'
+
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'panoramio'
+
+class Test::Unit::TestCase
+end

0 comments on commit 3b16fec

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