Class: Amiando::TicketType

Inherits:
Resource show all
Defined in:
lib/amiando/ticket_type.rb

Instance Attribute Summary

Attributes inherited from Resource

#request, #response, #success

Class Method Summary collapse

Methods inherited from Resource

#==, #extract_attributes_from, #initialize, method_missing, #populate_create

Methods included from Attributes

#[], #id, included, #method_missing, #respond_to?, #type

Methods included from Autorun

included

Constructor Details

This class inherits a constructor from Amiando::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Amiando::Attributes

Class Method Details

.create(event_id, type) ⇒ Object

Create a ticket type for an event

Parameters:

  • event_id
  • type

    string or symbol of the following:

    • TICKETTYPE_ETICKET

    • TICKETTYPE_PAPER

    • TICKETTYPE_BADGE

    • TICKETTYPE_CONFIRMATION

    • TICKETTYPE_ONSITE

    It will also accept :eticket, :paper, etc and convert them appropriately



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/amiando/ticket_type.rb', line 17

def self.create(event_id, type)
  type = type[:type] if type.is_a?(Hash)

  unless type =~ /^tickettype_\w+/i
    type = "tickettype_#{type}"
  end

  object = Result.new do |response_body, result|
    result.errors = response_body['errors']
    response_body['id'] || false
  end

  post object, "api/event/#{event_id}/ticketType/create", :params => { :type => type.upcase }

  object
end

.find(ticket_type_id) ⇒ TicketType

Find a Ticket Type

Parameters:

  • ticket_type_id

Returns:



68
69
70
71
72
73
# File 'lib/amiando/ticket_type.rb', line 68

def self.find(ticket_type_id)
  object = new
  get object, "api/ticketType/#{ticket_type_id}"

  object
end

.find_all_by_event_id(event_id) ⇒ Result

Find all Ticket Types of an event

Parameters:

  • event_id

Returns:

  • (Result)

    with the list of ticket types for that event.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/amiando/ticket_type.rb', line 40

def self.find_all_by_event_id(event_id)
  object = Result.new do |response_body, result|
    if response_body['success']
      ticket_types = response_body['results']['ticketTypes'].map do |ticket_type|
        new(ticket_type)
      end

      available = response_body['results']['availableTicketTypes']

      OpenStruct.new(:ticket_types => ticket_types,
                     :available_ticket_types => available)
    else
      result.errors = response_body['errors']
      false
    end
  end

  get object, "api/event/#{event_id}/ticketTypes"

  object
end

.update(ticket_type_id, attributes) ⇒ Boolean

Update a ticket type

Parameters:

  • ticket_type_id
  • attributes (Hash)

    attributes to be updated

Returns:

  • (Boolean)

    result of the operation



82
83
84
85
86
87
# File 'lib/amiando/ticket_type.rb', line 82

def self.update(ticket_type_id, attributes)
  object = Boolean.new('success')
  post object, "api/ticketType/#{ticket_type_id}", :params => attributes

  object
end