cmdrkeene-foursquare 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/foursquare.gemspec +19 -4
- data/init.rb +7 -1
- data/lib/foursquare.rb +6 -106
- data/lib/foursquare/base.rb +43 -0
- data/lib/foursquare/checkin.rb +58 -0
- data/lib/foursquare/user.rb +17 -0
- data/lib/foursquare/venue.rb +68 -0
- data/spec/foursquare/base_spec.rb +43 -0
- data/spec/foursquare/checkin_spec.rb +103 -0
- data/spec/foursquare/user_spec.rb +65 -0
- data/spec/foursquare/venue_spec.rb +113 -0
- data/spec/foursquare_spec.rb +0 -216
- data/spec/spec_helper.rb +2 -1
- metadata +28 -4
data/Rakefile
CHANGED
@@ -8,6 +8,7 @@ begin
|
|
8
8
|
gemspec.homepage = "http://github.com/cmdrkeene/foursquare"
|
9
9
|
gemspec.authors = ["Brandon Keene"]
|
10
10
|
gemspec.add_dependency('httparty', '>= 0.4.4')
|
11
|
+
gemspec.add_dependency('geokit', '>= 1.4.1')
|
11
12
|
end
|
12
13
|
rescue LoadError
|
13
14
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/foursquare.gemspec
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{foursquare}
|
8
|
-
s.version = "0.0.
|
7
|
+
s.name = %q{cmdrkeene-foursquare}
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brandon Keene"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-09-12}
|
13
13
|
s.description = %q{Ruby API for Foursquare (playfoursquare.com)}
|
14
14
|
s.email = %q{bkeene@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,6 +24,10 @@ Gem::Specification.new do |s|
|
|
24
24
|
"foursquare.gemspec",
|
25
25
|
"init.rb",
|
26
26
|
"lib/foursquare.rb",
|
27
|
+
"lib/foursquare/base.rb",
|
28
|
+
"lib/foursquare/checkin.rb",
|
29
|
+
"lib/foursquare/user.rb",
|
30
|
+
"lib/foursquare/venue.rb",
|
27
31
|
"spec/fixtures/checkin_failure.json",
|
28
32
|
"spec/fixtures/checkin_success.json",
|
29
33
|
"spec/fixtures/cities.json",
|
@@ -32,6 +36,10 @@ Gem::Specification.new do |s|
|
|
32
36
|
"spec/fixtures/user.json",
|
33
37
|
"spec/fixtures/venues_authenticated.json",
|
34
38
|
"spec/fixtures/venues_unauthenticated.json",
|
39
|
+
"spec/foursquare/base_spec.rb",
|
40
|
+
"spec/foursquare/checkin_spec.rb",
|
41
|
+
"spec/foursquare/user_spec.rb",
|
42
|
+
"spec/foursquare/venue_spec.rb",
|
35
43
|
"spec/foursquare_spec.rb",
|
36
44
|
"spec/spec_helper.rb"
|
37
45
|
]
|
@@ -41,7 +49,11 @@ Gem::Specification.new do |s|
|
|
41
49
|
s.rubygems_version = %q{1.3.5}
|
42
50
|
s.summary = %q{Ruby API for Foursquare (playfoursquare.com)}
|
43
51
|
s.test_files = [
|
44
|
-
"spec/
|
52
|
+
"spec/foursquare/base_spec.rb",
|
53
|
+
"spec/foursquare/checkin_spec.rb",
|
54
|
+
"spec/foursquare/user_spec.rb",
|
55
|
+
"spec/foursquare/venue_spec.rb",
|
56
|
+
"spec/foursquare_spec.rb",
|
45
57
|
"spec/spec_helper.rb"
|
46
58
|
]
|
47
59
|
|
@@ -51,10 +63,13 @@ Gem::Specification.new do |s|
|
|
51
63
|
|
52
64
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
65
|
s.add_runtime_dependency(%q<httparty>, [">= 0.4.4"])
|
66
|
+
s.add_runtime_dependency(%q<geokit>, [">= 1.4.1"])
|
54
67
|
else
|
55
68
|
s.add_dependency(%q<httparty>, [">= 0.4.4"])
|
69
|
+
s.add_dependency(%q<geokit>, [">= 1.4.1"])
|
56
70
|
end
|
57
71
|
else
|
58
72
|
s.add_dependency(%q<httparty>, [">= 0.4.4"])
|
73
|
+
s.add_dependency(%q<geokit>, [">= 1.4.1"])
|
59
74
|
end
|
60
75
|
end
|
data/init.rb
CHANGED
data/lib/foursquare.rb
CHANGED
@@ -1,126 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Foursquare
|
4
|
-
class AuthenticationRequiredError < StandardError;end
|
5
|
-
class VenueNotFoundError < StandardError;end
|
6
|
-
|
1
|
+
module Foursquare#:nodoc:
|
7
2
|
include HTTParty
|
8
3
|
base_uri "http://api.playfoursquare.com/v1"
|
9
4
|
format :json
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
# Allows you to check-in to a place.
|
16
|
-
#
|
17
|
-
# Options
|
18
|
-
# :vid => (optional, not necessary if you are 'shouting' or have a
|
19
|
-
# venue name). ID of the venue where you want to check-in.
|
20
|
-
# :venue => (optional, not necessary if you are 'shouting' or have a
|
21
|
-
# vid) if you don't have a venue ID, pass the venue name as
|
22
|
-
# a string using this parameter. foursquare will attempt to
|
23
|
-
# match it on the server-side
|
24
|
-
# :shout => (optional) a message about your check-in
|
25
|
-
# :private => (optional, defaults to the user's setting). true means
|
26
|
-
# "don't show your friends". false means "show everyone"
|
27
|
-
# :twitter => (optional, defaults to the user's setting). false means
|
28
|
-
# "send to twitter". false means "don't send to twitter"
|
29
|
-
# :geolat => (optional, but recommended)
|
30
|
-
# :geolong => (optional, but recommended)
|
31
|
-
def checkin(options = {})
|
32
|
-
unless options[:private].nil?
|
33
|
-
options[:private] = 1 if options[:private] == true
|
34
|
-
options[:private] = 0 if options[:private] == false
|
35
|
-
end
|
36
|
-
unless options[:twitter].nil?
|
37
|
-
options[:twitter] = 1 if options[:twitter] == true
|
38
|
-
options[:twitter] = 0 if options[:twitter] == false
|
39
|
-
end
|
40
|
-
response = self.class.post("/checkin.json",
|
41
|
-
:query => options,
|
42
|
-
:basic_auth => @auth)
|
43
|
-
raise VenueNotFoundError if response.keys.include?("addvenueprompt")
|
44
|
-
response["checkin"]
|
45
|
-
end
|
46
|
-
|
47
|
-
# Like self.venues(), except when authenticated the method will return venue
|
48
|
-
# meta-data related to you and your friends.
|
49
|
-
def venues(options = {})
|
50
|
-
self.class.require_latitude_and_longitude(options)
|
51
|
-
|
52
|
-
response = self.class.get("/venues.json",
|
53
|
-
:query => options,
|
54
|
-
:basic_auth => @auth)["venues"]
|
55
|
-
response && response.flatten
|
5
|
+
|
6
|
+
# API returned 401 Unauthorized
|
7
|
+
class UnauthorizedException < Exception
|
56
8
|
end
|
57
9
|
|
58
|
-
#
|
59
|
-
|
60
|
-
# Options
|
61
|
-
# :uid => userid for the user whose information you want to retrieve.
|
62
|
-
# if you do not specify a 'uid', the authenticated user's
|
63
|
-
# profile data will be returned.
|
64
|
-
# :badges => (optional, default: false) set to true ("1") to also show
|
65
|
-
# badges for this user
|
66
|
-
# :mayor => (optional, default: false) set to true ("1") to also show
|
67
|
-
# venues for which this user is a mayor
|
68
|
-
def user(options = {})
|
69
|
-
self.class.get("/user.json", :query => options)["user"]
|
10
|
+
# API could not find record
|
11
|
+
class RecordNotFound < Exception
|
70
12
|
end
|
71
13
|
|
72
|
-
############################################################################
|
73
|
-
# Class methods
|
74
|
-
############################################################################
|
75
|
-
|
76
14
|
# Returns a list of currently active cities.
|
77
15
|
# http://api.playfoursquare.com/v1/cities
|
78
16
|
def self.cities
|
79
17
|
get("/cities.json", :query => nil)["cities"]
|
80
18
|
end
|
81
19
|
|
82
|
-
# Returns a list of tips near the area specified. (The distance returned is
|
83
|
-
# in miles).
|
84
|
-
# Options
|
85
|
-
# :geolat => latitude (required)
|
86
|
-
# :geolong => longitude (required)
|
87
|
-
#
|
88
|
-
# http://api.playfoursquare.com/v1/tips
|
89
|
-
def self.tips(options = {})
|
90
|
-
require_latitude_and_longitude(options)
|
91
|
-
# XXX
|
92
|
-
end
|
93
|
-
|
94
|
-
# Returns a list of venues near the area specified or that match the search
|
95
|
-
# term. Distance returned is in miles. It will return venue meta-data
|
96
|
-
# related to you and your friends.
|
97
|
-
#
|
98
|
-
# Options
|
99
|
-
# :geolat => latitude (required)
|
100
|
-
# :geolong => longitude (required)
|
101
|
-
# :r => radius in miles (optional)
|
102
|
-
# :l => limit of results (optional, default 10)
|
103
|
-
# :q => keyword search (optional)
|
104
|
-
#
|
105
|
-
# http://api.playfoursquare.com/v1/venues
|
106
|
-
def self.venues(options = {})
|
107
|
-
require_latitude_and_longitude(options)
|
108
|
-
|
109
|
-
get("/venues.json", :query => options)["venues"]["group"]
|
110
|
-
end
|
111
|
-
|
112
20
|
# Test if API is up and available
|
113
21
|
# http://api.playfoursquare.com/v1/test
|
114
22
|
def self.available?
|
115
23
|
response = get("/test.json", :query => nil)
|
116
24
|
(!response.nil? && response["response"] == "ok") ? true : false
|
117
25
|
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def self.require_latitude_and_longitude(options)
|
122
|
-
unless options[:geolat] and options[:geolong]
|
123
|
-
raise ArgumentError, "you must supply :geolat and :geolong"
|
124
|
-
end
|
125
|
-
end
|
126
26
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Foursquare #:nodoc:
|
2
|
+
class Base
|
3
|
+
def self.connect(username, password)
|
4
|
+
@@authentication = {:username => username, :password => password}
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.location=(location)
|
8
|
+
@@location = GeoKit::LatLng.normalize(location)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.authentication
|
12
|
+
@@authentication
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.location
|
16
|
+
@@location
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.latitude
|
20
|
+
location.lat
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.longitude
|
24
|
+
location.lng
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.get(*args)
|
30
|
+
Foursquare.get(*args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.post(*args)
|
34
|
+
Foursquare.post(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Ripped from ActiveSupport::CoreExtensions::Array::ExtractOptions
|
38
|
+
def self.extract_options(*args)
|
39
|
+
args.flatten!
|
40
|
+
args.last.is_a?(::Hash) ? args.pop : {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Foursquare
|
2
|
+
class Checkin < Base
|
3
|
+
def self.attribute_names
|
4
|
+
[:id,
|
5
|
+
:message,
|
6
|
+
:created_at,
|
7
|
+
:badges,
|
8
|
+
:mayor,
|
9
|
+
:scoring,
|
10
|
+
:venue
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor *attribute_names
|
15
|
+
|
16
|
+
def initialize(attributes = nil)
|
17
|
+
if attributes
|
18
|
+
self.id = attributes['id']
|
19
|
+
self.message = attributes['message']
|
20
|
+
self.created_at = Time.parse(attributes['created'])
|
21
|
+
self.badges = [attributes['badges']['badge']]
|
22
|
+
self.mayor = attributes['mayor']
|
23
|
+
self.scoring = attributes['scoring']
|
24
|
+
self.venue = Venue.new(attributes['venue'])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Allows you to check-in to a place.
|
29
|
+
#
|
30
|
+
# Options
|
31
|
+
# :vid => (optional, not necessary if you are 'shouting' or have a
|
32
|
+
# venue name). ID of the venue where you want to check-in.
|
33
|
+
# :venue => (optional, not necessary if you are 'shouting' or have a
|
34
|
+
# vid) if you don't have a venue ID, pass the venue name as
|
35
|
+
# a string using this parameter. foursquare will attempt to
|
36
|
+
# match it on the server-side
|
37
|
+
# :shout => (optional) a message about your check-in
|
38
|
+
# :private => (optional, defaults to the user's setting). true means
|
39
|
+
# "don't show your friends". false means "show everyone"
|
40
|
+
# :twitter => (optional, defaults to the user's setting). false means
|
41
|
+
# "send to twitter". false means "don't send to twitter"
|
42
|
+
# :geolat => (optional, but recommended)
|
43
|
+
# :geolong => (optional, but recommended)
|
44
|
+
def self.create(options = {})
|
45
|
+
unless options[:private].nil?
|
46
|
+
options[:private] = options[:private] ? 1 : 0
|
47
|
+
end
|
48
|
+
unless options[:twitter].nil?
|
49
|
+
options[:twitter] = (options[:twitter] ? 1 : 0)
|
50
|
+
end
|
51
|
+
response = post "/checkin.json",
|
52
|
+
:query => options,
|
53
|
+
:basic_auth => authentication
|
54
|
+
raise RecordNotFound if response.keys.include?("addvenueprompt")
|
55
|
+
new(response["checkin"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Foursquare
|
2
|
+
class User < Base
|
3
|
+
# Returns data for a particular user
|
4
|
+
#
|
5
|
+
# Options
|
6
|
+
# :uid => userid for the user whose information you want to retrieve.
|
7
|
+
# if you do not specify a 'uid', the authenticated user's
|
8
|
+
# profile data will be returned.
|
9
|
+
# :badges => (optional, default: false) set to true ("1") to also show
|
10
|
+
# badges for this user
|
11
|
+
# :mayor => (optional, default: false) set to true ("1") to also show
|
12
|
+
# venues for which this user is a mayor
|
13
|
+
def self.find(options = {})
|
14
|
+
get("/user.json", :query => options)["user"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Foursquare
|
2
|
+
class Venue < Base
|
3
|
+
def self.attribute_names
|
4
|
+
[:id,
|
5
|
+
:name,
|
6
|
+
:address,
|
7
|
+
:city,
|
8
|
+
:state,
|
9
|
+
:zip,
|
10
|
+
:cross_street,
|
11
|
+
:phone,
|
12
|
+
:latitude,
|
13
|
+
:longitude,
|
14
|
+
:distance]
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_accessor *attribute_names
|
18
|
+
|
19
|
+
def initialize(attributes = nil)
|
20
|
+
if attributes
|
21
|
+
self.id = attributes['id']
|
22
|
+
self.name = attributes['name']
|
23
|
+
self.address = attributes['address']
|
24
|
+
self.city = attributes['city']
|
25
|
+
self.state = attributes['state']
|
26
|
+
self.zip = attributes['zip']
|
27
|
+
self.cross_street = attributes['crossstreet']
|
28
|
+
self.phone = attributes['phone']
|
29
|
+
self.latitude = attributes['geolat']
|
30
|
+
self.longitude = attributes['geolong']
|
31
|
+
self.distance = attributes['distance']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find(*args)
|
36
|
+
options = extract_options(args)
|
37
|
+
case args.first
|
38
|
+
when :all then find_all(options)
|
39
|
+
when :first then find_first(options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def self.find_all(options)
|
46
|
+
if options[:near]
|
47
|
+
latlng = GeoKit::LatLng.normalize(options.delete(:near))
|
48
|
+
options[:geolat] = latlng.lat
|
49
|
+
options[:geolong] = latlng.lng
|
50
|
+
else
|
51
|
+
options[:geolat] ||= latitude
|
52
|
+
options[:geolong] ||= longitude
|
53
|
+
end
|
54
|
+
options[:l] ||= options.delete(:limit) if options[:limit]
|
55
|
+
options[:q] ||= options.delete(:search) if options[:search]
|
56
|
+
options[:r] ||= options.delete(:radius) if options[:radius]
|
57
|
+
|
58
|
+
response = get("/venues.json", :query => options)
|
59
|
+
response["venues"]["group"].map do |venue_hash|
|
60
|
+
new(venue_hash)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.find_first(options)
|
65
|
+
find_all(options.merge(:limit => 1)).first
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Foursquare::Base do
|
4
|
+
describe "connect" do
|
5
|
+
it "should set authentication hash" do
|
6
|
+
Foursquare::Base.connect('example', 'sekret')
|
7
|
+
Foursquare::Base.authentication.should == {
|
8
|
+
:username => 'example',
|
9
|
+
:password => 'sekret'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "location" do
|
15
|
+
before do
|
16
|
+
Foursquare::Base.location = [25.7323, -80.2436]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should convert into a GeoKit::LatLng instance" do
|
20
|
+
Foursquare::Base.location.should be_a_kind_of(GeoKit::LatLng)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should get latitude from location" do
|
24
|
+
Foursquare::Base.latitude.should == 25.7323
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get longitude from location" do
|
28
|
+
Foursquare::Base.longitude.should == -80.2436
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".extract_options" do
|
33
|
+
it "should extract options hash from args" do
|
34
|
+
Foursquare::Base.send(:extract_options).should == {}
|
35
|
+
Foursquare::Base.send(:extract_options, :all).should == {}
|
36
|
+
Foursquare::Base.send(:extract_options, :first).should == {}
|
37
|
+
Foursquare::Base.send(:extract_options, :all, {:search=>"foo"}).should == {:search => 'foo'}
|
38
|
+
Foursquare::Base.send(:extract_options, [:all, {:search=>"foo"}]).should == {:search => 'foo'}
|
39
|
+
Foursquare::Base.send(:extract_options, :all, :name => 'foo').should == {:name => 'foo'}
|
40
|
+
Foursquare::Base.send(:extract_options, :all, :name => 'foo', :limit => 10).should == {:name => 'foo', :limit => 10}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Foursquare::Checkin do
|
4
|
+
describe ".create" do
|
5
|
+
before do
|
6
|
+
# TODO commonize these, cleanup URI strings
|
7
|
+
@username = 'user@example.com'
|
8
|
+
@password = 'secret'
|
9
|
+
@valid_vid = 84689
|
10
|
+
@invalid_vid = 111
|
11
|
+
|
12
|
+
# Success
|
13
|
+
FakeWeb.register_uri(:post,
|
14
|
+
"http://api.playfoursquare.com/v1/checkin.json?vid=#{@valid_vid}",
|
15
|
+
:body => "Unauthorized",
|
16
|
+
:status => ["401", "Unauthorized"])
|
17
|
+
FakeWeb.register_uri(:post,
|
18
|
+
"http://user%40example.com:secret@api.playfoursquare.com/v1/checkin.json?vid=#{@valid_vid}",
|
19
|
+
:body => fakeweb_read('checkin_success.json'))
|
20
|
+
|
21
|
+
# Failure
|
22
|
+
FakeWeb.register_uri(:post,
|
23
|
+
"http://api.playfoursquare.com/v1/checkin.json?vid=#{@invalid_vid}",
|
24
|
+
:body => "Unauthorized",
|
25
|
+
:status => ["401", "Unauthorized"])
|
26
|
+
FakeWeb.register_uri(:post,
|
27
|
+
"http://user%40example.com:secret@api.playfoursquare.com/v1/checkin.json?vid=#{@invalid_vid}",
|
28
|
+
:body => fakeweb_read('checkin_failure.json'))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise an error if user is invalid" do
|
32
|
+
lambda {
|
33
|
+
Foursquare.connect("bork@pork.com", "arglebargle")
|
34
|
+
}.should raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "to a valid venue, with a valid user" do
|
38
|
+
before do
|
39
|
+
Foursquare::Base.connect(@username, @password)
|
40
|
+
@checkin = Foursquare::Checkin.create(:vid => @valid_vid)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should check in and return check in data" do
|
44
|
+
@checkin.id.should == 701707
|
45
|
+
@checkin.message.should == "OK! We've got you @ Santana's Bay Park."
|
46
|
+
@checkin.created_at.should == Time.parse("Tue, 11 Aug 09 16:02:13 +0000")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "parses venue response" do
|
50
|
+
@checkin.venue.should be_a_kind_of(Foursquare::Venue)
|
51
|
+
@checkin.venue.name.should == "Santana's Bay Park"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "parses badges response" do
|
55
|
+
@checkin.badges.size.should == 1
|
56
|
+
@checkin.badges.first.should == {
|
57
|
+
"name" => "Newbie",
|
58
|
+
"text" => "Congrats on your first check-in!",
|
59
|
+
"icon" => "http://playfoursquare.com/images/badges/newbie_on.png",
|
60
|
+
"id" => 54494
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
it "parses scoring response" do
|
65
|
+
@checkin.scoring.should == {
|
66
|
+
"score" => {
|
67
|
+
"icon" => "http://playfoursquare.com/images/scoring/2.png",
|
68
|
+
"points" =>1,
|
69
|
+
"message" =>"First stop today"
|
70
|
+
},
|
71
|
+
"total" => {
|
72
|
+
"points" => 6,
|
73
|
+
"message" => "6 pts "
|
74
|
+
},
|
75
|
+
"rank" => {
|
76
|
+
"city" => {
|
77
|
+
"city" => "San Diego",
|
78
|
+
"position" => 42,
|
79
|
+
"message" => "#42 in San Diego (this week)"
|
80
|
+
},
|
81
|
+
"friends" => {
|
82
|
+
"position" => 1,
|
83
|
+
"message" => "#1 amongst friends"
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
it "parses mayor response" do
|
90
|
+
@checkin.mayor.should == {"type"=>"nochange", "message"=>"Casey W. is The Mayor of Santana's Bay Park."}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "with an invalid venue" do
|
95
|
+
it "should raise a record not found exception" do
|
96
|
+
lambda {
|
97
|
+
Foursquare::Base.connect(@username, @password)
|
98
|
+
Foursquare::Checkin.create(:vid => @invalid_vid).should == "foo"
|
99
|
+
}.should raise_error(Foursquare::RecordNotFound)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Foursquare::User do
|
4
|
+
describe ".find" do
|
5
|
+
before do
|
6
|
+
@username = 'user@example.com'
|
7
|
+
@password = 'secret'
|
8
|
+
Foursquare::Base.connect(@username, @password)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return user data for an arbitrary user" do
|
12
|
+
FakeWeb.register_uri(:get,
|
13
|
+
"http://api.playfoursquare.com/v1/user.json?uid=31786",
|
14
|
+
:body => fakeweb_read('user.json'))
|
15
|
+
|
16
|
+
Foursquare::User.find(:uid => 31786).should == {
|
17
|
+
"city" => {"shortname"=>"San Diego",
|
18
|
+
"name"=>"San Diego",
|
19
|
+
"geolong"=>-117.156,
|
20
|
+
"geolat"=>32.7153, "id"=>38},
|
21
|
+
"gender"=>"none",
|
22
|
+
"lastname"=>"Connor",
|
23
|
+
"id"=>31786,
|
24
|
+
"checkin"=>{"shout"=>nil,
|
25
|
+
"id"=>707746,
|
26
|
+
"display"=>"John C. @ Santana's Mexican Grill (Bay Park)",
|
27
|
+
"venue"=>{"address"=>"1975 Morena Blvd",
|
28
|
+
"name"=>"Santana's Mexican Grill (Bay Park)",
|
29
|
+
"geolong"=>-117.207,
|
30
|
+
"geolat"=>32.782,
|
31
|
+
"crossstreet"=>"Napier St",
|
32
|
+
"id"=>84689},
|
33
|
+
"created"=>"Wed, 12 Aug 09 10:21:33 +0000"},
|
34
|
+
"firstname"=>"John",
|
35
|
+
"settings"=>{"feeds_key"=>"9c0cf605ddd2251495640129c7c40c6e"}}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return user data for the authenticated user" do
|
39
|
+
FakeWeb.register_uri(:get,
|
40
|
+
"http://api.playfoursquare.com/v1/user.json",
|
41
|
+
:body => fakeweb_read('user.json'))
|
42
|
+
|
43
|
+
Foursquare::User.find == {
|
44
|
+
"city" => {"shortname"=>"San Diego",
|
45
|
+
"name"=>"San Diego",
|
46
|
+
"geolong"=>-117.156,
|
47
|
+
"geolat"=>32.7153, "id"=>38},
|
48
|
+
"gender"=>"none",
|
49
|
+
"lastname"=>"Connor",
|
50
|
+
"id"=>31786,
|
51
|
+
"checkin"=>{"shout"=>nil,
|
52
|
+
"id"=>707746,
|
53
|
+
"display"=>"John C. @ Santana's Mexican Grill (Bay Park)",
|
54
|
+
"venue"=>{"address"=>"1975 Morena Blvd",
|
55
|
+
"name"=>"Santana's Mexican Grill (Bay Park)",
|
56
|
+
"geolong"=>-117.207,
|
57
|
+
"geolat"=>32.782,
|
58
|
+
"crossstreet"=>"Napier St",
|
59
|
+
"id"=>84689},
|
60
|
+
"created"=>"Wed, 12 Aug 09 10:21:33 +0000"},
|
61
|
+
"firstname"=>"John",
|
62
|
+
"settings"=>{"feeds_key"=>"9c0cf605ddd2251495640129c7c40c6e"}}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Foursquare::Venue do
|
4
|
+
before do
|
5
|
+
FakeWeb.register_uri(:get,
|
6
|
+
"http://api.playfoursquare.com/v1/venues.json?geolat=25.7323&geolong=-80.2436",
|
7
|
+
:body => fakeweb_read('venues_unauthenticated.json'))
|
8
|
+
Foursquare::Base.location = [25.7323, -80.2436] # Miami, FL
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should initialize from hash" do
|
12
|
+
venue = Foursquare::Venue.new("city" => "Miami",
|
13
|
+
"address" => "3339 Virginia St",
|
14
|
+
"name" => "InfiniHQ",
|
15
|
+
"zip" => 33133,
|
16
|
+
"geolong" => -80.2413,
|
17
|
+
"geolat" => 25.7292,
|
18
|
+
"crossstreet" => "at Oak Ave",
|
19
|
+
"id" => 84676,
|
20
|
+
"phone" => 3057284641,
|
21
|
+
"state" => "FL",
|
22
|
+
"distance" => 0.3)
|
23
|
+
venue.city.should == "Miami"
|
24
|
+
venue.address.should == "3339 Virginia St"
|
25
|
+
venue.name.should == "InfiniHQ"
|
26
|
+
venue.zip.should == 33133
|
27
|
+
venue.longitude.should == -80.2413
|
28
|
+
venue.latitude.should == 25.7292
|
29
|
+
venue.cross_street.should == "at Oak Ave"
|
30
|
+
venue.id.should == 84676
|
31
|
+
venue.phone.should == 3057284641
|
32
|
+
venue.state.should == "FL"
|
33
|
+
venue.distance.should == 0.3
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".find" do
|
37
|
+
describe ":all" do
|
38
|
+
it "should return a list of venues" do
|
39
|
+
# JSON response => array of venue hashes
|
40
|
+
# [{"city"=>"Miami", "address"=>"3339 Virginia St", "name"=>"InfiniHQ", "zip"=>33133, "geolong"=>-80.2413, "geolat"=>25.7292, "crossstreet"=>"at Oak Ave", "id"=>84676, "phone"=>3057284641, "state"=>"FL", "distance"=>0.3}, ...]
|
41
|
+
venues = Foursquare::Venue.find(:all)
|
42
|
+
|
43
|
+
# Collection
|
44
|
+
venues.size.should == 20
|
45
|
+
|
46
|
+
# Venue
|
47
|
+
venue = venues.first
|
48
|
+
venue.should be_a_kind_of(Foursquare::Venue)
|
49
|
+
venue.city.should == "Miami"
|
50
|
+
venue.address.should == "3339 Virginia St"
|
51
|
+
venue.name.should == "InfiniHQ"
|
52
|
+
venue.zip.should == 33133
|
53
|
+
venue.longitude.should == -80.2413
|
54
|
+
venue.latitude.should == 25.7292
|
55
|
+
venue.cross_street.should == "at Oak Ave"
|
56
|
+
venue.id.should == 84676
|
57
|
+
venue.phone.should == 3057284641
|
58
|
+
venue.state.should == "FL"
|
59
|
+
venue.distance.should == 0.3
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "when authenticated" do
|
63
|
+
it "should pull user specific data"
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "with options" do
|
67
|
+
it "converts :search option to :q" do
|
68
|
+
FakeWeb.register_uri(:get,
|
69
|
+
"http://api.playfoursquare.com/v1/venues.json?geolong=-80.2436&q=foo&geolat=25.7323",
|
70
|
+
:body => fakeweb_read('venues_unauthenticated.json'))
|
71
|
+
Foursquare::Venue.find(:all, :search => 'foo').size.should == 20
|
72
|
+
end
|
73
|
+
|
74
|
+
it "converts :radius option to :r" do
|
75
|
+
FakeWeb.register_uri(:get,
|
76
|
+
"http://api.playfoursquare.com/v1/venues.json?geolong=-80.2436&r=10&geolat=25.7323",
|
77
|
+
:body => fakeweb_read('venues_unauthenticated.json'))
|
78
|
+
Foursquare::Venue.find(:all, :radius => 10).size.should == 20
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
it "converts :limit option to :l" do
|
83
|
+
FakeWeb.register_uri(:get,
|
84
|
+
"http://api.playfoursquare.com/v1/venues.json?geolong=-80.2436&l=20&geolat=25.7323",
|
85
|
+
:body => fakeweb_read('venues_unauthenticated.json'))
|
86
|
+
Foursquare::Venue.find(:all, :limit => 20).size.should == 20
|
87
|
+
end
|
88
|
+
|
89
|
+
it "converts :near condition (a normalizeable GeoKit object) to :geolat, :geolong" do
|
90
|
+
FakeWeb.register_uri(:get,
|
91
|
+
"http://api.playfoursquare.com/v1/venues.json?geolong=-70&geolat=20",
|
92
|
+
:body => fakeweb_read('venues_unauthenticated.json'))
|
93
|
+
Foursquare::Venue.find(:all, :near => [20, -70]).size.should == 20
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe ":first" do
|
99
|
+
it "should return a single venue" do
|
100
|
+
FakeWeb.register_uri(:get,
|
101
|
+
"http://api.playfoursquare.com/v1/venues.json?geolat=25.7323&geolong=-80.2436&l=1",
|
102
|
+
:body => fakeweb_read('venues_unauthenticated.json'))
|
103
|
+
|
104
|
+
venue = Foursquare::Venue.find(:first)
|
105
|
+
venue.should be_a_kind_of(Foursquare::Venue)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#checkin" do
|
111
|
+
it "should check the authenticated user into the venue"
|
112
|
+
end
|
113
|
+
end
|
data/spec/foursquare_spec.rb
CHANGED
@@ -2,74 +2,6 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
require File.dirname(__FILE__) + '/../init'
|
3
3
|
|
4
4
|
describe Foursquare do
|
5
|
-
before do
|
6
|
-
@username = "user@example.com"
|
7
|
-
@password = "secret"
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#checkin" do
|
11
|
-
before do
|
12
|
-
@valid_vid = 84689
|
13
|
-
@invalid_vid = 111
|
14
|
-
|
15
|
-
# Success
|
16
|
-
FakeWeb.register_uri(:post,
|
17
|
-
"http://api.playfoursquare.com/v1/checkin.json?vid=#{@valid_vid}",
|
18
|
-
:body => "Unauthorized",
|
19
|
-
:status => ["401", "Unauthorized"])
|
20
|
-
FakeWeb.register_uri(:post,
|
21
|
-
"http://user%40example.com:secret@api.playfoursquare.com/v1/checkin.json?vid=#{@valid_vid}",
|
22
|
-
:body => fakeweb_read('checkin_success.json'))
|
23
|
-
|
24
|
-
# Failure
|
25
|
-
FakeWeb.register_uri(:post,
|
26
|
-
"http://api.playfoursquare.com/v1/checkin.json?vid=#{@invalid_vid}",
|
27
|
-
:body => "Unauthorized",
|
28
|
-
:status => ["401", "Unauthorized"])
|
29
|
-
FakeWeb.register_uri(:post,
|
30
|
-
"http://user%40example.com:secret@api.playfoursquare.com/v1/checkin.json?vid=#{@invalid_vid}",
|
31
|
-
:body => fakeweb_read('checkin_failure.json'))
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should raise an error if user is invalid" do
|
35
|
-
lambda {
|
36
|
-
Foursquare.new("bork@pork.com", "arglebargle").checkin(@valid_vid)
|
37
|
-
}.should raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "to a valid venue, with a valid user" do
|
41
|
-
it "should check in and return check in data" do
|
42
|
-
@foursquare = Foursquare.new(@username, @password)
|
43
|
-
checkin = @foursquare.checkin(:vid => @valid_vid)
|
44
|
-
checkin.should == {
|
45
|
-
"mayor" => {"type"=>"nochange", "message"=>"Casey W. is The Mayor of Santana's Bay Park."},
|
46
|
-
"scoring" => {
|
47
|
-
"score" => {"icon"=>"http://playfoursquare.com/images/scoring/2.png", "points"=>1, "message"=>"First stop today"},
|
48
|
-
"total" => {"points"=>6, "message"=>"6 pts "},
|
49
|
-
"rank" => {
|
50
|
-
"city" => {"city"=>"San Diego", "position"=>42, "message"=>"#42 in San Diego (this week)"},
|
51
|
-
"friends" => {"position"=>1, "message"=>"#1 amongst friends"}
|
52
|
-
},
|
53
|
-
},
|
54
|
-
"id" => 701707,
|
55
|
-
"badges" => {
|
56
|
-
"badge" => {"name"=>"Newbie", "text"=>"Congrats on your first check-in!", "icon"=>"http://playfoursquare.com/images/badges/newbie_on.png", "id"=>54494}
|
57
|
-
},
|
58
|
-
"venue" => {"city"=>"San Diego", "address"=>"1975 Morena Blvd.", "name"=>"Santana's Bay Park", "zip"=>92110, "geolong"=>-117.207, "geolat"=>32.782, "crossstreet"=>nil, "id"=>84689, "cityid"=>38, "state"=>"CA"},
|
59
|
-
"message" => "OK! We've got you @ Santana's Bay Park.", "created"=>"Tue, 11 Aug 09 16:02:13 +0000"
|
60
|
-
}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "with an invalid venue" do
|
65
|
-
it "should raise an error" do
|
66
|
-
lambda {
|
67
|
-
@foursquare = Foursquare.new(@username, @password)
|
68
|
-
@foursquare.checkin(:vid => @invalid_vid).should == "foo"
|
69
|
-
}.should raise_error(Foursquare::VenueNotFoundError)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
5
|
|
74
6
|
describe ".cities" do
|
75
7
|
before do
|
@@ -105,155 +37,7 @@ describe Foursquare do
|
|
105
37
|
Foursquare.cities.should == cities
|
106
38
|
end
|
107
39
|
end
|
108
|
-
|
109
|
-
describe ".tips" do
|
110
|
-
# Having problems with the tips resource respect coordinates
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "#user" do
|
114
|
-
it "should return user data for an arbitrary user" do
|
115
|
-
FakeWeb.register_uri(:get,
|
116
|
-
"http://api.playfoursquare.com/v1/user.json?uid=31786",
|
117
|
-
:body => fakeweb_read('user.json'))
|
118
|
-
|
119
|
-
@foursquare = Foursquare.new(@username, @password)
|
120
|
-
@foursquare.user(:uid => 31786).should == {
|
121
|
-
"city" => {"shortname"=>"San Diego",
|
122
|
-
"name"=>"San Diego",
|
123
|
-
"geolong"=>-117.156,
|
124
|
-
"geolat"=>32.7153, "id"=>38},
|
125
|
-
"gender"=>"none",
|
126
|
-
"lastname"=>"Connor",
|
127
|
-
"id"=>31786,
|
128
|
-
"checkin"=>{"shout"=>nil,
|
129
|
-
"id"=>707746,
|
130
|
-
"display"=>"John C. @ Santana's Mexican Grill (Bay Park)",
|
131
|
-
"venue"=>{"address"=>"1975 Morena Blvd",
|
132
|
-
"name"=>"Santana's Mexican Grill (Bay Park)",
|
133
|
-
"geolong"=>-117.207,
|
134
|
-
"geolat"=>32.782,
|
135
|
-
"crossstreet"=>"Napier St",
|
136
|
-
"id"=>84689},
|
137
|
-
"created"=>"Wed, 12 Aug 09 10:21:33 +0000"},
|
138
|
-
"firstname"=>"John",
|
139
|
-
"settings"=>{"feeds_key"=>"9c0cf605ddd2251495640129c7c40c6e"}}
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should return user data for the authenticated user" do
|
143
|
-
FakeWeb.register_uri(:get,
|
144
|
-
"http://api.playfoursquare.com/v1/user.json",
|
145
|
-
:body => fakeweb_read('user.json'))
|
146
|
-
|
147
|
-
@foursquare = Foursquare.new(@username, @password)
|
148
|
-
@foursquare.user.should == {
|
149
|
-
"city" => {"shortname"=>"San Diego",
|
150
|
-
"name"=>"San Diego",
|
151
|
-
"geolong"=>-117.156,
|
152
|
-
"geolat"=>32.7153, "id"=>38},
|
153
|
-
"gender"=>"none",
|
154
|
-
"lastname"=>"Connor",
|
155
|
-
"id"=>31786,
|
156
|
-
"checkin"=>{"shout"=>nil,
|
157
|
-
"id"=>707746,
|
158
|
-
"display"=>"John C. @ Santana's Mexican Grill (Bay Park)",
|
159
|
-
"venue"=>{"address"=>"1975 Morena Blvd",
|
160
|
-
"name"=>"Santana's Mexican Grill (Bay Park)",
|
161
|
-
"geolong"=>-117.207,
|
162
|
-
"geolat"=>32.782,
|
163
|
-
"crossstreet"=>"Napier St",
|
164
|
-
"id"=>84689},
|
165
|
-
"created"=>"Wed, 12 Aug 09 10:21:33 +0000"},
|
166
|
-
"firstname"=>"John",
|
167
|
-
"settings"=>{"feeds_key"=>"9c0cf605ddd2251495640129c7c40c6e"}}
|
168
|
-
end
|
169
|
-
end
|
170
40
|
|
171
|
-
describe "#user" do
|
172
|
-
it "should return authenticated user's data" do
|
173
|
-
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe ".venue" do
|
178
|
-
before do
|
179
|
-
FakeWeb.register_uri(:get,
|
180
|
-
"http://api.playfoursquare.com/v1/venues.json?geolat=25.7323&geolong=80.2436",
|
181
|
-
:body => fakeweb_read('venues_unauthenticated.json'))
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should raise an error unless geolat and geolong are passed" do
|
185
|
-
lambda {
|
186
|
-
Foursquare.venues
|
187
|
-
}.should raise_error(ArgumentError)
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should return a list of nearby venues" do
|
191
|
-
venues = [
|
192
|
-
{"city"=>"Miami", "address"=>"3339 Virginia St", "name"=>"InfiniHQ", "zip"=>33133, "geolong"=>-80.2413, "geolat"=>25.7292, "crossstreet"=>"at Oak Ave", "id"=>84676, "phone"=>3057284641, "state"=>"FL", "distance"=>0.3},
|
193
|
-
{"city"=>"Miami", "address"=>"3342 Virginia St", "name"=>"Life", "zip"=>33133, "geolong"=>-80.2415, "geolat"=>25.7289, "crossstreet"=>nil, "id"=>10252, "phone"=>nil, "state"=>"FL", "distance"=>0.3},
|
194
|
-
{"city"=>"Miami", "address"=>"3064 Grand Ave", "name"=>"Sandbar", "zip"=>33133, "geolong"=>-80.2428, "geolat"=>25.7281, "crossstreet"=>nil, "id"=>10350, "phone"=>nil, "state"=>"FL", "distance"=>0.3},
|
195
|
-
{"city"=>"Miami", "address"=>"2911 Grand Ave", "name"=>"Oxygen Lounge", "zip"=>33133, "geolong"=>-80.2406, "geolat"=>25.7285, "crossstreet"=>nil, "id"=>10305, "phone"=>nil, "state"=>"FL", "distance"=>0.3},
|
196
|
-
{"city"=>"Coconut Grove", "address"=>"3415 Main Hwy", "name"=>"Boardwalk Tavern & Pizzeria", "zip"=>33133, "geolong"=>-80.2427, "geolat"=>25.7277, "crossstreet"=>nil, "id"=>45598, "phone"=>"305-567-0080", "state"=>"FL", "distance"=>0.3},
|
197
|
-
{"city"=>"Miami", "address"=>"3035 Fuller St,", "name"=>"Barracadu Bar & Grill }i{", "zip"=>33133, "geolong"=>-80.2432, "geolat"=>25.7276, "crossstreet"=>"btw Main Hwy and Grand ave", "id"=>88408, "phone"=>"(305) 448-1144", "state"=>"FL", "distance"=>0.3},
|
198
|
-
{"city"=>"Miami", "address"=>"3035 Fuller St", "name"=>"Barracadu Coconut Grove}i{", "zip"=>nil, "geolong"=>-80.2432, "geolat"=>25.7276, "crossstreet"=>"btw Main Hwy and Grand ave", "id"=>85556, "phone"=>"(305) 448-1144", "state"=>"FL", "distance"=>0.3},
|
199
|
-
{"city"=>"Miami", "address"=>"3035 Fuller St", "name"=>"Barracuda Bar", "zip"=>33133, "geolong"=>-80.2432, "geolat"=>25.7276, "crossstreet"=>"at Grand Ave", "id"=>18315, "phone"=>"305 448-1144", "state"=>"FL", "distance"=>0.3},
|
200
|
-
{"city"=>"Miami", "address"=>"3424 Main Highway", "name"=>"Hungry Sailor", "zip"=>33133, "geolong"=>-80.2428, "geolat"=>25.7276, "crossstreet"=>nil, "id"=>10219, "phone"=>nil, "state"=>"FL", "distance"=>0.3},
|
201
|
-
{"city"=>"Miami", "address"=>"3416 Main Highway", "name"=>"Tavern In The Grove", "zip"=>33133, "geolong"=>-80.2427, "geolat"=>25.7276, "crossstreet"=>nil, "id"=>10391, "phone"=>nil, "state"=>"FL", "distance"=>0.3},
|
202
|
-
{"city"=>"Miami", "address"=>"2801 Florida Ave", "name"=>"Quench", "zip"=>33133, "geolong"=>-80.2395, "geolat"=>25.7291, "crossstreet"=>nil, "id"=>10331, "phone"=>"305 448-8150", "state"=>"FL", "distance"=>0.3},
|
203
|
-
{"city"=>"Miami", "address"=>"3131 Commodore Plaza", "name"=>"Mr. Moe's", "zip"=>33133, "geolong"=>-80.2441, "geolat"=>25.7274, "crossstreet"=>nil, "id"=>10287, "phone"=>nil, "state"=>"FL", "distance"=>0.3},
|
204
|
-
{"city"=>"Miami", "address"=>"3120 Commodore Plaza", "name"=>"Don Quixote", "zip"=>33133, "geolong"=>-80.2447, "geolat"=>25.7271, "crossstreet"=>nil, "id"=>10147, "phone"=>nil, "state"=>"FL", "distance"=>0.4},
|
205
|
-
{"city"=>"Miami", "address"=>"2895 McFarlane RD.", "name"=>"Flavour", "zip"=>33133, "geolong"=>-80.2411, "geolat"=>25.7275, "crossstreet"=>nil, "id"=>10173, "phone"=>nil, "state"=>"FL", "distance"=>0.4},
|
206
|
-
{"city"=>"Miami", "address"=>"3480 Main Highway", "name"=>"Senor Frogs", "zip"=>33133, "geolong"=>-80.2442, "geolat"=>25.7267, "crossstreet"=>nil, "id"=>10356, "phone"=>nil, "state"=>"FL", "distance"=>0.4},
|
207
|
-
{"city"=>"Miami", "address"=>"3390 Mary St", "name"=>"Improv Comedy Club", "zip"=>33133, "geolong"=>-80.2393, "geolat"=>25.7282, "crossstreet"=>nil, "id"=>10224, "phone"=>nil, "state"=>"FL", "distance"=>0.4},
|
208
|
-
{"city"=>"Miami", "address"=>"2700 south bayshore drive", "name"=>"Cocont Grove Expo Center", "zip"=>33133, "geolong"=>-80.2379, "geolat"=>25.7282, "crossstreet"=>nil, "id"=>10124, "phone"=>nil, "state"=>"FL", "distance"=>0.5},
|
209
|
-
{"city"=>"Coconut Grove", "address"=>"Grand Ave", "name"=>"The Jewlicious Pad", "zip"=>nil, "geolong"=>-80.2499, "geolat"=>25.7278, "crossstreet"=>nil, "id"=>80526, "phone"=>nil, "twitter"=>"jewgonewild", "state"=>"FL", "distance"=>0.5},
|
210
|
-
{"city"=>"Miami", "address"=>"3540 Main Highway", "name"=>"Taurus Chops", "zip"=>33133, "geolong"=>-80.245, "geolat"=>25.7251, "crossstreet"=>nil, "id"=>10390, "phone"=>nil, "state"=>"FL", "distance"=>0.5},
|
211
|
-
{"city"=>"Miami", "address"=>"2649 South Bayshore Drive", "name"=>"Doubletree Coconut Grove", "zip"=>33133, "geolong"=>-80.2353, "geolat"=>25.7312, "crossstreet"=>nil, "id"=>83833, "phone"=>"305-858-2500", "state"=>"FL", "distance"=>0.5}
|
212
|
-
]
|
213
|
-
Foursquare.venues(:geolat => 25.7323, :geolong => 80.2436)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe "#venue" do
|
218
|
-
before do
|
219
|
-
FakeWeb.register_uri(:get,
|
220
|
-
"http://user%40example.com:secret@api.playfoursquare.com/v1/venues.json?geolat=25.7323&geolong=80.2436",
|
221
|
-
:body => fakeweb_read('venues_authenticated.json'))
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should return venues with user metadata" do
|
225
|
-
venues_with_user_data = [
|
226
|
-
{"city"=>"Miami", "address"=>"3064 Grand Ave", "name"=>"Sandbar", "zip"=>33133, "stats"=>{"checkins"=>18}, "geolong"=>-80.2428, "geolat"=>25.7281, "crossstreet"=>nil, "id"=>10350, "phone"=>nil, "state"=>"FL", "distance"=>0.1},
|
227
|
-
{"city"=>"Miami", "address"=>"3131 Commodore Plaza", "name"=>"Mr. Moe's", "zip"=>33133, "stats"=>{"checkins"=>6}, "geolong"=>-80.2441, "geolat"=>25.7274, "crossstreet"=>nil, "id"=>10287, "phone"=>nil, "state"=>"FL", "distance"=>0.1},
|
228
|
-
{"city"=>"Miami", "address"=>"3035 Fuller St", "name"=>"Barracuda Bar", "zip"=>33133, "stats"=>{"checkins"=>4}, "geolong"=>-80.2432, "geolat"=>25.7276, "crossstreet"=>"at Grand Ave", "id"=>18315, "phone"=>"305 448-1144", "state"=>"FL", "distance"=>0.1},
|
229
|
-
{"city"=>"Coconut Grove", "address"=>"3415 Main Hwy", "name"=>"Boardwalk Tavern & Pizzeria", "zip"=>33133, "stats"=>{"checkins"=>3}, "geolong"=>-80.2427, "geolat"=>25.7277, "crossstreet"=>nil, "id"=>45598, "phone"=>"305-567-0080", "state"=>"FL", "distance"=>0.1},
|
230
|
-
{"city"=>"Miami", "address"=>"3035 Fuller St,", "name"=>"Barracadu Bar & Grill }i{", "zip"=>33133, "geolong"=>-80.2432, "geolat"=>25.7276, "crossstreet"=>"btw Main Hwy and Grand ave", "id"=>88408, "phone"=>"(305) 448-1144", "state"=>"FL", "distance"=>0.1},
|
231
|
-
{"city"=>"Miami", "address"=>"3035 Fuller St", "name"=>"Barracadu Coconut Grove}i{", "zip"=>nil, "geolong"=>-80.2432, "geolat"=>25.7276, "crossstreet"=>"btw Main Hwy and Grand ave", "id"=>85556, "phone"=>"(305) 448-1144", "state"=>"FL", "distance"=>0.1},
|
232
|
-
{"city"=>"Miami", "address"=>"3120 Commodore Plaza", "name"=>"Don Quixote", "zip"=>33133, "geolong"=>-80.2447, "geolat"=>25.7271, "crossstreet"=>nil, "id"=>10147, "phone"=>nil, "state"=>"FL", "distance"=>0.1},
|
233
|
-
{"city"=>"Miami", "address"=>"3424 Main Highway", "name"=>"Hungry Sailor", "zip"=>33133, "geolong"=>-80.2428, "geolat"=>25.7276, "crossstreet"=>nil, "id"=>10219, "phone"=>nil, "state"=>"FL", "distance"=>0.1},
|
234
|
-
{"city"=>"Miami", "address"=>"3416 Main Highway", "name"=>"Tavern In The Grove", "zip"=>33133, "geolong"=>-80.2427, "geolat"=>25.7276, "crossstreet"=>nil, "id"=>10391, "phone"=>nil, "state"=>"FL", "distance"=>0.1},
|
235
|
-
{"city"=>"Miami", "address"=>"3480 Main Highway", "name"=>"Senor Frogs", "zip"=>33133, "geolong"=>-80.2442, "geolat"=>25.7267, "crossstreet"=>nil, "id"=>10356, "phone"=>nil, "state"=>"FL", "distance"=>0.1},
|
236
|
-
{"city"=>"Miami", "address"=>"3342 Virginia St", "name"=>"Life", "zip"=>33133, "geolong"=>-80.2415, "geolat"=>25.7289, "crossstreet"=>nil, "id"=>10252, "phone"=>nil, "state"=>"FL", "distance"=>0.2},
|
237
|
-
{"city"=>"Miami", "address"=>"3339 Virginia St", "name"=>"InfiniHQ", "zip"=>33133, "geolong"=>-80.2413, "geolat"=>25.7292, "crossstreet"=>"at Oak Ave", "id"=>84676, "phone"=>3057284641, "state"=>"FL", "distance"=>0.2},
|
238
|
-
{"city"=>"Miami", "address"=>"2895 McFarlane RD.", "name"=>"Flavour", "zip"=>33133, "geolong"=>-80.2411, "geolat"=>25.7275, "crossstreet"=>nil, "id"=>10173, "phone"=>nil, "state"=>"FL", "distance"=>0.2},
|
239
|
-
{"city"=>"Miami", "address"=>"3540 Main Highway", "name"=>"Taurus Chops", "zip"=>33133, "geolong"=>-80.245, "geolat"=>25.7251, "crossstreet"=>nil, "id"=>10390, "phone"=>nil, "state"=>"FL", "distance"=>0.2},
|
240
|
-
{"city"=>"Miami", "address"=>"2911 Grand Ave", "name"=>"Oxygen Lounge", "zip"=>33133, "geolong"=>-80.2406, "geolat"=>25.7285, "crossstreet"=>nil, "id"=>10305, "phone"=>nil, "state"=>"FL", "distance"=>0.2},
|
241
|
-
{"city"=>"Miami", "address"=>"2801 Florida Ave", "name"=>"Quench", "zip"=>33133, "geolong"=>-80.2395, "geolat"=>25.7291, "crossstreet"=>nil, "id"=>10331, "phone"=>"305 448-8150", "state"=>"FL", "distance"=>0.3},
|
242
|
-
{"city"=>"Miami", "address"=>"3390 Mary St", "name"=>"Improv Comedy Club", "zip"=>33133, "geolong"=>-80.2393, "geolat"=>25.7282, "crossstreet"=>nil, "id"=>10224, "phone"=>nil, "state"=>"FL", "distance"=>0.3},
|
243
|
-
{"city"=>"Coconut Grove", "address"=>"Grand Ave", "name"=>"The Jewlicious Pad", "zip"=>nil, "geolong"=>-80.2499, "geolat"=>25.7278, "crossstreet"=>nil, "id"=>80526, "phone"=>nil, "twitter"=>"jewgonewild", "state"=>"FL", "distance"=>0.4},
|
244
|
-
{"city"=>"Miami", "address"=>"2700 south bayshore drive", "name"=>"Cocont Grove Expo Center", "zip"=>33133, "geolong"=>-80.2379, "geolat"=>25.7282, "crossstreet"=>nil, "id"=>10124, "phone"=>nil, "state"=>"FL", "distance"=>0.4},
|
245
|
-
{"city"=>"Miami", "address"=>"650 williamstreet", "name"=>"Flordia", "zip"=>nil, "geolong"=>-80.2511, "geolat"=>25.7263, "crossstreet"=>"Sr mia", "id"=>66946, "phone"=>nil, "state"=>"FL", "distance"=>0.4},
|
246
|
-
{"city"=>"Miami", "address"=>"2649 South Bayshore Drive", "name"=>"Doubletree Coconut Grove", "zip"=>33133, "geolong"=>-80.2353, "geolat"=>25.7312, "crossstreet"=>nil, "id"=>83833, "phone"=>"305-858-2500", "state"=>"FL", "distance"=>0.6},
|
247
|
-
{"city"=>"Coconut grove", "address"=>"3381 pan American drive", "name"=>"Scottys Landing", "zip"=>33133, "geolong"=>-80.2342, "geolat"=>25.7278, "crossstreet"=>nil, "id"=>86452, "phone"=>nil, "state"=>"FL", "distance"=>0.6},
|
248
|
-
{"city"=>"Miami", "address"=>"2550 South Bayshore Drive", "name"=>"Monty's", "zip"=>33133, "geolong"=>-80.2326, "geolat"=>25.7321, "crossstreet"=>nil, "id"=>18241, "phone"=>"305 858-1431", "state"=>"FL", "distance"=>0.8},
|
249
|
-
{"city"=>"Miami", "address"=>"2884 S.W. 27th Ave", "name"=>"Berries in the Grove }i{", "zip"=>33133, "geolong"=>-80.2381, "geolat"=>25.7382, "crossstreet"=>"btw US1 and Coconut ave", "id"=>85554, "phone"=>"(305) 448-2111", "state"=>"FL", "distance"=>0.8}
|
250
|
-
]
|
251
|
-
|
252
|
-
@foursquare = Foursquare.new(@username, @password)
|
253
|
-
@foursquare.venues(:geolat => "25.7323", :geolong => "80.2436").should == venues_with_user_data
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
41
|
describe ".available?" do
|
258
42
|
it "it should return true when foursquare is up" do
|
259
43
|
FakeWeb.register_uri(:get,
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmdrkeene-foursquare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keene
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-12 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,16 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.4.4
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: geokit
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.1
|
34
|
+
version:
|
25
35
|
description: Ruby API for Foursquare (playfoursquare.com)
|
26
36
|
email: bkeene@gmail.com
|
27
37
|
executables: []
|
@@ -39,6 +49,10 @@ files:
|
|
39
49
|
- foursquare.gemspec
|
40
50
|
- init.rb
|
41
51
|
- lib/foursquare.rb
|
52
|
+
- lib/foursquare/base.rb
|
53
|
+
- lib/foursquare/checkin.rb
|
54
|
+
- lib/foursquare/user.rb
|
55
|
+
- lib/foursquare/venue.rb
|
42
56
|
- spec/fixtures/checkin_failure.json
|
43
57
|
- spec/fixtures/checkin_success.json
|
44
58
|
- spec/fixtures/cities.json
|
@@ -47,10 +61,16 @@ files:
|
|
47
61
|
- spec/fixtures/user.json
|
48
62
|
- spec/fixtures/venues_authenticated.json
|
49
63
|
- spec/fixtures/venues_unauthenticated.json
|
64
|
+
- spec/foursquare/base_spec.rb
|
65
|
+
- spec/foursquare/checkin_spec.rb
|
66
|
+
- spec/foursquare/user_spec.rb
|
67
|
+
- spec/foursquare/venue_spec.rb
|
50
68
|
- spec/foursquare_spec.rb
|
51
69
|
- spec/spec_helper.rb
|
52
|
-
has_rdoc:
|
70
|
+
has_rdoc: true
|
53
71
|
homepage: http://github.com/cmdrkeene/foursquare
|
72
|
+
licenses: []
|
73
|
+
|
54
74
|
post_install_message:
|
55
75
|
rdoc_options:
|
56
76
|
- --charset=UTF-8
|
@@ -71,10 +91,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
91
|
requirements: []
|
72
92
|
|
73
93
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.
|
94
|
+
rubygems_version: 1.3.5
|
75
95
|
signing_key:
|
76
96
|
specification_version: 3
|
77
97
|
summary: Ruby API for Foursquare (playfoursquare.com)
|
78
98
|
test_files:
|
99
|
+
- spec/foursquare/base_spec.rb
|
100
|
+
- spec/foursquare/checkin_spec.rb
|
101
|
+
- spec/foursquare/user_spec.rb
|
102
|
+
- spec/foursquare/venue_spec.rb
|
79
103
|
- spec/foursquare_spec.rb
|
80
104
|
- spec/spec_helper.rb
|