hellhound 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,86 @@
1
+ hellhound
2
+ =========
3
+
4
+ Hellhound is a Sinatra application gem to connect to facebook, twitter adn in the future other service.
5
+
6
+ It use memcached to store the user if the variable hellhound_cache is enable
7
+
8
+ How to use it
9
+ -------------
10
+
11
+ Configure the gem for facebook:
12
+
13
+ configure do
14
+ set :fb_api_key, 'your key'
15
+ set :fb_app_secret, 'your secret'
16
+
17
+ enable :hellhound_cache
18
+ end
19
+
20
+ Configure the gem for twitter:
21
+
22
+ configure do
23
+ include Rack::OAuth::Methods
24
+ use Rack::OAuth, :key => 'your key',
25
+ :secret => 'your secret',
26
+ :site => 'http://twitter.com'
27
+
28
+ enable :hellhound_cache
29
+ end
30
+
31
+
32
+ There are two more things that you should do include the helpers methods and implement get_user that is a method that retrieve the user from your data store
33
+
34
+ helpers do
35
+ include Sinatra::Hellhound::TwitterHelpers
36
+
37
+ def get_user id
38
+ # i.e. using DataMapper
39
+ User.fist :twitter_id => session[:user]
40
+ end
41
+ end
42
+
43
+
44
+ You will need to override the method get user. This method will search the user in the database in case that the user is not in the cache or the cache was not enabled
45
+
46
+ def get_user id
47
+ User.search(:twitter_id => id)
48
+ end
49
+
50
+
51
+ Hellhound provides some helpers:
52
+
53
+ * current_user
54
+ * logged_in?
55
+ * logout!
56
+
57
+
58
+ * create_or_retrive_xxx_user(&block)
59
+ ** create_or_retrieve_twitter_user(&block)
60
+ ** create_or_retrieve_facebook_user(&block)
61
+ ** ... (more in the future)
62
+
63
+ Also provide some routes
64
+
65
+ get /oauth_login # => redirect to /oauth_complete (twitter)
66
+ get /auth/facebook # => redirect to /auth/facebook/callback (facebook)
67
+
68
+ Both of the redirect the user to /oauth_complete
69
+
70
+ # The block should return the user in case the cache is on.
71
+ get "/oauth_complete" do
72
+ create_or_retrieve_twitter_user do |user_data|
73
+ User.first_or_create({
74
+ :user_name => user_data["name"],
75
+ :screen_name => user_data["screen_name"],
76
+ :twitter_id => user_data["id"]
77
+ })
78
+ end
79
+ redirect "/oauth_login"
80
+ end
81
+
82
+
83
+
84
+ == Copyright
85
+
86
+ Copyright (c) 2010 Pedro Del Gallego. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -6,8 +6,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), "../lib/hellhound.rb"
6
6
 
7
7
  configure do
8
8
 
9
- set :fb_api_key, '85b58936a196dcf2b57b863e2f3f6a37'
10
- set :fb_app_secret, 'd596ecc4fdc2d7753c15b2c920d50100'
9
+ set :fb_api_key, 'your key'
10
+ set :fb_app_secret, 'your secret'
11
11
 
12
12
  enable :hellhound_cache
13
13
  end
@@ -5,10 +5,12 @@
5
5
 
6
6
  configure do
7
7
  include Rack::OAuth::Methods
8
- use Rack::OAuth, :key => '97DyOmKn7gn1ki0wlyoGA',
9
- :secret => 'bBYIkLEEsdbLFEflWOV2fqaCieiBmYwzV4gXdvwwk',
8
+
9
+ use Rack::OAuth, :key => 'your key',
10
+ :secret => 'your secret',
10
11
  :site => 'http://twitter.com'
11
12
 
13
+
12
14
  enable :hellhound_cache
13
15
  end
14
16
 
@@ -1,46 +1,44 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hellhound}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pedro Del Gallego"]
12
- s.date = %q{2010-05-17}
12
+ s.date = %q{2010-11-21}
13
13
  s.email = %q{pedro.delgallego@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
16
- "README.rdoc"
16
+ "README.md"
17
17
  ]
18
18
  s.files = [
19
19
  ".document",
20
- ".gitignore",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "TAGS",
25
- "VERSION",
26
- "examples/facebook-app.rb",
27
- "examples/twitter-app.rb",
28
- "hellhound.gemspec",
29
- "lib/hellhound.rb",
30
- "spec/hellhound_spec.rb",
31
- "spec/spec.opts",
32
- "spec/spec_helper.rb"
20
+ "LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "TAGS",
24
+ "VERSION",
25
+ "examples/facebook-app.rb",
26
+ "examples/twitter-app.rb",
27
+ "hellhound.gemspec",
28
+ "lib/hellhound.rb",
29
+ "spec/hellhound_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
33
32
  ]
34
33
  s.homepage = %q{http://github.com/pedrodelgallego/hellhound}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
34
  s.require_paths = ["lib"]
37
35
  s.rubygems_version = %q{1.3.7}
38
36
  s.summary = %q{An authentication system based in third oauth party providers.}
39
37
  s.test_files = [
38
+ "examples/facebook-app.rb",
39
+ "examples/twitter-app.rb",
40
40
  "spec/hellhound_spec.rb",
41
- "spec/spec_helper.rb",
42
- "examples/twitter-app.rb",
43
- "examples/facebook-app.rb"
41
+ "spec/spec_helper.rb"
44
42
  ]
45
43
 
46
44
  if s.respond_to? :specification_version then
@@ -21,6 +21,15 @@ module Sinatra
21
21
  end
22
22
  end
23
23
 
24
+ ##
25
+ # Returns the current_user, it's an instance of <tt>user</tt> model
26
+ #
27
+ def refresh_current_user
28
+ if session[:user]
29
+ CACHE.set("user-#{session[:user]}", get_user(session[:user])) if options.hellhound_cache
30
+ end
31
+ end
32
+
24
33
  ##
25
34
  # Returns true if +current_user+ is logged and active.
26
35
  #
@@ -39,7 +48,17 @@ module Sinatra
39
48
  end
40
49
 
41
50
  end
42
-
51
+
52
+ module GithubHelpers
53
+ def get_credentials
54
+ raise Exception "Github support is not yet implemented"
55
+ end
56
+
57
+ def create_or_retrieve_github_user
58
+ raise Exception "Github support is not yet implemented"
59
+ end
60
+ end
61
+
43
62
  module TwitterHelpers
44
63
  ##
45
64
  # Retrieve the user from the database or create a new one if it
@@ -69,7 +88,9 @@ module Sinatra
69
88
  #
70
89
  def get_credentials
71
90
  user_data = JSON.parse(get_access_token.get('/account/verify_credentials.json').body)
72
- end
91
+ end
92
+
93
+
73
94
  end
74
95
 
75
96
  module FacebookHelpers
@@ -115,11 +136,18 @@ module Sinatra
115
136
  JSON.parse(access_token.get('/me'))
116
137
  end
117
138
 
118
- def client
139
+ def facebook_client
119
140
  OAuth2::Client.new(options.fb_api_key, options.fb_app_secret, :site => 'https://graph.facebook.com')
120
141
  end
121
142
 
122
- def redirect_uri
143
+ def github_redirect_uri
144
+ uri = URI.parse(request.url)
145
+ uri.path = '/auth/github/callback'
146
+ uri.query = nil
147
+ uri.to_s
148
+ end
149
+
150
+ def facebook_redirect_uri
123
151
  uri = URI.parse(request.url)
124
152
  uri.path = '/auth/facebook/callback'
125
153
  uri.query = nil
@@ -133,10 +161,17 @@ module Sinatra
133
161
  app.enable :sessions
134
162
  app.disable :hellhound_cache
135
163
  app.helpers
164
+
165
+ app.get '/auth/github' do
166
+ redirect github_client.web_server.authorize_url(
167
+ :redirect_uri => github_redirect_uri,
168
+ :scope => 'email,offline_access'
169
+ )
170
+ end
136
171
 
137
172
  app.get '/auth/facebook' do
138
- redirect client.web_server.authorize_url(
139
- :redirect_uri => redirect_uri,
173
+ redirect facebook_client.web_server.authorize_url(
174
+ :redirect_uri => facebook_redirect_uri,
140
175
  :scope => 'email,offline_access'
141
176
  )
142
177
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellhound
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pedro Del Gallego
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-17 00:00:00 +02:00
18
+ date: 2010-11-21 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -56,12 +56,11 @@ extensions: []
56
56
 
57
57
  extra_rdoc_files:
58
58
  - LICENSE
59
- - README.rdoc
59
+ - README.md
60
60
  files:
61
61
  - .document
62
- - .gitignore
63
62
  - LICENSE
64
- - README.rdoc
63
+ - README.md
65
64
  - Rakefile
66
65
  - TAGS
67
66
  - VERSION
@@ -77,8 +76,8 @@ homepage: http://github.com/pedrodelgallego/hellhound
77
76
  licenses: []
78
77
 
79
78
  post_install_message:
80
- rdoc_options:
81
- - --charset=UTF-8
79
+ rdoc_options: []
80
+
82
81
  require_paths:
83
82
  - lib
84
83
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -107,7 +106,7 @@ signing_key:
107
106
  specification_version: 3
108
107
  summary: An authentication system based in third oauth party providers.
109
108
  test_files:
109
+ - examples/facebook-app.rb
110
+ - examples/twitter-app.rb
110
111
  - spec/hellhound_spec.rb
111
112
  - spec/spec_helper.rb
112
- - examples/twitter-app.rb
113
- - examples/facebook-app.rb
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
@@ -1,41 +0,0 @@
1
- = hellhound
2
-
3
- Description goes here.
4
-
5
-
6
- == How to use it ==
7
-
8
- You will need to override the method get user. This method will search the user in the database in case that the user is not in the cache or the cache was not enabled
9
-
10
- =code
11
- def get_user id
12
- User.search(:twitter_id => id)
13
- end
14
- =
15
-
16
- Hellhound provides some helpers:
17
-
18
- * current_user
19
- * logged_in?
20
- * logout!
21
-
22
-
23
- * create_or_retrive_xxx_user(&block)
24
- ** create_or_retrive_twitter_user(&block)
25
- ** create_or_retrive_facebook_user(&block)
26
- ** ...
27
-
28
-
29
- == Note on Patches/Pull Requests
30
-
31
- * Fork the project.
32
- * Make your feature addition or bug fix.
33
- * Add tests for it. This is important so I don't break it in a
34
- future version unintentionally.
35
- * Commit, do not mess with rakefile, version, or history.
36
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
37
- * Send me a pull request. Bonus points for topic branches.
38
-
39
- == Copyright
40
-
41
- Copyright (c) 2010 Pedro Del Gallego. See LICENSE for details.