Sha256: 842509f2d0acd53e00ccd5c45ca91f33a063311c77f6a5c968f0132b840bf217
Contents?: true
Size: 1.39 KB
Versions: 31
Compression:
Stored size: 1.39 KB
Contents
module Tickethub class User < Resource path '/user', singleton: true require_relative 'user/supplier' collection :suppliers, User::Supplier association :token, Tickethub::Token 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 def self.reset(email) Tickethub.endpoint['/user/reset'].post email: email end 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 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 def full_name [first_name, last_name].reject(&:nil?).join ' ' end end end
Version data entries
31 entries across 31 versions & 1 rubygems