redditkit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +22 -0
  3. data/README.md +155 -0
  4. data/Rakefile +8 -0
  5. data/lib/redditkit.rb +26 -0
  6. data/lib/redditkit/base.rb +60 -0
  7. data/lib/redditkit/client.rb +142 -0
  8. data/lib/redditkit/client/account.rb +73 -0
  9. data/lib/redditkit/client/apps.rb +63 -0
  10. data/lib/redditkit/client/captcha.rb +36 -0
  11. data/lib/redditkit/client/comments.rb +54 -0
  12. data/lib/redditkit/client/flair.rb +148 -0
  13. data/lib/redditkit/client/links.rb +134 -0
  14. data/lib/redditkit/client/miscellaneous.rb +50 -0
  15. data/lib/redditkit/client/moderation.rb +179 -0
  16. data/lib/redditkit/client/multireddits.rb +207 -0
  17. data/lib/redditkit/client/private_messages.rb +74 -0
  18. data/lib/redditkit/client/search.rb +25 -0
  19. data/lib/redditkit/client/subreddits.rb +120 -0
  20. data/lib/redditkit/client/users.rb +109 -0
  21. data/lib/redditkit/client/utilities.rb +137 -0
  22. data/lib/redditkit/client/voting.rb +41 -0
  23. data/lib/redditkit/client/wiki.rb +83 -0
  24. data/lib/redditkit/comment.rb +54 -0
  25. data/lib/redditkit/creatable.rb +17 -0
  26. data/lib/redditkit/error.rb +111 -0
  27. data/lib/redditkit/link.rb +140 -0
  28. data/lib/redditkit/moderator_action.rb +19 -0
  29. data/lib/redditkit/multireddit.rb +32 -0
  30. data/lib/redditkit/multireddit_description.rb +14 -0
  31. data/lib/redditkit/paginated_response.rb +22 -0
  32. data/lib/redditkit/private_message.rb +27 -0
  33. data/lib/redditkit/response/parse_json.rb +29 -0
  34. data/lib/redditkit/response/raise_error.rb +21 -0
  35. data/lib/redditkit/subreddit.rb +86 -0
  36. data/lib/redditkit/thing.rb +20 -0
  37. data/lib/redditkit/user.rb +30 -0
  38. data/lib/redditkit/version.rb +19 -0
  39. data/lib/redditkit/votable.rb +37 -0
  40. data/redditkit.gemspec +25 -0
  41. data/spec/cassettes/RedditKit_Client/should_raise_an_error_with_invalid_credentials.yml +39 -0
  42. data/spec/cassettes/RedditKit_Client_Account/_sign_in/signs_the_user_in.yml +132 -0
  43. data/spec/cassettes/RedditKit_Client_Account/_update_session/updates_the_current_session.yml +133 -0
  44. data/spec/cassettes/RedditKit_Client_Captcha/_captcha_url/returns_a_CAPTCHA_url_from_an_identifier.yml +38 -0
  45. data/spec/cassettes/RedditKit_Client_Captcha/_needs_captcha_/checks_if_the_current_account_needs_a_CAPTCHA.yml +44 -0
  46. data/spec/cassettes/RedditKit_Client_Captcha/_new_captcha_identifier/returns_a_new_CAPTCHA_identifier.yml +38 -0
  47. data/spec/cassettes/RedditKit_Client_Comments/_comment/requests_the_correct_resource.yml +47 -0
  48. data/spec/cassettes/RedditKit_Client_Comments/_comments/with_a_RedditKit_Link/returns_comments_on_a_link.yml +140 -0
  49. data/spec/cassettes/RedditKit_Client_Comments/_comments/with_a_link_identifier/returns_comments_on_a_link.yml +89 -0
  50. data/spec/cassettes/RedditKit_Client_Comments/_submit_comment/requests_the_correct_resource.yml +313 -0
  51. data/spec/cassettes/RedditKit_Client_Flair/_apply_flair_template/clears_flair_templates.yml +52 -0
  52. data/spec/cassettes/RedditKit_Client_Flair/_clear_flair_templates/clears_flair_templates.yml +49 -0
  53. data/spec/cassettes/RedditKit_Client_Flair/_create_flair_template/creates_a_flair_template.yml +46 -0
  54. data/spec/cassettes/RedditKit_Client_Flair/_create_flair_template/raises_InvalidClassName.yml +46 -0
  55. data/spec/cassettes/RedditKit_Client_Flair/_create_flair_template/raises_TooManyClassNames.yml +47 -0
  56. data/spec/cassettes/RedditKit_Client_Flair/_delete_user_flair/requests_the_correct_resource.yml +60 -0
  57. data/spec/cassettes/RedditKit_Client_Flair/_flair_list/returns_the_list_of_flair.yml +44 -0
  58. data/spec/cassettes/RedditKit_Client_Flair/_set_flair/requests_the_correct_resource.yml +49 -0
  59. data/spec/cassettes/RedditKit_Client_Flair/_set_flair_options/sets_flair_options.yml +49 -0
  60. data/spec/cassettes/RedditKit_Client_Flair/_set_flair_with_csv/requests_the_correct_resource.yml +51 -0
  61. data/spec/cassettes/RedditKit_Client_Flair/_toggle_flair/requests_the_correct_resource.yml +49 -0
  62. data/spec/cassettes/RedditKit_Client_Links/_front_page/requests_the_correct_category.yml +498 -0
  63. data/spec/cassettes/RedditKit_Client_Links/_front_page/requests_the_correct_resource.yml +603 -0
  64. data/spec/cassettes/RedditKit_Client_Links/_hide/requests_the_correct_resource.yml +46 -0
  65. data/spec/cassettes/RedditKit_Client_Links/_link/returns_a_link.yml +55 -0
  66. data/spec/cassettes/RedditKit_Client_Links/_links/contains_pagination_information.yml +402 -0
  67. data/spec/cassettes/RedditKit_Client_Links/_links/requests_a_certain_number_of_links.yml +186 -0
  68. data/spec/cassettes/RedditKit_Client_Links/_links/requests_front_page_links_if_no_subreddit_is_present.yml +603 -0
  69. data/spec/cassettes/RedditKit_Client_Links/_links/requests_links_with_the_correct_time_frame.yml +375 -0
  70. data/spec/cassettes/RedditKit_Client_Links/_links/requests_the_correct_subreddit_and_category.yml +402 -0
  71. data/spec/cassettes/RedditKit_Client_Links/_links_with_domain/returns_links_with_a_specific_domain.yml +99 -0
  72. data/spec/cassettes/RedditKit_Client_Links/_mark_nsfw/requests_the_correct_resource.yml +46 -0
  73. data/spec/cassettes/RedditKit_Client_Links/_random_link/returns_a_random_link.yml +91 -0
  74. data/spec/cassettes/RedditKit_Client_Links/_submit/raises_RedditKit_InvalidCaptcha_if_no_CAPTCHA_is_filled_out.yml +54 -0
  75. data/spec/cassettes/RedditKit_Client_Links/_unhide/requests_the_correct_resource.yml +46 -0
  76. data/spec/cassettes/RedditKit_Client_Links/_unmark_nsfw/requests_the_correct_resource.yml +46 -0
  77. data/spec/cassettes/RedditKit_Client_Miscellaneous/_delete/requests_the_correct_resource.yml +46 -0
  78. data/spec/cassettes/RedditKit_Client_Miscellaneous/_edit/requests_the_correct_resource.yml +52 -0
  79. data/spec/cassettes/RedditKit_Client_Miscellaneous/_save/saves_an_object.yml +46 -0
  80. data/spec/cassettes/RedditKit_Client_Miscellaneous/_unsave/unsaves_an_object.yml +89 -0
  81. data/spec/cassettes/RedditKit_Client_Moderation/_accept_moderator_invitation/requests_the_correct_resource.yml +53 -0
  82. data/spec/cassettes/RedditKit_Client_Moderation/_ban/requests_the_correct_resource.yml +103 -0
  83. data/spec/cassettes/RedditKit_Client_Moderation/_contributors_to_subreddit/requests_the_correct_resource.yml +47 -0
  84. data/spec/cassettes/RedditKit_Client_Moderation/_ignore_reports/requests_the_correct_resource.yml +46 -0
  85. data/spec/cassettes/RedditKit_Client_Moderation/_moderation_log/returns_RedditKit_ModeratorAction_objects.yml +153 -0
  86. data/spec/cassettes/RedditKit_Client_Moderation/_moderators_of_subreddit/requests_the_correct_resource.yml +48 -0
  87. data/spec/cassettes/RedditKit_Client_Moderation/_reset_subreddit_header/requests_the_correct_resource.yml +55 -0
  88. data/spec/cassettes/RedditKit_Client_Moderation/_set_contest_mode/requests_the_correct_resource.yml +46 -0
  89. data/spec/cassettes/RedditKit_Client_Moderation/_set_sticky_post/requests_the_correct_resource.yml +46 -0
  90. data/spec/cassettes/RedditKit_Client_Moderation/_unban/requests_the_correct_resource.yml +54 -0
  91. data/spec/cassettes/RedditKit_Client_Moderation/_unignore_reports/requests_the_correct_resource.yml +46 -0
  92. data/spec/cassettes/RedditKit_Client_Multireddits/_add_subreddit_to_multireddit/adds_a_subreddit_to_a_multireddit.yml +177 -0
  93. data/spec/cassettes/RedditKit_Client_Multireddits/_create_multireddit/creates_a_multireddit.yml +137 -0
  94. data/spec/cassettes/RedditKit_Client_Multireddits/_create_multireddit/raises_RedditKit_Conflict_when_using_an_existing_name.yml +133 -0
  95. data/spec/cassettes/RedditKit_Client_Multireddits/_delete_multireddit/deletes_a_multireddit.yml +134 -0
  96. data/spec/cassettes/RedditKit_Client_Multireddits/_multireddit/with_a_path/returns_a_multireddit.yml +39 -0
  97. data/spec/cassettes/RedditKit_Client_Multireddits/_multireddit/without_a_path/returns_a_multireddit.yml +39 -0
  98. data/spec/cassettes/RedditKit_Client_Multireddits/_multireddit_description/with_a_multireddit/returns_a_multireddit_description.yml +81 -0
  99. data/spec/cassettes/RedditKit_Client_Multireddits/_multireddit_description/with_a_username_and_multireddit_name/returns_a_multireddit_description.yml +45 -0
  100. data/spec/cassettes/RedditKit_Client_Multireddits/_my_multireddits/return_s_the_user_s_multireddits.yml +47 -0
  101. data/spec/cassettes/RedditKit_Client_Multireddits/_remove_subreddit_from_multireddit/removes_a_subreddit_from_a_multireddit.yml +175 -0
  102. data/spec/cassettes/RedditKit_Client_Multireddits/_rename_multireddit/renames_a_multireddit.yml +134 -0
  103. data/spec/cassettes/RedditKit_Client_Multireddits/_set_multireddit_description/returns_a_multireddit_description.yml +48 -0
  104. data/spec/cassettes/RedditKit_Client_Multireddits/_update_multireddit/updates_a_multireddit.yml +184 -0
  105. data/spec/cassettes/RedditKit_Client_PrivateMessages/_block_author_of_message/requests_the_correct_resource.yml +46 -0
  106. data/spec/cassettes/RedditKit_Client_PrivateMessages/_mark_as_read/requests_the_correct_resource.yml +51 -0
  107. data/spec/cassettes/RedditKit_Client_PrivateMessages/_mark_as_unread/requests_the_correct_resource.yml +51 -0
  108. data/spec/cassettes/RedditKit_Client_PrivateMessages/_messages/requests_the_correct_resource.yml +187 -0
  109. data/spec/cassettes/RedditKit_Client_PrivateMessages/_unblock/requests_the_correct_resource.yml +46 -0
  110. data/spec/cassettes/RedditKit_Client_Search/_search/restricts_searches_to_a_specific_subreddit.yml +878 -0
  111. data/spec/cassettes/RedditKit_Client_Search/_search/returns_a_specific_number_of_results.yml +130 -0
  112. data/spec/cassettes/RedditKit_Client_Search/_search/returns_search_results.yml +844 -0
  113. data/spec/cassettes/RedditKit_Client_Subreddits/_random_subreddit/returns_a_random_subreddit.yml +181 -0
  114. data/spec/cassettes/RedditKit_Client_Subreddits/_recommended_subreddits/returns_subreddit_names.yml +37 -0
  115. data/spec/cassettes/RedditKit_Client_Subreddits/_search_subreddits_by_name/returns_subreddit_names.yml +875 -0
  116. data/spec/cassettes/RedditKit_Client_Subreddits/_subreddit/returns_a_specified_subreddit.yml +100 -0
  117. data/spec/cassettes/RedditKit_Client_Subreddits/_subreddits/returns_a_specified_number_of_subreddits.yml +505 -0
  118. data/spec/cassettes/RedditKit_Client_Subreddits/_subreddits/returns_subreddits_from_a_specific_category.yml +510 -0
  119. data/spec/cassettes/RedditKit_Client_Subreddits/_subreddits_by_topic/returns_subreddit_names.yml +41 -0
  120. data/spec/cassettes/RedditKit_Client_Subreddits/_subscribe/requests_the_correct_resource.yml +46 -0
  121. data/spec/cassettes/RedditKit_Client_Subreddits/_subscribed_subreddits/returns_a_specified_number_of_subreddits.yml +415 -0
  122. data/spec/cassettes/RedditKit_Client_Subreddits/_subscribed_subreddits/returns_subreddits_from_a_specific_category.yml +58 -0
  123. data/spec/cassettes/RedditKit_Client_Subreddits/_subscribed_subreddits/returns_the_user_s_subscribed_subreddits.yml +3469 -0
  124. data/spec/cassettes/RedditKit_Client_Subreddits/_unsubscribe/requests_the_correct_resource.yml +46 -0
  125. data/spec/cassettes/RedditKit_Client_Users/_friends/returns_the_user_s_friends.yml +48 -0
  126. data/spec/cassettes/RedditKit_Client_Users/_my_content/returns_the_user_s_content.yml +60 -0
  127. data/spec/cassettes/RedditKit_Client_Users/_user/requests_the_correct_resource.yml +48 -0
  128. data/spec/cassettes/RedditKit_Client_Users/_user/returns_a_specified_user.yml +48 -0
  129. data/spec/cassettes/RedditKit_Client_Users/_user/returns_the_authenticated_user.yml +48 -0
  130. data/spec/cassettes/RedditKit_Client_Users/_user_content/returns_the_user_s_content.yml +41 -0
  131. data/spec/cassettes/RedditKit_Client_Users/_username_available_/returns_false_for_an_unavailable_username.yml +36 -0
  132. data/spec/cassettes/RedditKit_Client_Users/_username_available_/returns_true_for_an_available_username.yml +36 -0
  133. data/spec/cassettes/RedditKit_Client_Voting/_downvote/with_a_comment_full_name_passed/downvotes_the_comment.yml +100 -0
  134. data/spec/cassettes/RedditKit_Client_Voting/_downvote/with_a_comment_passed/downvotes_the_comment.yml +154 -0
  135. data/spec/cassettes/RedditKit_Client_Voting/_downvote/with_a_link_full_name_passed/downvotes_the_link.yml +106 -0
  136. data/spec/cassettes/RedditKit_Client_Voting/_downvote/with_a_link_passed/downvotes_the_link.yml +166 -0
  137. data/spec/cassettes/RedditKit_Client_Voting/_upvote/with_a_comment_full_name_passed/upvotes_the_comment.yml +100 -0
  138. data/spec/cassettes/RedditKit_Client_Voting/_upvote/with_a_comment_passed/upvotes_the_comment.yml +154 -0
  139. data/spec/cassettes/RedditKit_Client_Voting/_upvote/with_a_link_full_name_passed/upvotes_the_link.yml +106 -0
  140. data/spec/cassettes/RedditKit_Client_Voting/_upvote/with_a_link_passed/upvotes_the_link.yml +166 -0
  141. data/spec/cassettes/RedditKit_Client_Voting/_withdraw_vote/with_a_comment_full_name_passed/withdraws_the_vote_on_the_comment.yml +154 -0
  142. data/spec/cassettes/RedditKit_Client_Voting/_withdraw_vote/with_a_comment_passed/withdraws_the_vote_on_the_comment.yml +208 -0
  143. data/spec/cassettes/RedditKit_Client_Voting/_withdraw_vote/with_a_link_full_name_passed/withdraws_the_vote_on_the_link.yml +166 -0
  144. data/spec/cassettes/RedditKit_Client_Voting/_withdraw_vote/with_a_link_passed/withdraws_the_vote_on_the_link.yml +226 -0
  145. data/spec/cassettes/RedditKit_Client_Wiki/_add_wiki_editor/requests_the_correct_resource.yml +46 -0
  146. data/spec/cassettes/RedditKit_Client_Wiki/_edit_wiki_page/requests_the_correct_resource.yml +48 -0
  147. data/spec/cassettes/RedditKit_Client_Wiki/_hide_wiki_revision/requests_the_correct_resource.yml +46 -0
  148. data/spec/cassettes/RedditKit_Client_Wiki/_remove_wiki_editor/requests_the_correct_resource.yml +46 -0
  149. data/spec/cassettes/RedditKit_Client_Wiki/_revert_to_revision/requests_the_correct_resource.yml +46 -0
  150. data/spec/cassettes/RedditKit_Comment/should_not_be_deleted_if_neither_author_and_comment_attributes_are_set_to_deleted_.yml +90 -0
  151. data/spec/cassettes/RedditKit_Comment/should_return_replies.yml +90 -0
  152. data/spec/cassettes/authenticated_client.yml +87 -0
  153. data/spec/redditkit/base_spec.rb +45 -0
  154. data/spec/redditkit/client/account_spec.rb +50 -0
  155. data/spec/redditkit/client/apps_spec.rb +58 -0
  156. data/spec/redditkit/client/captcha_spec.rb +30 -0
  157. data/spec/redditkit/client/comments_spec.rb +40 -0
  158. data/spec/redditkit/client/flair_spec.rb +92 -0
  159. data/spec/redditkit/client/links_spec.rb +103 -0
  160. data/spec/redditkit/client/miscellaneous_spec.rb +40 -0
  161. data/spec/redditkit/client/moderation_spec.rb +141 -0
  162. data/spec/redditkit/client/multireddits_spec.rb +158 -0
  163. data/spec/redditkit/client/private_messages_spec.rb +51 -0
  164. data/spec/redditkit/client/search_spec.rb +25 -0
  165. data/spec/redditkit/client/subreddits_spec.rb +83 -0
  166. data/spec/redditkit/client/users_spec.rb +92 -0
  167. data/spec/redditkit/client/voting_spec.rb +99 -0
  168. data/spec/redditkit/client/wiki_spec.rb +40 -0
  169. data/spec/redditkit/client_spec.rb +46 -0
  170. data/spec/redditkit/comment_spec.rb +26 -0
  171. data/spec/redditkit/creatable_spec.rb +24 -0
  172. data/spec/redditkit/error_spec.rb +61 -0
  173. data/spec/redditkit/link_spec.rb +33 -0
  174. data/spec/redditkit/multireddit_spec.rb +27 -0
  175. data/spec/redditkit/paginated_response_spec.rb +23 -0
  176. data/spec/redditkit/thing_spec.rb +18 -0
  177. data/spec/redditkit/votable_spec.rb +52 -0
  178. data/spec/redditkit_spec.rb +21 -0
  179. data/spec/spec_helper.rb +124 -0
  180. metadata +390 -0
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Client::Users, :vcr do
4
+
5
+ describe "#user" do
6
+ it "requests the correct resource" do
7
+ authenticated_client.user
8
+ expect(a_request(:get, "#{ RedditKit.api_endpoint }api/me.json")).to have_been_made
9
+ end
10
+
11
+ it "returns a specified user" do
12
+ user = authenticated_client.user 'amberlynns'
13
+ expect(user.name).to eq 'amberlynns'
14
+ end
15
+
16
+ it "returns the authenticated user" do
17
+ user = authenticated_client.user
18
+ expect(user.name).to eq redditkit_username
19
+ end
20
+ end
21
+
22
+ describe "#my_content" do
23
+ it "returns the user's content" do
24
+ content = authenticated_client.my_content :category => :overview
25
+ expect(content).to_not be_nil
26
+ end
27
+ end
28
+
29
+ describe "#user_content" do
30
+ it "returns the user's content" do
31
+ content = RedditKit.user_content redditkit_username, :category => :overview
32
+ expect(content).to_not be_nil
33
+ end
34
+ end
35
+
36
+ describe "#friends" do
37
+ it "returns the user's friends" do
38
+ friends = authenticated_client.friends
39
+ expect(friends).to_not be_nil
40
+ end
41
+ end
42
+
43
+ describe "#friend" do
44
+ before do
45
+ stub_empty_post_request 'api/friend'
46
+ end
47
+
48
+ it "requests the correct resource" do
49
+ authenticated_client.friend 'username'
50
+ expect(a_post('api/friend')).to have_been_made
51
+ end
52
+ end
53
+
54
+ describe "#unfriend" do
55
+ before do
56
+ stub_empty_post_request 'api/unfriend'
57
+ end
58
+
59
+ it "requests the correct resource" do
60
+ authenticated_client.unfriend 'username'
61
+ expect(a_post('api/unfriend')).to have_been_made
62
+ end
63
+ end
64
+
65
+ describe "#username_available?" do
66
+ it "returns false for an unavailable username" do
67
+ client = RedditKit::Client.new
68
+ available = client.username_available? 'samsymons'
69
+
70
+ expect(available).to_not be_true
71
+ end
72
+
73
+ it "returns true for an available username" do
74
+ client = RedditKit::Client.new
75
+ available = client.username_available? 'available_user'
76
+
77
+ expect(available).to be_true
78
+ end
79
+ end
80
+
81
+ describe "#register" do
82
+ before do
83
+ stub_empty_post_request 'api/register'
84
+ end
85
+
86
+ it "requests the correct resource" do
87
+ RedditKit.register 'username', 'password'
88
+ expect(a_post('api/register')).to have_been_made
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Client::Voting do
4
+
5
+ describe "#upvote", :vcr do
6
+ context "with a comment full name passed" do
7
+ it "upvotes the comment" do
8
+ authenticated_client.upvote test_comment_full_name
9
+ expect(test_comment.upvoted?).to be_true
10
+ end
11
+ end
12
+
13
+ context "with a link full name passed" do
14
+ it "upvotes the link" do
15
+ authenticated_client.upvote test_link_full_name
16
+ expect(test_link.upvoted?).to be_true
17
+ end
18
+ end
19
+
20
+ context "with a comment passed" do
21
+ it "upvotes the comment" do
22
+ authenticated_client.upvote test_comment
23
+ expect(test_comment.upvoted?).to be_true
24
+ end
25
+ end
26
+
27
+ context "with a link passed" do
28
+ it "upvotes the link" do
29
+ authenticated_client.upvote test_link
30
+ expect(test_link.upvoted?).to be_true
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#downvote", :vcr do
36
+ context "with a comment full name passed" do
37
+ it "downvotes the comment" do
38
+ authenticated_client.downvote test_comment_full_name
39
+ expect(test_comment.downvoted?).to be_true
40
+ end
41
+ end
42
+
43
+ context "with a link full name passed" do
44
+ it "downvotes the link" do
45
+ authenticated_client.downvote test_link_full_name
46
+ expect(test_link.downvoted?).to be_true
47
+ end
48
+ end
49
+
50
+ context "with a comment passed" do
51
+ it "downvotes the comment" do
52
+ authenticated_client.downvote test_comment
53
+ expect(test_comment.downvoted?).to be_true
54
+ end
55
+ end
56
+
57
+ context "with a link passed" do
58
+ it "downvotes the link" do
59
+ authenticated_client.downvote test_link
60
+ expect(test_link.downvoted?).to be_true
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "#withdraw_vote", :vcr do
66
+ context "with a comment full name passed" do
67
+ it "withdraws the vote on the comment" do
68
+ authenticated_client.withdraw_vote test_comment_full_name
69
+ expect(test_comment.upvoted?).to_not be_true
70
+ expect(test_comment.downvoted?).to_not be_true
71
+ end
72
+ end
73
+
74
+ context "with a link full name passed" do
75
+ it "withdraws the vote on the link" do
76
+ authenticated_client.withdraw_vote test_link_full_name
77
+ expect(test_link.upvoted?).to_not be_true
78
+ expect(test_link.downvoted?).to_not be_true
79
+ end
80
+ end
81
+
82
+ context "with a comment passed" do
83
+ it "withdraws the vote on the comment" do
84
+ authenticated_client.withdraw_vote test_comment
85
+ expect(test_comment.upvoted?).to_not be_true
86
+ expect(test_comment.downvoted?).to_not be_true
87
+ end
88
+ end
89
+
90
+ context "with a link passed" do
91
+ it "withdraws the vote on the link" do
92
+ authenticated_client.withdraw_vote test_link
93
+ expect(test_link.upvoted?).to_not be_true
94
+ expect(test_link.downvoted?).to_not be_true
95
+ end
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Client::Wiki, :vcr do
4
+
5
+ describe "#add_wiki_editor" do
6
+ it "requests the correct resource" do
7
+ authenticated_client.add_wiki_editor redditkit_subreddit, 'samsymons', 'some page'
8
+ expect(a_post("r/#{redditkit_subreddit}/api/wiki/alloweditor/add")).to have_been_made
9
+ end
10
+ end
11
+
12
+ describe "#remove_wiki_editor" do
13
+ it "requests the correct resource" do
14
+ authenticated_client.remove_wiki_editor redditkit_subreddit, 'samsymons', 'some page'
15
+ expect(a_post("r/#{redditkit_subreddit}/api/wiki/alloweditor/del")).to have_been_made
16
+ end
17
+ end
18
+
19
+ describe "#edit_wiki_page" do
20
+ it "requests the correct resource" do
21
+ authenticated_client.edit_wiki_page :subreddit => redditkit_subreddit, :page => 'fake-page', :revision => '12345'
22
+ expect(a_post("r/#{redditkit_subreddit}/api/wiki/edit")).to have_been_made
23
+ end
24
+ end
25
+
26
+ describe "#hide_wiki_revision" do
27
+ it "requests the correct resource" do
28
+ authenticated_client.hide_wiki_revision :subreddit => redditkit_subreddit, :page => 'fake-page', :revision => '12345'
29
+ expect(a_post("r/#{redditkit_subreddit}/api/wiki/hide")).to have_been_made
30
+ end
31
+ end
32
+
33
+ describe "#revert_to_revision" do
34
+ it "requests the correct resource" do
35
+ authenticated_client.revert_to_revision :subreddit => redditkit_subreddit, :page => 'fake-page', :revision => '12345'
36
+ expect(a_post("r/#{redditkit_subreddit}/api/wiki/revert")).to have_been_made
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Client, :vcr do
4
+
5
+ it "can retrieve default options" do
6
+ expect(RedditKit.api_endpoint).to eq 'http://www.reddit.com/'
7
+ expect(RedditKit.user_agent).to eq "RedditKit.rb #{RedditKit::Version}"
8
+ end
9
+
10
+ it "can configure options" do
11
+ client = RedditKit::Client.new
12
+ client.api_endpoint = "http://github.com/"
13
+
14
+ expect(client.api_endpoint).to eq "http://github.com/"
15
+ end
16
+
17
+ it "should have a modhash and cookie after signing in" do
18
+ expect(authenticated_client.modhash).to_not be_nil
19
+ expect(authenticated_client.cookie).to_not be_nil
20
+ end
21
+
22
+ it "should raise an error with invalid credentials" do
23
+ client = RedditKit::Client.new
24
+ expect { client.sign_in "samsymons", "hunter2" }.to raise_error RedditKit::InvalidCredentials
25
+ end
26
+
27
+ it "should tell us whether it is signed in", :authenticated do
28
+ client = authenticated_client
29
+
30
+ expect(client.signed_in?).to be_true
31
+ client.sign_out
32
+ expect(client.signed_in?).to_not be_true
33
+ end
34
+
35
+ it "should be able to sign out", :authenticated do
36
+ client = authenticated_client
37
+
38
+ expect(client.modhash).to_not be_nil
39
+ expect(client.cookie).to_not be_nil
40
+
41
+ client.sign_out
42
+
43
+ expect(client.modhash).to be_nil
44
+ expect(client.cookie).to be_nil
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Comment, :vcr do
4
+
5
+ it "should return replies" do
6
+ comments = RedditKit.comments '1n002d'
7
+ comment = comments.first
8
+
9
+ expect(comment.replies?).to be_true
10
+ end
11
+
12
+ it "should be deleted if both author and comment attributes are set to '[deleted]'" do
13
+ attributes = { :data => { :author => '[deleted]', :body => '[deleted]' } }
14
+ deleted_comment = RedditKit::Comment.new attributes
15
+
16
+ expect(deleted_comment.deleted?).to be_true
17
+ end
18
+
19
+ it "should not be deleted if neither author and comment attributes are set to '[deleted]'" do
20
+ comments = RedditKit.comments '1n002d'
21
+ comment = comments.first
22
+
23
+ expect(comment.deleted?).to_not be_true
24
+ end
25
+
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Creatable do
4
+
5
+ class CreatableClass
6
+ def initialize
7
+ @time = Time.new(2000)
8
+ @attributes = { :created_utc => @time.to_i }
9
+ end
10
+ end
11
+
12
+ before :all do
13
+ @creatable = CreatableClass.new
14
+ @creatable.extend RedditKit::Creatable
15
+ end
16
+
17
+ describe "#created_at" do
18
+ it "returns the time the object was created at" do
19
+ created_at = @creatable.created_at
20
+ expect(created_at.year).to eq 2000
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Error do
4
+
5
+ describe "#from_status_code_and_body" do
6
+
7
+ it "returns no error for a valid body" do
8
+ error = RedditKit::Error.from_status_code_and_body(200, {})
9
+ expect(error).to be_nil
10
+ end
11
+
12
+ it "returns RedditKit::AuthenticationRequired for the USER_REQUIRED error" do
13
+ body = { :jquery => "USER_REQUIRED" }
14
+ error = RedditKit::Error.from_status_code_and_body(200, body)
15
+ expect(error).to eq RedditKit::AuthenticationRequired
16
+ end
17
+
18
+ it "returns RedditKit::AuthenticationRequired for the RATELIMIT error" do
19
+ body = { :jquery => "RATELIMIT" }
20
+ error = RedditKit::Error.from_status_code_and_body(200, body)
21
+ expect(error).to eq RedditKit::RateLimited
22
+ end
23
+
24
+ it "returns RedditKit::Archived for the TOO_OLD error" do
25
+ body = { :jquery => "TOO_OLD" }
26
+ error = RedditKit::Error.from_status_code_and_body(200, body)
27
+ expect(error).to eq RedditKit::Archived
28
+ end
29
+
30
+ it "returns RedditKit::PermissionDenied for status code 403" do
31
+ body = { :jquery => "ERROR" }
32
+ error = RedditKit::Error.from_status_code_and_body(403, body)
33
+ expect(error).to eq RedditKit::PermissionDenied
34
+ end
35
+
36
+ it "returns RedditKit::Conflict for status code 409" do
37
+ body = { :jquery => "ERROR" }
38
+ error = RedditKit::Error.from_status_code_and_body(409, body)
39
+ expect(error).to eq RedditKit::Conflict
40
+ end
41
+
42
+ it "returns RedditKit::InternalServerError for status code 500" do
43
+ body = { :jquery => "ERROR" }
44
+ error = RedditKit::Error.from_status_code_and_body(500, body)
45
+ expect(error).to eq RedditKit::InternalServerError
46
+ end
47
+
48
+ it "returns RedditKit::BadGateway for status code 502" do
49
+ body = { :jquery => "ERROR" }
50
+ error = RedditKit::Error.from_status_code_and_body(502, body)
51
+ expect(error).to eq RedditKit::BadGateway
52
+ end
53
+
54
+ it "returns RedditKit::ServiceUnavailable for status code 503" do
55
+ body = { :jquery => "ERROR" }
56
+ error = RedditKit::Error.from_status_code_and_body(503, body)
57
+ expect(error).to eq RedditKit::ServiceUnavailable
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Link do
4
+
5
+ before :all do
6
+ attributes = { :data => { :id => '12345', :url => 'http://example.com/test.png', :permalink => 'permalink', :created_utc => Time.now.to_i } }
7
+ @link = RedditKit::Link.new attributes
8
+
9
+ old_link_attributes = { :data => { :id => '12345', :url => 'http://example.com/test.png', :created_utc => Time.new(2000, 1, 1).to_i } }
10
+ @old_link = RedditKit::Link.new old_link_attributes
11
+ end
12
+
13
+ it "does not show the score for new links" do
14
+ expect(@link.showing_link_score?).to be_false
15
+ end
16
+
17
+ it "shows the score for old links" do
18
+ expect(@old_link.showing_link_score?).to be_true
19
+ end
20
+
21
+ it "determines whether the link has an image extension" do
22
+ expect(@link.image_link?).to be_true
23
+ end
24
+
25
+ it "returns the link's permalink" do
26
+ expect(@link.permalink).to eq 'http://reddit.com/permalink'
27
+ end
28
+
29
+ it "returns the link's short URL" do
30
+ expect(@link.short_link).to eq 'http://redd.it/12345'
31
+ end
32
+
33
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedditKit::Multireddit do
4
+
5
+ before :all do
6
+ subreddits = []
7
+ subreddits << { :name => 'test1' }
8
+ subreddits << { :name => 'test2' }
9
+ subreddits << { :name => 'test3' }
10
+
11
+ attributes = { :data => { :id => '12345', :path => '/user/username/m/test', :subreddits => subreddits } }
12
+ @multireddit = RedditKit::Multireddit.new attributes
13
+ end
14
+
15
+ it "returns the multireddit's subreddits" do
16
+ subreddits = @multireddit.subreddits
17
+ result = subreddits.all? { |subreddit| subreddit.is_a? String }
18
+
19
+ expect(subreddits.length).to eq 3
20
+ expect(result).to be_true
21
+ end
22
+
23
+ it "returns the username of the multireddit's owner" do
24
+ expect(@multireddit.username).to eq 'username'
25
+ end
26
+
27
+ end