Class: SpreeCmCommissioner::Integrations::StadiumXV1::Resources::Zone

Inherits:
Base
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_collection

Constructor Details

#initialize(attributes = {}) ⇒ Zone

Returns a new instance of Zone.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 23

def initialize(attributes = {})
  super(attributes)

  @total_seats = attributes['total_seats'].to_i
  @available_seats = attributes['available_seats'].to_i
  @online_price = attributes['online_price'].to_f
  @walkin_price = attributes['walkin_price'].to_f
  @is_active = attributes['is_active'] != false
  @color_brand = valid_hex_color?(attributes['color_brand']) ? attributes['color_brand'].upcase : nil

  @created_at = Time.zone.at(attributes['created_at'] / 1000) if attributes['created_at'].present?
  @updated_at = Time.zone.at(attributes['updated_at'] / 1000) if attributes['updated_at'].present?

  @start_datetime = Time.zone.parse(attributes['start_datetime']) if attributes['start_datetime'].present?
  @end_datetime = Time.zone.parse(attributes['end_datetime']) if attributes['end_datetime'].present?
  @ticket_image = TicketImage.new(attributes['ticket_image']) if attributes['ticket_image'].is_a?(Hash)
end

Instance Attribute Details

#_idObject

Returns the value of attribute _id.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def _id
  @_id
end

#available_seatsObject

Returns the value of attribute available_seats.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def available_seats
  @available_seats
end

#club_idObject

Returns the value of attribute club_id.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def club_id
  @club_id
end

#color_brandObject

Returns the value of attribute color_brand.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def color_brand
  @color_brand
end

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def created_at
  @created_at
end

#created_byObject

Returns the value of attribute created_by.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def created_by
  @created_by
end

#end_datetimeObject

Returns the value of attribute end_datetime.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def end_datetime
  @end_datetime
end

#is_activeObject

Returns the value of attribute is_active.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def is_active
  @is_active
end

#is_earlybirdObject

Returns the value of attribute is_earlybird.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def is_earlybird
  @is_earlybird
end

#match_idObject

Returns the value of attribute match_id.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def match_id
  @match_id
end

#online_priceObject

Returns the value of attribute online_price.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def online_price
  @online_price
end

#start_datetimeObject

Returns the value of attribute start_datetime.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def start_datetime
  @start_datetime
end

#ticket_imageObject

Returns the value of attribute ticket_image.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def ticket_image
  @ticket_image
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def title
  @title
end

#total_seatsObject

Returns the value of attribute total_seats.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def total_seats
  @total_seats
end

#updated_atObject

Returns the value of attribute updated_at.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def updated_at
  @updated_at
end

#updated_byObject

Returns the value of attribute updated_by.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def updated_by
  @updated_by
end

#walkin_priceObject

Returns the value of attribute walkin_price.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 4

def walkin_price
  @walkin_price
end

Instance Method Details

#set_match_id(match_id) ⇒ Object

Manually set the match_id on the zone object. This is needed because the API does not return match_id but it’s required for ticket creation. This is a temporary workaround until the API returns the match_id.



44
45
46
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 44

def set_match_id(match_id) # rubocop:disable Naming/AccessorMethodName
  @match_id = match_id
end

#to_hashObject Also known as: to_h



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/resources/zone.rb', line 48

def to_hash
  hash = {
    '_id' => _id,
    'title' => title,
    'color_brand' => color_brand,
    'total_seats' => total_seats,
    'online_price' => online_price,
    'walkin_price' => walkin_price,
    'match_id' => match_id,
    'club_id' => club_id,
    'is_active' => is_active,
    'created_by' => created_by,
    'updated_by' => updated_by,
    'created_at' => created_at&.iso8601,
    'updated_at' => updated_at&.iso8601,
    'end_datetime' => end_datetime&.iso8601,
    'is_earlybird' => is_earlybird,
    'start_datetime' => start_datetime&.iso8601,
    'available_seats' => available_seats,
    'ticket_image' => ticket_image&.to_h
  }.compact

  hash['ticket_image'] = hash['ticket_image'].transform_keys(&:to_s) if hash['ticket_image']

  hash
end