Sha256: ce1139d0b5d3cb3625109ff42ac7fe591c1c0a6ca502293048e2982d4f9329b0

Contents?: true

Size: 1.07 KB

Versions: 45

Compression:

Stored size: 1.07 KB

Contents

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

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

    collection :apps, User::App
    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.[](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

45 entries across 45 versions & 1 rubygems

Version Path
tickethub-0.3.30 lib/tickethub/user.rb
tickethub-0.3.29 lib/tickethub/user.rb
tickethub-0.3.28 lib/tickethub/user.rb
tickethub-0.3.27 lib/tickethub/user.rb
tickethub-0.3.26 lib/tickethub/user.rb
tickethub-0.3.25 lib/tickethub/user.rb
tickethub-0.3.24 lib/tickethub/user.rb
tickethub-0.3.23 lib/tickethub/user.rb
tickethub-0.3.22 lib/tickethub/user.rb
tickethub-0.3.21 lib/tickethub/user.rb
tickethub-0.3.20 lib/tickethub/user.rb
tickethub-0.3.18 lib/tickethub/user.rb
tickethub-0.3.17 lib/tickethub/user.rb
tickethub-0.3.16 lib/tickethub/user.rb
tickethub-0.3.15 lib/tickethub/user.rb
tickethub-0.3.14 lib/tickethub/user.rb
tickethub-0.3.13 lib/tickethub/user.rb
tickethub-0.3.12 lib/tickethub/user.rb
tickethub-0.3.11 lib/tickethub/user.rb
tickethub-0.3.9 lib/tickethub/user.rb