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
- #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=, #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
#confirm_account! ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/faastruby/user.rb', line 50 def confirm_account! response = @api.confirm_account(@confirmation_token) @status_code = response.code if response.errors.any? @errors += response.errors return self end if response.body['credentials'] @api_key = response.body['credentials']['api_key'] @api_secret = response.body['credentials']['api_secret'] end self end |
#has_credentials? ⇒ Boolean
46 47 48 |
# File 'lib/faastruby/user.rb', line 46 def has_credentials? @api_key && @api_secret end |
#login ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/faastruby/user.rb', line 32 def login response = @api.login(email: @email, password: @password) @status_code = response.code if response.errors.any? @errors += response.errors return self end if response.body['credentials'] @api_key = response.body['credentials']['api_key'] @api_secret = response.body['credentials']['api_secret'] end self end |
#logout(all: false) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/faastruby/user.rb', line 25 def logout(all: false) response = @api.logout(api_key: @api_key, api_secret: @api_secret, all: all) @status_code = response.code @errors += response.errors if response.errors.any? self end |
#save_credentials ⇒ Object
71 72 73 74 |
# File 'lib/faastruby/user.rb', line 71 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
64 65 66 67 68 69 |
# File 'lib/faastruby/user.rb', line 64 def send_confirmation_code response = @api.send_confirmation_code(@email) @status_code = response.code @errors += response.errors if response.errors.any? self end |