Class: Redd::Client::Authenticated

Inherits:
Unauthenticated show all
Includes:
Account, Apps, Flair, Gold, LinksComments, Live, Moderation, Multis, PrivateMessages, Subreddits, Users, Wiki
Defined in:
lib/redd/client/authenticated.rb,
lib/redd/client/authenticated/apps.rb,
lib/redd/client/authenticated/gold.rb,
lib/redd/client/authenticated/live.rb,
lib/redd/client/authenticated/wiki.rb,
lib/redd/client/authenticated/flair.rb,
lib/redd/client/authenticated/users.rb,
lib/redd/client/authenticated/multis.rb,
lib/redd/client/authenticated/account.rb,
lib/redd/client/authenticated/moderation.rb,
lib/redd/client/authenticated/subreddits.rb,
lib/redd/client/authenticated/links_comments.rb,
lib/redd/client/authenticated/private_messages.rb

Overview

The class that handles requests when authenticated using a username and password.

Direct Known Subclasses

OAuth2

Defined Under Namespace

Modules: Account, Apps, Flair, Gold, LinksComments, Live, Moderation, Multis, PrivateMessages, Subreddits, Users, Wiki

Instance Attribute Summary collapse

Attributes inherited from Unauthenticated

#api_endpoint, #rate_limit, #user_agent

Instance Method Summary collapse

Methods included from Subreddits

#edit_subscription, #get_subreddits, #subscribe, #unsubscribe

Methods included from PrivateMessages

#block_message, #compose_message, #mark_as_read, #mark_as_unread, #messages

Methods included from Moderation

#accept_moderator_invite, #approve, #distinguish, #get_modqueue, #get_reports, #get_spam, #get_submissions, #get_unmoderated, #ignore_reports, #leave_contributor_status, #leave_moderator_status, #remove, #undistinguish, #unignore_reports

Methods included from LinksComments

#add_comment, #delete, #downvote, #edit, #hide, #mark_as_nsfw, #report, #save, #submit, #unhide, #unmark_as_nsfw, #unsave, #unvote, #upvote, #vote

Methods included from Flair

#get_flair, #get_flair_list, #set_flair

Methods included from Account

#me

Methods inherited from Unauthenticated

#connection, #delete, #get, #post, #put, #request

Methods included from Unauthenticated::Wiki

#get_wikipages, #wikipage

Methods included from Unauthenticated::Utilities

#comment_stream, #comments_from_response, #extract_attribute, #extract_fullname, #extract_id, #object_from_body, #object_from_kind, #object_from_response, #objects_from_listing, #submission_stream

Methods included from Unauthenticated::Subreddits

#get_subreddits, #search_subreddits, #subreddit

Methods included from Unauthenticated::Moderation

#stylesheet, #stylesheet_url

Methods included from Unauthenticated::Listing

#by_id, #get_comments, #get_controversial, #get_hot, #get_listing, #get_new, #get_random, #get_top

Methods included from Unauthenticated::LinksComments

#get_info, #get_replies, #replace_morecomments, #submission_comments

Methods included from Unauthenticated::Captcha

#captcha_url, #needs_captcha?, #new_captcha

Methods included from Unauthenticated::Account

#login

Constructor Details

#initialize(cookie, modhash, options = {}) ⇒ Authenticated

Set up an authenticated connection to reddit.

Parameters:

  • cookie (String)

    The cookie to use when sending a request.

  • modhash (String)

    The modhash to use when sending a request.

  • options (Hash) (defaults to: {})

    A hash of options to connect using.

Options Hash (options):

  • :user_agent (String)

    The User-Agent string to use in the header of every request.

  • :api_endpoint (String)

    The main domain to connect to, in this case, the URL for reddit.

  • :auth_endpoint (String)

    The domain to login with, in this case, the ssl subdomain using https.



59
60
61
62
63
64
65
66
# File 'lib/redd/client/authenticated.rb', line 59

def initialize(cookie, modhash, options = {})
  @cookie = cookie
  @modhash = modhash

  @rate_limit = options[:rate_limit] || Redd::RateLimit.new
  @user_agent = options[:user_agent] || "Redd/Ruby, v#{Redd::VERSION}"
  @api_endpoint = options[:api_endpoint] || "https://www.reddit.com/"
end

Instance Attribute Details

Returns The cookie used to store the current session.

Returns:

  • (String)

    The cookie used to store the current session.



38
39
40
# File 'lib/redd/client/authenticated.rb', line 38

def cookie
  @cookie
end

#modhashString (readonly)

Returns The returned modhash used when making requests.

Returns:

  • (String)

    The returned modhash used when making requests.



42
43
44
# File 'lib/redd/client/authenticated.rb', line 42

def modhash
  @modhash
end

#usernameString (readonly)

Returns The username of the logged-in user.

Returns:

  • (String)

    The username of the logged-in user.



34
35
36
# File 'lib/redd/client/authenticated.rb', line 34

def username
  @username
end

Instance Method Details

#headersHash (private)

Returns The headers that are sent with every request.

Returns:

  • (Hash)

    The headers that are sent with every request.



71
72
73
74
75
76
77
# File 'lib/redd/client/authenticated.rb', line 71

def headers
  @headers ||= {
    "User-Agent" => @user_agent,
    "Cookie" => "reddit_session=#{@cookie}",
    "X-Modhash" => @modhash
  }
end

#new_from_credentials(username, password, options = {}) ⇒ Object



44
45
46
# File 'lib/redd/client/authenticated.rb', line 44

def new_from_credentials(username, password, options = {})
  Redd::Client::Unauthenticated.new.(username, password, options)
end