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.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/meal_ticket.rb +25 -15
- data/meal_ticket.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -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.
|
1
|
+
0.1.1
|
data/lib/meal_ticket.rb
CHANGED
@@ -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=#{
|
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=#{
|
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" =>
|
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("#{
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
response.body
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
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}#{
|
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}#{
|
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
|
}
|
data/meal_ticket.gemspec
CHANGED
@@ -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.
|
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-
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
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-
|
20
|
+
date: 2011-05-26 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|