foursquare_rails_generators 0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foursquare_rails_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,19 +16,7 @@ email: pierre@foursquare.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
- files:
20
- - .gitignore
21
- - README.md
22
- - foursquare_rails_generators.gemspec
23
- - lib/foursquare_rails_generators.rb
24
- - lib/generators/foursquare/authentication/authentication_generator.rb
25
- - lib/generators/foursquare/authentication/templates/controllers/clients/foursquare_clients_controller.rb
26
- - lib/generators/foursquare/authentication/templates/controllers/users_controller.rb
27
- - lib/generators/foursquare/authentication/templates/models/foursquare_client.rb
28
- - lib/generators/foursquare/authentication/templates/models/foursquare_user.rb
29
- - lib/generators/foursquare/push/push_generator.rb
30
- - lib/generators/foursquare/push/templates/controllers/checkins_controller.rb
31
- - template.rb
19
+ files: []
32
20
  homepage: http://rubygems.org/gems/foursquare_rails_generators
33
21
  licenses: []
34
22
  post_install_message:
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- .DS_Store
data/README.md DELETED
@@ -1,4 +0,0 @@
1
- In 1 minute, get your Rails app with Foursquare running on Herolu
2
- ==========
3
-
4
- rails new my-foursquare-app -m {{url}} -d postgresql
@@ -1,12 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'foursquare_rails_generators'
3
- s.version = '0.1'
4
- s.date = '2012-10-26'
5
- s.summary = "Foursquare Rails Generators"
6
- s.description = "Collection of Rails generators for the Foursquare API"
7
- s.authors = ["Pierre Valade"]
8
- s.email = 'pierre@foursquare.com'
9
- s.files = `git ls-files`.split("\n")
10
- s.require_paths = ['lib']
11
- s.homepage = 'http://rubygems.org/gems/foursquare_rails_generators'
12
- end
@@ -1,4 +0,0 @@
1
- require 'rails/generators'
2
-
3
- require File.expand_path('../generators/foursquare/authentication/authentication_generator', __FILE__)
4
- require File.expand_path('../generators/foursquare/push/push_generator', __FILE__)
@@ -1,62 +0,0 @@
1
- module Foursquare
2
- module Generators
3
- class AuthenticationGenerator < Rails::Generators::Base
4
- source_root File.expand_path("../templates", __FILE__)
5
-
6
- desc "Adds Foursquare Connect to your app"
7
- argument :settings, type: :hash, banner: "client_id:id client_secret:secret"
8
-
9
- def validates_settings
10
- raise "incorret params" if settings['client_id'].blank? || settings['client_secret'].blank?
11
- end
12
-
13
- def add_oauth2_gem
14
- gem 'oauth2'
15
- end
16
-
17
- def create_foursquare_user_model
18
- # TODO: add index on foursquare_id
19
- generate 'model', 'foursquare_user foursquare_id:string access_token:string'
20
- template 'models/foursquare_user.rb', File.join('app/models/', 'foursquare_user.rb')
21
- end
22
-
23
- def create_foursquare_client_model
24
- template 'models/foursquare_client.rb', File.join('app/models/', 'foursquare_client.rb')
25
- end
26
-
27
- def run_migrations
28
- rake 'db:migrate'
29
- end
30
-
31
- def create_client_controller
32
- template 'controllers/clients/foursquare_clients_controller.rb', File.join('app/controllers/clients', 'foursquare_clients_controller.rb')
33
- end
34
-
35
- def add_root_routes
36
- route "root :to => 'users#new'"
37
- end
38
-
39
- def add_clients_routes
40
- route(
41
- %Q{
42
- scope module: 'clients' do
43
- resources :foursquare_clients, only: ['new'], path: 'clients/foursquare' do
44
- collection do
45
- get 'callback'
46
- end
47
- end
48
- end
49
- }
50
- )
51
- end
52
-
53
- def create_users_controller
54
- template 'controllers/users_controller.rb', File.join('app/controllers/', 'users_controller.rb')
55
- end
56
-
57
- def add_user_routes
58
- route "resource :user"
59
- end
60
- end
61
- end
62
- end
@@ -1,24 +0,0 @@
1
- class Clients::FoursquareClientsController < ApplicationController
2
- def new
3
- # https://developer.foursquare.com/overview/auth
4
- options = {
5
- redirect_uri: callback_foursquare_clients_url,
6
- }
7
- redirect_to client.auth_code.authorize_url options
8
- end
9
-
10
- def callback
11
- if params[:error]
12
- # TODO: manage error
13
- end
14
- token = client.auth_code.get_token params[:code], redirect_uri: callback_foursquare_clients_url
15
- user = FoursquareUser.find_or_create_by_access_token(token.token)
16
- session[:user_id] = user.id
17
- redirect_to user_path
18
- end
19
-
20
- private
21
- def client
22
- FoursquareClient.oauth2_client
23
- end
24
- end
@@ -1,14 +0,0 @@
1
- class UsersController < ApplicationController
2
- def new
3
- render text: "<a href='#{new_foursquare_client_path}'><img src='https://playfoursquare.s3.amazonaws.com/press/logo/connect-black.png' /></a>"
4
- end
5
-
6
- def show
7
- render text: "hello #{current_user.name}"
8
- end
9
-
10
- private
11
- def current_user
12
- @current_user ||= FoursquareUser.find(session[:user_id])
13
- end
14
- end
@@ -1,51 +0,0 @@
1
- # https://developer.foursquare.com/docs/
2
- class FoursquareClient
3
- attr_accessor :access_token
4
-
5
- def initialize(access_token)
6
- @access_token = access_token
7
- end
8
-
9
- def user_info
10
- @user_info ||= get('users/self').parsed['response']['user']
11
- end
12
-
13
- def user_id
14
- user_info['id']
15
- end
16
-
17
- def user_name
18
- [user_info['firstName'], user_info['lastName']].join(' ')
19
- end
20
-
21
- def oauth2_token
22
- @oauth2_token ||= OAuth2::AccessToken.from_hash(self.class.oauth2_client, {access_token: access_token}.merge(mode: :query, param_name: 'oauth_token'))
23
- end
24
-
25
- def get(path, params = {})
26
- oauth2_token.get(self.class.endpoint + path, params)
27
- end
28
-
29
- def post(path, params = {})
30
- oauth2_token.post(self.class.endpoint + path, params)
31
- end
32
-
33
- def create_checkin_reply(checkin_id, options = {})
34
- post("checkins/#{checkin_id}/reply", params: options)
35
- end
36
-
37
- class << self
38
- def endpoint
39
- 'https://api.foursquare.com/v2/'
40
- end
41
-
42
- def oauth2_client
43
- options = {
44
- authorize_url: 'https://foursquare.com/oauth2/authenticate',
45
- token_url: 'https://foursquare.com/oauth2/access_token',
46
- raise_errors: true,
47
- }
48
- OAuth2::Client.new("<%= settings['client_id'] %>", "<%= settings['client_secret'] %>", options)
49
- end
50
- end
51
- end
@@ -1,23 +0,0 @@
1
- class FoursquareUser < ActiveRecord::Base
2
- def name
3
- client.user_name
4
- end
5
-
6
- def client
7
- @client ||= FoursquareClient.new(access_token)
8
- end
9
-
10
- class << self
11
- def find_or_create_by_access_token(access_token)
12
- client = FoursquareClient.new(access_token)
13
-
14
- unless user = self.find_by_foursquare_id(client.user_id)
15
- user = self.new
16
- user.foursquare_id = client.user_id
17
- user.access_token = client.access_token
18
- user.save!
19
- end
20
- user
21
- end
22
- end
23
- end
@@ -1,17 +0,0 @@
1
- module Foursquare
2
- module Generators
3
- class PushGenerator < Rails::Generators::Base
4
- source_root File.expand_path("../templates", __FILE__)
5
-
6
- desc "Receive push from foursquare into your app"
7
-
8
- def add_routes
9
- route "resources :checkins"
10
- end
11
-
12
- def create_checkins_controller
13
- template 'controllers/checkins_controller.rb', File.join('app/controllers/', 'checkins_controller.rb')
14
- end
15
- end
16
- end
17
- end
@@ -1,11 +0,0 @@
1
- class CheckinsController < ApplicationController
2
- skip_before_filter :verify_authenticity_token
3
-
4
- def create
5
- checkin = JSON.parse(params['checkin'])
6
- # TODO: verify push secret
7
- user = FoursquareUser.find_by_foursquare_id(checkin['user']['id'])
8
- user.client.create_checkin_reply(checkin['id'], text: "hello world!")
9
- return head :ok
10
- end
11
- end
data/template.rb DELETED
@@ -1,30 +0,0 @@
1
- # make a new app with foursquare inside
2
- run "rm public/index.html"
3
-
4
- app_name = "foursquare-app-" + (0...8).map{65.+(rand(26)).chr}.join.downcase
5
-
6
- puts "your app's name: #{app_name}"
7
- puts "create a new app from: https://foursquare.com/developers/register"
8
- puts "Download / welcome page url: https://#{app_name}.herokuapp.com"
9
- puts "Callback url: https://#{app_name}.herokuapp.com/clients/foursquare/callback"
10
- puts "Push url: https://#{app_name}.herokuapp.com/checkins"
11
-
12
- client_id = ask("what is your client_id (https://foursquare.com/oauth) ?")
13
- client_secret = ask("what is your client_secret?")
14
-
15
- add_source 'http://gems.github.com'
16
- # gem('foursquare-generators')
17
- run "bundle install"
18
-
19
- generate('foursquare:authentication', "client_id:#{client_id} client_secret:#{client_secret}")
20
- generate('foursquare:push')
21
-
22
- if yes?('do you want to push this to Heroku?')
23
- run "git init ."
24
- run "git add ."
25
- run "git commit -m 'initial commit'"
26
- run "heroku apps:create #{app_name}"
27
- run "git push heroku master"
28
- run "heroku run rake db:migrate"
29
- run "heroku open"
30
- end