Code Monkey home page Code Monkey logo

foursquare-wrapper's Introduction

Foursquare Wrapper

This is a Ruby library that wraps the Foursquare API, i.e. we get to write Ruby code to get Foursquare data!

###Installation

  1. If you haven't already, create a new directory for your project - you might want to call it something like foursquare-app.
  • Hint: You can create this from your terminal by typing mkdir foursquare-app.
  1. Inside of the foursquare-app directory, create a file called foursquare.rb.
  • Hint: You can create this file from your command line, by entering the foursquare-app directory and typing touch foursquare.rb.
  1. Copy all of the code in foursquare.rb from this repository and paste it into the foursquare.rb file that you created on your computer.

  2. In terminal, from inside any directory, type gem install httparty

###Usage

####Setting up Client ID and Secret

Register a new app with Foursquare and copy and then paste your client id and client secret on lines 8 and 9 after the equals sign. These need to be strings, so make sure you surround them in quotation marks. Make sure to uncomment out the lines of code too, by deleting the # in front of the variables.

####Classes This library is wrapped in a Neighborhood class.

A neighborhood has the following attributes:

  • location
  • recommended_venues
  • venue_ids
  • venues_to_filter
  • venues_by_group
  • venues_by_tag

We'll be using these attributes to narrow down our search to find a group of recommended restaurant that fit certain search criteria. Here are the types of groups that we can search for:

  • Reservations
  • Credit Cards
  • Delivery
  • Outdoor Seating
  • Street Parking
  • Wheelchair Accessible

Create a New Neighborhood

  east_village = Neighborhood.new("East Village, New York, NY")

In this code, we are creating a new instance of the Neighborhood class by calling Neighborhood.new. We're storing that new instance in a variable called east_village.

The initialize method accepts one argument, the neighborhood you want to search. In this case, we're passing in East Village, New York, NY. Next

Get Recommended Venues

east_village.get_recommended_venues

This method uses the Foursquare API "venues/explore" endpoint to pull a list of up to 30 recommended restaurants for the selected neighborhood (we're limiting it to 10 for now) and stores all of their info in the @recommended_venues array.

Filter by Group

east_village.filter_by_group("outdoor seating")

The filter_by_group method checks for restaurants that match the specified grouping like "Outdoor Seating". If a restaurant matches the group the restaurant name is added to a @venues_by_group array. This method is set up to only store the restaurant names, but it can be tweaked to grab additional info for each restaurant.

The filter_by_group method relies on two other methods that are called in a cascade - filter_by_group calls get_venues_for_filtering which calls get_venue_ids. You don't necessarily need to know how these methods work to use the wrapper, but details are included below.

Filter by Tag

east_village.filter_by_tag("trendy")

The filter_by_tag method checks for restaurants that have a tag that matches what you are searching for - like "trendy". If a restaurant has that tag the restaurant name is added to a @venues_by_tag array. This method is set up to only store the restaurant names, but it can be tweaked to grab additional info for each restaurant.

The filter_by_tag method also relies the get_venues_for_filtering and get_venue_ids methods.

Other Methods in the Wrapper

The filter_by_group and filter_by_tag methods rely on a couple additional methods to narrow down the recommended restaurants.

We have a ton of info about each restaurant in our @recommended_venues list, but if we want to drill deeper and see which venues are wheelchair accessible or have outdoor seating or are tagged as "trendy" we need EVEN more detail. The methods below are used to create API calls to pull more info on each of the venues in our @recommended_venues list.

get_venue_ids

  east_village.get_venue_ids

The get_venue_ids method takes the array of all the recommended restaurants, and iterates through them to pull the unique id associated with each. This method returns an @venue_ids array, with just the unique id number for each restaurant.

get_venues_for_filtering

east_village.get_venues_for_filtering

The get_venues_for_filtering method iterates through the @venue_ids array, and makes a GET request to the Foursquare API to get all of the information that Foursquare has for each venue. It returns a @venues_to_filter array with the info we need to filter by groups and tags.

View Foursquare Wrapper on Learn.co and start learning to code for free.

foursquare-wrapper's People

Contributors

fislabstest avatar fs-lms-test-bot avatar vanessadean avatar victhevenot avatar

Watchers

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

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.