Class: FaaStRuby::User
- Inherits:
-
BaseObject
- Object
- BaseObject
- FaaStRuby::User
- Defined in:
- lib/faastruby/user.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#confirmation_token ⇒ Object
Returns the value of attribute confirmation_token.
-
#email ⇒ Object
Returns the value of attribute email.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#password ⇒ Object
Returns the value of attribute password.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
- #assign_credentials(response) ⇒ Object
- #confirm_account! ⇒ Object
- #has_credentials? ⇒ Boolean
- #login ⇒ Object
- #logout(all: false) ⇒ Object
- #save_credentials ⇒ Object
- #send_confirmation_code ⇒ Object
Methods inherited from BaseObject
#assign_attributes, #attributes=, #call_api, #initialize, #mass_assign
Constructor Details
This class inherits a constructor from FaaStRuby::BaseObject
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
23 24 25 |
# File 'lib/faastruby/user.rb', line 23 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
23 24 25 |
# File 'lib/faastruby/user.rb', line 23 def api_secret @api_secret end |
#confirmation_token ⇒ Object
Returns the value of attribute confirmation_token.
23 24 25 |
# File 'lib/faastruby/user.rb', line 23 def confirmation_token @confirmation_token end |
#email ⇒ Object
Returns the value of attribute email.
23 24 25 |
# File 'lib/faastruby/user.rb', line 23 def email @email end |
#errors ⇒ Object
Returns the value of attribute errors.
23 24 25 |
# File 'lib/faastruby/user.rb', line 23 def errors @errors end |
#password ⇒ Object
Returns the value of attribute password.
23 24 25 |
# File 'lib/faastruby/user.rb', line 23 def password @password end |
#status_code ⇒ Object
Returns the value of attribute status_code.
23 24 25 |
# File 'lib/faastruby/user.rb', line 23 def status_code @status_code end |
Class Method Details
.create(email:, password:) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/faastruby/user.rb', line 3 def self.create(email:, password:) api = API.new user = User.new(email: email) response = api.signup(email: email, password: password) user.status_code = response.code if response.errors.any? user.errors += response.errors return user end case response.code when 422 user.errors += ['(422) Unprocessable Entity', response.body] when 200, 201 true else user.errors << "(#{response.code}) Error" end return user end |
Instance Method Details
#assign_credentials(response) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/faastruby/user.rb', line 31 def assign_credentials(response) return if response.body['credentials'].nil? @api_key = response.body['credentials']['api_key'] @api_secret = response.body['credentials']['api_secret'] end |
#confirm_account! ⇒ Object
49 50 51 52 53 54 |
# File 'lib/faastruby/user.rb', line 49 def confirm_account! response = call_api { @api.confirm_account(@confirmation_token) } assign_credentials(response) unless response.errors.any? self end |
#has_credentials? ⇒ Boolean
45 46 47 |
# File 'lib/faastruby/user.rb', line 45 def has_credentials? @api_key && @api_secret end |
#login ⇒ Object
38 39 40 41 42 43 |
# File 'lib/faastruby/user.rb', line 38 def login response = call_api { @api.login(email: @email, password: @password) } assign_credentials(response) unless response.errors.any? self end |
#logout(all: false) ⇒ Object
25 26 27 28 29 |
# File 'lib/faastruby/user.rb', line 25 def logout(all: false) response = call_api { @api.logout(api_key: @api_key, api_secret: @api_secret, all: all) } self end |
#save_credentials ⇒ Object
62 63 64 65 66 |
# File 'lib/faastruby/user.rb', line 62 def save_credentials credentials_file = NewCredentials::CredentialsFile.new credentials_file.save(email: @email, api_key: @api_key, api_secret: @api_secret) end |
#send_confirmation_code ⇒ Object
56 57 58 59 60 |
# File 'lib/faastruby/user.rb', line 56 def send_confirmation_code response = call_api { @api.send_confirmation_code(@email) } self end |