Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add .rubocop.yml and clean up some more warnings.

  • Loading branch information...
commit 22d86247d7059848e612ec3a3f544995aa634d30 1 parent 733b3fa
Sam Symons authored
9 .rubocop.yml
View
@@ -0,0 +1,9 @@
+AllCops:
+ Excludes:
+ - spec/**
+LineLength:
+ Enabled: false
+HashSyntax:
+ Enabled: false
+TrailingBlankLines:
+ Enabled: false
10 lib/redditkit/client.rb
View
@@ -58,9 +58,7 @@ def initialize(username = nil, password = nil)
@cookie = nil
@modhash = nil
- unless @username.nil? or @password.nil?
- sign_in @username, @password
- end
+ sign_in(username, password) unless username.nil? || password.nil?
end
def api_endpoint
@@ -118,9 +116,9 @@ def request(method, path, parameters = {}, request_connection)
end
def authenticated_request_configuration(method, path, parameters)
- raise RedditKit::NotAuthenticated unless signed_in?
+ fail RedditKit::NotAuthenticated unless signed_in?
- Proc.new do |request|
+ proc do |request|
request.headers['Cookie'] = "reddit_session=#{@cookie}"
request.headers['X-Modhash'] = @modhash
end
@@ -135,7 +133,7 @@ def https_connection
end
def connection_with_url(url)
- Faraday.new(url, { :builder => middleware })
+ Faraday.new url, :builder => middleware
end
end
8 lib/redditkit/client/apps.rb
View
@@ -20,20 +20,20 @@ def create_app(name, options = {})
post('api/updateapp', parameters)
end
- alias update_app create_app
+ alias_method :update_app, :create_app
# Delete an app.
#
# @param app_identifier [String] The identifier of the app.
def delete_app(app_identifier)
- post('api/deleteapp', { :client_id => app_identifier })
+ post 'api/deleteapp', :client_id => app_identifier
end
# Revoke an app.
#
# @param app_identifier [String] The identifier of the app.
def revoke_app(app_identifier)
- post('api/revokeapp', { :client_id => app_identifier })
+ post 'api/revokeapp', :client_id => app_identifier
end
# Add a user as a developer of an app.
@@ -44,7 +44,7 @@ def add_developer(user, app_identifier)
username = extract_string user, :username
parameters = { :name => username, :client_id => app_identifier }
- post('api/adddeveloper', parameters)
+ post 'api/adddeveloper', parameters
end
# Remove an app's developer.
4 lib/redditkit/client/captcha.rb
View
@@ -8,7 +8,7 @@ module Captcha
#
# @return [Boolean]
def needs_captcha?
- response = get('api/needs_captcha.json', nil)
+ response = get 'api/needs_captcha.json'
needs_captcha = response[:body]
needs_captcha.to_s == 'true'
@@ -18,7 +18,7 @@ def needs_captcha?
#
# @return [String] The CAPTCHA identifier.
def new_captcha_identifier
- response = post('api/new_captcha', { :api_type => :json })
+ response = post 'api/new_captcha', :api_type => :json
data = response[:body][:json][:data]
data[:iden]
12 lib/redditkit/client/links.rb
View
@@ -94,36 +94,36 @@ def submit(title, subreddit, options = {})
parameters[:kind] = 'self'
end
- post('api/submit', parameters)
+ post 'api/submit', parameters
end
# Marks a link as not safe for work.
#
# @param link [String, RedditKit::Link] A link's full name, or a RedditKit::Link.
def mark_nsfw(link)
- post('api/marknsfw', { :id => extract_full_name(link) })
+ post 'api/marknsfw', :id => extract_full_name(link)
end
# Marks a link as safe for work.
#
# @param link [String, RedditKit::Subreddit] A link's full name, or a RedditKit::Link.
def mark_sfw(link)
- post('api/unmarknsfw', { :id => extract_full_name(link) })
+ post 'api/unmarknsfw', :id => extract_full_name(link)
end
- alias unmark_nsfw mark_sfw
+ alias_method :unmark_nsfw, :mark_sfw
# Hides a link.
#
# @param link [String, RedditKit::Link] A link's full name, or a RedditKit::Link.
def hide(link)
- post('api/hide', { :id => extract_full_name(link) })
+ post 'api/hide', :id => extract_full_name(link)
end
# Unhides a link.
#
# @param link [String, RedditKit::Link] A link's full name, or a RedditKit::Link.
def unhide(link)
- post('api/unhide', { :id => extract_full_name(link) })
+ post 'api/unhide', :id => extract_full_name(link)
end
# Gets a random link.
8 lib/redditkit/client/miscellaneous.rb
View
@@ -18,7 +18,7 @@ def edit(object, options)
# @param object [String, RedditKit::Comment, RedditKit::Link] A link or comment's full name, a RedditKit::Link, or a RedditKit::Subreddit.
def delete(object)
full_name = extract_full_name object
- post('api/del', { :id => full_name })
+ post 'api/del', :id => full_name
end
# Saves a link or comment.
@@ -26,7 +26,7 @@ def delete(object)
# @param object [String, RedditKit::Link, RedditKit::Subreddit] A link or comment's full name, a RedditKit::Link, or a RedditKit::Subreddit.
def save(object)
full_name = extract_full_name object
- post('api/save', { :id => full_name })
+ post 'api/save', :id => full_name
end
# Unsaves a link or comment.
@@ -34,7 +34,7 @@ def save(object)
# @param object [String, RedditKit::Link, RedditKit::Subreddit] A link or comment's full name, a RedditKit::Link, or a RedditKit::Subreddit.
def unsave(object)
full_name = extract_full_name object
- post('api/unsave', { :id => full_name })
+ post 'api/unsave', :id => full_name
end
# Reports a link or comment. The reddit API will also hide the link or comment.
@@ -42,7 +42,7 @@ def unsave(object)
# @param object [String, RedditKit::Link, RedditKit::Comment] A link or comment's full name, a RedditKit::Link, or a RedditKit::Subreddit.
def report(object)
full_name = extract_full_name object
- post('api/report', { :id => full_name })
+ post 'api/report', :id => full_name
end
end
22 lib/redditkit/client/moderation.rb
View
@@ -28,7 +28,7 @@ def unban(user, subreddit)
# @param link [String, RedditKit::Link] A link's full name, or a RedditKit::Link.
def approve(link)
full_name = extract_full_name link
- post('api/approve', { :id => full_name, :api_type => :json })
+ post 'api/approve', { :id => full_name, :api_type => :json }
end
# Removes a link or comment.
@@ -36,7 +36,7 @@ def approve(link)
# @param object [String, RedditKit::Comment, RedditKit::Link] The full name of a link/comment, a RedditKit::Comment, or a RedditKit::Link.
def remove(object)
full_name = extract_full_name object
- post('api/remove', { :id => full_name, :api_type => :json })
+ post 'api/remove', { :id => full_name, :api_type => :json }
end
# Ignores the reports on a link or comment.
@@ -44,7 +44,7 @@ def remove(object)
# @param object [String, RedditKit::Comment, RedditKit::Link] The full name of a link/comment, a RedditKit::Comment, or a RedditKit::Link.
def ignore_reports(object)
full_name = extract_full_name object
- post('api/ignore_reports', { :id => full_name, :api_type => :json })
+ post 'api/ignore_reports', { :id => full_name, :api_type => :json }
end
# Unignores the reports on a link or comment.
@@ -52,7 +52,7 @@ def ignore_reports(object)
# @param object [String, RedditKit::Comment, RedditKit::Link] The full name of a link/comment, a RedditKit::Comment, or a RedditKit::Link.
def unignore_reports(object)
full_name = extract_full_name object
- post('api/unignore_reports', { :id => full_name, :api_type => :json })
+ post 'api/unignore_reports', { :id => full_name, :api_type => :json }
end
# Distinguishes a comment as being posted by a moderator or admin.
@@ -64,7 +64,7 @@ def distinguish(comment, how = 'yes')
full_name = extract_full_name comment
parameters = { :id => full_name, :api_type => :json }
- post("api/distinguish/#{how}", parameters)
+ post "api/distinguish/#{how}", parameters
end
# Sets a post as have its contest mode enabled or disabled.
@@ -75,7 +75,7 @@ def set_contest_mode(link, contest_mode = true)
full_name = extract_full_name link
set_as_contest = contest_mode ? 'True' : 'False'
- post('api/set_contest_mode', { :id => full_name, :state => set_as_contest, :api_type => :json })
+ post 'api/set_contest_mode', { :id => full_name, :state => set_as_contest, :api_type => :json }
end
# Sets a post as sticky within its parent subreddit. This will replace the existing sticky post, if there is one.
@@ -86,7 +86,7 @@ def set_sticky_post(link, sticky = true)
full_name = extract_full_name link
set_as_sticky = sticky ? 'True' : 'False'
- post('api/set_subreddit_sticky', { :id => full_name, :state => set_as_sticky, :api_type => :json })
+ post 'api/set_subreddit_sticky', { :id => full_name, :state => set_as_sticky, :api_type => :json }
end
# Get the moderators of a subreddit.
@@ -110,7 +110,7 @@ def contributors_to_subreddit(subreddit)
# @param subreddit [String, RedditKit::Subreddit] The display name of the subreddit, or a RedditKit::Subreddit.
def accept_moderator_invitation(subreddit)
subreddit_name = extract_string(subreddit, :display_name)
- post('api/accept_moderator_invite', { :r => subreddit_name })
+ post 'api/accept_moderator_invite', :r => subreddit_name
end
# Resign as a contributor to a subreddit.
@@ -118,7 +118,7 @@ def accept_moderator_invitation(subreddit)
# @param subreddit [String, RedditKit::Subreddit] A subreddit's full name, or a RedditKit::Subreddit.
def resign_as_contributor(subreddit)
full_name = extract_full_name subreddit
- post('api/leavecontributor', { :id => full_name })
+ post 'api/leavecontributor', :id => full_name
end
# Resign as a moderator of a subreddit.
@@ -126,7 +126,7 @@ def resign_as_contributor(subreddit)
# @param subreddit [String, RedditKit::Subreddit] A subreddit's full name, or a RedditKit::Subreddit.
def resign_as_moderator(subreddit)
full_name = extract_full_name subreddit
- post('api/leavemoderator', { :id => full_name })
+ post 'api/leavemoderator', :id => full_name
end
# Resets a subreddit's header image.
@@ -134,7 +134,7 @@ def resign_as_moderator(subreddit)
# @param subreddit [String, RedditKit::Subreddit] The display name of the subreddit, or a RedditKit::Subreddit.
def reset_subreddit_header(subreddit)
subreddit_name = extract_string(subreddit, :display_name)
- post('api/delete_sr_header', { :r => subreddit_name })
+ post 'api/delete_sr_header', :r => subreddit_name
end
# Gets the moderation log for a subreddit.
6 lib/redditkit/client/multireddits.rb
View
@@ -24,7 +24,7 @@ def my_multireddits
# @param multireddit_name [String] The multireddit's name.
# @return [RedditKit::Multireddit]
def multireddit(*args)
- path = "api/multi"
+ path = 'api/multi'
if args.length == 1
path << args.first
@@ -93,7 +93,7 @@ def create_multireddit(multireddit, subreddits = [], visibility = 'private')
# @param subreddits [Array] An array of subreddit names or RedditKit::Subreddit objects.
# @param visibility [public, private] An array of subreddit names to be added to the multireddit.
def update_multireddit(multireddit, subreddits = [], visibility = 'private')
- create_or_update_multireddit(:put, multireddit, subreddits, visibility)
+ create_or_update_multireddit :put, multireddit, subreddits, visibility
end
# Copies a multireddit.
@@ -162,7 +162,7 @@ def add_subreddit_to_multireddit(multireddit, subreddit)
path = "api/multi#{multireddit_path}/r/#{subreddit_name}"
model = { :name => subreddit_name }
- put(path, { :model => model.to_json })
+ put path, :model => model.to_json
end
# Removes a subreddit from a multireddit owned by the current user.
8 lib/redditkit/client/subreddits.rb
View
@@ -52,7 +52,7 @@ def subscribe(subreddit)
full_name = extract_full_name subreddit
parameters = { :action => 'sub', :sr => full_name }
- post("api/subscribe", parameters)
+ post('api/subscribe', parameters)
end
# Unsubscribes from a subreddit.
@@ -62,7 +62,7 @@ def unsubscribe(subreddit)
full_name = extract_full_name subreddit
parameters = { :action => 'unsub', :sr => full_name }
- post("api/subscribe", parameters)
+ post('api/subscribe', parameters)
end
# Gets a random subreddit.
@@ -97,7 +97,7 @@ def subreddits_by_topic(topic)
response = get('api/subreddits_by_topic.json', parameters)
body = response[:body]
- body.collect { |subreddit| subreddit[:name] }
+ body.map { |subreddit| subreddit[:name] }
end
# Gets an array of recommended subreddits.
@@ -112,7 +112,7 @@ def recommended_subreddits(subreddits)
response = get('api/subreddit_recommendations.json', parameters)
body = response[:body]
- body.collect { |subreddit| subreddit[:sr_name] }
+ body.map { |subreddit| subreddit[:sr_name] }
end
end
4 lib/redditkit/client/users.rb
View
@@ -16,7 +16,7 @@ def user(username = nil)
if username
object_from_response(:get, "user/#{username}/about.json", nil)
else
- object_from_response(:get, "api/me.json", nil)
+ object_from_response(:get, 'api/me.json', nil)
end
end
@@ -60,7 +60,7 @@ def friends
body = response[:body]
friends = body[0][:data][:children]
- friends.collect { |friend| OpenStruct.new(friend) }
+ friends.map { |friend| OpenStruct.new(friend) }
end
# Adds a user to the current user's friend list.
16 lib/redditkit/client/utilities.rb
View
@@ -48,21 +48,21 @@ def object_class_from_response(response)
# @return [Class]
def object_class_from_kind(kind)
case kind
- when "t1"
+ when 't1'
RedditKit::Comment
- when "t2"
+ when 't2'
RedditKit::User
- when "t3"
+ when 't3'
RedditKit::Link
- when "t4"
+ when 't4'
RedditKit::PrivateMessage
- when "t5"
+ when 't5'
RedditKit::Subreddit
- when "LabeledMulti"
+ when 'LabeledMulti'
RedditKit::Multireddit
- when "LabeledMultiDescription"
+ when 'LabeledMultiDescription'
RedditKit::MultiredditDescription
- when "modaction"
+ when 'modaction'
RedditKit::ModeratorAction
end
end
6 lib/redditkit/comment.rb
View
@@ -26,8 +26,8 @@ class Comment < RedditKit::Thing
attr_reader :subreddit
attr_reader :subreddit_id
- alias text body
- alias posted_at created_at
+ alias_method :text, :body
+ alias_method :posted_at, :created_at
# Whether a comment has been deleted by its submitter or a moderator.
def deleted?
@@ -37,7 +37,7 @@ def deleted?
# The replies to a comment.
def replies
replies_listing = @attributes[:replies]
- return Array.new if replies_listing.empty?
+ return [] if replies_listing.empty?
replies_array = replies_listing[:data][:children]
4 lib/redditkit/error.rb
View
@@ -6,7 +6,7 @@ class << self
def from_status_code_and_body(status_code, body)
error_value = extract_error_value body
- return if status_code == 200 and error_value.nil?
+ return if status_code == 200 && error_value.nil?
case status_code
when 200
@@ -53,7 +53,7 @@ def from_status_code_and_body(status_code, body)
def extract_error_value(body)
return nil unless body.instance_of? Hash
- if body.key?(:json) and body[:json].key?(:errors)
+ if body.key?(:json) && body[:json].key?(:errors)
body[:json][:errors].to_s
elsif body.key?(:jquery)
body[:jquery].to_s
26 lib/redditkit/link.rb
View
@@ -94,17 +94,17 @@ class Link < RedditKit::Thing
# Whether the link has been visited by the current user. Requires that the current user have reddit gold.
attr_reader :visited
- alias approved? approved_by
- alias banned? banned_by
- alias nsfw? over_18
- alias self_post? is_self
- alias sticky? stickied
- alias subreddit_full_name subreddit_id
- alias text selftext
- alias text_html selftext_html
- alias thumbnail_url thumbnail
- alias total_comments num_comments
- alias total_reports num_reports
+ alias_method :approved?, :approved_by
+ alias_method :banned?, :banned_by
+ alias_method :nsfw?, :over_18
+ alias_method :self_post?, :is_self
+ alias_method :sticky?, :stickied
+ alias_method :subreddit_full_name, :subreddit_id
+ alias_method :text, :selftext
+ alias_method :text_html, :selftext_html
+ alias_method :thumbnail_url, :thumbnail
+ alias_method :total_comments, :num_comments
+ alias_method :total_reports, :num_reports
def title
@escaped_title ||= HTMLEntities.new.decode(@attributes[:title])
@@ -133,11 +133,11 @@ def showing_link_score?
# @return [Boolean]
def image_link?
extensions = %w(.png .jpg .jpeg .gif)
- extensions.any?{ |extension| url.end_with? extension }
+ extensions.any? { |extension| url.end_with? extension }
end
def permalink
- @permalink ||= "http://reddit.com/" << @attributes[:permalink]
+ @permalink ||= 'http://reddit.com/' << @attributes[:permalink]
end
# Returns the short URL for a link.
8 lib/redditkit/moderator_action.rb
View
@@ -10,10 +10,10 @@ class ModeratorAction < RedditKit::Thing
attr_reader :subreddit
attr_reader :sub_id36
- alias moderator_username mod
- alias moderator_identifier mod_id36
- alias subreddit_name subreddit
- alias subreddit_identifier sub_id36
+ alias_method :moderator_username, :mod
+ alias_method :moderator_identifier, :mod_id36
+ alias_method :subreddit_name, :subreddit
+ alias_method :subreddit_identifier, :sub_id36
end
end
4 lib/redditkit/multireddit.rb
View
@@ -12,13 +12,13 @@ class Multireddit < RedditKit::Base
attr_reader :visibility
attr_reader :path
- alias editable? can_edit
+ alias_method :editable?, :can_edit
# An array of subreddit display names.
#
# @return [Array<String>]
def subreddits
- @subreddits ||= @attributes[:subreddits].collect { |subreddit| subreddit[:name] }
+ @subreddits ||= @attributes[:subreddits].map { |subreddit| subreddit[:name] }
end
# The username of the multireddit's owner.
2  lib/redditkit/multireddit_description.rb
View
@@ -8,7 +8,7 @@ class MultiredditDescription < RedditKit::Base
attr_reader :body_html
attr_reader :body_md
- alias text body_md
+ alias_method :text, :body_md
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.