Git Product home page Git Product logo

gowalla's Introduction

Gowalla

Ruby wrapper for the Gowalla API.

Installation

sudo gem install gowalla

Get your API key

Be sure and get your API key: http://gowalla.com/api/keys

Usage

Instantiate a client (Basic Auth)

gowalla = Gowalla::Client.new(:username => 'pengwynn', :password => 'somepassword', :api_key => 'your_api_key')

or configure once

Gowalla.configure do |config|
  config.api_key = 'your_api_key'
  config.username = 'pengwynn'
  config.password = 'somepassword'
end
gowalla = Gowalla::Client.new

Instantiate a client (OAuth2)

For OAuth2, you'll need to specify a callback URL when you set up your app and get your API keys.

Let's create the client in a protected method in our controller:

protected
  def client
    Gowalla::Client.new (
      :api_key     => "your_api_key",
      :api_secret  => "your_api_secret",
      :access_token => session[:access_token]
    )
  end

We need to get an access token. Perhaps in an a before filter where you need to access Gowalla:

redirect(@client.web_server.authorize_url(:redirect_uri => redirect_uri, :state => 1))

or if you need read-write access:

redirect(@client.web_server.authorize_url(:redirect_uri => redirect_uri, :state => 1, :scope => 'read-write))

You'll need a callback route to catch the code coming back from Gowalla after a user grants you access and this must match what you specified when you created your app on Gowalla:

get '/auth/gowalla/callback' do
  access_token = client.web_server.get_access_token(
    params[:code],
    :redirect_uri => gowalla_callback_url
  )

  if access_token.expires_at < Time.now.utc
    access_token = client.web_server.refresh_access_token(
      session[:refresh_token]
    )
  end

  session[:access_token] = access_token.token
  session[:refresh_token] = access_token.refresh_token

  if session[:access_token]
    redirect '/auth/gowalla/test'
  else
    "Error retrieving access token."
  end
end

Now that we have an access token we can use the client to make calls, just like we would with Basic Auth. You can checkout a basic Sinatra example.

Examples

gowalla.user('pengwynn')
=> <#Hashie::Mash accept_url="/friendships/accept?user_id=1707" activity_url="/users/1707/events" bio="Web designer and Ruby developer." events_url="/users/1707/events" fb_id=605681706 first_name="Wynn" friends_count=27 friends_only=false friends_url="/users/1707/friends" hometown="Aubrey, TX" image_url="http://s3.amazonaws.com/static.gowalla.com/users/1707-standard.jpg?1262011383" is_friend=false items_count=5 items_url="/users/1707/items" last_name="Netherland" last_visit=<#Hashie::Mash comment="Closing every account I have " created_at="2010/01/26 15:31:46 +0000" spot=<#Hashie::Mash image_url="http://static.gowalla.com/categories/186-standard.png" name="Bank Of America" small_image_url="http://static.gowalla.com/categories/186-small-standard.png" url="/spots/164052"name="Wynn Netherland" pins_count=3 pins_url="/users/1707/pins" reject_url="/friendships/reject?user_id=1707" request_url="/friendships/request?user_id=1707" stamps_count=15 stamps_url="/users/1707/stamps" top_spots_url="/users/1707/top_spots" twitter_username="pengwynn" url="/users/1707" username="pengwynn" vaulted_kinds_count=0 visited_spots_count=15 website="http://wynnnetherland.com">

Details for the current user

gowalla.user

Details for another user

gowalla.user('bradleyjoyce')
gowalla.user(1707)

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) 2010 Wynn Netherland. See LICENSE for details.

gowalla's People

Contributors

armanddp avatar ctide avatar ehutzelman avatar jasonrudolph avatar kacy avatar mattt avatar pengwynn avatar rubenfonseca avatar sferik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gowalla's Issues

Invalid JSON String

Haven't tracked this all the way down but when trying to use list spots or featured spots I consistently get thrown an invalid json string:

Crack::ParseError: Invalid JSON string
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/crack-0.1.6/lib/crack/json.rb:14:in parse' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:116:injson'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:136:in send' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:136:inparse_supported_format'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:103:in parse' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:66:incall'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/request.rb:160:in parse_response' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/request.rb:155:inhandle_response'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/request.rb:60:in perform' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty.rb:243:inperform_request'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty.rb:195:in get' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/gowalla-0.1.2/lib/gowalla/client.rb:81:inlist_spots'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/gowalla-0.1.2/lib/gowalla/client.rb:85:in `featured_spots'
from (irb):3

error with gowalla.user

When I call gowalla.user after instantiating a client I get a big nasty error from Faraday: RuntimeError: Did not recognize your engine specification. Please specify either a symbol or a class.
from /home/BUS/djd226/.gems/gems/multi_json-0.0.4/lib/multi_json.rb:52:in engine=' from /home/BUS/djd226/.gems/gems/multi_json-0.0.4/lib/multi_json.rb:7:inengine'
from /home/BUS/djd226/.gems/gems/multi_json-0.0.4/lib/multi_json.rb:62:in decode' from /home/BUS/djd226/.gems/gems/faraday-middleware-0.0.1/lib/faraday/multi_json.rb:8:inregister_on_complete'
from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/response.rb:45:in call' from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/response.rb:45:infinish'
from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/response.rb:45:in each' from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/response.rb:45:infinish'
from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/builder.rb:18:in inner_app' from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/response.rb:17:incall'
from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/response.rb:17:in call' from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/adapter/net_http.rb:45:incall'
from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/request.rb:84:in run' from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/request.rb:26:inrun'
from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/connection.rb:155:in run_request' from /home/BUS/djd226/.gems/gems/faraday-0.4.6/lib/faraday/connection.rb:53:inget'
from /home/BUS/djd226/.gems/gems/gowalla-0.2.1/lib/gowalla/client.rb:27:in `user'

error in posting checkins

i'm getting this error when creating checkins

NoMethodError: undefined method `bytesize' for {}:Hash

Friends_events no longer functioning

Hate to open another issue but the friends_events call has stopped functioning as well. I think they may have changed how this is accessed recently but I'm not sure:

>> g = Gowalla::Client.new(:username => 'XXX', :password => 'YYY', :api_key => 'ZZZ')

>> g.friends_events
NoMethodError: undefined method `activity' for nil:NilClass

Crack::ParseError: Invalid JSON string

So all of a sudden I've started getting errors relating to crack being able to parse a spot request. As far as I can tell this ONLY effects spot requests. Example below, any idea what is going on?

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'gowalla'
=> true
irb(main):003:0> g = Gowalla::Client.new
=> #
irb(main):004:0> g.spot(90456)
Crack::ParseError: Invalid JSON string
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/crack-0.1.6/lib/crack/json.rb:14:in `parse'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:116:in `json'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:136:in `send'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:136:in `parse_supported_format'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:103:in `parse'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/parser.rb:66:in `call'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/request.rb:160:in `parse_response'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/request.rb:155:in `handle_response'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty/request.rb:60:in `perform'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty.rb:243:in `perform_request'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/httparty-0.5.2/lib/httparty.rb:195:in `get'
    from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/gowalla-0.1.3/lib/gowalla/client.rb:76:in `spot'
    from (irb):4
irb(main):005:0> HTTParty
=> HTTParty
irb(main):006:0> HTTParty.get('http://api.gowalla.com/spots/90456.json')
=> {"address"=>{"region"=>"CA", "locality"=>"Newport Beach"}, "name"=>"Sharkeez", "checkins_count"=>18, "created_at"=>"2009-11-10T00:46:58Z", "twitter_username"=>nil, "image_url"=>"http://static.gowalla.com/categories/130-standard.png", "max_items_count"=>10, "radius_meters"=>50, "creator"=>{"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/14245-standard.jpg?1259446826", "url"=>"/users/14245", "last_name"=>"Davis", "first_name"=>"Peter"}, "trending_level"=>0, "websites"=>[], "url"=>"/spots/90456", "users_count"=>15, "checkins_url"=>"/checkins?spot_id=90456", "map_bounds"=>{"south"=>nil, "north"=>nil, "west"=>nil, "east"=>nil}, "lng"=>-117.92792495, "spot_categories"=>[{"name"=>"Sports Bar", "url"=>"/categories/130"}], "list_image_url_320"=>nil, "founders"=>[{"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/142019-standard.jpg?1272317519", "url"=>"/users/142019", "last_name"=>"Herrick", "first_name"=>"Brooke"}, {"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/4685-standard.jpg?1267488622", "url"=>"/users/4685", "last_name"=>"Wilkins", "first_name"=>"Brian"}, {"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/5889-standard.jpg?1257455518", "url"=>"/users/5889", "last_name"=>"Moen", "first_name"=>"Michael"}, {"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/14245-standard.jpg?1259446826", "url"=>"/users/14245", "last_name"=>"Davis", "first_name"=>"Peter"}], "items_url"=>"/spots/90456/items", "items_count"=>4, "photos_url"=>"/spots/90456/photos", "description"=>"", "strict_radius"=>false, "last_checkins"=>[{"created_at"=>"2010-05-04T02:35:09Z", "url"=>"/checkins/7989531", "type"=>"checkin", "user"=>{"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/132416-standard.jpg?1267410749", "url"=>"/users/132416", "last_name"=>"Lambrakis", "first_name"=>"Mike"}, "message"=>"Going to the bathroom"}, {"created_at"=>"2010-05-04T02:32:53Z", "url"=>"/checkins/7989477", "type"=>"checkin", "user"=>{"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/142019-standard.jpg?1272317519", "url"=>"/users/142019", "last_name"=>"Herrick", "first_name"=>"Brooke"}, "message"=>""}, {"created_at"=>"2010-04-25T02:44:30Z", "url"=>"/checkins/7468966", "type"=>"checkin", "user"=>{"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/1152-standard.jpg?1239999453", "url"=>"/users/1152", "last_name"=>"McClure", "first_name"=>"Kari"}, "message"=>""}, {"created_at"=>"2010-04-24T20:01:07Z", "url"=>"/checkins/7444697", "type"=>"checkin", "user"=>{"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/1159-standard.jpg?1240006980", "url"=>"/users/1159", "last_name"=>"Webb", "first_name"=>"Shannon"}, "message"=>""}, {"created_at"=>"2010-04-16T07:02:39Z", "url"=>"/checkins/6915773", "type"=>"checkin", "user"=>{"image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/146485-standard.jpg?1271446838", "url"=>"/users/146485", "last_name"=>"Chen", "first_name"=>"Steve"}, "message"=>""}], "activity_url"=>"/spots/90456/events", "top_10"=>[{"checkins_count"=>"2", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/1152-standard.jpg?1239999453", "url"=>"/users/1152", "last_name"=>"McClure", "first_name"=>"Kari"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/132416-standard.jpg?1267410749", "url"=>"/users/132416", "last_name"=>"Lambrakis", "first_name"=>"Mike"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/142019-standard.jpg?1272317519", "url"=>"/users/142019", "last_name"=>"Herrick", "first_name"=>"Brooke"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/1159-standard.jpg?1240006980", "url"=>"/users/1159", "last_name"=>"Webb", "first_name"=>"Shannon"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/146485-standard.jpg?1271446838", "url"=>"/users/146485", "last_name"=>"Chen", "first_name"=>"Steve"}, {"checkins_count"=>"1", "image_url"=>"http://gowalla.com/images/default-user.jpg", "url"=>"/users/214810", "last_name"=>"Strohm", "first_name"=>"Aj"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/127568-standard.jpg?1266947968", "url"=>"/users/127568", "last_name"=>"Won", "first_name"=>"Andrew"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/6596-standard.jpg?1268798367", "url"=>"/users/6596", "last_name"=>"Lopez", "first_name"=>"David"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/90070-standard.jpg?1267163583", "url"=>"/users/90070", "last_name"=>"Fontanella", "first_name"=>"Jennifer"}, {"checkins_count"=>"1", "image_url"=>"http://s3.amazonaws.com/static.gowalla.com/users/4685-standard.jpg?1267488622", "url"=>"/users/4685", "last_name"=>"Wilkins", "first_name"=>"Brian"}], "lat"=>33.6084873667, "photos_count"=>0}

NameError: uninitialized constant Gowalla

I have successfully installed your wrapper on my Mac OS X 10.6:

$ gem install gowalla
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren't both writable.
When you HTTParty, you must party hard!
Successfully installed hashie-0.2.0
Successfully installed crack-0.1.6
Successfully installed httparty-0.5.2
Successfully installed gowalla-0.1.3
4 gems installed
Installing ri documentation for hashie-0.2.0...
Installing ri documentation for crack-0.1.6...
Installing ri documentation for httparty-0.5.2...
Installing ri documentation for gowalla-0.1.3...
Installing RDoc documentation for hashie-0.2.0...
Installing RDoc documentation for crack-0.1.6...
Installing RDoc documentation for httparty-0.5.2...
Installing RDoc documentation for gowalla-0.1.3...

But when I try the following I get that error message:

$ irb

gowalla = Gowalla::Client.new(:username => 'yraffah', :password => 'mypassword', :api_key => 'my_api_key')
NameError: uninitialized constant Gowalla
from (irb):1
exit

I have also tried the test_gowalla.rb and here is what I got:

$ ruby .gem/ruby/1.8/gems/gowalla-0.1.3/test/test_gowalla.rb
.gem/ruby/1.8/gems/gowalla-0.1.3/test/test_gowalla.rb:1:in `require': no such file to load -- helper (LoadError)
from .gem/ruby/1.8/gems/gowalla-0.1.3/test/test_gowalla.rb:1

Any idea of what can be wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.