Skip to content

Instantly share code, notes, and snippets.

@captproton
Created April 7, 2010 19:29
Show Gist options
  • Select an option

  • Save captproton/359315 to your computer and use it in GitHub Desktop.

Select an option

Save captproton/359315 to your computer and use it in GitHub Desktop.
Using httparty we get the following hash:
$ httparty http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photos.interestingness(20)&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
-bash: syntax error near unexpected token `('
TiVoHelp:recent-work.estherswhite.net heathertanner$ httparty http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photos.interestingness&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
[1] 70269
TiVoHelp:recent-work.estherswhite.net heathertanner$ {"query"=>
{"results"=>
{"photo"=>
[{"ispublic"=>"1",
"farm"=>"3",
"title"=>"Walled Gardens",
"id"=>"4496186567",
"isfamily"=>"0",
"server"=>"2700",
"secret"=>"16d6577224",
"isfriend"=>"0",
"owner"=>"64165252@N00"},
{"ispublic"=>"1",
"farm"=>"3",
"title"=>"The Plague",
"id"=>"4496807638",
"isfamily"=>"0",
"server"=>"2786",
"secret"=>"be0cd94cab",
"isfriend"=>"0",
"owner"=>"35223089@N05"},
{"ispublic"=>"1",
"farm"=>"5",
"title"=>"Patronage",
"id"=>"4496834364",
"isfamily"=>"0",
"server"=>"4052",
"secret"=>"fd6465b356",
"isfriend"=>"0",
"owner"=>"40800722@N02"},
{"ispublic"=>"1",
"farm"=>"3",
"title"=>"Beyond The Mind's Eye",
"id"=>"4496514721",
"isfamily"=>"0",
"server"=>"2773",
"secret"=>"943e5cc28e",
"isfriend"=>"0",
"owner"=>"34760108@N04"},
{"ispublic"=>"1",
"farm"=>"5",
"title"=>"all at sea",
"id"=>"4497088786",
"isfamily"=>"0",
"server"=>"4069",
"secret"=>"0b57aaafc2",
"isfriend"=>"0",
"owner"=>"95398362@N00"},
{"ispublic"=>"1",
"farm"=>"5",
"title"=>"Keep it up! - Reached Number 1 on Explore!!!!",
"id"=>"4498017150",
"isfamily"=>"0",
"server"=>"4038",
"secret"=>"eac24288c7",
"isfriend"=>"0",
"owner"=>"34593841@N04"},
{"ispublic"=>"1",
"farm"=>"5",
"title"=>"wild geese",
"id"=>"4497362662",
"isfamily"=>"0",
"server"=>"4038",
"secret"=>"4c34b2c532",
"isfriend"=>"0",
"owner"=>"26338263@N04"},
{"ispublic"=>"1",
"farm"=>"3",
"title"=>"The morning of life",
"id"=>"4496625476",
"isfamily"=>"0",
"server"=>"2793",
"secret"=>"e455c351c3",
"isfriend"=>"0",
"owner"=>"34124465@N08"},
{"ispublic"=>"1",
"farm"=>"5",
"title"=>"Infinite depth of field",
"id"=>"4495927881",
"isfamily"=>"0",
"server"=>"4040",
"secret"=>"e1b94dc04d",
"isfriend"=>"0",
"owner"=>"66967904@N00"},
{"ispublic"=>"1",
"farm"=>"5",
"title"=>"Night Colors",
"id"=>"4497609343",
"isfamily"=>"0",
"server"=>"4001",
"secret"=>"c57391d815",
"isfriend"=>"0",
"owner"=>"8481282@N02"}]},
"yahoo:count"=>"10",
"yahoo:created"=>"2010-04-07T07:19:35Z",
"yahoo:updated"=>"2010-04-07T07:19:35Z",
"diagnostics"=>
{"build_version"=>"5275",
"user_time"=>"195",
"service_time"=>"193",
"url"=>
"http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&page=1&per_page=10",
"publiclyCallable"=>"true"},
"xmlns:yahoo"=>"http://www.yahooapis.com/v1/base.rng",
"yahoo:uri"=>
"http://query.yahooapis.com/v1/yql?q=select+*+from+flickr.photos.interestingness",
"yahoo:lang"=>"en-US"}}
====
flickr.rb
class Flickr
include HTTParty
API_KEY = 'fe8cbedf3596ce4f2eb5379965bec29d'
PHOTOSET = 72157622782141504
base_uri 'http://query.yahooapis.com'
def self.photoset
get("/v1/public/yql", :query => {
:q => "select%20*%20from%20flickr.photos.interestingness&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys",
})
end
...
end
====
recent_work.rb
...
def get_photos
Flickr.photoset['query']['results']['photo']
end
...
====
NoMethodError - undefined method `[]' for nil:NilClass:
./recent_work.rb:11:in `get_photos'
./recent_work.rb:45:in `GET /'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:863:in `call'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:863:in `route'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:521:in `instance_eval'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:521:in `route_eval'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:500:in `route!'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:497:in `catch'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:497:in `route!'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:476:in `each'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:476:in `route!'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:601:in `dispatch!'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:411:in `call!'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in `instance_eval'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in `invoke'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in `catch'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in `invoke'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:411:in `call!'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:399:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/showexceptions.rb:24:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/commonlogger.rb:18:in `call'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:979:in `call'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:1005:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:979:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/content_length.rb:13:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/handler/webrick.rb:48:in `service'
/opt/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/opt/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/opt/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/opt/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `each'
/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/handler/webrick.rb:14:in `run'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:946:in `run!'
/opt/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/main.rb:25
./recent_work.rb:63
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment