Permalink
Browse files

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

  • Loading branch information...
1 parent 733b3fa commit 22d86247d7059848e612ec3a3f544995aa634d30 Sam Symons committed Jan 9, 2014
View
@@ -0,0 +1,9 @@
+AllCops:
+ Excludes:
+ - spec/**
+LineLength:
+ Enabled: false
+HashSyntax:
+ Enabled: false
+TrailingBlankLines:
+ Enabled: false
@@ -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
@@ -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.
@@ -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]
@@ -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.
@@ -18,31 +18,31 @@ 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.
#
# @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.
#
# @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.
#
# @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
@@ -28,31 +28,31 @@ 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.
#
# @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.
#
# @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.
#
# @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,31 +110,31 @@ 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.
#
# @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.
#
# @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.
#
# @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.
@@ -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.
@@ -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
@@ -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.
@@ -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
Oops, something went wrong.

0 comments on commit 22d8624

Please sign in to comment.