Class: Tickethub::Channel

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

Defined Under Namespace

Classes: Answer, Booking, Coupon, Customer, Discount, Extra, Fee, Option, Order, Payment, Product, Purchase, Question, Refund, Session, Supplier, Tax, Ticket, Tier, Variant

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, #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

#initialize(endpoint, attributes = nil) ⇒ Channel

Returns a new instance of Channel.



39
40
41
42
43
44
45
46
47
48
# File 'lib/tickethub/channel.rb', line 39

def initialize(endpoint, attributes = nil)
  attributes ||= endpoint.get

  if attributes['token']
    endpoint = Tickethub.endpoint(auth_type: :bearer,
      password: attributes['token']['access_token'])[self.class.path]
  end

  super(endpoint, attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Tickethub::Resource

Class Method Details

.[](attributes) ⇒ Object



33
34
35
36
37
# File 'lib/tickethub/channel.rb', line 33

def self.[](attributes)
  token = attributes[:token].is_a?(String) ? attributes[:token]
    : attributes[:token][:access_token]
  self.call Tickethub.endpoint(auth_type: :bearer, password: token)[path]
end