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,29 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module RedditKit
5
+
6
+ # Methods for handling responses from reddit.
7
+ module Response
8
+ class ParseJSON < Faraday::Response::Middleware
9
+
10
+ # Turn the response body into a JSON object.
11
+ #
12
+ # @note Because the reddit API sometimes returns invalid JSON objects with
13
+ # an application/json header, we want to return the body itself if the
14
+ # JSON parsing fails, because the response is still likely useful.
15
+ def parse(body)
16
+ JSON.parse(body, :symbolize_names => true) unless body.nil?
17
+ rescue JSON::ParserError
18
+ body
19
+ end
20
+
21
+ def on_complete(env)
22
+ if respond_to?(:parse)
23
+ env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+ require 'redditkit/error'
3
+
4
+ module RedditKit
5
+
6
+ # Methods for handling responses from reddit.
7
+ module Response
8
+ class RaiseError < Faraday::Response::Middleware
9
+
10
+ def on_complete(env)
11
+ status_code = env[:status]
12
+ body = env[:body]
13
+
14
+ if error = RedditKit::Error.from_status_code_and_body(status_code, body)
15
+ raise error
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,86 @@
1
+ require 'redditkit/thing'
2
+ require 'redditkit/creatable'
3
+
4
+ module RedditKit
5
+
6
+ # A class representing a subreddit.
7
+ class Subreddit < RedditKit::Thing
8
+ include RedditKit::Creatable
9
+
10
+ # The number of users currently active in the subreddit.
11
+ attr_reader :accounts_active
12
+
13
+ # The number of minutes comment scores are hidden for.
14
+ attr_reader :comment_score_hide_mins
15
+
16
+ # The description of the subreddit, in Markdown.
17
+ attr_reader :description
18
+
19
+ # The description of the subreddit, as HTML.
20
+ attr_reader :description_html
21
+
22
+ # The subreddit's display name. For reddit.com/r/programming, the display name is 'programming'.
23
+ attr_reader :display_name
24
+
25
+ # The URL to the subreddit's header image, if it has one.
26
+ attr_reader :header_img
27
+
28
+ # The size of the subreddit's header image, if it has one.
29
+ attr_reader :header_size
30
+
31
+ # The subreddit's header title.
32
+ attr_reader :header_title
33
+
34
+ # Whether the subreddit has been marked as having content directed at people over 18 years old.
35
+ attr_reader :over18
36
+
37
+ # The subreddit's public description.
38
+ attr_reader :public_description
39
+
40
+ # Whether the subreddit's traffic page is publicly visible.
41
+ attr_reader :public_traffic
42
+ attr_reader :spam_comments
43
+ attr_reader :spam_links
44
+ attr_reader :spam_selfpost
45
+ attr_reader :submission_type
46
+ attr_reader :submit_link_label
47
+ attr_reader :submit_text
48
+ attr_reader :submit_text_html
49
+ attr_reader :submit_text_label
50
+
51
+ # The subreddit's type, either 'public' or 'private'.
52
+ attr_reader :subreddit_type
53
+
54
+ # The number of subscribers to the subreddit.
55
+ attr_reader :subscribers
56
+
57
+ # The subreddit's title.
58
+ attr_reader :title
59
+
60
+ # The URL to the subreddit.
61
+ attr_reader :url
62
+
63
+ # Whether the current user is banned from the subreddit.
64
+ attr_reader :user_is_banned
65
+
66
+ # Whether the current user is a contributor to the subreddit.
67
+ attr_reader :user_is_contributor
68
+
69
+ # Whether the current user is a moderator of the subreddit.
70
+ attr_reader :user_is_moderator
71
+
72
+ # Whether the current user is a subscriber to the subreddit.
73
+ attr_reader :user_is_subscriber
74
+
75
+ alias banned? user_is_banned
76
+ alias comment_spam_filter_strength spam_comments
77
+ alias contributor? user_is_contributor
78
+ alias link_spam_filter_strength spam_links
79
+ alias moderator? user_is_moderator
80
+ alias name display_name
81
+ alias nsfw? over18
82
+ alias self_post_spam_filter_strength spam_selfpost
83
+ alias subscriber? user_is_subscriber
84
+
85
+ end
86
+ end
@@ -0,0 +1,20 @@
1
+ require 'redditkit/base'
2
+
3
+ module RedditKit
4
+
5
+ # A base class for objects which have both a kind and an identifier.
6
+ class Thing < RedditKit::Base
7
+
8
+ attr_reader :id
9
+ attr_reader :kind
10
+
11
+ def ==(other)
12
+ full_name == other.full_name
13
+ end
14
+
15
+ # Returns the object's full name.
16
+ def full_name
17
+ @full_name ||= "#{kind}_#{id}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'redditkit/thing'
2
+ require 'redditkit/creatable'
3
+
4
+ module RedditKit
5
+
6
+ # A class representing a reddit user.
7
+ class User < RedditKit::Thing
8
+ include RedditKit::Creatable
9
+
10
+ attr_reader :name
11
+ attr_reader :comment_karma
12
+ attr_reader :link_karma
13
+ attr_reader :has_mail
14
+ attr_reader :has_mod_mail
15
+ attr_reader :has_verified_email
16
+ attr_reader :is_gold
17
+ attr_reader :is_friend
18
+ attr_reader :is_mod
19
+ attr_reader :over_18
20
+
21
+ alias friend? is_friend
22
+ alias gold? is_gold
23
+ alias mail? has_mail
24
+ alias mod? is_mod
25
+ alias mod_mail? has_mod_mail
26
+ alias over_18? over_18
27
+ alias username name
28
+ alias verified? has_verified_email
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ module RedditKit
2
+
3
+ # A class for managing RedditKit's version number.
4
+ class Version
5
+ MAJOR = 1
6
+ MINOR = 0
7
+ PATCH = 0
8
+
9
+ class << self
10
+
11
+ # Return RedditKit.rb's version number as a string.
12
+ def to_s
13
+ [MAJOR, MINOR, PATCH].join('.')
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ module RedditKit
2
+
3
+ # Methods which determine the voting status of objects.
4
+ module Votable
5
+
6
+ # The number of upvotes an item has.
7
+ def upvotes
8
+ @attributes[:ups]
9
+ end
10
+
11
+ # The number of downvotes an item has.
12
+ def downvotes
13
+ @attributes[:downs]
14
+ end
15
+
16
+ # The score for an item.
17
+ def score
18
+ @attributes[:score]
19
+ end
20
+
21
+ # Whether the current user has upvoted this item.
22
+ def upvoted?
23
+ @attributes[:likes] == true
24
+ end
25
+
26
+ # Whether the current user has downvotes this item.
27
+ def downvoted?
28
+ @attributes[:likes] == false
29
+ end
30
+
31
+ # Whether the user has voted on this item (either upvoted or downvoted).
32
+ def voted?
33
+ !@attributes[:likes].nil?
34
+ end
35
+
36
+ end
37
+ end
data/redditkit.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redditkit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redditkit"
8
+ spec.version = RedditKit::Version
9
+ spec.authors = ["Sam Symons"]
10
+ spec.email = ["samsymons@me.com"]
11
+ spec.description = "A simple reddit API library, covering 100% of the reddit API."
12
+ spec.summary = "A simple reddit API library."
13
+ spec.homepage = "http://redditkit.com/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = %w(LICENSE.md README.md Rakefile redditkit.gemspec)
17
+ spec.files += Dir.glob("lib/**/*.rb")
18
+ spec.files += Dir.glob("spec/**/*")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'faraday', "~> 0.8"
24
+ spec.add_development_dependency 'dotenv'
25
+ end
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://ssl.reddit.com/api/login
6
+ body:
7
+ encoding: US-ASCII
8
+ string: user=samsymons&passwd=hunter2&api_type=json
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Sun, 10 Nov 2013 22:21:42 GMT
25
+ Connection:
26
+ - close
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '72'
31
+ Server:
32
+ - "'; DROP TABLE servertypes; --"
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\"json\": {\"errors\": [[\"WRONG_PASSWORD\", \"invalid password\",
36
+ \"passwd\"]]}}"
37
+ http_version:
38
+ recorded_at: Sun, 10 Nov 2013 22:21:41 GMT
39
+ recorded_with: VCR 2.6.0
@@ -0,0 +1,132 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://ssl.reddit.com/api/login
6
+ body:
7
+ encoding: US-ASCII
8
+ string: user=<REDDIT_USERNAME>&passwd=<REDDIT_USERNAME>Password&api_type=json
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Sun, 10 Nov 2013 19:36:01 GMT
25
+ Connection:
26
+ - close
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '182'
31
+ Set-Cookie:
32
+ - reddit_session=20332937%2C2013-11-10T11%3A36%3A01%2C3a94801911c4cba77d627c03ef1728c0b9452267;
33
+ Domain=reddit.com; Path=/; HttpOnly
34
+ Server:
35
+ - "'; DROP TABLE servertypes; --"
36
+ body:
37
+ encoding: UTF-8
38
+ string: "{\"json\": {\"errors\": [], \"data\": {\"modhash\": \"4a8hmswyon7999c6fc14c9b9882324382339cfb661896efda8\",
39
+ \"cookie\": \"20332937,2013-11-10T11:36:01,3a94801911c4cba77d627c03ef1728c0b9452267\"}}}"
40
+ http_version:
41
+ recorded_at: Sun, 10 Nov 2013 19:35:59 GMT
42
+ - request:
43
+ method: get
44
+ uri: http://www.reddit.com/user/<REDDIT_USERNAME>/about.json
45
+ body:
46
+ encoding: US-ASCII
47
+ string: ''
48
+ headers:
49
+ User-Agent:
50
+ - Faraday v0.8.8
51
+ Cookie:
52
+ - reddit_session=20332937,2013-11-10T11:36:01,3a94801911c4cba77d627c03ef1728c0b9452267
53
+ X-Modhash:
54
+ - 4a8hmswyon7999c6fc14c9b9882324382339cfb661896efda8
55
+ Accept-Encoding:
56
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
57
+ Accept:
58
+ - "*/*"
59
+ response:
60
+ status:
61
+ code: 200
62
+ message: OK
63
+ headers:
64
+ Content-Type:
65
+ - application/json; charset=UTF-8
66
+ Content-Length:
67
+ - '362'
68
+ Cache-Control:
69
+ - no-cache
70
+ Pragma:
71
+ - no-cache
72
+ Server:
73
+ - "'; DROP TABLE servertypes; --"
74
+ Date:
75
+ - Sun, 10 Nov 2013 19:36:01 GMT
76
+ Connection:
77
+ - keep-alive
78
+ body:
79
+ encoding: UTF-8
80
+ string: "{\"kind\": \"t2\", \"data\": {\"has_mail\": false, \"name\": \"<REDDIT_USERNAME>\",
81
+ \"is_friend\": false, \"created\": 1371758712.0, \"modhash\": \"qnb8yblbase93a673767165f25ce13096d6d0acc3deed51118\",
82
+ \"created_utc\": 1371755112.0, \"link_karma\": 1, \"comment_karma\": 0, \"over_18\":
83
+ true, \"is_gold\": false, \"is_mod\": true, \"has_verified_email\": null,
84
+ \"id\": \"c3szt\", \"has_mod_mail\": true}}"
85
+ http_version:
86
+ recorded_at: Sun, 10 Nov 2013 19:35:59 GMT
87
+ - request:
88
+ method: get
89
+ uri: http://www.reddit.com/api/me.json
90
+ body:
91
+ encoding: US-ASCII
92
+ string: ''
93
+ headers:
94
+ User-Agent:
95
+ - Faraday v0.8.8
96
+ Cookie:
97
+ - reddit_session=20332937,2013-11-10T11:36:01,3a94801911c4cba77d627c03ef1728c0b9452267
98
+ X-Modhash:
99
+ - 4a8hmswyon7999c6fc14c9b9882324382339cfb661896efda8
100
+ Accept-Encoding:
101
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
102
+ Accept:
103
+ - "*/*"
104
+ response:
105
+ status:
106
+ code: 200
107
+ message: OK
108
+ headers:
109
+ Content-Type:
110
+ - application/json; charset=UTF-8
111
+ Content-Length:
112
+ - '362'
113
+ Cache-Control:
114
+ - no-cache
115
+ Pragma:
116
+ - no-cache
117
+ Server:
118
+ - "'; DROP TABLE servertypes; --"
119
+ Date:
120
+ - Sun, 10 Nov 2013 19:36:01 GMT
121
+ Connection:
122
+ - keep-alive
123
+ body:
124
+ encoding: UTF-8
125
+ string: "{\"kind\": \"t2\", \"data\": {\"has_mail\": false, \"name\": \"<REDDIT_USERNAME>\",
126
+ \"is_friend\": false, \"created\": 1371758712.0, \"modhash\": \"3ctrgpd6g5dd6a9bbd57786bcd7eadc9848307bdd9234f141e\",
127
+ \"created_utc\": 1371755112.0, \"link_karma\": 1, \"comment_karma\": 0, \"over_18\":
128
+ true, \"is_gold\": false, \"is_mod\": true, \"has_verified_email\": null,
129
+ \"id\": \"c3szt\", \"has_mod_mail\": true}}"
130
+ http_version:
131
+ recorded_at: Sun, 10 Nov 2013 19:36:00 GMT
132
+ recorded_with: VCR 2.6.0