Class: SquareEvent::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/square_event/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, merchant_id, event_id, data, payload, environment, timestamp) ⇒ Event

Returns a new instance of Event.



25
26
27
28
29
30
31
32
33
# File 'lib/square_event/event.rb', line 25

def initialize(type, merchant_id, event_id, data, payload, environment, timestamp)
  @type = type
  @merchant_id = merchant_id
  @event_id = event_id
  @data = data
  @environment = environment
  @initial_delivery_timestamp = timestamp
  @internal_hash = {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/square_event/event.rb', line 3

def data
  @data
end

#environmentObject (readonly)

Returns the value of attribute environment.



3
4
5
# File 'lib/square_event/event.rb', line 3

def environment
  @environment
end

#event_idObject (readonly)

Returns the value of attribute event_id.



3
4
5
# File 'lib/square_event/event.rb', line 3

def event_id
  @event_id
end

#initial_delivery_timestampObject (readonly)

Returns the value of attribute initial_delivery_timestamp.



3
4
5
# File 'lib/square_event/event.rb', line 3

def initial_delivery_timestamp
  @initial_delivery_timestamp
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id.



3
4
5
# File 'lib/square_event/event.rb', line 3

def merchant_id
  @merchant_id
end

#payloadObject (readonly)

Returns the value of attribute payload.



3
4
5
# File 'lib/square_event/event.rb', line 3

def payload
  @payload
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/square_event/event.rb', line 3

def type
  @type
end

Class Method Details

.construct_from(payload, environment, timestamp) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/square_event/event.rb', line 16

def self.construct_from(payload, environment, timestamp)
  type        = payload[:type]
  merchant_id = payload[:merchant_id]
  event_id    = payload[:event_id]
  data        = payload[:data]

  new(type, merchant_id, event_id, data, payload, environment, timestamp)
end

Instance Method Details

#[](key) ⇒ Object



35
36
37
# File 'lib/square_event/event.rb', line 35

def [](key)
  @internal_hash[key]
end

#[]=(key, value) ⇒ Object



39
40
41
# File 'lib/square_event/event.rb', line 39

def []=(key, value)
  @internal_hash[key] = value
end

#livemodeObject Also known as: livemode?



43
44
45
# File 'lib/square_event/event.rb', line 43

def livemode
  environment != 'Sandbox'
end

#sandboxObject Also known as: sandbox?



48
49
50
# File 'lib/square_event/event.rb', line 48

def sandbox
  environment == 'Sandbox'
end

#to_hObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/square_event/event.rb', line 5

def to_h
  {
    type: type,
    merchant_id: merchant_id,
    event_id: event_id,
    data: data,
    environment: environment,
    initial_delivery_timestamp: initial_delivery_timestamp
  }
end