dailycred 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +14 -2
  3. data/Guardfile +15 -0
  4. data/README.md +159 -33
  5. data/Rakefile +30 -0
  6. data/app/controllers/sessions_controller.rb +31 -0
  7. data/app/views/sessions/info.html.erb +13 -0
  8. data/config/routes.rb +7 -0
  9. data/dailycred.gemspec +4 -3
  10. data/docs/lib/dailycred/acts_as_dailycred.html +42 -0
  11. data/docs/lib/dailycred/client.html +214 -0
  12. data/docs/lib/dailycred/engine.html +112 -0
  13. data/docs/lib/dailycred/helper.html +125 -0
  14. data/docs/lib/dailycred/middleware.html +42 -0
  15. data/docs/lib/dailycred/tests_helper.html +42 -0
  16. data/docs/lib/dailycred/user.html +133 -0
  17. data/docs/lib/dailycred.html +42 -0
  18. data/docs/lib/generators/dailycred_generator.html +42 -0
  19. data/docs/lib/generators/templates/migration_create_user.html +39 -0
  20. data/docs/lib/generators/templates/omniauth.html +71 -0
  21. data/docs/lib/generators/templates/sessions_controller.html +96 -0
  22. data/docs/lib/generators/templates/user.html +42 -0
  23. data/docs/lib/middleware/middleware.html +38 -0
  24. data/docs/lib/omniauth/strategies/dailycred.html +199 -0
  25. data/docs/lib/omniauth-dailycred/version.html +38 -0
  26. data/docs/lib/user/user.html +129 -0
  27. data/dummy/.gitignore +15 -0
  28. data/dummy/Gemfile +55 -0
  29. data/dummy/Guardfile +31 -0
  30. data/dummy/README.rdoc +261 -0
  31. data/dummy/Rakefile +7 -0
  32. data/dummy/app/assets/images/rails.png +0 -0
  33. data/dummy/app/assets/javascripts/application.js +15 -0
  34. data/dummy/app/assets/javascripts/posts.js.coffee +3 -0
  35. data/dummy/app/assets/stylesheets/application.css +13 -0
  36. data/dummy/app/assets/stylesheets/posts.css.scss +3 -0
  37. data/dummy/app/assets/stylesheets/scaffolds.css.scss +69 -0
  38. data/dummy/app/controllers/application_controller.rb +16 -0
  39. data/dummy/app/controllers/posts_controller.rb +85 -0
  40. data/dummy/app/helpers/application_helper.rb +2 -0
  41. data/dummy/app/helpers/posts_helper.rb +2 -0
  42. data/dummy/app/mailers/.gitkeep +0 -0
  43. data/dummy/app/models/.gitkeep +0 -0
  44. data/dummy/app/models/post.rb +3 -0
  45. data/dummy/app/models/user.rb +3 -0
  46. data/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/dummy/app/views/posts/_form.html.erb +21 -0
  48. data/dummy/app/views/posts/edit.html.erb +6 -0
  49. data/dummy/app/views/posts/index.html.erb +23 -0
  50. data/dummy/app/views/posts/new.html.erb +5 -0
  51. data/dummy/app/views/posts/show.html.erb +10 -0
  52. data/dummy/config/application.rb +62 -0
  53. data/dummy/config/boot.rb +6 -0
  54. data/dummy/config/database.yml +25 -0
  55. data/dummy/config/environment.rb +5 -0
  56. data/dummy/config/environments/development.rb +37 -0
  57. data/dummy/config/environments/production.rb +67 -0
  58. data/dummy/config/environments/test.rb +37 -0
  59. data/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/dummy/config/initializers/inflections.rb +15 -0
  61. data/dummy/config/initializers/mime_types.rb +5 -0
  62. data/dummy/config/initializers/omniauth.rb +13 -0
  63. data/dummy/config/initializers/secret_token.rb +7 -0
  64. data/dummy/config/initializers/session_store.rb +8 -0
  65. data/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/dummy/config/locales/en.yml +5 -0
  67. data/dummy/config/routes.rb +61 -0
  68. data/dummy/config.ru +4 -0
  69. data/dummy/db/migrate/20120925172903_create_users.rb +68 -0
  70. data/dummy/db/migrate/20120926012555_create_posts.rb +9 -0
  71. data/dummy/db/migrate/20121002192037_update_users_2.rb +70 -0
  72. data/dummy/db/schema.rb +45 -0
  73. data/dummy/db/seeds.rb +7 -0
  74. data/dummy/lib/assets/.gitkeep +0 -0
  75. data/dummy/lib/tasks/.gitkeep +0 -0
  76. data/dummy/log/.gitkeep +0 -0
  77. data/dummy/public/404.html +26 -0
  78. data/dummy/public/422.html +26 -0
  79. data/dummy/public/500.html +25 -0
  80. data/dummy/public/favicon.ico +0 -0
  81. data/dummy/public/index.html +241 -0
  82. data/dummy/public/robots.txt +5 -0
  83. data/dummy/script/rails +6 -0
  84. data/dummy/test/fixtures/.gitkeep +0 -0
  85. data/dummy/test/fixtures/posts.yml +7 -0
  86. data/dummy/test/fixtures/users.yml +3 -0
  87. data/dummy/test/functional/.gitkeep +0 -0
  88. data/dummy/test/functional/posts_controller_test.rb +51 -0
  89. data/dummy/test/integration/.gitkeep +0 -0
  90. data/dummy/test/performance/browsing_test.rb +12 -0
  91. data/dummy/test/test_helper.rb +62 -0
  92. data/dummy/test/unit/.gitkeep +0 -0
  93. data/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
  94. data/dummy/test/unit/post_test.rb +7 -0
  95. data/dummy/test/unit/user_test.rb +77 -0
  96. data/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  97. data/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  98. data/dummy/vendor/plugins/.gitkeep +0 -0
  99. data/lib/dailycred/acts_as_dailycred.rb +87 -0
  100. data/lib/dailycred/client.rb +105 -0
  101. data/lib/dailycred/engine.rb +52 -0
  102. data/lib/dailycred/helper.rb +60 -0
  103. data/lib/{middleware → dailycred}/middleware.rb +25 -15
  104. data/lib/dailycred/tests_helper.rb +5 -0
  105. data/lib/dailycred/user.rb +63 -0
  106. data/lib/dailycred.rb +1 -79
  107. data/lib/generators/dailycred_generator.rb +94 -44
  108. data/lib/generators/templates/info.html.erb +1 -1
  109. data/lib/generators/templates/login.html.erb +13 -0
  110. data/lib/generators/templates/migration_create_user.rb +60 -10
  111. data/lib/generators/templates/omniauth.rb +6 -17
  112. data/lib/generators/templates/sessions_controller.rb +8 -2
  113. data/lib/generators/templates/user.rb +1 -23
  114. data/lib/omniauth/strategies/dailycred.rb +37 -20
  115. data/script/download_info.rb +11 -0
  116. data/spec/{spec_helper.rb → helper_spec.rb} +4 -2
  117. data/spec/omniauth/strategies/dailycred_spec.rb +52 -10
  118. data/spec/support/dailycred_spec.rb +72 -0
  119. data/spec/support/shared_examples.rb +40 -0
  120. data/test/generator_test.rb +85 -0
  121. data/test/test_helper.rb +6 -0
  122. metadata +116 -8
  123. data/lib/omniauth-dailycred/version.rb +0 -5
@@ -0,0 +1,241 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Ruby on Rails: Welcome aboard</title>
5
+ <style type="text/css" media="screen">
6
+ body {
7
+ margin: 0;
8
+ margin-bottom: 25px;
9
+ padding: 0;
10
+ background-color: #f0f0f0;
11
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
12
+ font-size: 13px;
13
+ color: #333;
14
+ }
15
+
16
+ h1 {
17
+ font-size: 28px;
18
+ color: #000;
19
+ }
20
+
21
+ a {color: #03c}
22
+ a:hover {
23
+ background-color: #03c;
24
+ color: white;
25
+ text-decoration: none;
26
+ }
27
+
28
+
29
+ #page {
30
+ background-color: #f0f0f0;
31
+ width: 750px;
32
+ margin: 0;
33
+ margin-left: auto;
34
+ margin-right: auto;
35
+ }
36
+
37
+ #content {
38
+ float: left;
39
+ background-color: white;
40
+ border: 3px solid #aaa;
41
+ border-top: none;
42
+ padding: 25px;
43
+ width: 500px;
44
+ }
45
+
46
+ #sidebar {
47
+ float: right;
48
+ width: 175px;
49
+ }
50
+
51
+ #footer {
52
+ clear: both;
53
+ }
54
+
55
+ #header, #about, #getting-started {
56
+ padding-left: 75px;
57
+ padding-right: 30px;
58
+ }
59
+
60
+
61
+ #header {
62
+ background-image: url("assets/rails.png");
63
+ background-repeat: no-repeat;
64
+ background-position: top left;
65
+ height: 64px;
66
+ }
67
+ #header h1, #header h2 {margin: 0}
68
+ #header h2 {
69
+ color: #888;
70
+ font-weight: normal;
71
+ font-size: 16px;
72
+ }
73
+
74
+
75
+ #about h3 {
76
+ margin: 0;
77
+ margin-bottom: 10px;
78
+ font-size: 14px;
79
+ }
80
+
81
+ #about-content {
82
+ background-color: #ffd;
83
+ border: 1px solid #fc0;
84
+ margin-left: -55px;
85
+ margin-right: -10px;
86
+ }
87
+ #about-content table {
88
+ margin-top: 10px;
89
+ margin-bottom: 10px;
90
+ font-size: 11px;
91
+ border-collapse: collapse;
92
+ }
93
+ #about-content td {
94
+ padding: 10px;
95
+ padding-top: 3px;
96
+ padding-bottom: 3px;
97
+ }
98
+ #about-content td.name {color: #555}
99
+ #about-content td.value {color: #000}
100
+
101
+ #about-content ul {
102
+ padding: 0;
103
+ list-style-type: none;
104
+ }
105
+
106
+ #about-content.failure {
107
+ background-color: #fcc;
108
+ border: 1px solid #f00;
109
+ }
110
+ #about-content.failure p {
111
+ margin: 0;
112
+ padding: 10px;
113
+ }
114
+
115
+
116
+ #getting-started {
117
+ border-top: 1px solid #ccc;
118
+ margin-top: 25px;
119
+ padding-top: 15px;
120
+ }
121
+ #getting-started h1 {
122
+ margin: 0;
123
+ font-size: 20px;
124
+ }
125
+ #getting-started h2 {
126
+ margin: 0;
127
+ font-size: 14px;
128
+ font-weight: normal;
129
+ color: #333;
130
+ margin-bottom: 25px;
131
+ }
132
+ #getting-started ol {
133
+ margin-left: 0;
134
+ padding-left: 0;
135
+ }
136
+ #getting-started li {
137
+ font-size: 18px;
138
+ color: #888;
139
+ margin-bottom: 25px;
140
+ }
141
+ #getting-started li h2 {
142
+ margin: 0;
143
+ font-weight: normal;
144
+ font-size: 18px;
145
+ color: #333;
146
+ }
147
+ #getting-started li p {
148
+ color: #555;
149
+ font-size: 13px;
150
+ }
151
+
152
+
153
+ #sidebar ul {
154
+ margin-left: 0;
155
+ padding-left: 0;
156
+ }
157
+ #sidebar ul h3 {
158
+ margin-top: 25px;
159
+ font-size: 16px;
160
+ padding-bottom: 10px;
161
+ border-bottom: 1px solid #ccc;
162
+ }
163
+ #sidebar li {
164
+ list-style-type: none;
165
+ }
166
+ #sidebar ul.links li {
167
+ margin-bottom: 5px;
168
+ }
169
+
170
+ .filename {
171
+ font-style: italic;
172
+ }
173
+ </style>
174
+ <script type="text/javascript">
175
+ function about() {
176
+ info = document.getElementById('about-content');
177
+ if (window.XMLHttpRequest)
178
+ { xhr = new XMLHttpRequest(); }
179
+ else
180
+ { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
181
+ xhr.open("GET","rails/info/properties",false);
182
+ xhr.send("");
183
+ info.innerHTML = xhr.responseText;
184
+ info.style.display = 'block'
185
+ }
186
+ </script>
187
+ </head>
188
+ <body>
189
+ <div id="page">
190
+ <div id="sidebar">
191
+ <ul id="sidebar-items">
192
+ <li>
193
+ <h3>Browse the documentation</h3>
194
+ <ul class="links">
195
+ <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
196
+ <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
197
+ <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
198
+ <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
199
+ </ul>
200
+ </li>
201
+ </ul>
202
+ </div>
203
+
204
+ <div id="content">
205
+ <div id="header">
206
+ <h1>Welcome aboard</h1>
207
+ <h2>You&rsquo;re riding Ruby on Rails!</h2>
208
+ </div>
209
+
210
+ <div id="about">
211
+ <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
212
+ <div id="about-content" style="display: none"></div>
213
+ </div>
214
+
215
+ <div id="getting-started">
216
+ <h1>Getting started</h1>
217
+ <h2>Here&rsquo;s how to get rolling:</h2>
218
+
219
+ <ol>
220
+ <li>
221
+ <h2>Use <code>rails generate</code> to create your models and controllers</h2>
222
+ <p>To see all available options, run it without parameters.</p>
223
+ </li>
224
+
225
+ <li>
226
+ <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
227
+ <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
228
+ </li>
229
+
230
+ <li>
231
+ <h2>Create your database</h2>
232
+ <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
233
+ </li>
234
+ </ol>
235
+ </div>
236
+ </div>
237
+
238
+ <div id="footer">&nbsp;</div>
239
+ </div>
240
+ </body>
241
+ </html>
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
File without changes
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ title: MyString
5
+
6
+ two:
7
+ title: MyString
@@ -0,0 +1,3 @@
1
+ basic:
2
+ uid: 89c93c0a-5999-4b80-811b-c66a3240651b
3
+ email: dummy@dailycred.com
File without changes
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ class PostsControllerTest < ActionController::TestCase
4
+ setup do
5
+ @post = posts(:one)
6
+ @user = users(:basic)
7
+ @controller.expects(:current_user).returns(@user)
8
+ end
9
+
10
+ test "should get index" do
11
+ get :index
12
+ assert_response :success
13
+ assert_not_nil assigns(:posts)
14
+ end
15
+
16
+ test "should get new" do
17
+ get :new
18
+ assert_response :success
19
+ end
20
+
21
+ test "should create post" do
22
+ assert_difference('Post.count') do
23
+ post :create, post: { title: @post.title }
24
+ end
25
+
26
+ assert_redirected_to post_path(assigns(:post))
27
+ end
28
+
29
+ test "should show post" do
30
+ get :show, id: @post
31
+ assert_response :success
32
+ end
33
+
34
+ test "should get edit" do
35
+ get :edit, id: @post
36
+ assert_response :success
37
+ end
38
+
39
+ test "should update post" do
40
+ put :update, id: @post, post: { title: @post.title }
41
+ assert_redirected_to post_path(assigns(:post))
42
+ end
43
+
44
+ test "should destroy post" do
45
+ assert_difference('Post.count', -1) do
46
+ delete :destroy, id: @post
47
+ end
48
+
49
+ assert_redirected_to posts_path
50
+ end
51
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+ require 'rails/performance_test_help'
3
+
4
+ class BrowsingTest < ActionDispatch::PerformanceTest
5
+ # Refer to the documentation for all available options
6
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
7
+ # :output => 'tmp/performance', :formats => [:flat] }
8
+
9
+ def test_homepage
10
+ get '/'
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+ #uncomment the following line to use spork with the debugger
4
+ #require 'spork/ext/ruby-debug'
5
+
6
+ Spork.prefork do
7
+ # Loading more in this block will cause your tests to run faster. However,
8
+ # if you change any configuration or code from libraries loaded here, you'll
9
+ # need to restart spork for it take effect.
10
+ ENV["RAILS_ENV"] = "test"
11
+ require File.expand_path('../../config/environment', __FILE__)
12
+ require 'rails/test_help'
13
+
14
+ class ActiveSupport::TestCase
15
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
16
+ #
17
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
18
+ # -- they do not yet inherit this setting
19
+ fixtures :all
20
+
21
+ # Add more helper methods to be used by all tests here...
22
+ end
23
+
24
+ end
25
+
26
+ Spork.each_run do
27
+ # This code will be run each time you run your specs.
28
+ end
29
+
30
+ # --- Instructions ---
31
+ # Sort the contents of this file into a Spork.prefork and a Spork.each_run
32
+ # block.
33
+ #
34
+ # The Spork.prefork block is run only once when the spork server is started.
35
+ # You typically want to place most of your (slow) initializer code in here, in
36
+ # particular, require'ing any 3rd-party gems that you don't normally modify
37
+ # during development.
38
+ #
39
+ # The Spork.each_run block is run each time you run your specs. In case you
40
+ # need to load files that tend to change during development, require them here.
41
+ # With Rails, your application modules are loaded automatically, so sometimes
42
+ # this block can remain empty.
43
+ #
44
+ # Note: You can modify files loaded *from* the Spork.each_run block without
45
+ # restarting the spork server. However, this file itself will not be reloaded,
46
+ # so if you change any of the code inside the each_run block, you still need to
47
+ # restart the server. In general, if you have non-trivial code in this file,
48
+ # it's advisable to move it into a separate file so you can easily edit it
49
+ # without restarting spork. (For example, with RSpec, you could move
50
+ # non-trivial code into a file spec/support/my_helper.rb, making sure that the
51
+ # spec/support/* files are require'd from inside the each_run block.)
52
+ #
53
+ # Any code that is left outside the two blocks will be run during preforking
54
+ # *and* during each_run -- that's probably not what you want.
55
+ #
56
+ # These instructions should self-destruct in 10 seconds. If they don't, feel
57
+ # free to delete them.
58
+
59
+
60
+
61
+
62
+
File without changes
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class PostsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../test_helper.rb'
2
+ class UserTest < ActiveSupport::TestCase
3
+ setup do
4
+ @user = users(:basic)
5
+ end
6
+ test 'tagging a user' do
7
+ @user.tag 'awesome'
8
+ assert_tag 'awesome'
9
+ end
10
+ test 'untagging a user' do
11
+ t = 'bad'
12
+ @user.tag t
13
+ assert_tag t
14
+ @user.untag t
15
+ assert_not_tag t
16
+ end
17
+
18
+ test 'resetting a password' do
19
+ assert_true json_response(@user.reset_password)['worked']
20
+ end
21
+
22
+ test 'updating from dailycred' do
23
+ dc = {
24
+ email: 'hank@2.com',
25
+ tags: ['hello','awesome'],
26
+ referred: ['danny', 'betty'],
27
+ username: 'hstove',
28
+ created: 111222333,
29
+ verified: false,
30
+ admin: false,
31
+ referred_by: 'marky',
32
+ referred: ['chris', 'mike'],
33
+ facebook: {
34
+ id: 100203,
35
+ email: 'hank@facebook.com'
36
+ },
37
+ provider: 'dailycred',
38
+ token: 'ha243k',
39
+ twitter: {
40
+ screen_name: 'heynky'
41
+ },
42
+ google: {
43
+ email: 'hstove@gg.com'
44
+ },
45
+ github: {
46
+ repos: ['123','ruby on rails']
47
+ },
48
+ subscribed: false,
49
+ display: 'hanky'
50
+ }
51
+ @user.update_from_dailycred dc
52
+ dc.each do |k,v|
53
+ assert_equal v, @user[k], "user should have value of |#{v}| for |#{k}| but was |#{@user[k].to_s}|"
54
+ end
55
+ end
56
+
57
+ test 'firing an event' do
58
+ assert_true json_response(@user.fire_event 'got tested')['worked']
59
+ end
60
+
61
+ test 'making a referral link' do
62
+ id = @user.uid
63
+ assert_equal @user.referral_link('http://me.com'), "https://www.dailycred.com/r/#{id}?redirect_uri=http://me.com"
64
+ end
65
+
66
+ def json_response response
67
+ JSON.parse response.body
68
+ end
69
+
70
+
71
+ def assert_tag tag
72
+ assert_true @user.tags.include?(tag), "user should have tag: #{tag} but has tags: #{@user.tags}"
73
+ end
74
+ def assert_not_tag tag
75
+ assert_false @user.tags.include?(tag), "user should not have tag: #{tag} but has tags: #{@user.tags}"
76
+ end
77
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,87 @@
1
+ module ActsAsDailycred
2
+ def acts_as_dailycred
3
+ serialize :facebook, Hash
4
+ serialize :twitter, Hash
5
+ serialize :google, Hash
6
+ serialize :github, Hash
7
+ serialize :tags, Array
8
+ serialize :referred, Array
9
+ serialize :access_tokens, Hash
10
+
11
+ extend ActsAsDailycred::SingletonMethods
12
+ include ActsAsDailycred::InstanceMethods
13
+ include Dailycred::Helpers
14
+ end
15
+ module SingletonMethods
16
+ def find_or_create_with_omniauth(model)
17
+ @user = User.find_by_provider_and_uid(model[:provider], model[:uid]) || User.new
18
+ @user.update_from_dailycred model[:info]
19
+ @user
20
+ end
21
+ end
22
+ module InstanceMethods
23
+ def tag tag
24
+ dc = get_client
25
+ response = dc.tag self.uid, tag
26
+ json = JSON.parse(response.body)
27
+ if json['worked']
28
+ self.tags << tag
29
+ save!
30
+ end
31
+ end
32
+
33
+ def untag tag
34
+ dc = get_client
35
+ response = dc.untag self.uid, tag
36
+ json = JSON.parse(response.body)
37
+ if json['worked']
38
+ self.tags.delete tag
39
+ save!
40
+ end
41
+ end
42
+
43
+ def display_name
44
+ display = self.email || ""
45
+ p '1'
46
+ if self.facebook != {}
47
+ p '2'
48
+ return self.facebook["name"]
49
+ elsif self.google != {}
50
+ p '3'
51
+ return self.google["name"]
52
+ elsif self.twitter != {}
53
+ p '4'
54
+ return "@"+self.twitter["screen_name"]
55
+ end
56
+ display
57
+ end
58
+
59
+ def referral_link url
60
+ "https://www.dailycred.com/r/#{self.uid}?redirect_uri=#{url}"
61
+ end
62
+ def reset_password
63
+ get_client.reset_password self.email
64
+ end
65
+
66
+ def update_from_dailycred dc
67
+ dc.each do |k,v|
68
+ self[k] = v if self.respond_to?(k)
69
+ end
70
+ save!
71
+ end
72
+
73
+ def fire_event key, val=""
74
+ get_client.event self.uid, key, val
75
+ end
76
+
77
+ def get_client
78
+ @dailycred ||= Dailycred::Client.new Rails.configuration.DAILYCRED_CLIENT_ID, Rails.configuration.DAILYCRED_SECRET_KEY
79
+ end
80
+
81
+ def connect_path provider
82
+ "/auth/dailycred?identity_provider=#{provider.to_s}"
83
+ end
84
+ end
85
+ end
86
+ require 'active_record'
87
+ ActiveRecord::Base.extend ActsAsDailycred
@@ -0,0 +1,105 @@
1
+ module Dailycred
2
+ class Client
3
+ attr_accessor :client_id, :secret_key, :options, :url
4
+
5
+ URL = "https://www.dailycred.com"
6
+
7
+ ROUTES = {
8
+ :signup => "/user/api/signup.json",
9
+ :login => "/user/api/signin.json"
10
+ }
11
+
12
+ # Initializes a dailycred object
13
+ #
14
+ # - @param [String] client\_id the client's daiycred client id
15
+ # - @param [String] secret\_key the clients secret key
16
+ # - @param [Hash] opts a hash of options
17
+ def initialize(client_id, secret_key="", opts={})
18
+ @client_id = client_id
19
+ @secret_key = secret_key
20
+ @options = opts
21
+ opts[:client_options] ||= {}
22
+ @url = opts[:client_options][:site] || Dailycred::Client::URL
23
+ end
24
+
25
+ # Generates a Dailycred event
26
+ #
27
+ # - @param [String] user_id the user's dailycred user id
28
+ # - @param [String] key the name of the event type
29
+ # - @param [String] val the value of the event (optional)
30
+ def event(user_id, key, val="")
31
+ opts = {
32
+ :key => key,
33
+ :valuestring => val,
34
+ :user_id => user_id
35
+ }
36
+ post "/admin/api/customevent.json", opts
37
+ end
38
+
39
+ # Tag a user in dailycred
40
+ #
41
+ # - @param [String] user_id the user's dailycred user id
42
+ # - @param [String] tag the desired tag to add
43
+ def tag(user_id, tag)
44
+ opts = {
45
+ :user_id => user_id,
46
+ :tag => tag
47
+ }
48
+ post "/admin/api/user/tag.json", opts
49
+ end
50
+
51
+ # Untag a user in dailycred
52
+ # (see #tag)
53
+ def untag(user_id, tag)
54
+ opts = {
55
+ :user_id => user_id,
56
+ :tag => tag
57
+ }
58
+ post "/admin/api/user/untag.json", opts
59
+ end
60
+
61
+ # Send a reset password email
62
+ #
63
+ # - @param [string] user the user's email or username
64
+ def reset_password(user)
65
+ opts = {
66
+ :user => user
67
+ }
68
+ post "/password/api/reset", opts
69
+ end
70
+
71
+ # A wildcard for making any post requests to dailycred.
72
+ # client_id and client_secret are automatically added to the request
73
+ #
74
+ # - @param [string] url
75
+ # - @param [hash] opts
76
+ # - @param [boolean] secure whether the client_secret should be passed. Defaults to true
77
+ def post(url, opts, secure=true)
78
+ opts.merge! base_opts(secure)
79
+ response = get_conn.post url, opts
80
+ end
81
+
82
+ private
83
+
84
+ def ssl_opts
85
+ opts = {}
86
+ if @options[:client_options] && @options[:client_options][:ssl]
87
+ opts[:ssl] = @options[:client_options][:ssl]
88
+ elsif Rails.configuration.respond_to? "DAILYCRED_OPTIONS"
89
+ opts[:ssl] = Rails.configuration.DAILYCRED_OPTIONS[:client_options][:ssl]
90
+ end
91
+ opts
92
+ end
93
+
94
+ def base_opts secure=true
95
+ opts = {:client_id => @client_id}
96
+ opts[:client_secret] = @secret_key if secure
97
+ opts
98
+ end
99
+
100
+ def get_conn
101
+ Faraday::Connection.new @url, ssl_opts
102
+ end
103
+ end
104
+
105
+ end