Class: SpreeCmCommissioner::Integrations::Larryta::Resources::Passenger

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

Overview

Represents a passenger record from Larryta API

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_api_response

Constructor Details

#initialize(data) ⇒ Passenger

rubocop:disable Lint/MissingSuper



6
7
8
9
10
11
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/passenger.rb', line 6

def initialize(data) # rubocop:disable Lint/MissingSuper
  @customer_id = data['customer_id']
  @customer_code = data['customer_code']
  @status = data['status']
  @msg = data['msg']
end

Instance Attribute Details

#customer_codeObject

Returns the value of attribute customer_code.



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

def customer_code
  @customer_code
end

#customer_idObject

Returns the value of attribute customer_id.



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

def customer_id
  @customer_id
end

#msgObject

Returns the value of attribute msg.



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

def msg
  @msg
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#error_messageObject

Returns the error message if failed



29
30
31
32
33
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/passenger.rb', line 29

def error_message
  return msg if failed?

  nil
end

#failed?Boolean

Returns true if passenger creation failed

Returns:

  • (Boolean)


24
25
26
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/passenger.rb', line 24

def failed?
  !success?
end

#idObject

Returns the passenger ID



14
15
16
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/passenger.rb', line 14

def id
  customer_id
end

#success?Boolean

Returns true if the passenger was created successfully

Returns:

  • (Boolean)


19
20
21
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/passenger.rb', line 19

def success?
  status == true && customer_id.present?
end

#to_hObject

Returns a hash representation



36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/passenger.rb', line 36

def to_h
  {
    id: id,
    customer_code: customer_code,
    success: success?,
    failed: failed?,
    error_message: error_message,
    status: status,
    message: msg
  }
end