Module: RedditKit::Client::Account
- Included in:
- RedditKit::Client
- Defined in:
- lib/redditkit/client/account.rb
Overview
Methods which operate on a user’s account.
Instance Method Summary collapse
-
#sign_in(username, password) ⇒ Object
Sign in to a reddit account.
-
#sign_out ⇒ Object
Sign the current user out.
-
#signed_in? ⇒ Boolean
Check is a user is currently signed in.
-
#update_account(options) ⇒ Object
Updates the current user’s email or password.
-
#update_session(password) ⇒ String
Invalidates all session cookies and updates the current one.
Instance Method Details
#sign_in(username, password) ⇒ Object
Sign in to a reddit account.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/redditkit/client/account.rb', line 12 def sign_in(username, password) response = https_post 'api/login', { :user => username, :passwd => password, :api_type => :json } body = response[:body] data = body[:json][:data] @modhash = data[:modhash] @cookie = data[:cookie] @username = username @current_user = user @username @username = @current_user.username end |
#sign_out ⇒ Object
Sign the current user out.
34 35 36 37 38 39 40 |
# File 'lib/redditkit/client/account.rb', line 34 def sign_out @username = nil @current_user = nil @modhash = nil @cookie = nil end |
#signed_in? ⇒ Boolean
Check is a user is currently signed in.
29 30 31 |
# File 'lib/redditkit/client/account.rb', line 29 def signed_in? !!@modhash and !!@cookie end |
#update_account(options) ⇒ Object
Updates the current user’s email or password.
48 49 50 51 52 53 |
# File 'lib/redditkit/client/account.rb', line 48 def update_account() password = [:new_password] parameters = { :curpass => [:current_password], :email => [:email], :newpass => password, :verpass => password, :api_type => :json } post('api/update', parameters) end |
#update_session(password) ⇒ String
Invalidates all session cookies and updates the current one.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/redditkit/client/account.rb', line 60 def update_session(password) response = post('api/clear_sessions', :dest => api_endpoint, :curpass => password, :api_type => 'json') response_headers = response[:response_headers] = response_headers['set-cookie'] = [/reddit_session=(.*?);/m, 1] @cookie = end |