Class: WhatsappSdk::Resource::ParameterObject

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp_sdk/resource/parameter_object.rb

Defined Under Namespace

Modules: Type Classes: InvalidType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, text: nil, currency: nil, date_time: nil, image: nil, document: nil, video: nil, location: nil) ⇒ ParameterObject

Returns a new instance of ParameterObject.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 82

def initialize(
  type:,
  text: nil,
  currency: nil,
  date_time: nil,
  image: nil,
  document: nil,
  video: nil,
  location: nil
)
  @type = type
  @text = text
  @currency = currency
  @date_time = date_time
  @image = image
  @document = document
  @video = video
  @location = location
  validate
end

Instance Attribute Details

#currencyObject

Returns Currency if the parameter object type is currency.



55
56
57
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 55

def currency
  @currency
end

#date_timeObject

Returns date_time if the parameter object type is date_time.



60
61
62
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 60

def date_time
  @date_time
end

#documentObject

Returns document if the parameter object type is document.



70
71
72
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 70

def document
  @document
end

#imageObject

Returns image if the parameter object type is image.



65
66
67
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 65

def image
  @image
end

#locationObject

Returns location if the parameter object type is location



80
81
82
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 80

def location
  @location
end

#textObject

Returns Text string if the parameter object type is text. For the header component, the character limit is 60 characters. For the body component, the character limit is 1024 characters.



50
51
52
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 50

def text
  @text
end

#typeObject

Returns the parameter type.



19
20
21
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 19

def type
  @type
end

#videoObject

Returns video if the parameter object type is video.



75
76
77
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 75

def video
  @video
end

Instance Method Details

#to_jsonObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 103

def to_json
  json = { type: type }
  json[type.to_sym] = case type
                      when "text"
                        text
                      when "currency"
                        currency.to_json
                      when "date_time"
                        date_time.to_json
                      when "image"
                        image.to_json
                      when "document"
                        document.to_json
                      when "video"
                        video.to_json
                      when "location"
                        location.to_json
                      else
                        raise "Invalid type: #{type}"
                      end

  json
end