disqus_rails 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- metadata +36 -79
- data/.gitignore +0 -18
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -296
- data/Rakefile +0 -1
- data/disqus_rails.gemspec +0 -27
- data/lib/disqus_rails.rb +0 -31
- data/lib/disqus_rails/active_record/acts_as_disqusable.rb +0 -24
- data/lib/disqus_rails/active_record/acts_as_disquser.rb +0 -48
- data/lib/disqus_rails/api.rb +0 -79
- data/lib/disqus_rails/api.yml +0 -855
- data/lib/disqus_rails/category.rb +0 -20
- data/lib/disqus_rails/collection.rb +0 -90
- data/lib/disqus_rails/forum.rb +0 -54
- data/lib/disqus_rails/helpers.rb +0 -65
- data/lib/disqus_rails/model.rb +0 -45
- data/lib/disqus_rails/post.rb +0 -106
- data/lib/disqus_rails/thread.rb +0 -130
- data/lib/disqus_rails/user.rb +0 -68
- data/lib/disqus_rails/version.rb +0 -3
- data/spec/disqus_rails/active_record/acts_as_disqusable_spec.rb +0 -118
- data/spec/disqus_rails/active_record/acts_as_disquser_spec.rb +0 -44
- data/spec/disqus_rails/api_spec.rb +0 -266
- data/spec/disqus_rails/category_spec.rb +0 -77
- data/spec/disqus_rails/collection_spec.rb +0 -9
- data/spec/disqus_rails/forum_spec.rb +0 -102
- data/spec/disqus_rails/model_spec.rb +0 -24
- data/spec/disqus_rails/post_spec.rb +0 -218
- data/spec/disqus_rails/thread_spec.rb +0 -174
- data/spec/disqus_rails/user_spec.rb +0 -101
- data/spec/disqus_rails_spec.rb +0 -17
- data/spec/spec_helper.rb +0 -13
- data/vendor/assets/javascripts/disqus_rails.js.coffee +0 -78
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 715641735b00fbc5288f351cfd8d7ae8f2cd2cd1
|
4
|
+
data.tar.gz: 3db92d0024c17e36841ffe27fd1ed99eca34e3c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4dda3d56b89d215e161d4c7bc7582a98eb23a0515e71d0f7afe619b912551992afc6b99cc92cd043453fe6cedf6163c2e2c38bb9ebfb0b87e1feea6d262be2bf
|
7
|
+
data.tar.gz: 41bac90f9606d853d183298f7ae8e2333707a817b5ee9d9db842ec3334dc5d3255c75e39c1392017fbe98e7bc2d35700645a7c5e8c7ef19c347f867caa3c41c4
|
metadata
CHANGED
@@ -1,94 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disqus_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Anton Kyrychenko
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: travis-lint
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
|
-
- -
|
73
|
+
- - ">="
|
68
74
|
- !ruby/object:Gem::Version
|
69
75
|
version: '0'
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
|
-
- -
|
80
|
+
- - ">="
|
76
81
|
- !ruby/object:Gem::Version
|
77
82
|
version: '0'
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
84
|
name: rails
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
86
|
requirements:
|
83
|
-
- -
|
87
|
+
- - ">="
|
84
88
|
- !ruby/object:Gem::Version
|
85
89
|
version: '0'
|
86
90
|
type: :runtime
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
93
|
requirements:
|
91
|
-
- -
|
94
|
+
- - ">="
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: '0'
|
94
97
|
description: Disqus 2012 Ruby on Rails wrapper
|
@@ -97,75 +100,29 @@ email:
|
|
97
100
|
executables: []
|
98
101
|
extensions: []
|
99
102
|
extra_rdoc_files: []
|
100
|
-
files:
|
101
|
-
- .gitignore
|
102
|
-
- Gemfile
|
103
|
-
- LICENSE.txt
|
104
|
-
- README.md
|
105
|
-
- Rakefile
|
106
|
-
- disqus_rails.gemspec
|
107
|
-
- lib/disqus_rails.rb
|
108
|
-
- lib/disqus_rails/active_record/acts_as_disqusable.rb
|
109
|
-
- lib/disqus_rails/active_record/acts_as_disquser.rb
|
110
|
-
- lib/disqus_rails/api.rb
|
111
|
-
- lib/disqus_rails/api.yml
|
112
|
-
- lib/disqus_rails/category.rb
|
113
|
-
- lib/disqus_rails/collection.rb
|
114
|
-
- lib/disqus_rails/forum.rb
|
115
|
-
- lib/disqus_rails/helpers.rb
|
116
|
-
- lib/disqus_rails/model.rb
|
117
|
-
- lib/disqus_rails/post.rb
|
118
|
-
- lib/disqus_rails/thread.rb
|
119
|
-
- lib/disqus_rails/user.rb
|
120
|
-
- lib/disqus_rails/version.rb
|
121
|
-
- spec/disqus_rails/active_record/acts_as_disqusable_spec.rb
|
122
|
-
- spec/disqus_rails/active_record/acts_as_disquser_spec.rb
|
123
|
-
- spec/disqus_rails/api_spec.rb
|
124
|
-
- spec/disqus_rails/category_spec.rb
|
125
|
-
- spec/disqus_rails/collection_spec.rb
|
126
|
-
- spec/disqus_rails/forum_spec.rb
|
127
|
-
- spec/disqus_rails/model_spec.rb
|
128
|
-
- spec/disqus_rails/post_spec.rb
|
129
|
-
- spec/disqus_rails/thread_spec.rb
|
130
|
-
- spec/disqus_rails/user_spec.rb
|
131
|
-
- spec/disqus_rails_spec.rb
|
132
|
-
- spec/spec_helper.rb
|
133
|
-
- vendor/assets/javascripts/disqus_rails.js.coffee
|
103
|
+
files: []
|
134
104
|
homepage: https://github.com/sandric/disqus_rails
|
135
105
|
licenses:
|
136
106
|
- MIT
|
107
|
+
metadata: {}
|
137
108
|
post_install_message:
|
138
109
|
rdoc_options: []
|
139
110
|
require_paths:
|
140
111
|
- lib
|
141
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
-
none: false
|
143
113
|
requirements:
|
144
|
-
- -
|
114
|
+
- - ">="
|
145
115
|
- !ruby/object:Gem::Version
|
146
116
|
version: '0'
|
147
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
-
none: false
|
149
118
|
requirements:
|
150
|
-
- -
|
119
|
+
- - ">="
|
151
120
|
- !ruby/object:Gem::Version
|
152
121
|
version: '0'
|
153
122
|
requirements: []
|
154
123
|
rubyforge_project:
|
155
|
-
rubygems_version:
|
124
|
+
rubygems_version: 2.6.13
|
156
125
|
signing_key:
|
157
|
-
specification_version:
|
126
|
+
specification_version: 4
|
158
127
|
summary: Integrates Disqus service into your Ruby on Rails application
|
159
|
-
test_files:
|
160
|
-
- spec/disqus_rails/active_record/acts_as_disqusable_spec.rb
|
161
|
-
- spec/disqus_rails/active_record/acts_as_disquser_spec.rb
|
162
|
-
- spec/disqus_rails/api_spec.rb
|
163
|
-
- spec/disqus_rails/category_spec.rb
|
164
|
-
- spec/disqus_rails/collection_spec.rb
|
165
|
-
- spec/disqus_rails/forum_spec.rb
|
166
|
-
- spec/disqus_rails/model_spec.rb
|
167
|
-
- spec/disqus_rails/post_spec.rb
|
168
|
-
- spec/disqus_rails/thread_spec.rb
|
169
|
-
- spec/disqus_rails/user_spec.rb
|
170
|
-
- spec/disqus_rails_spec.rb
|
171
|
-
- spec/spec_helper.rb
|
128
|
+
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Anton Kirichenko
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,296 +0,0 @@
|
|
1
|
-
# DisqusRails
|
2
|
-
|
3
|
-
DisqusRails is a gem for including [Disqus](http://disqus.com/) service into Ruby on Rails application.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
`gem 'disqus_rails'`
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
`$ bundle`
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
`$ gem install disqus_rails`
|
18
|
-
|
19
|
-
And add to your javascript manifest file:
|
20
|
-
|
21
|
-
`//= require disqus_rails`
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
### Getting started
|
25
|
-
|
26
|
-
Create new initializer, lets say 'disqus_rails.rb' in config/initializers directory with this:
|
27
|
-
```ruby
|
28
|
-
DisqusRails.setup do |config|
|
29
|
-
config::SHORT_NAME = "your_short_name"
|
30
|
-
config::SECRET_KEY = "your_secret_disqus_key" #leave blank if not used
|
31
|
-
config::PUBLIC_KEY = "your public_disqus_key" #leave blank if not used
|
32
|
-
config::ACCESS_TOKEN = "your_access_token" #you got it, right? ;-)
|
33
|
-
end
|
34
|
-
```
|
35
|
-
In your layout file place 'disqus_init' helper:
|
36
|
-
```erb
|
37
|
-
<%= disqus_init %>
|
38
|
-
```
|
39
|
-
In your view, where you want to display Disqus thread, place 'disqus_thread' helper:
|
40
|
-
```erb
|
41
|
-
<%= disqus_thread %>
|
42
|
-
```
|
43
|
-
And you are ready to go.
|
44
|
-
|
45
|
-
####additional params:
|
46
|
-
|
47
|
-
You can omit creating initializer if you want - you can pass all those params right into 'disqus_init' helper as hash:
|
48
|
-
```erb
|
49
|
-
<%= disqus_init :short_name => "short_name", :public_key => "public key", :secret_key => "secret_key", :access_token => "access_token" %>
|
50
|
-
```
|
51
|
-
also you can pass reset option to 'disqus_init' to invoke 'DISQUS.reset' function to be triggered on 'onReady' disqus event:
|
52
|
-
```erb
|
53
|
-
<%= disqus_init :reset => true %>
|
54
|
-
```
|
55
|
-
This is for ajax-heavy sites, read more [here](http://help.disqus.com/customer/portal/articles/472107-using-disqus-on-ajax-sites)
|
56
|
-
|
57
|
-
'disqus_thread' has two params - first is 'ident' identifier and the second is title:
|
58
|
-
```erb
|
59
|
-
<%= disqus_thread 1, "some title, that will preferred to document.title" %>
|
60
|
-
```
|
61
|
-
|
62
|
-
###Api
|
63
|
-
|
64
|
-
####Api calls
|
65
|
-
|
66
|
-
'DisqusRails::Api' stands for [Disqus API](http://disqus.com/api/docs/) calls. Each entity of Disqus API (Posts, Users, Forums, etc...)
|
67
|
-
has its own class in 'DisqusRails::Api' module. Lets say you want to get all reactions for some forum with limit of 50 results, with desc order:
|
68
|
-
```ruby
|
69
|
-
DisqusRails::Api::Reactions.list(:forum => "forum_id", :limit => 50, :order => "desc")
|
70
|
-
```
|
71
|
-
or, for example to update some post:
|
72
|
-
```ruby
|
73
|
-
DisqusRails::Api::Posts.update(:post => post_id, :message => "some updated message")
|
74
|
-
```
|
75
|
-
Disqus return data as json, 'DisqusRails::Api' requests translates it to hash with symbolized keys.
|
76
|
-
All methods with required and optional params you can see in 'api.yml' file. If any of required params not passed - it will generate
|
77
|
-
exeption, so as if passed param neither required nor optional. Also, you have to initialize access_token for methods that has
|
78
|
-
'require authentication' option set to true.
|
79
|
-
|
80
|
-
####Models
|
81
|
-
|
82
|
-
For more flexibility and using Disqus entities as an ActiveRecord model there is 'DisqusRails::Model' class that is inherited by
|
83
|
-
'DisqusRails::Forum', 'DisqusRails::Category', 'DisqusRails::Thread', 'DisqusRails::Post' and 'DisqusRails::User'.
|
84
|
-
Lets take previous example and turn it into model's presentation:
|
85
|
-
```ruby
|
86
|
-
new_post = DisqusRails::Post.create(:message => "initial message")
|
87
|
-
new_post.update(:message => "updated message")
|
88
|
-
new_post.author.checkUsername("John Doe")
|
89
|
-
new_post.remove
|
90
|
-
new_post.restore
|
91
|
-
```
|
92
|
-
If Disqus entity has 'details' api method, than model has 'find' singleton method
|
93
|
-
```ruby
|
94
|
-
user = DisqusRails::User.find(:user => "user_id")
|
95
|
-
user_posts.follow()
|
96
|
-
```
|
97
|
-
Each 'DisqusRails::Model' has number of attributes that you can find in model's code. For example, here is Posts:
|
98
|
-
```ruby
|
99
|
-
class Post < Model
|
100
|
-
attr_accessor :id,
|
101
|
-
:isJuliaFlagged,
|
102
|
-
:isFlagged,
|
103
|
-
:parent,
|
104
|
-
:media,
|
105
|
-
:isApproved,
|
106
|
-
:dislikes,
|
107
|
-
:raw_message,
|
108
|
-
:points,
|
109
|
-
:createdAt,
|
110
|
-
:isEdited,
|
111
|
-
:message,
|
112
|
-
:isHighlighted,
|
113
|
-
:ipAddress,
|
114
|
-
:isSpam,
|
115
|
-
:isDeleted,
|
116
|
-
:likes,
|
117
|
-
|
118
|
-
:author,
|
119
|
-
:thread,
|
120
|
-
:forum
|
121
|
-
```
|
122
|
-
|
123
|
-
####Collections
|
124
|
-
|
125
|
-
Collections, as you may guess, is a list of similar Models. Its inherited from Enumerable. There is similar to models
|
126
|
-
number of collection - 'DisqusRails::Forums', 'DisqusRails::Categories', 'DisqusRails::Threads', 'DisqusRails::Posts' and 'DisqusRails::Users'.
|
127
|
-
Here some examples:
|
128
|
-
```ruby
|
129
|
-
user = DisqusRails.User.find(:user => "user_id")
|
130
|
-
user.active_threads(:limit => 50)[15].posts.each do |post|
|
131
|
-
post.update(:message => "my post is nothing comparing to #{user.username} writings...")
|
132
|
-
end
|
133
|
-
```
|
134
|
-
If there is 'list' method in Disqus entity - it transforms to 'where' singleton method of model that creates corresponding collection. For example:
|
135
|
-
```ruby
|
136
|
-
forum_categories = DisqusRails::Category.where(:forum => "forum_id")
|
137
|
-
```
|
138
|
-
Disqus API is designed in such way, that you can only get maximum 100 results for list query, and by default its 25. To get more
|
139
|
-
results you are given with 'cursor' object that have 'next' and 'prev' values, passing which into query you can walk through
|
140
|
-
results as if it was a list data structure. To define if there is more values to get, Disqus provides 'hasNext' and 'hasPrev' boolean
|
141
|
-
values. For example, to get first 225 posts you can use this code:
|
142
|
-
```ruby
|
143
|
-
posts = DisqusRails::Post.where(:limit => 75)
|
144
|
-
2.times do
|
145
|
-
if posts.has_cursor_next?
|
146
|
-
previous_items = posts.items
|
147
|
-
posts.cursor_next!
|
148
|
-
posts.items = previous_items + posts.items
|
149
|
-
end
|
150
|
-
end
|
151
|
-
```
|
152
|
-
In future I, may be, will rewrite this to handle common cases for :limit attribute to be set to any number. As you saw, in
|
153
|
-
previous example were used 'cursor_next!' method. There is both 'cursor_next', 'cursor_next!' and 'cursor_prev', 'cursor_prev!' methods.
|
154
|
-
The difference is in returned values - method with bang in the end initializes new collection right in invoked instance,
|
155
|
-
when method without it - just returns new collection.
|
156
|
-
Also, each collection has singleton method 'find_all_#collection_class_name#!' that will get all results for query:
|
157
|
-
```ruby
|
158
|
-
threads = Disqus::Thread.where(:forum => "forum_name", :limit => 100).find_all_threads!
|
159
|
-
```
|
160
|
-
|
161
|
-
###Connection to ActiveRecord models
|
162
|
-
|
163
|
-
####acts_as_disqusable and disqus_thread
|
164
|
-
|
165
|
-
Lets say you have a 'Content' ActiveRecord model that implements logic for displaying some content information, and you add to that displaying
|
166
|
-
Disqus thread. Then you may want to match threads info with different Content model instances. For example you may want to know
|
167
|
-
how many comments and what is the last comment for each model instance.
|
168
|
-
For this you need to wright 'acts_as_disqusable' in models definition:
|
169
|
-
```ruby
|
170
|
-
class Content < ActiveRecord::Base
|
171
|
-
acts_as_disqusable
|
172
|
-
...
|
173
|
-
end
|
174
|
-
```
|
175
|
-
And then all your model instances will be populated with 'disqus_thread' method that will return 'DisqusRails::Thread' instance
|
176
|
-
that is found by Disqus 'ident' identifier which you can pass to 'disqus_thread' helper in your view. Here is full example:
|
177
|
-
|
178
|
-
Your model:
|
179
|
-
```ruby
|
180
|
-
class Content < ActiveRecord::Base
|
181
|
-
acts_as_disqusable
|
182
|
-
...
|
183
|
-
end
|
184
|
-
```
|
185
|
-
Your model's details view
|
186
|
-
```erb
|
187
|
-
<%= disqus_thread @content.id %>
|
188
|
-
|
189
|
-
```
|
190
|
-
And now, when you run this
|
191
|
-
```ruby
|
192
|
-
disqus_thread = Content.first.disqus_thread #It will be thanslated to DisqusRails::Thread.find(:'thread:ident' => Content.first.id)
|
193
|
-
disqus_thread.posts_count #number of posts
|
194
|
-
disqus_thread.posts(:limit => 1).createdAt #last comment date
|
195
|
-
```
|
196
|
-
This work also in opposite direction - after you include 'acts_as_disqusable' in your model definition, all 'DisqusRails::Thread'
|
197
|
-
instances you will have method 'disqusable' what will return your model instance that is linked to Disqus thread via 'ident' identificator.
|
198
|
-
As an example lets say that we want to get all threads from Disqus service and update comments_count attribute in Content model:
|
199
|
-
```ruby
|
200
|
-
DisqusRails.Thread.where().find_all_threads!.each do |thread|
|
201
|
-
thread.disqusable.comments_count = thread.posts_count
|
202
|
-
thread.disqusable.save()
|
203
|
-
end
|
204
|
-
```
|
205
|
-
|
206
|
-
####acts_as_disquser and Single Sign On
|
207
|
-
|
208
|
-
Disqus provides [SSO service](http://help.disqus.com/customer/portal/articles/236206-integrating-single-sign-on) which gives
|
209
|
-
ability to link your local users info to Disqus users, read more in Disqus tutorial. To do this, as and for linking model to
|
210
|
-
Disqus thread - you have to add 'acts_as_disquser' line in your users model. You need pass there four attributes:
|
211
|
-
'id', 'username', 'email' and 'avatar'(avatar is an optional field, so you can omit this). Here is example:
|
212
|
-
```ruby
|
213
|
-
class User < ActiveRecord::Base
|
214
|
-
acts_as_disquser :username => :full_name, :email => :email, :avatar => Proc.new{ avatar.url }
|
215
|
-
...
|
216
|
-
end
|
217
|
-
```
|
218
|
-
As you see, you can pass there or symbols, or procs. First will try to get instance variable with such name from model's instance,
|
219
|
-
second will evaluate code inside Proc with context of model's instance. Important - only Proc are available for second way of
|
220
|
-
defining attribute, no lambdas.
|
221
|
-
Also, you may not implicitly pass `acts_as_disquser :id => :id` - it will try to get id automatically if it is not defined.
|
222
|
-
Next, you need to specify in disqus_init helper attributes 'disquser' with current user instance, and 'sso' as
|
223
|
-
boolean to enable or disable SSO.
|
224
|
-
```erb
|
225
|
-
<%= disqus_init :disquser => current_user, :sso => true %>
|
226
|
-
```
|
227
|
-
After this is done, when users will post comments via Disqus, their username, email and avatar will be taken from your site.
|
228
|
-
|
229
|
-
###Javascript events
|
230
|
-
|
231
|
-
Disqus provides developer with set of events which could be used to implement some logic that depends on it. The problem is
|
232
|
-
that instead of triggering events we have to append function definitions in array for each of this events - for example look
|
233
|
-
at [this article](http://help.disqus.com/customer/portal/articles/466258-how-can-i-capture-disqus-commenting-activity-in-my-own-analytics-tool-).
|
234
|
-
I found that it might be a little bit more useful to set event listener for this, so I defined separate event for every Disqus event
|
235
|
-
that developer can implicitly create listener:
|
236
|
-
```coffeescript
|
237
|
-
@callbacks.afterRender = [->
|
238
|
-
$(document).trigger "disqus:after_render"
|
239
|
-
]
|
240
|
-
@callbacks.onInit = [->
|
241
|
-
$(document).trigger "disqus:on_init"
|
242
|
-
]
|
243
|
-
@callbacks.onNewComment = [->
|
244
|
-
$(document).trigger "disqus:on_new_comment"
|
245
|
-
]
|
246
|
-
@callbacks.onPaginate = [->
|
247
|
-
$(document).trigger "disqus:on_paginate"
|
248
|
-
]
|
249
|
-
@callbacks.onReady = [->
|
250
|
-
$(document).trigger "disqus:on_ready"
|
251
|
-
]
|
252
|
-
@callbacks.preData = [->
|
253
|
-
$(document).trigger "disqus:pre_data"
|
254
|
-
]
|
255
|
-
@callbacks.preInit = [->
|
256
|
-
$(document).trigger "disqus:pre_init"
|
257
|
-
]
|
258
|
-
@callbacks.preReset = [->
|
259
|
-
$(document).trigger "disqus:pre_reset"
|
260
|
-
]
|
261
|
-
```
|
262
|
-
For more information about coffeescript global class 'DisqusRails' look into 'disqus_rails.js.coffee' file.
|
263
|
-
|
264
|
-
### Keeping data up to date
|
265
|
-
It is equally little hard to do that with Disqus for now, as for me. The problem is that you can not set some callback for user
|
266
|
-
actions - all you can is to set event listener for 'disqus:on_new_comment', but that will not be valid for all circumstances.
|
267
|
-
Lets say user deleted or created new post from his users admin page in Disqus site. Disqus does not provide any callback for setting url
|
268
|
-
where should query go, or some other futuristic way like web socket channel (sarcasm tag). So we should create some cron task for keeping data
|
269
|
-
that we need up to date. For example, lets go back to problem of getting comments count and last comment for each Disqus thread.
|
270
|
-
Here is example of such rake task that could be scheduled with whenever (or any else) gem:
|
271
|
-
|
272
|
-
```ruby
|
273
|
-
require 'resque/tasks'
|
274
|
-
|
275
|
-
namespace :disqus do
|
276
|
-
desc "Refreshing local data about remote disqus comments"
|
277
|
-
task :refresh => :environment do
|
278
|
-
threads = DisqusRails::Thread.where(:forum => "forum_name", :limit => 100).find_all_threads!
|
279
|
-
threads.each do |thread|
|
280
|
-
if thread.disqusable_id && Content.find_by_id(thread.disqusable_id)
|
281
|
-
content = thread.disqusable
|
282
|
-
if (content.comments_count != thread.posts_count) || (thread.posts_count > 0 && thread.posts(:limit => 1).first.createdAt != content.last_comment_at)
|
283
|
-
content.comments_count = thread.posts_count
|
284
|
-
if thread.posts_count > 0
|
285
|
-
content.last_comment_at = DateTime.parse(thread.posts(:limit => 1).first.createdAt)
|
286
|
-
else
|
287
|
-
content.last_comment_at = nil
|
288
|
-
end
|
289
|
-
content.save
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
```
|