muck-oauth 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ begin
22
22
  gem.add_dependency "agree2"
23
23
  gem.add_dependency "fireeagle"
24
24
  gem.add_dependency "linkedin"
25
+ gem.add_dependency "overlord"
25
26
  gem.add_dependency "muck-engine"
26
27
  gem.add_dependency "muck-users"
27
28
  gem.add_development_dependency "shoulda"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -2,11 +2,17 @@ require 'oauth/controllers/consumer_controller'
2
2
  class OauthConsumersController < ApplicationController
3
3
  include Oauth::Controllers::ConsumerController
4
4
 
5
- layout :choose_layout
6
-
7
5
  def index
8
6
  end
9
7
 
8
+ def show
9
+ if @token
10
+ render 'oauth_consumers/show', :layout => false
11
+ else
12
+ super
13
+ end
14
+ end
15
+
10
16
  protected
11
17
 
12
18
  # Change this to decide where you want to redirect user to after callback is finished.
@@ -17,8 +23,4 @@ class OauthConsumersController < ApplicationController
17
23
  redirect_back_or_default('/')
18
24
  end
19
25
 
20
- def choose_layout
21
- 'popup'
22
- end
23
-
24
26
  end
@@ -1,10 +1,10 @@
1
1
  <% content_for :javascript do -%>
2
2
  jQuery(document).ready(function() {
3
3
  jQuery('a.oauthfancybox').fancybox({
4
- 'hideOnContentClick': true,
4
+ 'hideOnContentClick': false,
5
5
  'overlayShow': true,
6
- 'frameWidth': 800,
7
- 'frameHeight': 600
6
+ 'frameWidth': 400,
7
+ 'frameHeight': 300
8
8
  });
9
9
  });
10
10
  <% end -%>
@@ -6,17 +6,27 @@
6
6
  credentials = {}
7
7
  credentials[:twitter] = { :key => GlobalConfig.twitter_oauth_key,
8
8
  :secret => GlobalConfig.twitter_oauth_secret } if GlobalConfig.twitter_oauth_key
9
- credentials[:google] = { :scope => "https://mail.google.com/mail/feed/atom/", # see http://code.google.com/apis/gdata/faq.html#AuthScopes
9
+
10
+ # see http://code.google.com/apis/gdata/faq.html#AuthScopes
11
+ credentials[:google] = { :scope => ["https://mail.google.com/mail/feed/atom/",
12
+ "https://www.google.com/calendar/feeds/",
13
+ "https://www.google.com/m8/feeds/",
14
+ "http://www-opensocial.googleusercontent.com/api/people"].join(' '),
10
15
  :key => GlobalConfig.google_oauth_key,
11
16
  :secret => GlobalConfig.google_oauth_secret } if GlobalConfig.google_oauth_key
17
+
12
18
  credentials[:yahoo] = { :key => GlobalConfig.yahoo_oauth_key,
13
19
  :secret => GlobalConfig.yahoo_oauth_secret } if GlobalConfig.yahoo_oauth_key
20
+
14
21
  credentials[:flickr] = { :key => GlobalConfig.flickr_oauth_key,
15
22
  :secret => GlobalConfig.flickr_oauth_secret } if GlobalConfig.flickr_oauth_key
23
+
16
24
  credentials[:linkedin] = { :key => GlobalConfig.linkedin_oauth_key,
17
25
  :secret => GlobalConfig.linkedin_oauth_secret } if GlobalConfig.linkedin_oauth_key
26
+
18
27
  credentials[:fireeagle] = { :key => GlobalConfig.fireeagle_oauth_key,
19
28
  :secret => GlobalConfig.fireeagle_oauth_secret } if GlobalConfig.fireeagle_oauth_key
29
+
20
30
  credentials[:friendfeed] = { :key => GlobalConfig.friendfeed_oauth_key,
21
31
  :secret => GlobalConfig.friendfeed_oauth_secret } if GlobalConfig.friendfeed_oauth_key
22
32
 
data/lib/muck_oauth.rb CHANGED
@@ -1,6 +1,12 @@
1
+ require 'muck_oauth/services/friendfeed_token'
2
+ require 'muck_oauth/services/google_token'
3
+ require 'muck_oauth/services/linkedin_token'
4
+ require 'muck_oauth/services/yahoo_token'
5
+ require 'muck_oauth/exceptions'
1
6
 
2
7
  ActionController::Base.send :helper, MuckOauthHelper
3
8
 
4
9
  ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckOauthUser }
10
+ ActiveRecord::Base.class_eval { include MuckOauth::Exceptions }
5
11
 
6
12
  I18n.load_path += Dir[ File.join(File.dirname(__FILE__), '..', 'locales', '*.{rb,yml}') ]
@@ -0,0 +1,5 @@
1
+ module MuckOauth
2
+ module Exceptions
3
+ class HTTPResultError < StandardError; end
4
+ end
5
+ end
@@ -3,7 +3,7 @@ class FriendfeedToken < ConsumerToken
3
3
  :site => "https://friendfeed.com",
4
4
  :request_token_path => "/account/oauth/request_token",
5
5
  :authorize_path => "/account/oauth/authorize",
6
- :access_token_path => "/accounts/account/oauth/access_token",
6
+ :access_token_path => "/account/oauth/access_token",
7
7
  }
8
8
 
9
9
  def self.consumer
@@ -18,4 +18,8 @@ class FriendfeedToken < ConsumerToken
18
18
  consumer.get_request_token({ :oauth_callback => callback_url })
19
19
  end
20
20
 
21
- end
21
+ def client
22
+ raise 'Implement client for friend feed.'
23
+ end
24
+
25
+ end
@@ -0,0 +1,71 @@
1
+ require 'portablecontacts'
2
+
3
+ class GoogleToken < ConsumerToken
4
+
5
+ GOOGLE_SETTINGS={
6
+ :site=>"https://www.google.com",
7
+ :request_token_path => "/accounts/OAuthGetRequestToken",
8
+ :authorize_path => "/accounts/OAuthAuthorizeToken",
9
+ :access_token_path => "/accounts/OAuthGetAccessToken",
10
+ }
11
+
12
+ def self.consumer
13
+ @consumer||=create_consumer
14
+ end
15
+
16
+ def self.create_consumer(options={})
17
+ OAuth::Consumer.new credentials[:key], credentials[:secret], GOOGLE_SETTINGS.merge(options)
18
+ end
19
+
20
+ def self.get_request_token(callback_url, scope=nil)
21
+ consumer.get_request_token({:oauth_callback=>callback_url}, :scope=>scope||credentials[:scope]||"http://www-opensocial.googleusercontent.com/api/people")
22
+ end
23
+
24
+ def portable_contacts
25
+ @portable_contacts||= PortableContacts::Client.new "http://www-opensocial.googleusercontent.com/api/people", client
26
+ end
27
+
28
+ # Gets and parses contacts from google into objects.
29
+ # limit: Maximum number of contacts to retrieve
30
+ def contacts(limit = 10000)
31
+ convert_google_contacts_json_to_users(load_contacts(limit))
32
+ end
33
+
34
+ # Loads contacts using Google api and OAuth token.
35
+ def load_contacts(limit = 10000)
36
+ get("http://www.google.com/m8/feeds/contacts/default/full?max-results=#{limit}")
37
+ end
38
+
39
+ # Converts json returned from google into a feed object
40
+ def convert_google_contacts_json_to_users(json)
41
+ if json['feed'] && json['feed']['entry']
42
+ json['feed']['entry'].collect do |entry|
43
+ emails = entry['gd$email'].collect { |gd| gd['address'] } if entry['gd$email']
44
+ phones = entry['gd$phoneNumber'].collect { |gd| gd['t'] } if entry['gd$phoneNumber']
45
+ if entry['gd$name']
46
+ first_name = entry['gd$name']['gd$givenName'] if entry['gd$name']['gd$givenName']
47
+ last_name = entry['gd$name']['gd$familyName'] if entry['gd$name']['gd$familyName']
48
+ end
49
+ OpenStruct.new( { :emails => emails,
50
+ :phones => phones,
51
+ :first_name => first_name,
52
+ :last_name => last_name } )
53
+ end
54
+ end
55
+ end
56
+
57
+ # Loads a user's groups using Google api and OAuth token.
58
+ def load_groups(limit = 10000)
59
+ get("http://www.google.com/m8/feeds/groups/default/full?max-results=#{limit}")
60
+ end
61
+
62
+ def get(path)
63
+ response = self.client.get(path + "&alt=json&v=3.0")
64
+ if response.code == '200'
65
+ JSON.parse(response.body)
66
+ else
67
+ raise MuckOauth::Exceptions::HTTPResultError, I18n.t('muck.oauth.http_result_error', :error => response.to_s)
68
+ end
69
+ end
70
+
71
+ end
@@ -22,7 +22,7 @@ class LinkedinToken < ConsumerToken
22
22
 
23
23
  def client
24
24
  unless @client
25
- @client = LinkedIn::Client.new(LinkedInToken.consumer.key, LinkedInToken.consumer.secret)
25
+ @client = ::LinkedIn::Client.new(LinkedinToken.consumer.key, LinkedinToken.consumer.secret)
26
26
  @client.authorize_from_access(token, secret)
27
27
  end
28
28
  @client
data/locales/en.yml CHANGED
@@ -51,3 +51,4 @@ en:
51
51
  we_support_hmac_sha: We support hmac-sha1 (recommended) as well as plain text in ssl mode.
52
52
  consume_secret: "Consumer Secret:"
53
53
  request_disallowed: You have disallowed this request
54
+ http_result_error: "There was a problem with your request {{error}}"
data/muck-oauth.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muck-oauth}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Ball"]
12
- s.date = %q{2009-12-22}
12
+ s.date = %q{2009-12-24}
13
13
  s.description = %q{A simple wrapper for the oauth and oauth-plugin gems so that it is faster to include oauth in muck based applications.}
14
14
  s.email = %q{justin@tatemae.com}
15
15
  s.extra_rdoc_files = [
@@ -30,12 +30,9 @@ Gem::Specification.new do |s|
30
30
  "app/models/access_token.rb",
31
31
  "app/models/client_application.rb",
32
32
  "app/models/consumer_token.rb",
33
- "app/models/friendfeed_token.rb",
34
- "app/models/linkedin_token.rb",
35
33
  "app/models/oauth_nonce.rb",
36
34
  "app/models/oauth_token.rb",
37
35
  "app/models/request_token.rb",
38
- "app/models/yahoo_token.rb",
39
36
  "app/views/oauth/authorize.html.erb",
40
37
  "app/views/oauth/authorize_failure.html.erb",
41
38
  "app/views/oauth/authorize_success.html.erb",
@@ -55,7 +52,12 @@ Gem::Specification.new do |s|
55
52
  "db/migrate/20091210172015_create_oauth_tables.rb",
56
53
  "lib/active_record/acts/muck_oauth_user.rb",
57
54
  "lib/muck_oauth.rb",
55
+ "lib/muck_oauth/exceptions.rb",
58
56
  "lib/muck_oauth/initialize_routes.rb",
57
+ "lib/muck_oauth/services/friendfeed_token.rb",
58
+ "lib/muck_oauth/services/google_token.rb",
59
+ "lib/muck_oauth/services/linkedin_token.rb",
60
+ "lib/muck_oauth/services/yahoo_token.rb",
59
61
  "lib/muck_oauth/tasks.rb",
60
62
  "locales/ar.yml",
61
63
  "locales/bg.yml",
@@ -1826,6 +1828,7 @@ Gem::Specification.new do |s|
1826
1828
  s.add_runtime_dependency(%q<agree2>, [">= 0"])
1827
1829
  s.add_runtime_dependency(%q<fireeagle>, [">= 0"])
1828
1830
  s.add_runtime_dependency(%q<linkedin>, [">= 0"])
1831
+ s.add_runtime_dependency(%q<overlord>, [">= 0"])
1829
1832
  s.add_runtime_dependency(%q<muck-engine>, [">= 0"])
1830
1833
  s.add_runtime_dependency(%q<muck-users>, [">= 0"])
1831
1834
  s.add_development_dependency(%q<shoulda>, [">= 0"])
@@ -1837,6 +1840,7 @@ Gem::Specification.new do |s|
1837
1840
  s.add_dependency(%q<agree2>, [">= 0"])
1838
1841
  s.add_dependency(%q<fireeagle>, [">= 0"])
1839
1842
  s.add_dependency(%q<linkedin>, [">= 0"])
1843
+ s.add_dependency(%q<overlord>, [">= 0"])
1840
1844
  s.add_dependency(%q<muck-engine>, [">= 0"])
1841
1845
  s.add_dependency(%q<muck-users>, [">= 0"])
1842
1846
  s.add_dependency(%q<shoulda>, [">= 0"])
@@ -1849,6 +1853,7 @@ Gem::Specification.new do |s|
1849
1853
  s.add_dependency(%q<agree2>, [">= 0"])
1850
1854
  s.add_dependency(%q<fireeagle>, [">= 0"])
1851
1855
  s.add_dependency(%q<linkedin>, [">= 0"])
1856
+ s.add_dependency(%q<overlord>, [">= 0"])
1852
1857
  s.add_dependency(%q<muck-engine>, [">= 0"])
1853
1858
  s.add_dependency(%q<muck-users>, [">= 0"])
1854
1859
  s.add_dependency(%q<shoulda>, [">= 0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ball
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-22 00:00:00 -07:00
12
+ date: 2009-12-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,16 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: "0"
84
84
  version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: overlord
87
+ type: :runtime
88
+ version_requirement:
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
85
95
  - !ruby/object:Gem::Dependency
86
96
  name: muck-engine
87
97
  type: :runtime
@@ -135,12 +145,9 @@ files:
135
145
  - app/models/access_token.rb
136
146
  - app/models/client_application.rb
137
147
  - app/models/consumer_token.rb
138
- - app/models/friendfeed_token.rb
139
- - app/models/linkedin_token.rb
140
148
  - app/models/oauth_nonce.rb
141
149
  - app/models/oauth_token.rb
142
150
  - app/models/request_token.rb
143
- - app/models/yahoo_token.rb
144
151
  - app/views/oauth/authorize.html.erb
145
152
  - app/views/oauth/authorize_failure.html.erb
146
153
  - app/views/oauth/authorize_success.html.erb
@@ -160,7 +167,12 @@ files:
160
167
  - db/migrate/20091210172015_create_oauth_tables.rb
161
168
  - lib/active_record/acts/muck_oauth_user.rb
162
169
  - lib/muck_oauth.rb
170
+ - lib/muck_oauth/exceptions.rb
163
171
  - lib/muck_oauth/initialize_routes.rb
172
+ - lib/muck_oauth/services/friendfeed_token.rb
173
+ - lib/muck_oauth/services/google_token.rb
174
+ - lib/muck_oauth/services/linkedin_token.rb
175
+ - lib/muck_oauth/services/yahoo_token.rb
164
176
  - lib/muck_oauth/tasks.rb
165
177
  - locales/ar.yml
166
178
  - locales/bg.yml