dailycred 0.1.30 → 0.1.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Gemfile +4 -0
  2. data/README.md +102 -2
  3. data/Rakefile +10 -0
  4. data/app/controllers/sessions_controller.rb +32 -0
  5. data/app/views/sessions/info.html.erb +7 -0
  6. data/config/routes.rb +7 -0
  7. data/dailycred.gemspec +3 -3
  8. data/docs/lib/dailycred/acts_as_dailycred.html +42 -0
  9. data/docs/lib/dailycred/client.html +214 -0
  10. data/docs/lib/dailycred/engine.html +112 -0
  11. data/docs/lib/dailycred/helper.html +119 -0
  12. data/docs/lib/dailycred/middleware.html +42 -0
  13. data/docs/lib/dailycred/tests_helper.html +42 -0
  14. data/docs/lib/dailycred/user.html +133 -0
  15. data/docs/lib/dailycred.html +7 -177
  16. data/docs/lib/generators/dailycred_generator.html +7 -3
  17. data/docs/lib/generators/templates/migration_create_user.html +2 -1
  18. data/docs/lib/generators/templates/omniauth.html +36 -3
  19. data/docs/lib/generators/templates/sessions_controller.html +7 -2
  20. data/docs/lib/generators/templates/user.html +7 -3
  21. data/docs/lib/omniauth/strategies/dailycred.html +14 -9
  22. data/lib/dailycred/acts_as_dailycred.rb +25 -0
  23. data/lib/dailycred/client.rb +103 -0
  24. data/lib/dailycred/engine.rb +51 -0
  25. data/lib/dailycred/helper.rb +39 -1
  26. data/lib/{middleware → dailycred}/middleware.rb +12 -14
  27. data/lib/dailycred/tests_helper.rb +5 -0
  28. data/lib/dailycred/user.rb +2 -2
  29. data/lib/dailycred.rb +1 -106
  30. data/lib/generators/dailycred_generator.rb +3 -59
  31. data/lib/generators/templates/info.html.erb +1 -1
  32. data/lib/generators/templates/omniauth.rb +6 -17
  33. data/lib/generators/templates/user.rb +1 -16
  34. data/lib/omniauth/strategies/dailycred.rb +6 -5
  35. data/script/download_info.rb +11 -0
  36. data/spec/omniauth/strategies/dailycred_spec.rb +2 -2
  37. data/spec/support/dailycred_spec.rb +2 -2
  38. data/test/generator_test.rb +5 -36
  39. metadata +20 -6
  40. data/lib/omniauth-dailycred/version.rb +0 -5
data/Gemfile CHANGED
@@ -12,3 +12,7 @@ gem 'guard'
12
12
  gem 'guard-test'
13
13
  gem 'guard-rspec'
14
14
  gem 'mocha'
15
+ gem 'fl-rocco'
16
+ gem 'redcarpet', '~> 1.17'
17
+ gem 'markdown'
18
+ gem 'maruku'
data/README.md CHANGED
@@ -1,8 +1,107 @@
1
1
  # Dailycred
2
2
 
3
- ## Rails gem for instant authentication using Dailycred with Ruby on Rails
3
+ ## Introduction
4
4
 
5
- ### Check out the documenation at [dailycred.com]("https://www.dailycred.com/docs/ruby")
5
+ The Dailycred ruby gem is everything you need to get off the ground running with robust authentication. It includes an [omniauth](https://github.com/intridea/omniauth) provider and a generator to create necessary models and controllers. The generated authentication structure is inspired by [nifty-generators](https://github.com/ryanb/nifty-generators). To get started using Dailycred with Ruby on Rails, the first thing you need to do is add the dailycred gem to your gemfile:
6
+
7
+
8
+ gem 'dailycred'
9
+
10
+ Make sure you've signed up for Dailycred, and head over to your [settings](https://www.dailycred.com/admin/settings) page to get your API keys. Once you've done that, head back to the command line and run:
11
+
12
+ bundle
13
+ rails g dailycred
14
+ rake db:migrate
15
+
16
+ Thats it! You've successfully added authentication to your app, and you can start signing up users. Run `rails s` to start your
17
+ server, and point your browser to [http://localhost:3000/auth](http://localhost:3000/auth) and you'll see a pre-built page with links to sign up.
18
+
19
+ Here's what the dailycred gem generates for you:
20
+
21
+ * A few helper methods to `/app/controllers/application_controller.rb`.
22
+ * An initializer file at `/config/initializers/omniauth.rb` which configures your dailycred API keys.
23
+ * `/app/models/user.rb`, the User model.
24
+ * A migration file to create the user table in your database.
25
+
26
+
27
+ While this is enough to get off the ground running with user authentication, this setup is meant to be lightweight and flexible, so feel free to tinker with
28
+ any of the generated code to better match your needs.
29
+
30
+ ## Authenticating
31
+
32
+ To protect a controller method from unauthorized users, use the 'authorize' helper method as a `before_filter`.
33
+
34
+ #before_filter :authenticate, :except => [:index] #don't authenticate some
35
+ #before_filter :authenticate, :only => [:create, :new] #only authenticate some
36
+ before_filter :authenticate #all methods
37
+
38
+ There are a few other helper methods available:
39
+
40
+ #### current_user
41
+
42
+ Returns the current logged in user or nil. Example usage:
43
+
44
+ if !current_user.nil?
45
+ redirect_to :controller => 'welcome', :action => 'thanks'
46
+ end
47
+
48
+ #### dailycred
49
+
50
+ A helper for instantiating a dailycred client instance. Use as a `before_filter` to load a @dailycred instance variable, or just use it as a helper method. Example usage:
51
+
52
+ As a before filter:
53
+
54
+ before_filter :dailycred
55
+
56
+ def index
57
+ @dailycred.event(current_user.uid, "New Task", @task.name)
58
+ end
59
+
60
+ or just as a helper
61
+
62
+ def index
63
+ dailycred.event(current_user.uid, "New Task", @task.name)
64
+ end
65
+
66
+ #### login_path
67
+
68
+ A helper for linking to the authentication url. Usage:
69
+
70
+ <%= link_to 'sign up', login_path %>
71
+ # => <a href="/auth/dailycred">sign up</a>
72
+
73
+ #### Logging out
74
+
75
+ To logout a user, simply send them to `/auth/logout`.
76
+
77
+ <%= link_to 'logout', logout_path %>
78
+ # => <a href="/auth/logout">logout</a>
79
+
80
+ ## Dailycred API
81
+
82
+ For reference, have a look at the [annotated source code.](https://www.dailycred.com/public/docs/ruby/lib/dailycred.html)
83
+
84
+ For all API calls, you must first initalize a Dailycred client:
85
+
86
+ @dailycred = Dailycred.new "YOUR_CLIENT_ID", "your_secret_key", opts
87
+
88
+ Where opts is an optional hash for passing options. After initializing your client, you can create events as well as tag and untag users:
89
+
90
+ @dailycred.event(current_user.uid, "New Task", @task.name) # user_id, key, value
91
+ @dailycred.tag(current_user.uid, "Failed Checkout") # user_id, key
92
+ @dailycred.untag(current_user.uid, "Failed Checkout") # user_id, key
93
+
94
+
95
+ #### Configuration
96
+
97
+ To specify where users should be redirected after authentication actions, setup configure an `after_auth` property on a `Rails.configuration.DAILYCRED_OPTIONS` variable. Example:
98
+
99
+ # configure where users should be redirected after authentication
100
+ #
101
+ # Rails.configuration.DAILYCRED_OPTIONS = {
102
+ # :after_auth => '/hello', #after login
103
+ # :after_unauth => '/goodbye' #after logout
104
+ # }
6
105
 
7
106
  ## Contributing
8
107
 
@@ -11,3 +110,4 @@
11
110
  3. Commit your changes (`git commit -am 'Added some feature'`)
12
111
  4. Push to the branch (`git push origin my-new-feature`)
13
112
  5. Create new Pull Request
113
+
data/Rakefile CHANGED
@@ -12,10 +12,20 @@ RSpec::Core::RakeTask.new do |t|
12
12
  end
13
13
 
14
14
  begin
15
+ require 'rocco'
15
16
  require 'rocco/tasks'
16
17
  require 'fileutils'
18
+ require 'maruku'
17
19
  Rocco::make 'docs/'
18
20
  FileUtils.cp_r "docs/lib/", "/Users/hank/rails/dailycred/public/docs/ruby/", :verbose => true
21
+ md = ""
22
+ File.open("README.md", "r") do |infile|
23
+ while (line = infile.gets)
24
+ md += line
25
+ end
26
+ end
27
+ doc = Maruku.new(md)
28
+ File.open("/Users/hank/rails/dailycred/app/views/tags/ruby.html", 'w') {|f| f.write doc.to_html}
19
29
  rescue LoadError
20
30
  warn "#$! -- rocco tasks not loaded."
21
31
  task :rocco
@@ -0,0 +1,32 @@
1
+ class SessionsController < ApplicationController
2
+ before_filter :authenticate, :only => [:destroy]
3
+ before_filter :current_user
4
+
5
+ # Callback Route for OAuth flow
6
+ def create
7
+ @user = User.find_or_create_with_omniauth auth_hash
8
+ session[:user_id] = @user.id
9
+ redirect_to_auth
10
+ end
11
+
12
+ #GET /logout
13
+ def destroy
14
+ session[:user_id] = nil
15
+ redirect_to_auth
16
+ end
17
+
18
+ def failure
19
+ conf = Rails.configuration.DAILYCRED_OPTIONS
20
+ path = !conf[:after_unauth].nil? ? conf[:after_unauth] : dailycred_engine.auth_info_path
21
+ redirect_to path, notice: params[:message]
22
+ end
23
+
24
+ def info
25
+ end
26
+
27
+ private
28
+
29
+ def auth_hash
30
+ request.env['omniauth.auth']
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ <% if current_user %>
2
+ <p>Hello <%= current_user.email %> <br>
3
+ <%= link_to 'Logout', dailycred_engine.logout_path %>
4
+ </p>
5
+ <% else %>
6
+ <%= link_to 'Log In', login_path() %>
7
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Dailycred::Engine.routes.draw do
2
+ match "/:provider/callback" => "sessions#create"
3
+ match "/logout" => "sessions#destroy", :as => :logout
4
+ match "/" => "sessions#info", :as => :auth_info
5
+ # get "/dailycred", :as => :login
6
+ match "/failure" => "sessions#failure"
7
+ end
data/dailycred.gemspec CHANGED
@@ -3,8 +3,8 @@
3
3
  Gem::Specification.new do |gem|
4
4
  gem.authors = ["Hank Stoever"]
5
5
  gem.email = ["hstove@gmail.com"]
6
- gem.description = %q{descript}
7
- gem.summary = %q{summary}
6
+ gem.description = %q{A Ruby on Rails engine for authentication with Dailycred.}
7
+ gem.summary = %q{}
8
8
  gem.homepage = "https://www.dailycred.com"
9
9
  gem.add_dependency("omniauth")
10
10
  gem.add_dependency("omniauth-oauth2")
@@ -15,5 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
16
  gem.name = "dailycred"
17
17
  gem.require_paths = ["lib"]
18
- gem.version = "0.1.30"
18
+ gem.version = "0.1.31"
19
19
  end
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>acts_as_dailycred.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../dailycred.html">dailycred.rb</a>
16
+ <a class="source" href="acts_as_dailycred.html">acts_as_dailycred.rb</a>
17
+ <a class="source" href="client.html">client.rb</a>
18
+ <a class="source" href="engine.html">engine.rb</a>
19
+ <a class="source" href="helper.html">helper.rb</a>
20
+ <a class="source" href="middleware.html">middleware.rb</a>
21
+ <a class="source" href="tests_helper.html">tests_helper.rb</a>
22
+ <a class="source" href="user.html">user.rb</a>
23
+ <a class="source" href="../generators/dailycred_generator.html">dailycred_generator.rb</a>
24
+ <a class="source" href="../generators/templates/migration_create_user.html">migration_create_user.rb</a>
25
+ <a class="source" href="../generators/templates/omniauth.html">omniauth.rb</a>
26
+ <a class="source" href="../generators/templates/sessions_controller.html">sessions_controller.rb</a>
27
+ <a class="source" href="../generators/templates/user.html">user.rb</a>
28
+ <a class="source" href="../omniauth/strategies/dailycred.html">dailycred.rb</a>
29
+ </div>
30
+ </div>
31
+ </div>
32
+ <table cellspacing=0 cellpadding=0>
33
+ <thead>
34
+ <tr>
35
+ <th class=docs><h1>acts_as_dailycred.rb</h1></th>
36
+ <th class=code></th>
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ </table>
41
+ </div>
42
+ </body>
@@ -0,0 +1,214 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>client.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../dailycred.html">dailycred.rb</a>
16
+ <a class="source" href="acts_as_dailycred.html">acts_as_dailycred.rb</a>
17
+ <a class="source" href="client.html">client.rb</a>
18
+ <a class="source" href="engine.html">engine.rb</a>
19
+ <a class="source" href="helper.html">helper.rb</a>
20
+ <a class="source" href="middleware.html">middleware.rb</a>
21
+ <a class="source" href="tests_helper.html">tests_helper.rb</a>
22
+ <a class="source" href="user.html">user.rb</a>
23
+ <a class="source" href="../generators/dailycred_generator.html">dailycred_generator.rb</a>
24
+ <a class="source" href="../generators/templates/migration_create_user.html">migration_create_user.rb</a>
25
+ <a class="source" href="../generators/templates/omniauth.html">omniauth.rb</a>
26
+ <a class="source" href="../generators/templates/sessions_controller.html">sessions_controller.rb</a>
27
+ <a class="source" href="../generators/templates/user.html">user.rb</a>
28
+ <a class="source" href="../omniauth/strategies/dailycred.html">dailycred.rb</a>
29
+ </div>
30
+ </div>
31
+ </div>
32
+ <table cellspacing=0 cellpadding=0>
33
+ <thead>
34
+ <tr>
35
+ <th class=docs><h1>client.rb</h1></th>
36
+ <th class=code></th>
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ <tr id='section-1'>
41
+ <td class=docs>
42
+ <div class="pilwrap">
43
+ <a class="pilcrow" href="#section-1">&#182;</a>
44
+ </div>
45
+
46
+ </td>
47
+ <td class=code>
48
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">Dailycred</span>
49
+ <span class="k">class</span> <span class="nc">Client</span>
50
+ <span class="kp">attr_accessor</span> <span class="ss">:client_id</span><span class="p">,</span> <span class="ss">:secret_key</span><span class="p">,</span> <span class="ss">:options</span><span class="p">,</span> <span class="ss">:url</span>
51
+
52
+ <span class="no">URL</span> <span class="o">=</span> <span class="s2">&quot;https://www.dailycred.com&quot;</span>
53
+
54
+ <span class="no">ROUTES</span> <span class="o">=</span> <span class="p">{</span>
55
+ <span class="ss">:signup</span> <span class="o">=&gt;</span> <span class="s2">&quot;/user/api/signup.json&quot;</span><span class="p">,</span>
56
+ <span class="ss">:login</span> <span class="o">=&gt;</span> <span class="s2">&quot;/user/api/signin.json&quot;</span>
57
+ <span class="p">}</span></pre></div>
58
+ </td>
59
+ </tr>
60
+ <tr id='section-2'>
61
+ <td class=docs>
62
+ <div class="pilwrap">
63
+ <a class="pilcrow" href="#section-2">&#182;</a>
64
+ </div>
65
+ <p>Initializes a dailycred object</p>
66
+
67
+ <ul>
68
+ <li>@param [String] client_id the client&rsquo;s daiycred client id</li>
69
+ <li>@param [String] secret_key the clients secret key</li>
70
+ <li>@param [Hash] opts a hash of options</li>
71
+ </ul>
72
+ </td>
73
+ <td class=code>
74
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">client_id</span><span class="p">,</span> <span class="n">secret_key</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="p">{})</span>
75
+ <span class="vi">@client_id</span> <span class="o">=</span> <span class="n">client_id</span>
76
+ <span class="vi">@secret_key</span> <span class="o">=</span> <span class="n">secret_key</span>
77
+ <span class="vi">@options</span> <span class="o">=</span> <span class="n">opts</span>
78
+ <span class="n">opts</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">]</span> <span class="o">||=</span> <span class="p">{}</span>
79
+ <span class="vi">@url</span> <span class="o">=</span> <span class="n">opts</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">][</span><span class="ss">:site</span><span class="o">]</span> <span class="o">||</span> <span class="no">Dailycred</span><span class="o">::</span><span class="no">Client</span><span class="o">::</span><span class="no">URL</span>
80
+ <span class="k">end</span></pre></div>
81
+ </td>
82
+ </tr>
83
+ <tr id='section-3'>
84
+ <td class=docs>
85
+ <div class="pilwrap">
86
+ <a class="pilcrow" href="#section-3">&#182;</a>
87
+ </div>
88
+ <p>Generates a Dailycred event</p>
89
+
90
+ <ul>
91
+ <li>@param [String] user_id the user&rsquo;s dailycred user id</li>
92
+ <li>@param [String] key the name of the event type</li>
93
+ <li>@param [String] val the value of the event (optional)</li>
94
+ </ul>
95
+ </td>
96
+ <td class=code>
97
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">event</span><span class="p">(</span><span class="n">user_id</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
98
+ <span class="n">opts</span> <span class="o">=</span> <span class="p">{</span>
99
+ <span class="ss">:key</span> <span class="o">=&gt;</span> <span class="n">key</span><span class="p">,</span>
100
+ <span class="ss">:valuestring</span> <span class="o">=&gt;</span> <span class="n">val</span><span class="p">,</span>
101
+ <span class="ss">:user_id</span> <span class="o">=&gt;</span> <span class="n">user_id</span>
102
+ <span class="p">}</span>
103
+ <span class="n">post</span> <span class="s2">&quot;/admin/api/customevent.json&quot;</span><span class="p">,</span> <span class="n">opts</span>
104
+ <span class="k">end</span></pre></div>
105
+ </td>
106
+ </tr>
107
+ <tr id='section-4'>
108
+ <td class=docs>
109
+ <div class="pilwrap">
110
+ <a class="pilcrow" href="#section-4">&#182;</a>
111
+ </div>
112
+ <p>Tag a user in dailycred</p>
113
+
114
+ <ul>
115
+ <li>@param [String] user_id the user&rsquo;s dailycred user id</li>
116
+ <li>@param [String] tag the desired tag to add</li>
117
+ </ul>
118
+ </td>
119
+ <td class=code>
120
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">tag</span><span class="p">(</span><span class="n">user_id</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span>
121
+ <span class="n">opts</span> <span class="o">=</span> <span class="p">{</span>
122
+ <span class="ss">:user_id</span> <span class="o">=&gt;</span> <span class="n">user_id</span><span class="p">,</span>
123
+ <span class="ss">:tag</span> <span class="o">=&gt;</span> <span class="n">tag</span>
124
+ <span class="p">}</span>
125
+ <span class="n">post</span> <span class="s2">&quot;/admin/api/user/tag.json&quot;</span><span class="p">,</span> <span class="n">opts</span>
126
+ <span class="k">end</span></pre></div>
127
+ </td>
128
+ </tr>
129
+ <tr id='section-5'>
130
+ <td class=docs>
131
+ <div class="pilwrap">
132
+ <a class="pilcrow" href="#section-5">&#182;</a>
133
+ </div>
134
+ <p>Untag a user in dailycred
135
+ (see #tag)</p>
136
+ </td>
137
+ <td class=code>
138
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">untag</span><span class="p">(</span><span class="n">user_id</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span>
139
+ <span class="n">opts</span> <span class="o">=</span> <span class="p">{</span>
140
+ <span class="ss">:user_id</span> <span class="o">=&gt;</span> <span class="n">user_id</span><span class="p">,</span>
141
+ <span class="ss">:tag</span> <span class="o">=&gt;</span> <span class="n">tag</span>
142
+ <span class="p">}</span>
143
+ <span class="n">post</span> <span class="s2">&quot;/admin/api/user/untag.json&quot;</span><span class="p">,</span> <span class="n">opts</span>
144
+ <span class="k">end</span></pre></div>
145
+ </td>
146
+ </tr>
147
+ <tr id='section-6'>
148
+ <td class=docs>
149
+ <div class="pilwrap">
150
+ <a class="pilcrow" href="#section-6">&#182;</a>
151
+ </div>
152
+ <p>Send a reset password email</p>
153
+
154
+ <ul>
155
+ <li>@param [string] user the user&rsquo;s email or username</li>
156
+ </ul>
157
+ </td>
158
+ <td class=code>
159
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">passReset</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
160
+ <span class="n">opts</span> <span class="o">=</span> <span class="p">{</span>
161
+ <span class="ss">:user</span> <span class="o">=&gt;</span> <span class="n">user</span>
162
+ <span class="p">}</span>
163
+ <span class="n">post</span> <span class="s2">&quot;/password/api/reset&quot;</span><span class="p">,</span> <span class="n">opts</span>
164
+ <span class="k">end</span></pre></div>
165
+ </td>
166
+ </tr>
167
+ <tr id='section-7'>
168
+ <td class=docs>
169
+ <div class="pilwrap">
170
+ <a class="pilcrow" href="#section-7">&#182;</a>
171
+ </div>
172
+ <p>A wildcard for making any post requests to dailycred.
173
+ client<em>id and client</em>secret are automatically added to the request</p>
174
+
175
+ <ul>
176
+ <li>@param [string] url</li>
177
+ <li>@param [hash] opts</li>
178
+ <li>@param [boolean] secure whether the client_secret should be passed. Defaults to true</li>
179
+ </ul>
180
+
181
+ </td>
182
+ <td class=code>
183
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">opts</span><span class="p">,</span> <span class="n">secure</span><span class="o">=</span><span class="kp">true</span><span class="p">)</span>
184
+ <span class="n">opts</span><span class="o">.</span><span class="n">merge!</span> <span class="n">base_opts</span><span class="p">(</span><span class="n">secure</span><span class="p">)</span>
185
+ <span class="n">response</span> <span class="o">=</span> <span class="n">get_conn</span><span class="o">.</span><span class="n">post</span> <span class="n">url</span><span class="p">,</span> <span class="n">opts</span>
186
+ <span class="k">end</span>
187
+
188
+ <span class="kp">private</span>
189
+
190
+ <span class="k">def</span> <span class="nf">ssl_opts</span>
191
+ <span class="n">opts</span> <span class="o">=</span> <span class="p">{}</span>
192
+ <span class="k">if</span> <span class="vi">@options</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="vi">@options</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">][</span><span class="ss">:ssl</span><span class="o">]</span>
193
+ <span class="n">opts</span><span class="o">[</span><span class="ss">:ssl</span><span class="o">]</span> <span class="o">=</span> <span class="vi">@options</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">][</span><span class="ss">:ssl</span><span class="o">]</span>
194
+ <span class="k">end</span>
195
+ <span class="n">opts</span>
196
+ <span class="k">end</span>
197
+
198
+ <span class="k">def</span> <span class="nf">base_opts</span> <span class="n">secure</span><span class="o">=</span><span class="kp">true</span>
199
+ <span class="n">opts</span> <span class="o">=</span> <span class="p">{</span><span class="ss">:client_id</span> <span class="o">=&gt;</span> <span class="vi">@client_id</span><span class="p">}</span>
200
+ <span class="n">opts</span><span class="o">[</span><span class="ss">:client_secret</span><span class="o">]</span> <span class="o">=</span> <span class="vi">@secret_key</span> <span class="k">if</span> <span class="n">secure</span>
201
+ <span class="n">opts</span>
202
+ <span class="k">end</span>
203
+
204
+ <span class="k">def</span> <span class="nf">get_conn</span>
205
+ <span class="no">Faraday</span><span class="o">::</span><span class="no">Connection</span><span class="o">.</span><span class="n">new</span> <span class="vi">@url</span><span class="p">,</span> <span class="n">ssl_opts</span>
206
+ <span class="k">end</span>
207
+ <span class="k">end</span>
208
+
209
+ <span class="k">end</span></pre></div>
210
+ </td>
211
+ </tr>
212
+ </table>
213
+ </div>
214
+ </body>
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>engine.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../dailycred.html">dailycred.rb</a>
16
+ <a class="source" href="acts_as_dailycred.html">acts_as_dailycred.rb</a>
17
+ <a class="source" href="client.html">client.rb</a>
18
+ <a class="source" href="engine.html">engine.rb</a>
19
+ <a class="source" href="helper.html">helper.rb</a>
20
+ <a class="source" href="middleware.html">middleware.rb</a>
21
+ <a class="source" href="tests_helper.html">tests_helper.rb</a>
22
+ <a class="source" href="user.html">user.rb</a>
23
+ <a class="source" href="../generators/dailycred_generator.html">dailycred_generator.rb</a>
24
+ <a class="source" href="../generators/templates/migration_create_user.html">migration_create_user.rb</a>
25
+ <a class="source" href="../generators/templates/omniauth.html">omniauth.rb</a>
26
+ <a class="source" href="../generators/templates/sessions_controller.html">sessions_controller.rb</a>
27
+ <a class="source" href="../generators/templates/user.html">user.rb</a>
28
+ <a class="source" href="../omniauth/strategies/dailycred.html">dailycred.rb</a>
29
+ </div>
30
+ </div>
31
+ </div>
32
+ <table cellspacing=0 cellpadding=0>
33
+ <thead>
34
+ <tr>
35
+ <th class=docs><h1>engine.rb</h1></th>
36
+ <th class=code></th>
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ <tr id='section-1'>
41
+ <td class=docs>
42
+ <div class="pilwrap">
43
+ <a class="pilcrow" href="#section-1">&#182;</a>
44
+ </div>
45
+
46
+ </td>
47
+ <td class=code>
48
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;rails&#39;</span>
49
+ <span class="k">module</span> <span class="nn">Dailycred</span>
50
+
51
+ <span class="k">class</span> <span class="nc">Engine</span> <span class="o">&lt;</span> <span class="no">Rails</span><span class="o">::</span><span class="no">Engine</span>
52
+
53
+ <span class="n">initializer</span> <span class="s1">&#39;dailycred.setup&#39;</span><span class="p">,</span> <span class="ss">:after</span><span class="o">=&gt;</span><span class="s2">&quot;dailycred&quot;</span> <span class="k">do</span> <span class="o">|</span><span class="n">app</span><span class="o">|</span>
54
+ <span class="n">conf</span> <span class="o">=</span> <span class="no">Rails</span><span class="o">.</span><span class="n">configuration</span><span class="c1"># alias for configuration</span>
55
+ <span class="k">if</span> <span class="n">conf</span><span class="o">.</span><span class="n">respond_to?</span> <span class="s1">&#39;DAILYCRED_CLIENT_ID&#39;</span>
56
+ <span class="nb">id</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">DAILYCRED_CLIENT_ID</span>
57
+ <span class="n">secret</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">DAILYCRED_SECRET_KEY</span></pre></div>
58
+ </td>
59
+ </tr>
60
+ <tr id='section-2'>
61
+ <td class=docs>
62
+ <div class="pilwrap">
63
+ <a class="pilcrow" href="#section-2">&#182;</a>
64
+ </div>
65
+ <p>setup omniauth options, can be overridden. ex:
66
+ Rails.application.DAILYCRED<em>OPTIONS = {
67
+ :client</em>options =&gt; {
68
+ :site =&gt; &lsquo;https://www.dailycred.com&rsquo;,
69
+ :authorize<em>url =&gt; &lsquo;/connect&rsquo;,
70
+ :token</em>url =&gt; &lsquo;/oauth/access_token&rsquo;
71
+ }
72
+ }</p>
73
+
74
+ </td>
75
+ <td class=code>
76
+ <div class='highlight'><pre> <span class="k">if</span> <span class="n">conf</span><span class="o">.</span><span class="n">respond_to?</span> <span class="s1">&#39;DAILYCRED_OPTIONS&#39;</span>
77
+ <span class="n">opts</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">DAILYCRED_OPTIONS</span>
78
+ <span class="n">opts</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">]</span> <span class="o">||=</span> <span class="p">{}</span>
79
+ <span class="n">opts</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">][</span><span class="ss">:ssl</span><span class="o">]</span> <span class="o">=</span> <span class="p">{}</span>
80
+ <span class="k">else</span>
81
+ <span class="n">opts</span> <span class="o">=</span> <span class="p">{</span><span class="ss">:client_options</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:ssl</span> <span class="o">=&gt;</span> <span class="p">{}}}</span>
82
+ <span class="n">conf</span><span class="o">.</span><span class="n">DAILYCRED_OPTIONS</span> <span class="o">=</span> <span class="n">opts</span>
83
+ <span class="k">end</span>
84
+
85
+ <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="s1">&#39;/etc/ssl/certs&#39;</span><span class="p">)</span>
86
+ <span class="n">opts</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">][</span><span class="ss">:ssl</span><span class="o">][</span><span class="ss">:ca_path</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;/etc/ssl/certs&#39;</span>
87
+ <span class="k">end</span>
88
+ <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="s1">&#39;/opt/local/share/curl/curl-ca-bundle.crt&#39;</span><span class="p">)</span>
89
+ <span class="n">opts</span><span class="o">[</span><span class="ss">:client_options</span><span class="o">][</span><span class="ss">:ssl</span><span class="o">][</span><span class="ss">:ca_file</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;/opt/local/share/curl/curl-ca-bundle.crt&#39;</span>
90
+ <span class="k">end</span>
91
+
92
+ <span class="no">Rails</span><span class="o">.</span><span class="n">application</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">middleware</span><span class="o">.</span><span class="n">use</span> <span class="no">OmniAuth</span><span class="o">::</span><span class="no">Builder</span> <span class="k">do</span>
93
+ <span class="n">provider</span> <span class="ss">:dailycred</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">secret</span><span class="p">,</span> <span class="n">opts</span>
94
+ <span class="k">end</span>
95
+
96
+ <span class="no">Rails</span><span class="o">.</span><span class="n">application</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">middleware</span><span class="o">.</span><span class="n">use</span> <span class="s2">&quot;Dailycred::Middleware&quot;</span><span class="p">,</span> <span class="nb">id</span>
97
+
98
+ <span class="no">ActiveSupport</span><span class="o">.</span><span class="n">on_load</span><span class="p">(</span><span class="ss">:action_controller</span><span class="p">)</span> <span class="k">do</span>
99
+ <span class="kp">include</span> <span class="no">Dailycred</span><span class="o">::</span><span class="no">Helpers</span>
100
+ <span class="k">end</span>
101
+ <span class="k">end</span>
102
+ <span class="k">end</span>
103
+
104
+
105
+ <span class="k">end</span>
106
+
107
+ <span class="k">end</span></pre></div>
108
+ </td>
109
+ </tr>
110
+ </table>
111
+ </div>
112
+ </body>