dailycred 0.1.25 → 0.1.26

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ task :default => :spec
7
7
 
8
8
  desc "Run specs"
9
9
  RSpec::Core::RakeTask.new do |t|
10
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
10
+ # t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
11
11
  # Put spec opts in a file named .rspec in root
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ begin
15
15
  require 'rocco/tasks'
16
16
  require 'fileutils'
17
17
  Rocco::make 'docs/'
18
- FileUtils.cp_r "docs/lib/", "/Users/hank/rails/dailycred/public/docs/ruby/"
18
+ FileUtils.cp_r "docs/lib/", "/Users/hank/rails/dailycred/public/docs/ruby/", :verbose => true
19
19
  rescue LoadError
20
20
  warn "#$! -- rocco tasks not loaded."
21
21
  task :rocco
data/dailycred.gemspec CHANGED
@@ -14,5 +14,5 @@ Gem::Specification.new do |gem|
14
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
15
  gem.name = "dailycred"
16
16
  gem.require_paths = ["lib"]
17
- gem.version = "0.1.25"
17
+ gem.version = "0.1.26"
18
18
  end
@@ -0,0 +1,212 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>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="generators/dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="generators/templates/migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="generators/templates/omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="generators/templates/sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="generators/templates/user.html">user.rb</a>
21
+ <a class="source" href="middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>dailycred.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ <tr id='section-1'>
37
+ <td class=docs>
38
+ <div class="pilwrap">
39
+ <a class="pilcrow" href="#section-1">&#182;</a>
40
+ </div>
41
+
42
+ </td>
43
+ <td class=code>
44
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s2">&quot;omniauth-dailycred/version&quot;</span>
45
+ <span class="nb">require</span> <span class="s2">&quot;omniauth/strategies/dailycred&quot;</span>
46
+ <span class="nb">require</span> <span class="s2">&quot;middleware/middleware&quot;</span>
47
+
48
+ <span class="k">class</span> <span class="nc">Dailycred</span>
49
+
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">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></pre></div>
208
+ </td>
209
+ </tr>
210
+ </table>
211
+ </div>
212
+ </body>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>dailycred_generator.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="dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="templates/migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="templates/omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="templates/sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="templates/user.html">user.rb</a>
21
+ <a class="source" href="../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>dailycred_generator.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ </table>
37
+ </div>
38
+ </body>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>migration_create_user.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="../dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="user.html">user.rb</a>
21
+ <a class="source" href="../../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="../../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="../../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>migration_create_user.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ </table>
37
+ </div>
38
+ </body>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>omniauth.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="../dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="user.html">user.rb</a>
21
+ <a class="source" href="../../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="../../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="../../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>omniauth.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ </table>
37
+ </div>
38
+ </body>
@@ -0,0 +1,91 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>sessions_controller.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="../dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="user.html">user.rb</a>
21
+ <a class="source" href="../../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="../../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="../../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>sessions_controller.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ <tr id='section-1'>
37
+ <td class=docs>
38
+ <div class="pilwrap">
39
+ <a class="pilcrow" href="#section-1">&#182;</a>
40
+ </div>
41
+
42
+ </td>
43
+ <td class=code>
44
+ <div class='highlight'><pre><span class="k">class</span> <span class="nc">SessionsController</span> <span class="o">&lt;</span> <span class="no">ApplicationController</span>
45
+ <span class="n">before_filter</span> <span class="ss">:authenticate</span><span class="p">,</span> <span class="ss">:only</span> <span class="o">=&gt;</span> <span class="o">[</span><span class="ss">:destroy</span><span class="o">]</span>
46
+ <span class="n">before_filter</span> <span class="ss">:current_user</span></pre></div>
47
+ </td>
48
+ </tr>
49
+ <tr id='section-2'>
50
+ <td class=docs>
51
+ <div class="pilwrap">
52
+ <a class="pilcrow" href="#section-2">&#182;</a>
53
+ </div>
54
+ <p>Callback Route for OAuth flow</p>
55
+ </td>
56
+ <td class=code>
57
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">create</span>
58
+ <span class="vi">@user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">find_or_create_with_omniauth</span> <span class="n">auth_hash</span>
59
+ <span class="n">session</span><span class="o">[</span><span class="ss">:user_id</span><span class="o">]</span> <span class="o">=</span> <span class="vi">@user</span><span class="o">.</span><span class="n">id</span>
60
+ <span class="n">redirect_to</span> <span class="s2">&quot;/auth&quot;</span>
61
+ <span class="k">end</span></pre></div>
62
+ </td>
63
+ </tr>
64
+ <tr id='section-3'>
65
+ <td class=docs>
66
+ <div class="pilwrap">
67
+ <a class="pilcrow" href="#section-3">&#182;</a>
68
+ </div>
69
+ <p>GET /logout</p>
70
+
71
+ </td>
72
+ <td class=code>
73
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">destroy</span>
74
+ <span class="n">session</span><span class="o">[</span><span class="ss">:user_id</span><span class="o">]</span> <span class="o">=</span> <span class="kp">nil</span>
75
+ <span class="n">redirect_to</span> <span class="n">auth_path</span>
76
+ <span class="k">end</span>
77
+
78
+ <span class="k">def</span> <span class="nf">info</span>
79
+ <span class="k">end</span>
80
+
81
+ <span class="kp">private</span>
82
+
83
+ <span class="k">def</span> <span class="nf">auth_hash</span>
84
+ <span class="n">request</span><span class="o">.</span><span class="n">env</span><span class="o">[</span><span class="s1">&#39;omniauth.auth&#39;</span><span class="o">]</span>
85
+ <span class="k">end</span>
86
+ <span class="k">end</span></pre></div>
87
+ </td>
88
+ </tr>
89
+ </table>
90
+ </div>
91
+ </body>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>user.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="../dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="user.html">user.rb</a>
21
+ <a class="source" href="../../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="../../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="../../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>user.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ </table>
37
+ </div>
38
+ </body>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>middleware.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="../generators/dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="../generators/templates/migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="../generators/templates/omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="../generators/templates/sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="../generators/templates/user.html">user.rb</a>
21
+ <a class="source" href="middleware.html">middleware.rb</a>
22
+ <a class="source" href="../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>middleware.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ </table>
37
+ </div>
38
+ </body>
@@ -0,0 +1,194 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>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="../../generators/dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="../../generators/templates/migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="../../generators/templates/omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="../../generators/templates/sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="../../generators/templates/user.html">user.rb</a>
21
+ <a class="source" href="../../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="../../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>dailycred.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ <tr id='section-1'>
37
+ <td class=docs>
38
+ <div class="pilwrap">
39
+ <a class="pilcrow" href="#section-1">&#182;</a>
40
+ </div>
41
+
42
+ </td>
43
+ <td class=code>
44
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;omniauth-oauth2&#39;</span>
45
+ <span class="nb">require</span> <span class="s1">&#39;faraday&#39;</span>
46
+ <span class="nb">require</span> <span class="s1">&#39;net/https&#39;</span>
47
+ <span class="nb">require</span> <span class="s1">&#39;json&#39;</span>
48
+ <span class="nb">require</span> <span class="s1">&#39;pp&#39;</span></pre></div>
49
+ </td>
50
+ </tr>
51
+ <tr id='section-The_Dailycred_Omniauth_Strategy'>
52
+ <td class=docs>
53
+ <div class="pilwrap">
54
+ <a class="pilcrow" href="#section-The_Dailycred_Omniauth_Strategy">&#182;</a>
55
+ </div>
56
+ <h1>The Dailycred Omniauth Strategy</h1>
57
+ </td>
58
+ <td class=code>
59
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">OmniAuth</span>
60
+ <span class="k">module</span> <span class="nn">Strategies</span>
61
+ <span class="k">class</span> <span class="nc">Dailycred</span> <span class="o">&lt;</span> <span class="no">OmniAuth</span><span class="o">::</span><span class="no">Strategies</span><span class="o">::</span><span class="no">OAuth2</span></pre></div>
62
+ </td>
63
+ </tr>
64
+ <tr id='section-3'>
65
+ <td class=docs>
66
+ <div class="pilwrap">
67
+ <a class="pilcrow" href="#section-3">&#182;</a>
68
+ </div>
69
+ <p>default options</p>
70
+ </td>
71
+ <td class=code>
72
+ <div class='highlight'><pre> <span class="n">option</span> <span class="ss">:client_options</span><span class="p">,</span> <span class="p">{</span>
73
+ <span class="ss">:site</span> <span class="o">=&gt;</span> <span class="s2">&quot;https://www.dailycred.com&quot;</span><span class="p">,</span>
74
+ <span class="ss">:authorize_url</span> <span class="o">=&gt;</span> <span class="s1">&#39;/connect&#39;</span><span class="p">,</span>
75
+ <span class="ss">:token_url</span> <span class="o">=&gt;</span> <span class="s1">&#39;/oauth/access_token&#39;</span>
76
+ <span class="p">}</span></pre></div>
77
+ </td>
78
+ </tr>
79
+ <tr id='section-4'>
80
+ <td class=docs>
81
+ <div class="pilwrap">
82
+ <a class="pilcrow" href="#section-4">&#182;</a>
83
+ </div>
84
+ <p>parameters to expect and return from dailycred responses</p>
85
+ </td>
86
+ <td class=code>
87
+ <div class='highlight'><pre> <span class="no">ATTRIBUTES</span> <span class="o">=</span> <span class="o">[</span><span class="s2">&quot;email&quot;</span><span class="p">,</span> <span class="s2">&quot;username&quot;</span><span class="p">,</span> <span class="s2">&quot;created&quot;</span><span class="p">,</span> <span class="s2">&quot;verified&quot;</span><span class="p">,</span> <span class="s2">&quot;admin&quot;</span><span class="p">,</span> <span class="s2">&quot;referred_by&quot;</span><span class="p">,</span> <span class="s2">&quot;tags&quot;</span><span class="p">,</span> <span class="s2">&quot;referred&quot;</span><span class="o">]</span></pre></div>
88
+ </td>
89
+ </tr>
90
+ <tr id='section-5'>
91
+ <td class=docs>
92
+ <div class="pilwrap">
93
+ <a class="pilcrow" href="#section-5">&#182;</a>
94
+ </div>
95
+ <p>allows parameters to be passed through</p>
96
+ </td>
97
+ <td class=code>
98
+ <div class='highlight'><pre> <span class="no">AUTH_PARAMS</span> <span class="o">=</span> <span class="o">[</span><span class="s2">&quot;action&quot;</span><span class="p">,</span><span class="s2">&quot;identity_provider&quot;</span><span class="p">,</span><span class="s2">&quot;referrer&quot;</span><span class="o">]</span>
99
+
100
+ <span class="n">option</span> <span class="ss">:authorize_options</span><span class="p">,</span> <span class="no">OmniAuth</span><span class="o">::</span><span class="no">Strategies</span><span class="o">::</span><span class="no">Dailycred</span><span class="o">::</span><span class="no">AUTH_PARAMS</span>
101
+
102
+ <span class="n">uid</span> <span class="p">{</span> <span class="n">user</span><span class="o">[</span><span class="s1">&#39;id&#39;</span><span class="o">]</span> <span class="p">}</span>
103
+
104
+ <span class="n">info</span> <span class="k">do</span>
105
+ <span class="n">user</span>
106
+ <span class="k">end</span>
107
+
108
+ <span class="k">alias</span> <span class="ss">:old_request_phase</span> <span class="ss">:request_phase</span>
109
+
110
+
111
+ <span class="k">def</span> <span class="nf">authorize_params</span>
112
+ <span class="k">super</span><span class="o">.</span><span class="n">tap</span> <span class="k">do</span> <span class="o">|</span><span class="n">params</span><span class="o">|</span>
113
+ <span class="n">params</span><span class="o">[</span><span class="ss">:state</span><span class="o">]</span> <span class="o">||=</span> <span class="p">{}</span>
114
+ <span class="k">end</span>
115
+ <span class="k">end</span></pre></div>
116
+ </td>
117
+ </tr>
118
+ <tr id='section-6'>
119
+ <td class=docs>
120
+ <div class="pilwrap">
121
+ <a class="pilcrow" href="#section-6">&#182;</a>
122
+ </div>
123
+ <p>this step allows auth_params to be added to the url</p>
124
+ </td>
125
+ <td class=code>
126
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">request_phase</span>
127
+ <span class="no">OmniAuth</span><span class="o">::</span><span class="no">Strategies</span><span class="o">::</span><span class="no">Dailycred</span><span class="o">::</span><span class="no">AUTH_PARAMS</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">param</span><span class="o">|</span>
128
+ <span class="n">val</span> <span class="o">=</span> <span class="n">session</span><span class="o">[</span><span class="s1">&#39;omniauth.params&#39;</span><span class="o">][</span><span class="n">param</span><span class="o">]</span>
129
+ <span class="k">if</span> <span class="n">val</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">val</span><span class="o">.</span><span class="n">empty?</span>
130
+ <span class="n">options</span><span class="o">[</span><span class="ss">:authorize_params</span><span class="o">]</span> <span class="o">||=</span> <span class="p">{}</span>
131
+ <span class="n">options</span><span class="o">[</span><span class="ss">:authorize_params</span><span class="o">].</span><span class="n">merge!</span><span class="p">(</span><span class="n">param</span> <span class="o">=&gt;</span> <span class="n">val</span><span class="p">)</span>
132
+ <span class="k">end</span>
133
+ <span class="k">end</span>
134
+ <span class="n">old_request_phase</span>
135
+ <span class="k">end</span>
136
+
137
+ <span class="kp">private</span></pre></div>
138
+ </td>
139
+ </tr>
140
+ <tr id='section-7'>
141
+ <td class=docs>
142
+ <div class="pilwrap">
143
+ <a class="pilcrow" href="#section-7">&#182;</a>
144
+ </div>
145
+ <p>This is the phase where the gem calls me.json, which returns information about the user</p>
146
+ </td>
147
+ <td class=code>
148
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">user</span>
149
+ <span class="k">return</span> <span class="vi">@duser</span> <span class="k">if</span> <span class="o">!</span><span class="vi">@duser</span><span class="o">.</span><span class="n">nil?</span>
150
+ <span class="n">connection</span> <span class="o">=</span> <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="n">options</span><span class="o">.</span><span class="n">client_options</span><span class="o">[</span><span class="ss">:site</span><span class="o">]</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">client_options</span><span class="o">[</span><span class="ss">:ssl</span><span class="o">]</span>
151
+ <span class="n">response</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;/graph/me.json?access_token=</span><span class="si">#{</span><span class="n">access_token</span><span class="o">.</span><span class="n">token</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
152
+ <span class="n">json</span> <span class="o">=</span> <span class="no">JSON</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">body</span><span class="p">)</span></pre></div>
153
+ </td>
154
+ </tr>
155
+ <tr id='section-8'>
156
+ <td class=docs>
157
+ <div class="pilwrap">
158
+ <a class="pilcrow" href="#section-8">&#182;</a>
159
+ </div>
160
+ <p>pp json</p>
161
+ </td>
162
+ <td class=code>
163
+ <div class='highlight'><pre> <span class="vi">@duser</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;token&#39;</span> <span class="o">=&gt;</span> <span class="n">access_token</span><span class="o">.</span><span class="n">token</span><span class="p">}</span>
164
+ <span class="vi">@duser</span><span class="o">[</span><span class="s1">&#39;provider&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="s1">&#39;dailycred&#39;</span>
165
+ <span class="vi">@duser</span><span class="o">[</span><span class="s1">&#39;uid&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="n">json</span><span class="o">[</span><span class="s1">&#39;id&#39;</span><span class="o">]</span> <span class="o">||</span> <span class="n">json</span><span class="o">[</span><span class="s1">&#39;user_id&#39;</span><span class="o">]</span>
166
+ <span class="no">OmniAuth</span><span class="o">::</span><span class="no">Strategies</span><span class="o">::</span><span class="no">Dailycred</span><span class="o">::</span><span class="no">ATTRIBUTES</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="kp">attr</span><span class="o">|</span>
167
+ <span class="vi">@duser</span><span class="o">[</span><span class="kp">attr</span><span class="o">]</span> <span class="o">=</span> <span class="n">json</span><span class="o">[</span><span class="kp">attr</span><span class="o">]</span>
168
+ <span class="k">end</span>
169
+ <span class="k">if</span> <span class="o">!</span><span class="n">json</span><span class="o">[</span><span class="s2">&quot;FACEBOOK&quot;</span><span class="o">].</span><span class="n">nil?</span>
170
+ <span class="vi">@duser</span><span class="o">[</span><span class="s1">&#39;facebook&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="n">json</span><span class="o">[</span><span class="s2">&quot;FACEBOOK&quot;</span><span class="o">][</span><span class="s2">&quot;members&quot;</span><span class="o">]</span>
171
+ <span class="vi">@duser</span><span class="o">[</span><span class="s1">&#39;facebook&#39;</span><span class="o">][</span><span class="s1">&#39;access_token&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="n">json</span><span class="o">[</span><span class="s2">&quot;FACEBOOK&quot;</span><span class="o">][</span><span class="s1">&#39;access_token&#39;</span><span class="o">]</span>
172
+ <span class="k">end</span></pre></div>
173
+ </td>
174
+ </tr>
175
+ <tr id='section-9'>
176
+ <td class=docs>
177
+ <div class="pilwrap">
178
+ <a class="pilcrow" href="#section-9">&#182;</a>
179
+ </div>
180
+ <p>pp @duser</p>
181
+
182
+ </td>
183
+ <td class=code>
184
+ <div class='highlight'><pre> <span class="vi">@duser</span>
185
+ <span class="k">end</span>
186
+
187
+ <span class="k">end</span>
188
+ <span class="k">end</span>
189
+ <span class="k">end</span></pre></div>
190
+ </td>
191
+ </tr>
192
+ </table>
193
+ </div>
194
+ </body>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>version.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="../generators/dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="../generators/templates/migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="../generators/templates/omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="../generators/templates/sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="../generators/templates/user.html">user.rb</a>
21
+ <a class="source" href="../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="version.html">version.rb</a>
23
+ <a class="source" href="../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="../user/user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>version.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ </table>
37
+ </div>
38
+ </body>
@@ -0,0 +1,129 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>user.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="../generators/dailycred_generator.html">dailycred_generator.rb</a>
17
+ <a class="source" href="../generators/templates/migration_create_user.html">migration_create_user.rb</a>
18
+ <a class="source" href="../generators/templates/omniauth.html">omniauth.rb</a>
19
+ <a class="source" href="../generators/templates/sessions_controller.html">sessions_controller.rb</a>
20
+ <a class="source" href="../generators/templates/user.html">user.rb</a>
21
+ <a class="source" href="../middleware/middleware.html">middleware.rb</a>
22
+ <a class="source" href="../omniauth-dailycred/version.html">version.rb</a>
23
+ <a class="source" href="../omniauth/strategies/dailycred.html">dailycred.rb</a>
24
+ <a class="source" href="user.html">user.rb</a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <table cellspacing=0 cellpadding=0>
29
+ <thead>
30
+ <tr>
31
+ <th class=docs><h1>user.rb</h1></th>
32
+ <th class=code></th>
33
+ </tr>
34
+ </thead>
35
+ <tbody>
36
+ <tr id='section-1'>
37
+ <td class=docs>
38
+ <div class="pilwrap">
39
+ <a class="pilcrow" href="#section-1">&#182;</a>
40
+ </div>
41
+
42
+ </td>
43
+ <td class=code>
44
+ <div class='highlight'><pre><span class="k">class</span> <span class="nc">Dailycred</span>
45
+ <span class="k">class</span> <span class="nc">Auth</span>
46
+ <span class="kp">include</span> <span class="no">ActiveModel</span><span class="o">::</span><span class="no">Validations</span>
47
+ <span class="kp">include</span> <span class="no">ActiveModel</span><span class="o">::</span><span class="no">Serialization</span>
48
+
49
+ <span class="n">validates_presence_of</span> <span class="ss">:email</span><span class="p">,</span> <span class="ss">:pass</span>
50
+
51
+ <span class="kp">attr_accessor</span> <span class="ss">:client</span><span class="p">,</span> <span class="ss">:email</span><span class="p">,</span> <span class="ss">:pass</span><span class="p">,</span> <span class="ss">:authorized</span>
52
+
53
+ <span class="k">def</span> <span class="nf">initialize</span> <span class="n">client</span><span class="p">,</span> <span class="n">user</span> <span class="o">=</span> <span class="p">{}</span>
54
+ <span class="nb">self</span><span class="o">.</span><span class="n">client</span> <span class="o">=</span> <span class="n">client</span>
55
+ <span class="nb">self</span><span class="o">.</span><span class="n">authorized</span> <span class="o">=</span> <span class="kp">false</span>
56
+ <span class="n">user</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">k</span><span class="p">,</span><span class="n">v</span><span class="o">|</span>
57
+ <span class="nb">self</span><span class="o">[</span><span class="n">k</span><span class="o">]</span> <span class="o">=</span> <span class="n">v</span> <span class="k">if</span> <span class="nb">self</span><span class="o">.</span><span class="n">respond_to</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
58
+ <span class="k">end</span>
59
+ <span class="k">end</span>
60
+
61
+ <span class="k">def</span> <span class="nf">login</span>
62
+ <span class="k">if</span> <span class="o">!</span><span class="nb">self</span><span class="o">.</span><span class="n">valid?</span></pre></div>
63
+ </td>
64
+ </tr>
65
+ <tr id='section-2'>
66
+ <td class=docs>
67
+ <div class="pilwrap">
68
+ <a class="pilcrow" href="#section-2">&#182;</a>
69
+ </div>
70
+ <p>it didn&rsquo;t work already, return false</p>
71
+ </td>
72
+ <td class=code>
73
+ <div class='highlight'><pre> <span class="k">return</span> <span class="kp">false</span>
74
+ <span class="k">end</span>
75
+
76
+ <span class="n">response</span> <span class="o">=</span> <span class="no">JSON</span><span class="o">.</span><span class="n">parse</span> <span class="n">client</span><span class="o">.</span><span class="n">login</span><span class="p">(</span><span class="nb">self</span><span class="o">.</span><span class="n">to_hash</span><span class="p">)</span>
77
+ <span class="n">err_parser</span> <span class="n">response</span>
78
+
79
+ <span class="k">return</span> <span class="kp">false</span> <span class="k">if</span> <span class="o">!</span><span class="nb">self</span><span class="o">.</span><span class="n">valid?</span>
80
+ <span class="kp">true</span>
81
+ <span class="k">end</span>
82
+
83
+ <span class="k">def</span> <span class="nf">to_hash</span>
84
+ <span class="p">{</span>
85
+ <span class="ss">:email</span> <span class="o">=&gt;</span> <span class="nb">self</span><span class="o">.</span><span class="n">email</span><span class="p">,</span>
86
+ <span class="ss">:pass</span> <span class="o">=&gt;</span> <span class="nb">self</span><span class="o">.</span><span class="n">pass</span>
87
+ <span class="p">}</span>
88
+ <span class="k">end</span>
89
+
90
+ <span class="kp">private</span></pre></div>
91
+ </td>
92
+ </tr>
93
+ <tr id='section-3'>
94
+ <td class=docs>
95
+ <div class="pilwrap">
96
+ <a class="pilcrow" href="#section-3">&#182;</a>
97
+ </div>
98
+ <p>response is a hash, which is
99
+ a json-parsed http response body</p>
100
+
101
+ </td>
102
+ <td class=code>
103
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">err_parser</span> <span class="n">response</span>
104
+ <span class="k">if</span> <span class="o">!</span><span class="n">response</span><span class="o">[</span><span class="s2">&quot;worked&quot;</span><span class="o">]</span>
105
+ <span class="nb">self</span><span class="o">.</span><span class="n">authorized</span> <span class="o">=</span> <span class="kp">false</span>
106
+ <span class="n">response</span><span class="o">[</span><span class="s2">&quot;errors&quot;</span><span class="o">].</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">err</span><span class="o">|</span>
107
+ <span class="n">attrib</span> <span class="o">=</span> <span class="n">err</span><span class="o">[</span><span class="s2">&quot;attribute&quot;</span><span class="o">]</span>
108
+ <span class="n">message</span> <span class="o">=</span> <span class="n">err</span><span class="o">[</span><span class="s2">&quot;message&quot;</span><span class="o">]</span>
109
+ <span class="k">if</span> <span class="n">attrib</span> <span class="o">==</span> <span class="s2">&quot;form&quot;</span>
110
+ <span class="nb">self</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">add_to_base</span> <span class="n">message</span>
111
+ <span class="k">else</span>
112
+ <span class="k">if</span> <span class="n">attrib</span> <span class="o">==</span> <span class="s2">&quot;user&quot;</span>
113
+ <span class="nb">self</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">add</span> <span class="ss">:email</span><span class="p">,</span> <span class="n">message</span>
114
+ <span class="k">elsif</span> <span class="nb">self</span><span class="o">.</span><span class="n">respond_to</span> <span class="n">attrib</span>
115
+ <span class="nb">self</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">add</span> <span class="n">attrib</span><span class="p">,</span> <span class="n">message</span>
116
+ <span class="k">end</span>
117
+ <span class="k">end</span>
118
+ <span class="k">end</span>
119
+ <span class="k">end</span>
120
+ <span class="k">end</span>
121
+
122
+ <span class="k">end</span>
123
+
124
+ <span class="k">end</span></pre></div>
125
+ </td>
126
+ </tr>
127
+ </table>
128
+ </div>
129
+ </body>
data/lib/dailycred.rb CHANGED
@@ -62,8 +62,24 @@ class Dailycred
62
62
  post "/admin/api/user/untag.json", opts
63
63
  end
64
64
 
65
- def post(url, opts)
66
- opts.merge! base_opts
65
+ # Send a reset password email
66
+ #
67
+ # - @param [string] user the user's email or username
68
+ def passReset(user)
69
+ opts = {
70
+ :user => user
71
+ }
72
+ post "/password/api/reset", opts
73
+ end
74
+
75
+ # A wildcard for making any post requests to dailycred.
76
+ # client_id and client_secret are automatically added to the request
77
+ #
78
+ # - @param [string] url
79
+ # - @param [hash] opts
80
+ # - @param [boolean] secure whether the client_secret should be passed. Defaults to true
81
+ def post(url, opts, secure=true)
82
+ opts.merge! base_opts(secure)
67
83
  response = get_conn.post url, opts
68
84
  end
69
85
 
@@ -77,11 +93,10 @@ class Dailycred
77
93
  opts
78
94
  end
79
95
 
80
- def base_opts
81
- {
82
- :client_id => @client_id,
83
- :client_secret => @secret_key
84
- }
96
+ def base_opts secure=true
97
+ opts = {:client_id => @client_id}
98
+ opts[:client_secret] = @secret_key if secure
99
+ opts
85
100
  end
86
101
 
87
102
  def get_conn
@@ -10,6 +10,7 @@ class DailycredGenerator < Rails::Generators::Base
10
10
  match '/auth/:provider/callback' => 'sessions#create'
11
11
  match "/logout" => "sessions#destroy", :as => :logout
12
12
  match "/auth" => "sessions#info", :as => :auth
13
+ match "/auth/dailycred"
13
14
  EOS
14
15
 
15
16
  APP_CONTROLLER_LINES =<<-EOS
@@ -33,16 +34,6 @@ class DailycredGenerator < Rails::Generators::Base
33
34
  redirect_to auth_path unless current_user
34
35
  end
35
36
 
36
- # link to sign up
37
- def signup_path
38
- "/auth/dailycred"
39
- end
40
-
41
- # link to login
42
- def login_path
43
- "/auth/dailycred?action=signin"
44
- end
45
-
46
37
  # helper method for getting an instance of dailycred
47
38
  # example:
48
39
  # dailycred.tagUser "user_id", "tag"
@@ -54,6 +45,13 @@ class DailycredGenerator < Rails::Generators::Base
54
45
  end
55
46
  EOS
56
47
 
48
+ APP_HELPER_LINES = <<-EOS
49
+ def connect_path(provider)
50
+ url = "/auth/dailycred?identity_provider=#{provider.to_s}"
51
+ url += "&referrer=#{request.protocol}#{request.host_with_port}#{request.fullpath}"
52
+ end
53
+ EOS
54
+
57
55
  def install
58
56
  dailycred_ascii =<<-EOS
59
57
  *****
@@ -75,6 +73,8 @@ class DailycredGenerator < Rails::Generators::Base
75
73
  copy_file "sessions_controller.rb", "app/controllers/sessions_controller.rb"
76
74
  # application controller
77
75
  inject_into_class "app/controllers/application_controller.rb", ApplicationController, APP_CONTROLLER_LINES
76
+ # application helper
77
+ inject_into_class "app/helpers/application_helper.rb", ApplicationController, APP_HELPER_LINES
78
78
  # add user_model
79
79
  copy_file "user.rb", "app/models/user.rb"
80
80
  # session_controller
@@ -20,7 +20,7 @@ module OmniAuth
20
20
  ATTRIBUTES = ["email", "username", "created", "verified", "admin", "referred_by", "tags", "referred"]
21
21
 
22
22
  # allows parameters to be passed through
23
- AUTH_PARAMS = ["action"]
23
+ AUTH_PARAMS = ["action","identity_provider","referrer"]
24
24
 
25
25
  option :authorize_options, OmniAuth::Strategies::Dailycred::AUTH_PARAMS
26
26
 
@@ -59,7 +59,7 @@ module OmniAuth
59
59
  connection = Faraday::Connection.new options.client_options[:site], options.client_options[:ssl]
60
60
  response = connection.get("/graph/me.json?access_token=#{access_token.token}")
61
61
  json = JSON.parse(response.body)
62
- pp json
62
+ # pp json
63
63
  @duser = {'token' => access_token.token}
64
64
  @duser['provider'] = 'dailycred'
65
65
  @duser['uid'] = json['id'] || json['user_id']
@@ -68,8 +68,9 @@ module OmniAuth
68
68
  end
69
69
  if !json["FACEBOOK"].nil?
70
70
  @duser['facebook'] = json["FACEBOOK"]["members"]
71
+ @duser['facebook']['access_token'] = json["FACEBOOK"]['access_token']
71
72
  end
72
- pp @duser
73
+ # pp @duser
73
74
 
74
75
  @duser
75
76
  end
data/spec/helper_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
- $:.unshift File.expand_path('..', __FILE__)
2
- $:.unshift File.expand_path('../../lib', __FILE__)
1
+ # $:.unshift File.expand_path('..', __FILE__)
2
+ # $:.unshift File.expand_path('../../lib', __FILE__)
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
5
  require 'rspec'
@@ -1,4 +1,6 @@
1
- require 'helper_spec'
1
+ # require 'helper_spec'
2
+ require 'omniauth'
3
+ require 'dailycred'
2
4
  describe OmniAuth::Strategies::Dailycred do
3
5
  subject do
4
6
  OmniAuth::Strategies::Dailycred.new(nil, @options || {})
@@ -35,24 +35,37 @@ describe Dailycred do
35
35
  end
36
36
 
37
37
  it "tags a user" do
38
- response = @dc.tag(@user_id, "loser")
39
- json = JSON.parse response.body
38
+ json = json_response @dc.tag(@user_id, "loser")
40
39
  json["worked"].should == true
41
40
  user = json["user"]
42
41
  # user["tags"].should include('loser') #will work in next push
43
42
  end
44
43
 
45
44
  it "untags a user" do
46
- response = @dc.untag(@user_id, "loser")
47
- json = JSON.parse response.body
45
+ json = json_response @dc.untag(@user_id, "loser")
48
46
  json["worked"].should == true
49
47
  user = json["user"]
50
48
  # user["tags"].should == nil #will work in next push
51
49
  end
52
50
 
53
51
  it "fires an event" do
54
- response = @dc.event(@user_id, "became a loser")
55
- json = JSON.parse response.body
52
+ json = json_response @dc.event(@user_id, "became a loser")
56
53
  json["worked"].should == true
57
54
  end
55
+
56
+ it "resets a password" do
57
+ json = json_response @dc.passReset("useruseruseruser@gmail.com")
58
+ json["worked"].should == true
59
+ end
60
+
61
+ # it "changes a password" do
62
+ # json = json_response @dc.changePass("0c19c355-2a71-4c8e-805e-f7a6087ea84c", "wrongPass", "newPass")
63
+ # json["worked"].should == false
64
+ # json["message"].should != nil
65
+ # end
66
+
67
+
68
+ def json_response response
69
+ JSON.parse response.body
70
+ end
58
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dailycred
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.26
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
@@ -56,6 +56,16 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - dailycred.gemspec
59
+ - docs/lib/dailycred.html
60
+ - docs/lib/generators/dailycred_generator.html
61
+ - docs/lib/generators/templates/migration_create_user.html
62
+ - docs/lib/generators/templates/omniauth.html
63
+ - docs/lib/generators/templates/sessions_controller.html
64
+ - docs/lib/generators/templates/user.html
65
+ - docs/lib/middleware/middleware.html
66
+ - docs/lib/omniauth-dailycred/version.html
67
+ - docs/lib/omniauth/strategies/dailycred.html
68
+ - docs/lib/user/user.html
59
69
  - lib/dailycred.rb
60
70
  - lib/generators/USAGE
61
71
  - lib/generators/dailycred_generator.rb