foursquare 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/History +6 -0
  2. data/README.rdoc +31 -14
  3. data/Rakefile +2 -2
  4. data/lib/foursquare.rb +160 -40
  5. metadata +3 -2
data/History CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.2.0 February 7th, 2010
2
+ * updated methods to reflect updates to Foursquare API
3
+ * added validations
4
+ * deprecated cities, check_city, switch_city, and friend_checkins calls in line with updates to the Foursquare API
5
+ * updated readme to reflect code changes
6
+
1
7
  == 0.1.0 November 8th, 2009
2
8
  * added website
3
9
  * added defaults for optional method variables
data/README.rdoc CHANGED
@@ -10,24 +10,41 @@ A simple Ruby Gem wrapper for the Foursquare API.
10
10
 
11
11
  require 'rubygems'
12
12
  require 'foursquare'
13
-
13
+
14
+ # foursquare's site uses email as the user name
14
15
  fq = Foursquare.new('username_or_phone','password')
15
16
 
16
17
  fq.test
17
- fq.cities
18
- fq.venues(lat,long,radius,limit,query)
19
- fq.tips(lat,long,limit)
20
- fq.check_city(lat, long)
21
- fq.switch_city(city_id)
22
- fq.friend_checkins
23
- fq.checkin(vid,venue,shout,private_checkin,tweetThis,geolat,geolong)
24
- fq.history(limit)
25
- fq.user_details(user_id,badges,mayor)
26
- fq.friends
18
+
19
+ fq.venues(geolat, geolong, {:limit=>10,:q=>'pizza'})
20
+ fq.tips(geolat,geolong,{:limit=>10})
21
+ fq.checkins({:geolat=>'',:geolong=>''})
22
+ fq.checkin(vid,venue,shout,{:private=>0,:twitter=>0,:facebook=>1,:geolat=>'12.03',:geolong=>'-123.33'})
23
+ fq.history({:limit=>10})
24
+ fq.user_details(user_id,{:badges=>0,:mayor=>0})
25
+ fq.friends({:uid=>99999})
27
26
  fq.venue_details(venue_id)
28
- fq.add_venue(city_id,name,address,cross_street,city,state,zip,phone)
29
- fq.add_tip(venue_id,text,type)
30
-
27
+ fq.add_venue(name,address,cross_street,city,state,options)
28
+ fq.propose_edit(venue_id,name,address,cross_street,city,state,options)
29
+ fq.flag_venue_as_closed(venue_id)
30
+ fq.add_tip(venue_id,text,{:type=type})
31
+ fq.mark_tip_as_todo(tid)
32
+ fq.mark_tip_as_done(tid)
33
+ fq.friend_requests
34
+ fq.friend_approve(uid)
35
+ fq.friend_deny(uid)
36
+ fq.request_friend(uid)
37
+ fq.find_friends_by_name('Bugs Bunny')
38
+ fq.find_friends_by_phone('8675309')
39
+ fq.find_friends_by_twitter('github')
40
+ fq.set_pings('self','goodnight')
41
+
42
+
43
+ # Foursquare is moving the API to geolat/geolong and removing the concept of cities
44
+ fq.cities
45
+ fq.check_city(geolat, geolong)
46
+ fq.switch_city(city_id)
47
+ fq.friend_checkins({:geolat=>'',:geolong=>''})
31
48
 
32
49
  == license
33
50
 
data/Rakefile CHANGED
@@ -6,8 +6,8 @@ require 'spec/rake/spectask'
6
6
 
7
7
  spec = Gem::Specification.new do |s|
8
8
  s.name = "foursquare"
9
- s.version = "0.1.0"
10
- s.author = "Jeremy Welch"
9
+ s.version = "0.2.0"
10
+ s.authors = ['Jeremy Welch', 'Thomas Hanley']
11
11
  s.email = "hello@jeremyrwelch.com"
12
12
  s.homepage = "http://foursquare.rubyforge.org"
13
13
  s.description = s.summary = "A simple Ruby wrapper for the Foursquare API"
data/lib/foursquare.rb CHANGED
@@ -2,76 +2,196 @@ require 'rubygems'
2
2
  require 'httparty'
3
3
 
4
4
  class Foursquare
5
+ # Current Version of the Foursquare API: http://groups.google.com/group/foursquare-api/web/api-documentation
5
6
 
6
7
  include HTTParty
7
8
  base_uri 'api.foursquare.com'
8
9
  format :xml
9
-
10
10
 
11
- # auth user
12
- def initialize(user="",pass="")
11
+ # auth user
12
+ # TODO: add OAuth support (follow Twitter gem from jnunemaker http://github.com/jnunemaker/twitter)
13
+ def initialize(user="",pass="", options={})
13
14
  self.class.basic_auth user, pass
15
+ self.class.headers(options[:headers]) if options.has_key?(:headers)
14
16
  end
15
-
16
-
17
- # test for response from Foursquare
17
+
18
+ # =========================
19
+ # = No Auth Required Methods =
20
+ # =========================
21
+ # test for response from Foursquare
18
22
  def test
19
- self.class.get("/v1/test")
23
+ self.class.get("/v1/test")
20
24
  end
21
25
 
22
- # no auth required
23
- def cities
24
- self.class.get("/v1/cities")
25
- end
26
-
27
- def venues(geolat,geolong,radius="",limit="",query="")
28
- self.class.get("/v1/venues?geolat=#{geolat}&geolong=#{geolong}&r=#{radius}&l=#{limit}&q=#{query}")
26
+ def venues(geolat, geolong, options={})
27
+ options.merge!({:geolat=>geolat, :geolong=>geolong})
28
+ self.class.get("/v1/venues", :query=>options)
29
29
  end
30
-
31
- def tips(geolat,geolong,limit="")
32
- self.class.get("/v1/tips?geolat=#{geolat}&geolong=#{geolong}&l=#{limit}")
30
+
31
+ def tips(geolat,geolong,options={})
32
+ options.merge!({:geolat=>geolat, :geolong=>geolong})
33
+ self.class.get("/v1/tips", :query=>options)
33
34
  end
34
35
 
36
+ # =========================
37
+ # = Auth Required Methods =
38
+ # =========================
39
+ def checkins(options={})
40
+ self.class.get("/v1/checkins",:query=>options)
41
+ end
35
42
 
36
- # auth required
37
- def check_city(geolat, geolong)
38
- self.class.get("/v1/checkcity?geolat=#{geolat}&geolong=#{geolong}")
43
+ def checkin(vid=nil,venue=nil,shout=nil,options={})
44
+ unless vid || venue || shout
45
+ raise ArgumentError, "A vid or venue or shout is required to checkin", caller
46
+ end
47
+ options.merge!({:vid=>vid, :venue=>venue, :shout=>shout})
48
+ self.class.post("/v1/checkin", :body => options)
39
49
  end
40
-
41
- def switch_city(city_id)
42
- self.class.post("/v1/switchcity", :body => {:cityid => city_id})
50
+
51
+ def history(options={})
52
+ limit = options.delete(:limit) || 10
53
+ uri = "/v1/history?l=#{limit}"
54
+ sinceid = options.delete(:sinceid)
55
+ uri << "&sinceid=#{sinceid}" unless sinceid.nil?
56
+ self.class.get(uri)
43
57
  end
44
-
45
- def friend_checkins
46
- self.class.get("/v1/checkins")
58
+
59
+ def user_details(user_id,options={})
60
+ unless user_id
61
+ raise ArgumentError, "A user_id is required to get details about a user", caller
62
+ end
63
+ self.class.get("/v1/user",:query=>options)
47
64
  end
48
65
 
49
- def checkin(vid,venue,shout,private_checkin,tweetThis,geolat,geolong)
50
- self.class.get("/v1/checkin?vid=#{vid}&venue=#{venue}&shout=#{shout}&private=#{private_checkin}&twitter=#{tweetThis}&geolat=#{geolat}&geolong=#{geolong}")
66
+ def friends(options={})
67
+ self.class.get("/v1/friends",:query=>options)
51
68
  end
52
69
 
53
- def history(limit="10")
54
- self.class.get("/v1/history?l=#{limit}")
70
+ def venue_details(venue_id)
71
+ self.class.get("/v1/venue?vid=#{venue_id}")
72
+ end
73
+
74
+ # city_id has been removed from API
75
+ def add_venue(name,address,cross_street,city,state,options={})
76
+ unless name && address && cross_street && city && state
77
+ raise ArgumentError, "A venue's name, address, cross_street, city, state are required to add_venue", caller
78
+ end
79
+ options.merge!({:name=>name, :address=>address, :cross_street=>cross_street, :city=>city, :state=>state})
80
+ self.class.post("/v1/addvenue", :body => options)
55
81
  end
56
82
 
57
- def user_details(user_id,badges="0",mayor="0")
58
- self.class.get("/v1/user?uid=#{user_id}&badges=#{badges}&mayor=#{mayor}")
83
+ def propose_edit(venue_id,name,address,cross_street,city,state,options={})
84
+ unless venue_id && name && address && cross_street && city && state
85
+ raise ArgumentError, "A venue's venue_id, name, address, cross_street, city, state are required to propose_edit", caller
86
+ end
87
+ options.merge!({:venue_id=>venue_id,:name=>name, :address=>address, :cross_street=>cross_street, :city=>city, :state=>state})
88
+ self.class.post("/v1/venue/proposeedit", :body => options)
89
+ end
90
+
91
+ def flag_venue_as_closed(venue_id)
92
+ unless venue_id
93
+ raise ArgumentError, "A venue's venue_id is required to flag as closed", caller
94
+ end
95
+ self.class.post("/v1/venue/flagclosed?vid=#{venue_id}")
59
96
  end
60
97
 
61
- def friends
62
- self.class.get("/v1/friends")
98
+ # ===============
99
+ # = TIP methods =
100
+ # ===============
101
+ def add_tip(venue_id,text,options={})
102
+ unless venue_id && text
103
+ raise ArgumentError, "venue_id and text are required to add_tip", caller
104
+ end
105
+ options.merge!({:vid=>venue_id, :text=>text})
106
+ self.class.post("/v1/addtip", :body => options)
63
107
  end
64
108
 
65
- def venue_details(venue_id)
66
- self.class.get("/v1/venue?vid=#{venue_id}")
109
+ def mark_tip_as_todo(tid)
110
+ unless tid
111
+ raise ArgumentError, "tip_id is required to mark tip as todo", caller
112
+ end
113
+ self.class.post("/v1/tip/marktodo", :body => {:tip=>tip})
114
+ end
115
+
116
+ def mark_tip_as_done(tid)
117
+ unless tid
118
+ raise ArgumentError, "tid is required to mark tip as done", caller
119
+ end
120
+ self.class.post("/v1/tip/markdone", :body => {:tip=>tip})
121
+ end
122
+
123
+ # ==================
124
+ # = FRIEND Methods =
125
+ # ==================
126
+ def friend_requests
127
+ self.class.get("/v1/friend/requests")
128
+ end
129
+
130
+ def friend_approve(uid)
131
+ unless uid
132
+ raise ArgumentError, "uid is required to approve friend request", caller
133
+ end
134
+ self.class.post("/v1/friend/requests", :body => {:uid=>uid})
135
+ end
136
+
137
+ def friend_deny(uid)
138
+ unless uid
139
+ raise ArgumentError, "uid is required to deny friend request", caller
140
+ end
141
+ self.class.post("/v1/friend/deny", :body => {:uid=>uid})
142
+ end
143
+
144
+ def request_friend(uid)
145
+ unless uid
146
+ raise ArgumentError, "uid is required to request friend", caller
147
+ end
148
+ self.class.post("/v1/friend/sendrequest", :body => {:uid=>uid})
67
149
  end
68
150
 
69
- def add_venue(city_id,name,address,cross_street,city,state,zip="",phone="")
70
- self.class.post("/v1/addvenue", :body => {:name => name, :address => address, :crossstreet => cross_street, :city => city, :state => state, :zip => zip, :cityid => city_id, :phone => phone})
151
+ # ================
152
+ # = FIND Methods =
153
+ # ================
154
+ def find_friends_by_name(q)
155
+ self.class.get("/v1/findfriends/byname", :query=>{:q=>q})
156
+ end
157
+
158
+ def find_friends_by_phone(q)
159
+ self.class.get("/v1/findfriends/byphone", :query=>{:q=>q})
160
+ end
161
+
162
+ def find_friends_by_twitter(q)
163
+ self.class.get("/v1/findfriends/bytwitter", :query=>{:q=>q})
164
+ end
165
+
166
+ # ===============
167
+ # = SET methods =
168
+ # ===============
169
+ def set_pings(user_id=nil,ping=nil)
170
+ uid = user_id || "self"
171
+ self.class.post("/v1/settings/setpings?#{uid}=#{ping}")
71
172
  end
72
173
 
73
- def add_tip(venue_id,text,type)
74
- self.class.post("/v1/addtip", :body => {:vid => venue_id, :text => text, :type => type})
174
+ # From Foursquare API
175
+ # 20100108 - naveen - the concept of cities (cityid and all city-related methods) has now been removed
176
+ # Deprecated
177
+ def cities
178
+ self.class.get("/v1/cities")
75
179
  end
180
+ # Deprecated
181
+ def check_city(geolat, geolong)
182
+ $stderr.puts "`check_city` Deprecated: The idea of \"cityid\" is now deprecated from the API"
183
+ self.class.get("/v1/checkcity?geolat=#{geolat}&geolong=#{geolong}")
184
+ end
185
+ # Deprecated
186
+ def switch_city(city_id)
187
+ $stderr.puts "`switch_city` Deprecated: The idea of \"cityid\" is now deprecated from the API"
188
+ self.class.post("/v1/switchcity", :body => {:cityid => city_id})
189
+ end
190
+ # Method changed to call checkins to match API
191
+ def friend_checkins(options={})
192
+ $stderr.puts "`friend_checkins` now calls `checkins` to match the foursquare api method call"
193
+ $stderr.puts "http://groups.google.com/group/foursquare-api/web/api-documentation"
194
+ checkins(options)
195
+ end
76
196
 
77
197
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foursquare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Welch
8
+ - Thomas Hanley
8
9
  autorequire: foursquare
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-11-08 00:00:00 -05:00
13
+ date: 2010-02-07 00:00:00 -05:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency