Class: Tickethub::User

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

Defined Under Namespace

Classes: 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



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tickethub/user.rb', line 29

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



11
12
13
14
15
16
# File 'lib/tickethub/user.rb', line 11

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



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

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

.verify(attributes) ⇒ Object



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

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



43
44
45
# File 'lib/tickethub/user.rb', line 43

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