Class: Gist::User
- Inherits:
-
Object
- Object
- Gist::User
- Defined in:
- lib/gist/user.rb
Overview
Class to hold user information
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Personal access token.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#authenticate ⇒ Object
Authentication method, will set the authentication token for the user.
-
#initialize(username = nil, password = nil) ⇒ User
constructor
Create the GistUser instance.
Constructor Details
#initialize(username = nil, password = nil) ⇒ User
Create the GistUser instance
9 10 11 12 13 14 15 |
# File 'lib/gist/user.rb', line 9 def initialize(username = nil, password = nil) @username = username @password = password @http = Net::HTTP.new(Gist::API_URL, Gist::API_PORT) @http.use_ssl = true @access_token = load_token if saved? end |
Instance Attribute Details
#access_token ⇒ Object
Personal access token
6 7 8 |
# File 'lib/gist/user.rb', line 6 def access_token @access_token end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/gist/user.rb', line 5 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
4 5 6 |
# File 'lib/gist/user.rb', line 4 def username @username end |
Instance Method Details
#authenticate ⇒ Object
Authentication method, will set the authentication token for the user
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gist/user.rb', line 18 def authenticate # If we already have authenticated, don't let it happen again return unless @access_token.nil? # If not, let's authenticate @http.start do |http| response = http.request(auth_obj) json_response = JSON.parse(response.body) @access_token = json_response['token'] end # Then save save populate_methods(user_info) end |