Class: TicketNetwork::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ticket_network/base.rb

Direct Known Subclasses

Catalog::Base, Checkout::Base

Defined Under Namespace

Classes: Action, Request

Class Method Summary collapse

Class Method Details

.action(operation, options = {}, &block) ⇒ Object

Creates a new operation.



139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ticket_network/base.rb', line 139

def action(operation, options={}, &block)
  options[:service] ||= service
  options[:defaults] ||= defaults
  options[:parser] ||= self::Parser
  action = Action.new(operation, options, &block)

  self.singleton_class.class_eval do
    define_method(action.name) do |*args|
      action.execute(*args)
    end
  end
end

.defaults(&block) ⇒ Object

Sets or returns action defaults.



120
121
122
123
124
125
126
# File 'lib/ticket_network/base.rb', line 120

def defaults(&block)
  unless block
    read_inheritable_attribute(:defaults)
  else
    write_inheritable_array(:defaults, [block])
  end
end

.get(operation, options = {}, &block) ⇒ Object

Creates a new GET operation.



129
130
131
# File 'lib/ticket_network/base.rb', line 129

def get(operation, options={}, &block)
  action(operation, options.merge(:method => :get), &block)
end

.post(operation, options = {}, &block) ⇒ Object

Creates a new POST operation.



134
135
136
# File 'lib/ticket_network/base.rb', line 134

def post(operation, options={}, &block)
  action(operation, options.merge(:method => :post), &block)
end

.service(service = nil) ⇒ Object

Sets or returns the service.



111
112
113
114
115
116
117
# File 'lib/ticket_network/base.rb', line 111

def service(service=nil)
  unless service
    read_inheritable_attribute(:service)
  else
    write_inheritable_attribute(:service, service)
  end
end