disqus_rails 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'yaml'
6
+ require 'active_support/core_ext/hash'
7
+ require 'active_support/core_ext/string'
8
+
9
+ module DisqusRails
10
+ module Api
11
+ requests = ActiveSupport::HashWithIndifferentAccess.new YAML::load(File.open(File.join(File.dirname(__FILE__), "api.yml")))
12
+
13
+ requests.each do |section_name, section|
14
+ const = const_set(section_name, Class.new)
15
+
16
+ section.each do |method_name, method|
17
+ const.define_singleton_method(method_name) do |*arguments|
18
+ arguments[0] ||= {}
19
+
20
+ method[:params][:required].each do |required_method_name|
21
+ unless arguments[0].has_key?(required_method_name.to_sym)
22
+ raise "Required parameter '#{required_method_name}' not passed to DisqusRails::Api::#{section_name}.#{method_name}"
23
+ end
24
+ end
25
+
26
+ unless (unknown_params = arguments[0].stringify_keys!.keys - (method[:params][:required] + method[:params][:optional])).empty?
27
+ raise "Unknown #{"param".pluralize unknown_params.size} '#{unknown_params.join " "}' passed to DisqusRails::Api::#{section_name}.#{method_name}"
28
+ end
29
+
30
+ arguments[0][:api_key] = PUBLIC_KEY
31
+ if method[:requires_authentication]
32
+ arguments[0][:access_token] = ACCESS_TOKEN
33
+ end
34
+ response = DisqusRails::Api.send method[:method].downcase, arguments[0], method[:url]
35
+
36
+ arguments[0].delete(:api_key)
37
+ arguments[0].delete(:access_token)
38
+
39
+ response
40
+ end
41
+ end
42
+ end
43
+
44
+ class << self
45
+
46
+ def parse_response(response)
47
+ if response[:code] > 0
48
+ raise "Error, Disqus responsed with code #{response[:code]} - #{response[:response]}"
49
+ else
50
+ response.delete(:code)
51
+ response
52
+ end
53
+ end
54
+
55
+ def get(args, url)
56
+ populated_url = url + '?'
57
+ args.each{ |k, v| populated_url += "#{k}=#{v}&" }
58
+ url.chomp('&')
59
+
60
+ parse_response JSON.parse( open(populated_url){ |u| u.read } ).symbolize_keys
61
+ end
62
+
63
+ def post(args, url)
64
+ uri = URI.parse(url)
65
+ http = Net::HTTP.new(uri.host, uri.port)
66
+ http.use_ssl = true
67
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
68
+
69
+ request = Net::HTTP::Post.new(url)
70
+ request.add_field('Content-Type', 'application/json')
71
+ params_string = args.inject(""){|params_string, (param_name, param_value)| params_string += "#{param_name}=#{param_value}&" }
72
+ request.body = params_string
73
+
74
+ parse_response JSON.parse(http.request(request).body).symbolize_keys
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,855 @@
1
+ ---
2
+ Applications:
3
+ listUsage:
4
+ params:
5
+ required: []
6
+ optional:
7
+ - application
8
+ - days
9
+ requires_authentication: true
10
+ url: https://disqus.com/api/3.0/applications/listUsage.json
11
+ method: GET
12
+ Blacklists:
13
+ add:
14
+ params:
15
+ required:
16
+ - forum
17
+ optional:
18
+ - domain
19
+ - word
20
+ - retroactive
21
+ - notes
22
+ - ip
23
+ - user
24
+ - email
25
+ requires_authentication: true
26
+ url: https://disqus.com/api/3.0/blacklists/add.json
27
+ method: POST
28
+ list:
29
+ params:
30
+ required:
31
+ - forum
32
+ optional:
33
+ - since
34
+ - related
35
+ - cursor
36
+ - limit
37
+ - since_id
38
+ - query
39
+ - type
40
+ - order
41
+ requires_authentication: true
42
+ url: https://disqus.com/api/3.0/blacklists/list.json
43
+ method: GET
44
+ remove:
45
+ params:
46
+ required:
47
+ - forum
48
+ optional:
49
+ - domain
50
+ - word
51
+ - ip
52
+ - user
53
+ - email
54
+ requires_authentication: true
55
+ url: https://disqus.com/api/3.0/blacklists/remove.json
56
+ method: POST
57
+ Categories:
58
+ create:
59
+ params:
60
+ required:
61
+ - forum
62
+ - title
63
+ optional:
64
+ - default
65
+ requires_authentication: true
66
+ url: https://disqus.com/api/3.0/categories/create.json
67
+ method: POST
68
+ details:
69
+ params:
70
+ required:
71
+ - category
72
+ optional: []
73
+ requires_authentication: false
74
+ url: https://disqus.com/api/3.0/categories/details.json
75
+ method: GET
76
+ list:
77
+ params:
78
+ required: []
79
+ optional:
80
+ - forum
81
+ - since_id
82
+ - cursor
83
+ - limit
84
+ - order
85
+ requires_authentication: false
86
+ url: https://disqus.com/api/3.0/categories/list.json
87
+ method: GET
88
+ listPosts:
89
+ params:
90
+ required:
91
+ - category
92
+ optional:
93
+ - since
94
+ - related
95
+ - cursor
96
+ - limit
97
+ - query
98
+ - include
99
+ - order
100
+ requires_authentication: false
101
+ url: https://disqus.com/api/3.0/categories/listPosts.json
102
+ method: GET
103
+ listThreads:
104
+ params:
105
+ required:
106
+ - category
107
+ optional:
108
+ - since
109
+ - related
110
+ - cursor
111
+ - limit
112
+ - order
113
+ requires_authentication: false
114
+ url: https://disqus.com/api/3.0/categories/listThreads.json
115
+ method: GET
116
+ Discovery:
117
+ listAds:
118
+ params:
119
+ required: []
120
+ optional:
121
+ - active
122
+ requires_authentication: false
123
+ url: https://disqus.com/api/3.0/discovery/listAds.json
124
+ method: GET
125
+ Exports:
126
+ exportForum:
127
+ params:
128
+ required:
129
+ - forum
130
+ optional:
131
+ - format
132
+ requires_authentication: true
133
+ url: https://disqus.com/api/3.0/exports/exportForum.json
134
+ method: POST
135
+ Forums:
136
+ addModerator:
137
+ params:
138
+ required:
139
+ - user
140
+ - forum
141
+ optional: []
142
+ requires_authentication: true
143
+ url: https://disqus.com/api/3.0/forums/addModerator.json
144
+ method: POST
145
+ create:
146
+ params:
147
+ required:
148
+ - website
149
+ - name
150
+ - short_name
151
+ optional: []
152
+ requires_authentication: true
153
+ url: https://disqus.com/api/3.0/forums/create.json
154
+ method: POST
155
+ details:
156
+ params:
157
+ required:
158
+ - forum
159
+ optional:
160
+ - related
161
+ requires_authentication: false
162
+ url: https://disqus.com/api/3.0/forums/details.json
163
+ method: GET
164
+ listCategories:
165
+ params:
166
+ required:
167
+ - forum
168
+ optional:
169
+ - since_id
170
+ - cursor
171
+ - limit
172
+ - order
173
+ requires_authentication: false
174
+ url: https://disqus.com/api/3.0/forums/listCategories.json
175
+ method: GET
176
+ listModerators:
177
+ params:
178
+ required:
179
+ - forum
180
+ optional: []
181
+ requires_authentication: true
182
+ url: https://disqus.com/api/3.0/forums/listModerators.json
183
+ method: GET
184
+ listMostActiveUsers:
185
+ params:
186
+ required:
187
+ - forum
188
+ optional:
189
+ - cursor
190
+ - limit
191
+ - order
192
+ requires_authentication: false
193
+ url: https://disqus.com/api/3.0/forums/listMostActiveUsers.json
194
+ method: GET
195
+ listMostLikedUsers:
196
+ params:
197
+ required:
198
+ - forum
199
+ optional:
200
+ - cursor
201
+ - limit
202
+ - order
203
+ requires_authentication: false
204
+ url: https://disqus.com/api/3.0/forums/listMostLikedUsers.json
205
+ method: GET
206
+ listPosts:
207
+ params:
208
+ required:
209
+ - forum
210
+ optional:
211
+ - since
212
+ - related
213
+ - cursor
214
+ - limit
215
+ - query
216
+ - include
217
+ - order
218
+ requires_authentication: false
219
+ url: https://disqus.com/api/3.0/forums/listPosts.json
220
+ method: GET
221
+ listThreads:
222
+ params:
223
+ required:
224
+ - forum
225
+ optional:
226
+ - thread
227
+ - since
228
+ - related
229
+ - cursor
230
+ - limit
231
+ - include
232
+ - order
233
+ requires_authentication: false
234
+ url: https://disqus.com/api/3.0/forums/listThreads.json
235
+ method: GET
236
+ listUsers:
237
+ params:
238
+ required:
239
+ - forum
240
+ optional:
241
+ - since_id
242
+ - cursor
243
+ - limit
244
+ - order
245
+ requires_authentication: false
246
+ url: https://disqus.com/api/3.0/forums/listUsers.json
247
+ method: GET
248
+ removeModerator:
249
+ params:
250
+ required:
251
+ - moderator
252
+ optional: []
253
+ requires_authentication: true
254
+ url: https://disqus.com/api/3.0/forums/removeModerator.json
255
+ method: POST
256
+ Imports:
257
+ details:
258
+ params:
259
+ required:
260
+ - group
261
+ - forum
262
+ optional: []
263
+ requires_authentication: true
264
+ url: https://disqus.com/api/3.0/imports/details.json
265
+ method: GET
266
+ list:
267
+ params:
268
+ required:
269
+ - forum
270
+ optional:
271
+ - cursor
272
+ requires_authentication: true
273
+ url: https://disqus.com/api/3.0/imports/list.json
274
+ method: GET
275
+ Posts:
276
+ approve:
277
+ params:
278
+ required:
279
+ - post
280
+ optional: []
281
+ requires_authentication: true
282
+ url: https://disqus.com/api/3.0/posts/approve.json
283
+ method: POST
284
+ create:
285
+ params:
286
+ required:
287
+ - message
288
+ optional:
289
+ - parent
290
+ - thread
291
+ - author_email
292
+ - author_name
293
+ - state
294
+ - author_url
295
+ - date
296
+ - ip_address
297
+ requires_authentication: true
298
+ url: https://disqus.com/api/3.0/posts/create.json
299
+ method: POST
300
+ details:
301
+ params:
302
+ required:
303
+ - post
304
+ optional:
305
+ - related
306
+ requires_authentication: false
307
+ url: https://disqus.com/api/3.0/posts/details.json
308
+ method: GET
309
+ getContext:
310
+ params:
311
+ required:
312
+ - post
313
+ optional:
314
+ - depth
315
+ - related
316
+ requires_authentication: false
317
+ url: https://disqus.com/api/3.0/posts/getContext.json
318
+ method: GET
319
+ highlight:
320
+ params:
321
+ required:
322
+ - post
323
+ optional: []
324
+ requires_authentication: true
325
+ url: https://disqus.com/api/3.0/posts/highlight.json
326
+ method: POST
327
+ list:
328
+ params:
329
+ required: []
330
+ optional:
331
+ - category
332
+ - thread
333
+ - forum
334
+ - since
335
+ - related
336
+ - cursor
337
+ - limit
338
+ - offset
339
+ - query
340
+ - include
341
+ - order
342
+ requires_authentication: false
343
+ url: https://disqus.com/api/3.0/posts/list.json
344
+ method: GET
345
+ listPopular:
346
+ params:
347
+ required: []
348
+ optional:
349
+ - category
350
+ - interval
351
+ - thread
352
+ - forum
353
+ - since
354
+ - related
355
+ - limit
356
+ - offset
357
+ - query
358
+ - include
359
+ - order
360
+ requires_authentication: false
361
+ url: https://disqus.com/api/3.0/posts/listPopular.json
362
+ method: GET
363
+ remove:
364
+ params:
365
+ required:
366
+ - post
367
+ optional: []
368
+ requires_authentication: true
369
+ url: https://disqus.com/api/3.0/posts/remove.json
370
+ method: POST
371
+ report:
372
+ params:
373
+ required:
374
+ - post
375
+ optional: []
376
+ requires_authentication: false
377
+ url: https://disqus.com/api/3.0/posts/report.json
378
+ method: POST
379
+ restore:
380
+ params:
381
+ required:
382
+ - post
383
+ optional: []
384
+ requires_authentication: true
385
+ url: https://disqus.com/api/3.0/posts/restore.json
386
+ method: POST
387
+ spam:
388
+ params:
389
+ required:
390
+ - post
391
+ optional: []
392
+ requires_authentication: true
393
+ url: https://disqus.com/api/3.0/posts/spam.json
394
+ method: POST
395
+ unhighlight:
396
+ params:
397
+ required:
398
+ - post
399
+ optional: []
400
+ requires_authentication: true
401
+ url: https://disqus.com/api/3.0/posts/unhighlight.json
402
+ method: POST
403
+ update:
404
+ params:
405
+ required:
406
+ - message
407
+ - post
408
+ optional: []
409
+ requires_authentication: true
410
+ url: https://disqus.com/api/3.0/posts/update.json
411
+ method: POST
412
+ vote:
413
+ params:
414
+ required:
415
+ - vote
416
+ - post
417
+ optional: []
418
+ requires_authentication: false
419
+ url: https://disqus.com/api/3.0/posts/vote.json
420
+ method: POST
421
+ Reactions:
422
+ details:
423
+ params:
424
+ required:
425
+ - reaction
426
+ - forum
427
+ optional: []
428
+ requires_authentication: false
429
+ url: https://disqus.com/api/3.0/reactions/details.json
430
+ method: GET
431
+ list:
432
+ params:
433
+ required:
434
+ - forum
435
+ optional:
436
+ - since_id
437
+ - cursor
438
+ - limit
439
+ - related
440
+ - order
441
+ requires_authentication: false
442
+ url: https://disqus.com/api/3.0/reactions/list.json
443
+ method: POST, GET
444
+ remove:
445
+ params:
446
+ required:
447
+ - reaction
448
+ - forum
449
+ optional: []
450
+ requires_authentication: true
451
+ url: https://disqus.com/api/3.0/reactions/remove.json
452
+ method: POST
453
+ restore:
454
+ params:
455
+ required:
456
+ - reaction
457
+ - forum
458
+ optional: []
459
+ requires_authentication: true
460
+ url: https://disqus.com/api/3.0/reactions/restore.json
461
+ method: POST
462
+ Reports:
463
+ domains:
464
+ params:
465
+ required: []
466
+ optional:
467
+ - limit
468
+ - page
469
+ - forum
470
+ requires_authentication: false
471
+ url: https://disqus.com/api/3.0/reports/domains.json
472
+ method: GET
473
+ threads:
474
+ params:
475
+ required: []
476
+ optional:
477
+ - limit
478
+ - page
479
+ - forum
480
+ requires_authentication: false
481
+ url: https://disqus.com/api/3.0/reports/threads.json
482
+ method: GET
483
+ Threads:
484
+ close:
485
+ params:
486
+ required:
487
+ - thread
488
+ optional:
489
+ - forum
490
+ requires_authentication: true
491
+ url: https://disqus.com/api/3.0/threads/close.json
492
+ method: POST
493
+ create:
494
+ params:
495
+ required:
496
+ - forum
497
+ - title
498
+ optional:
499
+ - category
500
+ - url
501
+ - date
502
+ - message
503
+ - identifier
504
+ - slug
505
+ requires_authentication: true
506
+ url: https://disqus.com/api/3.0/threads/create.json
507
+ method: POST
508
+ details:
509
+ params:
510
+ required:
511
+ - thread
512
+ optional:
513
+ - related
514
+ - forum
515
+ requires_authentication: false
516
+ url: https://disqus.com/api/3.0/threads/details.json
517
+ method: GET
518
+ list:
519
+ params:
520
+ required: []
521
+ optional:
522
+ - category
523
+ - forum
524
+ - thread
525
+ - author
526
+ - since
527
+ - related
528
+ - cursor
529
+ - limit
530
+ - include
531
+ - order
532
+ - thread:ident
533
+ requires_authentication: false
534
+ url: https://disqus.com/api/3.0/threads/list.json
535
+ method: GET
536
+ listHot:
537
+ params:
538
+ required: []
539
+ optional:
540
+ - category
541
+ - forum
542
+ - author
543
+ - related
544
+ - limit
545
+ - include
546
+ requires_authentication: false
547
+ url: https://disqus.com/api/3.0/threads/listHot.json
548
+ method: GET
549
+ listPopular:
550
+ params:
551
+ required: []
552
+ optional:
553
+ - category
554
+ - interval
555
+ - forum
556
+ - author
557
+ - since
558
+ - related
559
+ - limit
560
+ - with_top_post
561
+ - include
562
+ requires_authentication: false
563
+ url: https://disqus.com/api/3.0/threads/listPopular.json
564
+ method: GET
565
+ listPosts:
566
+ params:
567
+ required:
568
+ - thread
569
+ optional:
570
+ - forum
571
+ - since
572
+ - related
573
+ - cursor
574
+ - limit
575
+ - query
576
+ - include
577
+ - order
578
+ requires_authentication: false
579
+ url: https://disqus.com/api/3.0/threads/listPosts.json
580
+ method: GET
581
+ listReactions:
582
+ params:
583
+ required:
584
+ - thread
585
+ optional:
586
+ - forum
587
+ - cursor
588
+ - limit
589
+ requires_authentication: false
590
+ url: https://disqus.com/api/3.0/threads/listReactions.json
591
+ method: GET
592
+ open:
593
+ params:
594
+ required:
595
+ - thread
596
+ optional:
597
+ - forum
598
+ requires_authentication: true
599
+ url: https://disqus.com/api/3.0/threads/open.json
600
+ method: POST
601
+ remove:
602
+ params:
603
+ required:
604
+ - thread
605
+ optional:
606
+ - forum
607
+ requires_authentication: true
608
+ url: https://disqus.com/api/3.0/threads/remove.json
609
+ method: POST
610
+ restore:
611
+ params:
612
+ required:
613
+ - thread
614
+ optional:
615
+ - forum
616
+ requires_authentication: true
617
+ url: https://disqus.com/api/3.0/threads/restore.json
618
+ method: POST
619
+ set:
620
+ params:
621
+ required:
622
+ - thread
623
+ optional:
624
+ - related
625
+ - forum
626
+ requires_authentication: false
627
+ url: https://disqus.com/api/3.0/threads/set.json
628
+ method: GET
629
+ subscribe:
630
+ params:
631
+ required:
632
+ - thread
633
+ optional:
634
+ - email
635
+ requires_authentication: true
636
+ url: https://disqus.com/api/3.0/threads/subscribe.json
637
+ method: POST
638
+ unsubscribe:
639
+ params:
640
+ required:
641
+ - thread
642
+ optional:
643
+ - email
644
+ requires_authentication: true
645
+ url: https://disqus.com/api/3.0/threads/unsubscribe.json
646
+ method: POST
647
+ update:
648
+ params:
649
+ required:
650
+ - thread
651
+ optional:
652
+ - category
653
+ - forum
654
+ - title
655
+ - url
656
+ - author
657
+ - message
658
+ - identifier
659
+ - slug
660
+ requires_authentication: true
661
+ url: https://disqus.com/api/3.0/threads/update.json
662
+ method: POST
663
+ vote:
664
+ params:
665
+ required:
666
+ - vote
667
+ - thread
668
+ optional:
669
+ - forum
670
+ requires_authentication: false
671
+ url: https://disqus.com/api/3.0/threads/vote.json
672
+ method: POST
673
+ Trends:
674
+ listThreads:
675
+ params:
676
+ required: []
677
+ optional:
678
+ - limit
679
+ - related
680
+ - forum
681
+ requires_authentication: false
682
+ url: https://disqus.com/api/3.0/trends/listThreads.json
683
+ method: GET
684
+ Users:
685
+ checkUsername:
686
+ params:
687
+ required: []
688
+ optional:
689
+ - username
690
+ requires_authentication: true
691
+ url: https://disqus.com/api/3.0/users/checkUsername.json
692
+ method: POST
693
+ details:
694
+ params:
695
+ required: []
696
+ optional:
697
+ - user
698
+ requires_authentication: false
699
+ url: https://disqus.com/api/3.0/users/details.json
700
+ method: GET
701
+ follow:
702
+ params:
703
+ required:
704
+ - target
705
+ optional: []
706
+ requires_authentication: true
707
+ url: https://disqus.com/api/3.0/users/follow.json
708
+ method: POST
709
+ listActiveForums:
710
+ params:
711
+ required: []
712
+ optional:
713
+ - since_id
714
+ - cursor
715
+ - limit
716
+ - user
717
+ - order
718
+ requires_authentication: false
719
+ url: https://disqus.com/api/3.0/users/listActiveForums.json
720
+ method: GET
721
+ listActiveThreads:
722
+ params:
723
+ required: []
724
+ optional:
725
+ - forum
726
+ - since
727
+ - related
728
+ - cursor
729
+ - limit
730
+ - user
731
+ - include
732
+ - order
733
+ requires_authentication: false
734
+ url: https://disqus.com/api/3.0/users/listActiveThreads.json
735
+ method: GET
736
+ listActivity:
737
+ params:
738
+ required: []
739
+ optional:
740
+ - since
741
+ - related
742
+ - cursor
743
+ - limit
744
+ - user
745
+ - query
746
+ - include
747
+ - anon_user
748
+ requires_authentication: false
749
+ url: https://disqus.com/api/3.0/users/listActivity.json
750
+ method: GET
751
+ listFollowers:
752
+ params:
753
+ required: []
754
+ optional:
755
+ - since_id
756
+ - cursor
757
+ - limit
758
+ - user
759
+ - order
760
+ requires_authentication: false
761
+ url: https://disqus.com/api/3.0/users/listFollowers.json
762
+ method: GET
763
+ listFollowing:
764
+ params:
765
+ required: []
766
+ optional:
767
+ - since_id
768
+ - cursor
769
+ - limit
770
+ - user
771
+ - order
772
+ requires_authentication: false
773
+ url: https://disqus.com/api/3.0/users/listFollowing.json
774
+ method: GET
775
+ listForums:
776
+ params:
777
+ required: []
778
+ optional:
779
+ - since_id
780
+ - cursor
781
+ - limit
782
+ - user
783
+ - order
784
+ requires_authentication: false
785
+ url: https://disqus.com/api/3.0/users/listForums.json
786
+ method: GET
787
+ listMostActiveForums:
788
+ params:
789
+ required: []
790
+ optional:
791
+ - limit
792
+ - user
793
+ requires_authentication: false
794
+ url: https://disqus.com/api/3.0/users/listMostActiveForums.json
795
+ method: GET
796
+ listPosts:
797
+ params:
798
+ required: []
799
+ optional:
800
+ - since
801
+ - related
802
+ - cursor
803
+ - limit
804
+ - user
805
+ - include
806
+ - order
807
+ requires_authentication: false
808
+ url: https://disqus.com/api/3.0/users/listPosts.json
809
+ method: GET
810
+ unfollow:
811
+ params:
812
+ required:
813
+ - target
814
+ optional: []
815
+ requires_authentication: true
816
+ url: https://disqus.com/api/3.0/users/unfollow.json
817
+ method: POST
818
+ Whitelists:
819
+ add:
820
+ params:
821
+ required:
822
+ - forum
823
+ optional:
824
+ - notes
825
+ - email
826
+ - user
827
+ requires_authentication: true
828
+ url: https://disqus.com/api/3.0/whitelists/add.json
829
+ method: POST
830
+ list:
831
+ params:
832
+ required:
833
+ - forum
834
+ optional:
835
+ - since
836
+ - related
837
+ - cursor
838
+ - limit
839
+ - since_id
840
+ - query
841
+ - type
842
+ - order
843
+ requires_authentication: true
844
+ url: https://disqus.com/api/3.0/whitelists/list.json
845
+ method: GET
846
+ remove:
847
+ params:
848
+ required:
849
+ - forum
850
+ optional:
851
+ - email
852
+ - user
853
+ requires_authentication: true
854
+ url: https://disqus.com/api/3.0/whitelists/remove.json
855
+ method: POST