disqussion 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,182 +1,182 @@
1
- module EventMachine
2
- module Disqus
3
- # Disqus Widget generator.
4
- #
5
- # All of the methods accept various options, and "account" is required for
6
- # all of them. You can avoid having to pass in the account each time by
7
- # setting it in the defaults like this:
8
- #
9
- # Disqus::defaults[:account] = "my_account"
10
- class Widget
11
-
12
- VALID_COLORS = ['blue', 'grey', 'green', 'red', 'orange']
13
- VALID_NUM_ITEMS = 5..20
14
- VALID_DEFAULT_TABS = ['people', 'recent', 'popular']
15
- VALID_AVATAR_SIZES = [24, 32, 48, 92, 128]
16
- VALID_ORIENTATIONS = ['horizontal', 'vertical']
1
+ # From Norman Clarke's Disqus gem
2
+ # Needs to be refactored/rewrote to match new Disqus API
3
+ module Disqussion
4
+ # Disqus Widget generator.
5
+ #
6
+ # All of the methods accept various options, and "account" is required for
7
+ # all of them. You can avoid having to pass in the account each time by
8
+ # setting it in the defaults like this:
9
+ #
10
+ # Disqus::defaults[:account] = "my_account"
11
+ class Widget
17
12
 
18
- ROOT_PATH = 'http://disqus.com/forums/%s/'
19
- THREAD = ROOT_PATH + 'embed.js'
20
- COMBO = ROOT_PATH + 'combination_widget.js?num_items=%d&color=%s&default_tab=%s'
21
- RECENT = ROOT_PATH + 'recent_comments_widget.js?num_items=%d&avatar_size=%d'
22
- POPULAR = ROOT_PATH + 'popular_threads_widget.js?num_items=%d'
23
- TOP = ROOT_PATH + 'top_commenters_widget.js?num_items=%d&avatar_size=%d&orientation=%s'
24
- class << self
13
+ VALID_COLORS = ['blue', 'grey', 'green', 'red', 'orange']
14
+ VALID_NUM_ITEMS = 5..20
15
+ VALID_DEFAULT_TABS = ['people', 'recent', 'popular']
16
+ VALID_AVATAR_SIZES = [24, 32, 48, 92, 128]
17
+ VALID_ORIENTATIONS = ['horizontal', 'vertical']
18
+
19
+ ROOT_PATH = 'http://disqus.com/forums/%s/'
20
+ THREAD = ROOT_PATH + 'embed.js'
21
+ COMBO = ROOT_PATH + 'combination_widget.js?num_items=%d&color=%s&default_tab=%s'
22
+ RECENT = ROOT_PATH + 'recent_comments_widget.js?num_items=%d&avatar_size=%d'
23
+ POPULAR = ROOT_PATH + 'popular_threads_widget.js?num_items=%d'
24
+ TOP = ROOT_PATH + 'top_commenters_widget.js?num_items=%d&avatar_size=%d&orientation=%s'
25
+ class << self
25
26
 
26
- # Show the main Disqus thread widget.
27
- # Options:
28
- # * <tt>account:</tt> Your Discus account (required).
29
- def thread(opts = {})
30
- opts = Disqus::defaults.merge(opts)
31
- opts[:view_thread_text] ||= "View the discussion thread"
32
- validate_opts!(opts)
33
- s = ''
34
- if opts[:developer]
35
- s << '<script type="text/javascript">var disqus_developer = 1;</script>'
36
- end
37
- s << '<div id="disqus_thread"></div>'
38
- s << '<script type="text/javascript" src="' + THREAD + '"></script>'
39
- s << '<noscript><a href="http://%s.disqus.com/?url=ref">'
40
- s << opts[:view_thread_text]
41
- s << '</a></noscript>'
42
- if opts[:show_powered_by]
43
- s << '<a href="http://disqus.com" class="dsq-brlink">blog comments '
44
- s << 'powered by <span class="logo-disqus">Disqus</span></a>'
45
- end
46
- s % [opts[:account], opts[:account]]
27
+ # Show the main Disqus thread widget.
28
+ # Options:
29
+ # * <tt>account:</tt> Your Discus account (required).
30
+ def thread(opts = {})
31
+ opts = Disqus::defaults.merge(opts)
32
+ opts[:view_thread_text] ||= "View the discussion thread"
33
+ validate_opts!(opts)
34
+ s = ''
35
+ if opts[:developer]
36
+ s << '<script type="text/javascript">var disqus_developer = 1;</script>'
37
+ end
38
+ s << '<div id="disqus_thread"></div>'
39
+ s << '<script type="text/javascript" src="' + THREAD + '"></script>'
40
+ s << '<noscript><a href="http://%s.disqus.com/?url=ref">'
41
+ s << opts[:view_thread_text]
42
+ s << '</a></noscript>'
43
+ if opts[:show_powered_by]
44
+ s << '<a href="http://disqus.com" class="dsq-brlink">blog comments '
45
+ s << 'powered by <span class="logo-disqus">Disqus</span></a>'
47
46
  end
47
+ s % [opts[:account], opts[:account]]
48
+ end
48
49
 
49
- # Loads Javascript to show the number of comments for the page.
50
- #
51
- # The Javascript sets the inner html to the comment count for any links
52
- # on the page that have the anchor "disqus_thread". For example, "View
53
- # Comments" below would be replaced by "1 comment" or "23 comments" etc.
54
- #
55
- # <a href="http://my.website/article-permalink#disqus_thread">View Comments</a>
56
- # <a href="http://my.website/different-permalink#disqus_thread">View Comments</a>
57
- # Options:
58
- # * <tt>account:</tt> Your Discus account (required).
59
- def comment_counts(opts = {})
60
- opts = Disqus::defaults.merge(opts)
61
- validate_opts!(opts)
62
- s = <<-WHIMPER
63
- <script type="text/javascript">
64
- //<![CDATA[
65
- (function() {
66
- var links = document.getElementsByTagName('a');
67
- var query = '?';
68
- for(var i = 0; i < links.length; i++) {
69
- if(links[i].href.indexOf('#disqus_thread') >= 0) {
70
- query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
71
- }
50
+ # Loads Javascript to show the number of comments for the page.
51
+ #
52
+ # The Javascript sets the inner html to the comment count for any links
53
+ # on the page that have the anchor "disqus_thread". For example, "View
54
+ # Comments" below would be replaced by "1 comment" or "23 comments" etc.
55
+ #
56
+ # <a href="http://my.website/article-permalink#disqus_thread">View Comments</a>
57
+ # <a href="http://my.website/different-permalink#disqus_thread">View Comments</a>
58
+ # Options:
59
+ # * <tt>account:</tt> Your Discus account (required).
60
+ def comment_counts(opts = {})
61
+ opts = Disqus::defaults.merge(opts)
62
+ validate_opts!(opts)
63
+ s = <<-WHIMPER
64
+ <script type="text/javascript">
65
+ //<![CDATA[
66
+ (function() {
67
+ var links = document.getElementsByTagName('a');
68
+ var query = '?';
69
+ for(var i = 0; i < links.length; i++) {
70
+ if(links[i].href.indexOf('#disqus_thread') >= 0) {
71
+ query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
72
72
  }
73
- document.write('<' + 'script type="text/javascript" src="#{ROOT_PATH}get_num_replies.js' + query + '"></' + 'script>');
74
- })();
75
- //]]>
76
- </script>
77
- WHIMPER
78
- s % opts[:account]
79
- end
73
+ }
74
+ document.write('<' + 'script type="text/javascript" src="#{ROOT_PATH}get_num_replies.js' + query + '"></' + 'script>');
75
+ })();
76
+ //]]>
77
+ </script>
78
+ WHIMPER
79
+ s % opts[:account]
80
+ end
80
81
 
81
- # Show the top commenters Disqus thread widget.
82
- # Options:
83
- # * <tt>account:</tt> Your Discus account (required).
84
- # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
85
- # * <tt>show_powered_by:</tt> Show or hide the powered by Disqus text.
86
- # * <tt>num_items:</tt>: How many items to show.
87
- # * <tt>hide_mods:</tt> Don't show moderators.
88
- # * <tt>hide_avatars:</tt> Don't show avatars.
89
- # * <tt>avatar_size:</tt> Avatar size.
90
- def top_commenters(opts = {})
91
- opts = Disqus::defaults.merge(opts)
92
- opts[:header] ||= '<h2 class="dsq-widget-title">Top Commenters</h2>'
93
- validate_opts!(opts)
94
- s = '<div id="dsq-topcommenters" class="dsq-widget">'
95
- s << opts[:header]
96
- s << '<script type="text/javascript" src="'
97
- s << TOP
98
- s << '&hide_avatars=1' if opts[:hide_avatars]
99
- s << '&hide_mods=1' if opts[:hide_mods]
100
- s << '"></script>'
101
- s << '</div>'
102
- if opts[:show_powered_by]
103
- s << '<a href="http://disqus.com">Powered by Disqus</a>'
104
- end
105
- s % [opts[:account], opts[:num_items], opts[:avatar_size], opts[:orientation]]
82
+ # Show the top commenters Disqus thread widget.
83
+ # Options:
84
+ # * <tt>account:</tt> Your Discus account (required).
85
+ # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
86
+ # * <tt>show_powered_by:</tt> Show or hide the powered by Disqus text.
87
+ # * <tt>num_items:</tt>: How many items to show.
88
+ # * <tt>hide_mods:</tt> Don't show moderators.
89
+ # * <tt>hide_avatars:</tt> Don't show avatars.
90
+ # * <tt>avatar_size:</tt> Avatar size.
91
+ def top_commenters(opts = {})
92
+ opts = Disqus::defaults.merge(opts)
93
+ opts[:header] ||= '<h2 class="dsq-widget-title">Top Commenters</h2>'
94
+ validate_opts!(opts)
95
+ s = '<div id="dsq-topcommenters" class="dsq-widget">'
96
+ s << opts[:header]
97
+ s << '<script type="text/javascript" src="'
98
+ s << TOP
99
+ s << '&hide_avatars=1' if opts[:hide_avatars]
100
+ s << '&hide_mods=1' if opts[:hide_mods]
101
+ s << '"></script>'
102
+ s << '</div>'
103
+ if opts[:show_powered_by]
104
+ s << '<a href="http://disqus.com">Powered by Disqus</a>'
106
105
  end
106
+ s % [opts[:account], opts[:num_items], opts[:avatar_size], opts[:orientation]]
107
+ end
107
108
 
108
- # Show the popular threads Disqus widget.
109
- # Options:
110
- # * <tt>account:</tt> Your Discus account (required).
111
- # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
112
- # * <tt>num_items:</tt>: How many items to show.
113
- # * <tt>hide_mods:</tt> Don't show moderators.
114
- def popular_threads(opts = {})
115
- opts = Disqus::defaults.merge(opts)
116
- opts[:header] ||= '<h2 class="dsq-widget-title">Popular Threads</h2>'
117
- validate_opts!(opts)
118
- s = '<div id="dsq-popthreads" class="dsq-widget">'
119
- s << opts[:header]
120
- s << '<script type="text/javascript" src="'
121
- s << POPULAR
122
- s << '&hide_mods=1' if opts[:hide_mods]
123
- s << '"></script>'
124
- s << '</div>'
125
- s << '<a href="http://disqus.com">Powered by Disqus</a>' if opts[:show_powered_by]
126
- s % [opts[:account], opts[:num_items]]
127
- end
128
-
129
- # Show the recent comments Disqus widget.
130
- # Options:
131
- # * <tt>account:</tt> Your Discus account (required).
132
- # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
133
- # * <tt>num_items:</tt>: How many items to show.
134
- # * <tt>hide_avatars:</tt> Don't show avatars.
135
- # * <tt>avatar_size:</tt> Avatar size.
136
- def recent_comments(opts = {})
137
- opts = Disqus::defaults.merge(opts)
138
- opts[:header] ||= '<h2 class="dsq-widget-title">Recent Comments</h2>'
139
- validate_opts!(opts)
140
- s = '<div id="dsq-recentcomments" class="dsq-widget">'
141
- s << opts[:header]
142
- s << '<script type="text/javascript" src="'
143
- s << RECENT
144
- s << '&hide_avatars=1' if opts[:hide_avatars]
145
- s << '"></script>'
146
- s << '</div>'
147
- if opts[:show_powered_by]
148
- s << '<a href="http://disqus.com">Powered by Disqus</a>'
149
- end
150
- s % [opts[:account], opts[:num_items], opts[:avatar_size]]
151
- end
109
+ # Show the popular threads Disqus widget.
110
+ # Options:
111
+ # * <tt>account:</tt> Your Discus account (required).
112
+ # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
113
+ # * <tt>num_items:</tt>: How many items to show.
114
+ # * <tt>hide_mods:</tt> Don't show moderators.
115
+ def popular_threads(opts = {})
116
+ opts = Disqus::defaults.merge(opts)
117
+ opts[:header] ||= '<h2 class="dsq-widget-title">Popular Threads</h2>'
118
+ validate_opts!(opts)
119
+ s = '<div id="dsq-popthreads" class="dsq-widget">'
120
+ s << opts[:header]
121
+ s << '<script type="text/javascript" src="'
122
+ s << POPULAR
123
+ s << '&hide_mods=1' if opts[:hide_mods]
124
+ s << '"></script>'
125
+ s << '</div>'
126
+ s << '<a href="http://disqus.com">Powered by Disqus</a>' if opts[:show_powered_by]
127
+ s % [opts[:account], opts[:num_items]]
128
+ end
152
129
 
153
- # Show the Disqus combo widget. This is a three-tabbed box with links
154
- # popular threads, top posters, and recent threads.
155
- # Options:
156
- # * <tt>:account:</tt> Your Discus account (required).
157
- # * <tt>:num_items:</tt> How many items to show.
158
- # * <tt>:hide_mods:</tt> Don't show moderators.
159
- # * <tt>:default_tab:</tt> Should be 'people', 'recent', or 'popular'.
160
- def combo(opts = {})
161
- opts = Disqus::defaults.merge(opts)
162
- validate_opts!(opts)
163
- s = '<script type="text/javascript" src="'
164
- s << COMBO
165
- s << '&hide_mods=1' if opts[:hide_mods]
166
- s << '"></script>'
167
- s % [opts[:account], opts[:num_items], opts[:color], opts[:default_tab]]
130
+ # Show the recent comments Disqus widget.
131
+ # Options:
132
+ # * <tt>account:</tt> Your Discus account (required).
133
+ # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
134
+ # * <tt>num_items:</tt>: How many items to show.
135
+ # * <tt>hide_avatars:</tt> Don't show avatars.
136
+ # * <tt>avatar_size:</tt> Avatar size.
137
+ def recent_comments(opts = {})
138
+ opts = Disqus::defaults.merge(opts)
139
+ opts[:header] ||= '<h2 class="dsq-widget-title">Recent Comments</h2>'
140
+ validate_opts!(opts)
141
+ s = '<div id="dsq-recentcomments" class="dsq-widget">'
142
+ s << opts[:header]
143
+ s << '<script type="text/javascript" src="'
144
+ s << RECENT
145
+ s << '&hide_avatars=1' if opts[:hide_avatars]
146
+ s << '"></script>'
147
+ s << '</div>'
148
+ if opts[:show_powered_by]
149
+ s << '<a href="http://disqus.com">Powered by Disqus</a>'
168
150
  end
151
+ s % [opts[:account], opts[:num_items], opts[:avatar_size]]
152
+ end
169
153
 
170
- private
171
-
172
- def validate_opts!(opts)
173
- raise ArgumentError.new("You must specify an :account") if !opts[:account]
174
- raise ArgumentError.new("Invalid color") if opts[:color] && !VALID_COLORS.include?(opts[:color])
175
- raise ArgumentError.new("Invalid num_items") if opts[:num_items] && !VALID_NUM_ITEMS.include?(opts[:num_items])
176
- raise ArgumentError.new("Invalid default_tab") if opts[:default_tab] && !VALID_DEFAULT_TABS.include?(opts[:default_tab])
177
- raise ArgumentError.new("Invalid avatar size") if opts[:avatar_size] && !VALID_AVATAR_SIZES.include?(opts[:avatar_size])
178
- raise ArgumentError.new("Invalid orientation") if opts[:orientation] && !VALID_ORIENTATIONS.include?(opts[:orientation])
179
- end
154
+ # Show the Disqus combo widget. This is a three-tabbed box with links
155
+ # popular threads, top posters, and recent threads.
156
+ # Options:
157
+ # * <tt>:account:</tt> Your Discus account (required).
158
+ # * <tt>:num_items:</tt> How many items to show.
159
+ # * <tt>:hide_mods:</tt> Don't show moderators.
160
+ # * <tt>:default_tab:</tt> Should be 'people', 'recent', or 'popular'.
161
+ def combo(opts = {})
162
+ opts = Disqus::defaults.merge(opts)
163
+ validate_opts!(opts)
164
+ s = '<script type="text/javascript" src="'
165
+ s << COMBO
166
+ s << '&hide_mods=1' if opts[:hide_mods]
167
+ s << '"></script>'
168
+ s % [opts[:account], opts[:num_items], opts[:color], opts[:default_tab]]
169
+ end
170
+
171
+ private
172
+
173
+ def validate_opts!(opts)
174
+ raise ArgumentError.new("You must specify an :account") if !opts[:account]
175
+ raise ArgumentError.new("Invalid color") if opts[:color] && !VALID_COLORS.include?(opts[:color])
176
+ raise ArgumentError.new("Invalid num_items") if opts[:num_items] && !VALID_NUM_ITEMS.include?(opts[:num_items])
177
+ raise ArgumentError.new("Invalid default_tab") if opts[:default_tab] && !VALID_DEFAULT_TABS.include?(opts[:default_tab])
178
+ raise ArgumentError.new("Invalid avatar size") if opts[:avatar_size] && !VALID_AVATAR_SIZES.include?(opts[:avatar_size])
179
+ raise ArgumentError.new("Invalid orientation") if opts[:orientation] && !VALID_ORIENTATIONS.include?(opts[:orientation])
180
180
  end
181
181
  end
182
182
  end
@@ -20,21 +20,14 @@ module Faraday
20
20
  private
21
21
 
22
22
  def error_message(env)
23
- "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
23
+ "#{env[:method].to_s.upcase} #{env[:url].to_s}: (#{env[:status]}) #{error_body(env[:body])}"
24
24
  end
25
25
 
26
26
  def error_body(body)
27
- if body.nil?
27
+ if body['code'] && body['response']
28
+ "Disqus Error #{body['code']}: #{body['response']}"
29
+ else
28
30
  nil
29
- elsif body['error']
30
- ": #{body['error']}"
31
- elsif body['errors']
32
- first = body['errors'].to_a.first
33
- if first.kind_of? Hash
34
- ": #{first['message'].chomp}"
35
- else
36
- ": #{first.chomp}"
37
- end
38
31
  end
39
32
  end
40
33
  end
@@ -0,0 +1,76 @@
1
+ require 'helper'
2
+
3
+ describe Disqussion::Categories do
4
+ Disqussion::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = Disqussion::Client.categories
8
+ end
9
+
10
+ describe ".creates" do
11
+ before do
12
+ stub_post("categories/create.json", :body => { :forum => "the88", :title => "My category" }).
13
+ to_return(:body => fixture("categories/create.json"), :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "returns new category infos." do
17
+ @client.create("the88", "My category")
18
+ a_post("categories/create.json", :body => { :forum => "the88", :title => "My category" }).
19
+ should have_been_made
20
+ end
21
+ end
22
+
23
+ describe ".details" do
24
+ before do
25
+ stub_get("categories/details.json", :query => { :category => "827231" }).
26
+ to_return(:body => fixture("categories/details.json"), :headers => {:content_type => "application/json; charset=utf-8"})
27
+ end
28
+
29
+ it "returns details on the requested forum." do
30
+ @client.details(827231)
31
+ a_get("categories/details.json", :query => { :category => "827231" }).
32
+ should have_been_made
33
+ end
34
+ end
35
+
36
+ describe ".list" do
37
+ before do
38
+ stub_get("categories/list.json", :query => { :forum => "the88" }).
39
+ to_return(:body => fixture("categories/list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
40
+ end
41
+
42
+ it "returns a list of categories within a forum." do
43
+ @client.list(:forum => "the88")
44
+ a_get("categories/list.json", :query => { :forum => "the88" }).
45
+ should have_been_made
46
+ end
47
+ end
48
+
49
+ describe ".listPosts" do
50
+ before do
51
+ stub_get("categories/listPosts.json", :query => { :category => "827231" }).
52
+ to_return(:body => fixture("categories/listPosts.json"), :headers => {:content_type => "application/json; charset=utf-8"})
53
+ end
54
+
55
+ it "returns a list of posts within a category." do
56
+ @client.listPosts(827231)
57
+ a_get("categories/listPosts.json", :query => { :category => "827231" }).
58
+ should have_been_made
59
+ end
60
+ end
61
+
62
+ describe ".listThreads" do
63
+ before do
64
+ stub_get("categories/listThreads.json", :query => { :category => "827231" }).
65
+ to_return(:body => fixture("categories/listThreads.json"), :headers => {:content_type => "application/json; charset=utf-8"})
66
+ end
67
+
68
+ it "returns a list of threads within a category sorted by the date created." do
69
+ @client.listThreads(827231)
70
+ a_get("categories/listThreads.json", :query => { :category => "827231" }).
71
+ should have_been_made
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,24 @@
1
+ require 'helper'
2
+
3
+ describe Disqussion::Exports do
4
+ Disqussion::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = Disqussion::Client.exports
8
+ end
9
+
10
+ describe ".create" do
11
+ before do
12
+ stub_post("exports/exportForum.json", :body => { :forum => "the88" }).
13
+ to_return(:body => fixture("exports/exportForum.json"), :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "exports a forum." do
17
+ @client.exportForum("the88")
18
+ a_post("exports/exportForum.json", :body => { :forum => "the88" }).
19
+ should have_been_made
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ describe Disqussion::Imports do
4
+ Disqussion::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = Disqussion::Client.imports
8
+ end
9
+
10
+ describe ".details" do
11
+ before do
12
+ stub_get("imports/details.json", :query => { :group => "987" }).
13
+ to_return(:body => fixture("imports/details.json"), :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "returns ." do
17
+ @client.details(987)
18
+ a_get("imports/details.json", :query => { :group => "987" }).
19
+ should have_been_made
20
+ end
21
+ end
22
+
23
+ describe ".list" do
24
+ before do
25
+ stub_get("imports/list.json", :query => { :forum => "the88" }).
26
+ to_return(:body => fixture("imports/list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
27
+ end
28
+
29
+ it "returns ." do
30
+ @client.list("the88")
31
+ a_get("imports/list.json", :query => { :forum => "the88" }).
32
+ should have_been_made
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+
3
+ describe Disqussion::Reports do
4
+ Disqussion::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = Disqussion::Client.reports
8
+ end
9
+
10
+ describe ".domains" do
11
+ before do
12
+ stub_get("reports/domains.json", :query => { }).
13
+ to_return(:body => fixture("reports/domains.json"), :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "returns report on domains." do
17
+ @client.domains
18
+ a_get("reports/domains.json", :query => { }).
19
+ should have_been_made
20
+ end
21
+ end
22
+
23
+ describe ".ips" do
24
+ before do
25
+ stub_get("reports/ips.json", :query => { }).
26
+ to_return(:body => fixture("reports/ips.json"), :headers => {:content_type => "application/json; charset=utf-8"})
27
+ end
28
+
29
+ it "returns report on ips." do
30
+ @client.ips
31
+ a_get("reports/ips.json", :query => { }).
32
+ should have_been_made
33
+ end
34
+ end
35
+
36
+ describe ".threads" do
37
+ before do
38
+ stub_get("reports/threads.json", :query => { }).
39
+ to_return(:body => fixture("reports/threads.json"), :headers => {:content_type => "application/json; charset=utf-8"})
40
+ end
41
+
42
+ it "returns report on threads." do
43
+ @client.threads
44
+ a_get("reports/threads.json", :query => { }).
45
+ should have_been_made
46
+ end
47
+ end
48
+
49
+ describe ".users" do
50
+ before do
51
+ stub_get("reports/users.json", :query => { }).
52
+ to_return(:body => fixture("reports/users.json"), :headers => {:content_type => "application/json; charset=utf-8"})
53
+ end
54
+
55
+ it "returns report on users." do
56
+ @client.users
57
+ a_get("reports/users.json", :query => { }).
58
+ should have_been_made
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -16,13 +16,12 @@ describe Faraday::Response do
16
16
 
17
17
  before do
18
18
  stub_get('users/details.json').
19
- with(:query => {:"user:username" => 'the88'}).
20
- to_return(:status => status)
19
+ to_return(:status => status, :body => fixture("faraday/error2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
21
20
  end
22
21
 
23
22
  it "should raise #{exception.name} error" do
24
23
  lambda do
25
- @client.details('the88')
24
+ @client.details
26
25
  end.should raise_error(exception)
27
26
  end
28
27
  end
@@ -0,0 +1,10 @@
1
+ {
2
+ "code": 0,
3
+ "response": {
4
+ "id": "827231",
5
+ "forum": "the88",
6
+ "order": 0,
7
+ "isDefault": false,
8
+ "title": "My category"
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "code": 0,
3
+ "response": {
4
+ "id": "827231",
5
+ "forum": "the88",
6
+ "order": 0,
7
+ "isDefault": false,
8
+ "title": "My category"
9
+ }
10
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "cursor": {
3
+ "prev": null,
4
+ "hasNext": false,
5
+ "next": "808233:0:0",
6
+ "hasPrev": false,
7
+ "total": null,
8
+ "id": "808233:0:0",
9
+ "more": false
10
+ },
11
+ "code": 0,
12
+ "response": [
13
+ {
14
+ "id": "595772",
15
+ "forum": "the88",
16
+ "order": 0,
17
+ "isDefault": true,
18
+ "title": "General"
19
+ }
20
+ ]
21
+ }