Class: Tickethub::User
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Resource
#==, #[], #[]=, all, association, attribute, attributes, collection, descendants, #destroy, dump_value, #eql?, #errors, #hash, inherited, #initialize, #inspect, load, #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
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tickethub/user.rb', line 20 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
13 14 15 16 17 18 |
# File 'lib/tickethub/user.rb', line 13 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 |
Instance Method Details
#full_name ⇒ Object
34 35 36 |
# File 'lib/tickethub/user.rb', line 34 def full_name [first_name, last_name].reject(&:nil?).join ' ' end |