-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4sq
More file actions
executable file
·63 lines (54 loc) · 1.76 KB
/
4sq
File metadata and controls
executable file
·63 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
require 'rubygems'
require 'foursquare'
require 'simplegeo'
require 'restclient'
meth = ARGV[0].strip if ARGV[0]
raise "Currently only checking in is supported. Usage: $ 4sq checkin [venue-id] [shout]" unless meth && meth == 'checkin'
vid = ARGV[1].to_i
#raise "Usage: $ 4sq checkin venue-id [shout]" unless vid > 0
oauth_key = FOURSQUARE_KEY
oauth_secret = FOURSQUARE_SECRET
access_token = ACCESS_TOKEN
access_secret = ACCESS_SECRET
oauth = Foursquare::OAuth.new(oauth_key, oauth_secret)
oauth.authorize_from_access(access_token, access_secret)
$foursquare = Foursquare::Base.new(oauth)
sg_key = SIMPLEGEO_KEY
sg_secret = SIMPLEGEO_SECRET
SimpleGeo::Client.set_credentials(sg_key, sg_secret)
# ip = RestClient.get('collison.ie/ip')
# locdata = SimpleGeo::Client.get_places_by_ip(ip)
# lon, lat = locdata[:features].first[:geometry][:coordinates]
def checkin(vid)
v = $foursquare.venue :vid => vid
checkin = {
:vid => vid,
:shout => ARGV[2],
:twitter => 0,
:geolat => v['geolat'],
:geolong => v['geolong']
}
nc = $foursquare.checkin(checkin)
puts "Checked into #{v['name']}\nhttp://foursquare.com/venue/#{vid}"
end
if vid > 0
checkin(vid)
else
print "Rough address: "
lon, lat = SimpleGeo::Client.get_places_by_address(STDIN.gets.chomp)[:features].first[:geometry][:coordinates]
print "Name of venue: "
query = {:geolat => lat, :geolong => lon, :limit => 10}
query[:q] = STDIN.gets.chomp
resp = $foursquare.venues query
venues = resp['groups'][0]['venues']
venues.each do |v|
puts "(#{venues.index(v)+1}) #{v['name']}, #{v['address']}, #{v['city']}"
end
index = 0
while index == 0 || index > venues.length + 1
print "Select a venue: "
index = STDIN.gets.chomp.to_i
end
checkin(venues[index-1]['id'])
end