Sha256: 0376a43e5410745866a6318c0b8b4f66008353e1e7eede8c5880bb00e055e3f8

Contents?: true

Size: 1.53 KB

Versions: 36

Compression:

Stored size: 1.53 KB

Contents

module Tickethub
  class User < Resource
    path '/user', singleton: true

    require_relative 'user/app'
    require_relative 'user/reseller'
    require_relative 'user/supplier'

    collection :apps, User::App
    collection :resellers, User::Reseller
    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

36 entries across 36 versions & 1 rubygems

Version Path
tickethub-0.3.67 lib/tickethub/user.rb
tickethub-0.3.66 lib/tickethub/user.rb
tickethub-0.3.65 lib/tickethub/user.rb
tickethub-0.3.64 lib/tickethub/user.rb
tickethub-0.3.63 lib/tickethub/user.rb
tickethub-0.3.62 lib/tickethub/user.rb
tickethub-0.3.61 lib/tickethub/user.rb
tickethub-0.3.60 lib/tickethub/user.rb
tickethub-0.3.59 lib/tickethub/user.rb
tickethub-0.3.58 lib/tickethub/user.rb
tickethub-0.3.57 lib/tickethub/user.rb
tickethub-0.3.56 lib/tickethub/user.rb
tickethub-0.3.55 lib/tickethub/user.rb
tickethub-0.3.54 lib/tickethub/user.rb
tickethub-0.3.53 lib/tickethub/user.rb
tickethub-0.3.52 lib/tickethub/user.rb
tickethub-0.3.51 lib/tickethub/user.rb
tickethub-0.3.50 lib/tickethub/user.rb
tickethub-0.3.49 lib/tickethub/user.rb
tickethub-0.3.47 lib/tickethub/user.rb