Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
development.log
*.sqlite3
*.swp
*.swo
2 changes: 2 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# config.gem "aws-s3", :lib => "aws/s3"
config.gem "haml"
config.gem "authlogic", :version => "= 2.1.6"
config.gem "typhoeus"
config.gem "quimby"

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
Expand Down
61 changes: 61 additions & 0 deletions lib/foursquare/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module EXFoursquare
class Base
# Constants
API = "https://api.foursquare.com/v2/"

# Constructor
def initialize(*args)
case args.size
when 1
@access_token = args.first
when 2
@client_id, @client_secret = args
else
raise ArgumentError, "either access_token or (client_id + client_secret) should be passed"
end
end

def venues
EXFoursquare::Venue.new(self)
end

def get(path, query_params={})
require 'uri'
require 'net/http'
require 'net/https'

add_credential_params(query_params)

# create a URI object
param_array = []
query_params.each {|key, value| param_array << "#{key}=#{value}"}
api_url = API << path << '?' << param_array.join("&")
uri = URI.parse(api_url)

# create an http object with ssl (for https)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.set_debug_output($stdout)

# create the GET request
request = Net::HTTP::Get.new(uri.request_uri)

# execute the request
response = http.request(request)

# get and return the results
#result = ActiveSupport::JSON.decode(response.body)
end

private

def add_credential_params(params)
if @access_token
params.merge!(:oauth_token => @access_token)
else
params.merge!(:client_id => @client_id, :client_secret => @client_secret)
end
end
end
end
6 changes: 6 additions & 0 deletions lib/foursquare/tester.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'base'
require 'venue'

f = EXFoursquare::Base.new('HH0W0R34BDBXBU44OOXNIWT0VF4EBR0G4I0R1CDRDY5UNSPB', 'KSWT0P3UATRZUOFZO203YX5KR24U0I3XXXFB0QXXOA2TCNAD')
#@venues = f.venues.search({:ll => "48.857,2.349"})
@venues = f.venues.search(:near => "Chicago")
11 changes: 11 additions & 0 deletions lib/foursquare/venue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module EXFoursquare
class Venue
def initialize(foursquare)
@foursquare = foursquare
end

def search(options={})
puts @foursquare.get('venues/search', options)
end
end
end