Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrevalade committed Apr 28, 2011
1 parent 30ecb11 commit ada3b6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 87 deletions.
Binary file modified .DS_Store
Binary file not shown.
92 changes: 5 additions & 87 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,14 +1,14 @@
# Foursquare Rails Examples # Foursquare Rails Examples


This is a working Rails application that connects to the Foursquare API using [Quimby](http://github.com/groupme/quimby). This is a working Rails application that connects to the Foursquare API using [Quimby](http://github.com/groupme/quimby).
The application is live on Heroku at [http://foursquare-rails-example.heroku.com](http://foursquare-rails-example.heroku.com) The application is live on Heroku at [http://foursquare-rails-examples.heroku.com](http://foursquare-rails-example.heroku.com)


## Configuration ## Configuration


### Register your application ### Register your application


First, you need to [register your application](https://foursquare.com/oauth). First, you need to [register your application](https://foursquare.com/oauth).
Be sure to set your callback url to something like `{MY_APP_ROOT_URL}/session/callback`. Be sure to set your callback url to something like `{MY_APP_ROOT_URL}/session/callback` (this could be http://localhost:3000/session/callback).


Then, update `config/application.yml` with your `app_id` and `app_secret`. Then, update `config/application.yml` with your `app_id` and `app_secret`.


Expand All @@ -24,90 +24,8 @@ Go check `app/controllers/examples_controller.rb`


Documentation of Quimby, the Ruby wrapper used in this example application, is available [here](http://github.com/groupme/quimby). Documentation of Quimby, the Ruby wrapper used in this example application, is available [here](http://github.com/groupme/quimby).


#### Web server application Documentation of Foursquare API is available [here](http://developer.foursquare.com).


Get a foursquare with your `client_id` and `client_secret` ## Fork it!


foursquare = Foursquare::Base.new("CLIENT_ID", "CLIENT_SECRET") Want to contribute? Add some examples? That's great! Fork this project and send a pull request :O - I'll add your name to the list of contributors.

Redirect users to the Foursquare authentication page. You need to pass your `callback_url`. Get the url to redirect to with:

foursquare.authorize_url("CALLBACK_SESSION_URL")

Then Foursquare will redirect the user to your callback url with a code parameter in the url. Exchange this code for an access token using:

access_token = foursquare.access_token(params["code"], "CALLBACK_SESSION_URL")

Now you can get a foursquare using only an access token and make requests on user's behalf:

foursquare = Foursquare::Base.new("ACCESS_TOKEN")

### Users

Find a user:

user = foursquare.users.find("USER_ID")

Now we've got a `Foursquare::User` object. You can call sweet methods like `user.name` and even
`user.last_checkin`. **In general, John Mayer's Foursquare object methods are just snake-cased
versions of the attributes returned in the JSON.** Now let's accidentally that user's friends:

user.friends

This will return an array of `Foursquare::User` objects. Don't worry about the fact that they're
populated by limited JSON. Quimby will fetch the extra JSON if you need it. For example:

friend = user.friends.first
friend.name # Will not trigger a network call, since we already have it
friend.twitter # Will trigger a network to load the user's contact information

### Checkins

But wait, Foursquare isn't just users! It's checkins too! So let's find some checkins:

user.checkins

Now we have an array of `Foursquare::Checkin` objects. We can also grab a specific checkin:

checkin = foursquare.checkins.find("CHECKIN_ID")

You also have a convenient method if you want to get all the user checkins:

user.all_checkins

### Venues

We can get at a checkin's venue by calling `checkin.venue`. Pretty easy, RIGHT? Right. If you want to
find a venue directly, here ya go:

foursquare.venues.find("VENUE_ID")

You can also search venues:

foursquare.venues.search(:ll => "40.7236307,-73.9999479") # Returns all resulting groups
foursquare.venues.nearby(:ll => "40.7236307,-73.9999479") # Returns only nearby venues
foursquare.venues.trending(:ll => "40.7236307,-73.9999479") # Returns only trending venues
foursquare.venues.favorites(:ll => "40.7236307,-73.9999479") # Returns only favorite venues

The `:ll` option is required for venue searches. You can also feel free to pass any of the other
available Foursquare API options, as specified in the docs.

### Logging

If you want to see what's going on up in there, you can set `Foursquare.verbose` to `true`

Foursquare.verbose = true

Right now it'll log to `STDOUT`. Maybe I'll add nicer logging later. If you're lucky. In the meantime,
if you want to use your own logger, and you're kind of a jerk like me, you can do something like this:

Foursquare.verbose = true
def Foursquare.log(message)
Rails.logger.info("[foursquare] #{message}") # HAX, SORRY BRANDON
end

## TODO

* Creating checkins works, but it should really return notifications. Also, if the
checkin can't be created, it should return errors.
* I don't know, so much other stuff.

0 comments on commit ada3b6e

Please sign in to comment.