Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:aaronpk/Foursquare-NASDAQ

  • Loading branch information...
commit b3b7f2cb501d6ee0bf6ded71698f1871955baa3c 2 parents 04a18fa + 2cddf06
@kyledrake kyledrake authored
Showing with 50 additions and 6 deletions.
  1. +2 −0  Gemfile
  2. +6 −0 Gemfile.lock
  3. +42 −6 app.rb
View
2  Gemfile
@@ -3,6 +3,8 @@ gem 'sinatra'
gem 'omniauth-foursquare'
gem 'sequel'
gem 'mysql2'
+gem 'fuzz_ball'
+gem 'rest-client'
group :development do
gem 'puma'
View
6 Gemfile.lock
@@ -12,11 +12,13 @@ GEM
debugger-ruby_core_source (1.1.6)
faraday (0.8.4)
multipart-post (~> 1.1)
+ fuzz_ball (0.9.1)
hashie (1.2.0)
httpauth (0.2.0)
jwt (0.1.5)
multi_json (>= 1.0)
method_source (0.8.1)
+ mime-types (1.19)
multi_json (1.5.0)
multipart-post (1.1.5)
mysql2 (0.3.11)
@@ -47,6 +49,8 @@ GEM
rack (1.4.1)
rack-protection (1.3.2)
rack
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
sequel (3.42.0)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
@@ -59,9 +63,11 @@ PLATFORMS
ruby
DEPENDENCIES
+ fuzz_ball
mysql2
omniauth-foursquare
pry-debugger
puma
+ rest-client
sequel
sinatra
View
48 app.rb
@@ -1,5 +1,6 @@
require 'bundler/setup'
Bundler.require
+require 'json'
Bundler.require(:development) if development?
require 'cgi'
require 'csv'
@@ -21,8 +22,8 @@
if DB.table_exists?(:users) == false
DB.create_table :users do
- String :token, primary_key: true, index: true
- String :uid, index: true
+ String :uid, primary_key: true, index: true
+ String :token, index: true
end
end
@@ -56,11 +57,46 @@ def get_quote(symbol)
get '/auth/:name/callback' do
token, uid = request.env['omniauth.auth'].credentials.token, request.env['omniauth.auth'].uid
- user = DB[:users].filter(token: token).first
+ user = DB[:users].filter(uid: uid).first
- if token.nil?
- DB[:users].insert token: token, uid: uid
+ if user.nil?
+ DB[:users].insert uid: uid, token: token
end
'ok'
-end
+end
+
+# When a user checks in, Foursquare will send a post request here
+post '/foursquare/push' do
+ puts "=============================="
+ puts params['secret']
+
+ checkin = JSON.parse params['checkin'], symbolize_names: true
+ puts checkin.inspect
+
+ # User ID is at: checkin[:user][:id]
+ # Venue name is at: checkin[:venue][:name]
+ # See https://developer.foursquare.com/overview/realtime for more docs
+
+ user = DB[:users].filter(uid: checkin[:user][:id]).first
+
+ unless user.nil?
+
+
+
+ # Now send a message back to the checkin so Foursquare shows it in the app
+
+ # https://developer.foursquare.com/docs/checkins/reply
+ # Params to send:
+ # CHECKIN_ID from checkin[:id]
+ # text
+ # oauth_token
+
+ RestClient.post "https://api.foursquare.com/v2/checkins/#{checkin[:id]}/reply", {
+ oauth_token: user[:token],
+ text: "Check this out!"
+ }
+
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.