Class: Tickethub::User

Inherits:
Resource show all
Defined in:
lib/tickethub/user.rb

Defined Under Namespace

Classes: App, Reseller, Supplier

Instance Attribute Summary

Attributes inherited from Resource

#endpoint

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, all, association, attribute, attributes, call, collection, collection_method, collection_methods, descendants, #destroy, dump_value, #eql?, #errors, #hash, inherited, #initialize, #inspect, #load, load_value, path, polymorphic, register_type, registered_types, #reload!, #respond_to?, scope, scopes, serialize, singleton?, #to_h, #to_param, #to_s, #update, #valid?

Constructor Details

This class inherits a constructor from Tickethub::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tickethub::Resource

Class Method Details

.[](attributes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tickethub/user.rb', line 33

def self.[](attributes)
  token = if attributes[:email]
    Tickethub.endpoint['/user/token'].post(grant_type: 'password',
      username: attributes[:email], password: attributes[:password])
        .decoded['access_token']
  else
    attributes[:token].is_a?(String) ? attributes[:token]
      : attributes[:token][:access_token]
  end

  endpoint = Tickethub.endpoint(auth_type: :bearer, password: token)['/user']
  self.new endpoint
end

.create(attributes) ⇒ Object



15
16
17
18
19
20
# File 'lib/tickethub/user.rb', line 15

def self.create(attributes)
  response = Tickethub.endpoint['/user'].post(attributes)
  self[attributes.slice 'email', 'password']
rescue Tickethub::ResourceInvalid => err
  new nil, Tickethub::Response.new(err.response).decoded
end

.reset(email) ⇒ Object



22
23
24
# File 'lib/tickethub/user.rb', line 22

def self.reset(email)
  Tickethub.endpoint['/user/reset'].post email: email
end

.verify(attributes) ⇒ Object



26
27
28
29
30
31
# File 'lib/tickethub/user.rb', line 26

def self.verify(attributes)
  response = Tickethub.endpoint['/user/verify'].post(attributes)
  self[email: response.decoded['email'], password: attributes['password']]
rescue Tickethub::ResourceInvalid => err
  new nil, Tickethub::Response.new(err.response).decoded
end

Instance Method Details

#full_nameObject



47
48
49
# File 'lib/tickethub/user.rb', line 47

def full_name
  [first_name, last_name].reject(&:nil?).join ' '
end