meal_ticket 0.1.0 → 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.
@@ -75,7 +75,7 @@ Create global constants that look something like this:
75
75
  Now, redirect users to facebook_auth_url, passing the permissions you want to ask for. Like so:
76
76
 
77
77
  # For a full list of permissions, see https://developers.facebook.com/docs/authentication/permissions/
78
- redirect_to facebook_auth_url("user_photos,publish_stream")
78
+ redirect_to facebook_auth_url(root_url, "user_photos,publish_stream")
79
79
 
80
80
 
81
81
  After they authenticate, they'll be redirected to your +FACEBOOK_CALLBACK+ URL with query string params like:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -8,12 +8,12 @@ module MealTicketRoutes
8
8
  # [root_url] The base url of your app, eg "http://www.google.com/". If you're running a rails app, you can literally type root_url
9
9
  # [scope] A comma-separated list of permissions. For a full list of permissions, see https://developers.facebook.com/docs/authentication/permissions/
10
10
  def facebook_auth_url(root_url, scope)
11
- "https://graph.facebook.com/oauth/authorize?client_id=#{FACEBOOK_APP_ID}&redirect_uri=#{root_url}meal_ticket/facebook_callback&scope=#{scope}"
11
+ "https://graph.facebook.com/oauth/authorize?client_id=#{MealTicket::Config.facebook_app_id}&redirect_uri=#{root_url}meal_ticket/facebook_callback&scope=#{scope}"
12
12
  end
13
13
 
14
14
  # Generates the URL for the 2nd step of Facebook auth - exchanging the code for user data
15
15
  def facebook_exchange_url(root_url, code) # :nodoc:
16
- "https://graph.facebook.com/oauth/access_token?client_id=#{FACEBOOK_APP_ID}&redirect_uri=#{root_url}meal_ticket/facebook_callback&client_secret=#{FACEBOOK_SECRET}&code=#{CGI::escape code}"
16
+ "https://graph.facebook.com/oauth/access_token?client_id=#{MealTicket::Config.facebook_app_id}&redirect_uri=#{root_url}meal_ticket/facebook_callback&client_secret=#{MealTicket::Config.facebook_secret}&code=#{CGI::escape code}"
17
17
  end
18
18
 
19
19
  # [perm] A single permission level. Permissions can be read, write, or delete. Each successive permission implies the ones before it, eg "write" implies "read". For more information, see http://www.flickr.com/services/api/auth.spec.html
@@ -29,7 +29,7 @@ module MealTicketRoutes
29
29
  private
30
30
 
31
31
  def flickr_url(arg_hash, endpoint = "rest")
32
- arg_hash.merge!({"api_key" => FLICKR_TOKEN})
32
+ arg_hash.merge!({"api_key" => MealTicket::Config.flickr_token})
33
33
  arg_list = []
34
34
  arg_hash.each do |key, value|
35
35
  arg_list << "#{key}=#{value}"
@@ -43,7 +43,7 @@ module MealTicketRoutes
43
43
  arg_list << key
44
44
  arg_list << arg_hash[key]
45
45
  end
46
- Digest::MD5.hexdigest("#{FLICKR_SECRET}#{arg_list.join()}")
46
+ Digest::MD5.hexdigest("#{MealTicket::Config.flickr_secret}#{arg_list.join()}")
47
47
  end
48
48
  end
49
49
 
@@ -53,6 +53,12 @@ require 'net/https'
53
53
  require 'crack'
54
54
  require 'json'
55
55
  class MealTicket
56
+
57
+ class Config
58
+ cattr_accessor :facebook_app_id, :facebook_secret, :facebook_callback
59
+ cattr_accessor :flickr_token, :flickr_secret, :flickr_callback
60
+ end
61
+
56
62
  include MealTicketRoutes
57
63
 
58
64
  def initialize(app)
@@ -71,21 +77,25 @@ class MealTicket
71
77
  end
72
78
 
73
79
  def facebook_callback
74
- response = get facebook_exchange_url(get_root_url, get_query_string_parameter("code"))
75
-
76
- if response.body.include? "access_token"
77
- response.body =~ /access_token=([^&]+)(?:&expires=(.*))?/ # TODO: genericize get_query_string_parameter to handle this?
78
- token = $1 || ""
79
- expires = $2 || ""
80
- query_string = "facebook[token]=#{CGI.escape(token)}&facebook[expires]=#{CGI.escape(expires)}"
80
+ if get_query_string_parameter("code")
81
+ response = get facebook_exchange_url(get_root_url, get_query_string_parameter("code"))
82
+
83
+ if response.body.include? "access_token"
84
+ response.body =~ /access_token=([^&]+)(?:&expires=(.*))?/ # TODO: genericize get_query_string_parameter to handle this?
85
+ token = $1 || ""
86
+ expires = $2 || ""
87
+ query_string = "facebook[token]=#{CGI.escape(token)}&facebook[expires]=#{CGI.escape(expires)}"
88
+ else
89
+ parsed = JSON.parse(response.body)
90
+ query_string = to_params({:facebook => parsed})
91
+ end
81
92
  else
82
- parsed = JSON.parse(response.body)
83
- query_string = to_params({:facebook => parsed})
93
+ query_string = "facebook[error]=#{get_query_string_parameter("error")}"
84
94
  end
85
95
 
86
96
  body = %(<html><body>You are being redirected.</body></html>)
87
97
  headers = {
88
- 'Location' => "#{get_root_url}#{FACEBOOK_CALLBACK}?#{query_string}",
98
+ 'Location' => "#{get_root_url}#{MealTicket::Config.facebook_callback}?#{query_string}",
89
99
  'Content-Type' => 'text/html',
90
100
  'Content-Length' => body.length.to_s
91
101
  }
@@ -109,7 +119,7 @@ class MealTicket
109
119
 
110
120
  body = %(<html><body>You are being redirected.</body></html>)
111
121
  headers = {
112
- 'Location' => "#{get_root_url}#{FLICKR_CALLBACK}?#{query_string}",
122
+ 'Location' => "#{get_root_url}#{MealTicket::Config.flickr_callback}?#{query_string}",
113
123
  'Content-Type' => 'text/html',
114
124
  'Content-Length' => body.length.to_s
115
125
  }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{meal_ticket}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Doyle", "Kerri Miller", "John Postlethwait"]
12
- s.date = %q{2011-03-08}
12
+ s.date = %q{2011-05-26}
13
13
  s.description = %q{Meal Ticket is the easiest way to authenticate users for 3rd-party social APIs. Built to be used in conjunction with Buffet.}
14
14
  s.email = %q{archslide@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meal_ticket
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Doyle
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-03-08 00:00:00 -08:00
20
+ date: 2011-05-26 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency