Class: Twilio::REST::Api::V2010::AccountContext::MessageInstance

Inherits:
InstanceResource
  • Object
show all
Defined in:
lib/twilio-ruby/rest/api/v2010/account/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, payload, account_sid: nil, sid: nil) ⇒ MessageInstance

Initialize the MessageInstance

Parameters:

  • version (Version)

    Version that contains the resource

  • payload (Hash)

    payload that contains response from Twilio

  • account_sid (String) (defaults to: nil)

    The SID of the Account that created this Message resource.

  • sid (String) (defaults to: nil)

    The SID of the Call resource to fetch.



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 395

def initialize(version, payload , account_sid: nil, sid: nil)
    super(version)
    
    # Marshaled Properties
    @properties = { 
        'body' => payload['body'],
        'num_segments' => payload['num_segments'],
        'direction' => payload['direction'],
        'from' => payload['from'],
        'to' => payload['to'],
        'date_updated' => Twilio.deserialize_rfc2822(payload['date_updated']),
        'price' => payload['price'],
        'error_message' => payload['error_message'],
        'uri' => payload['uri'],
        'account_sid' => payload['account_sid'],
        'num_media' => payload['num_media'],
        'status' => payload['status'],
        'messaging_service_sid' => payload['messaging_service_sid'],
        'sid' => payload['sid'],
        'date_sent' => Twilio.deserialize_rfc2822(payload['date_sent']),
        'date_created' => Twilio.deserialize_rfc2822(payload['date_created']),
        'error_code' => payload['error_code'] == nil ? payload['error_code'] : payload['error_code'].to_i,
        'price_unit' => payload['price_unit'],
        'api_version' => payload['api_version'],
        'subresource_uris' => payload['subresource_uris'],
    }

    # Context
    @instance_context = nil
    @params = { 'account_sid' =>   ,'sid' => sid  || @properties['sid']  , }
end

Instance Method Details

#account_sidString

Returns The SID of the [Account](www.twilio.com/docs/iam/api/account) that sent the message that created the resource.

Returns:



494
495
496
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 494

def 
    @properties['account_sid']
end

#api_versionString

Returns The API version used to process the message.

Returns:

  • (String)

    The API version used to process the message.



548
549
550
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 548

def api_version
    @properties['api_version']
end

#bodyString

Returns The message text. Can be up to 1,600 characters long.

Returns:

  • (String)

    The message text. Can be up to 1,600 characters long.



440
441
442
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 440

def body
    @properties['body']
end

#contextMessageContext

Generate an instance context for the instance, the context is capable of performing various actions. All instance actions are proxied to the context

Returns:



431
432
433
434
435
436
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 431

def context
    unless @instance_context
        @instance_context = MessageContext.new(@version , @params['account_sid'], @params['sid'])
    end
    @instance_context
end

#date_createdTime

Returns The date and time in GMT that the resource was created specified in [RFC 2822](www.ietf.org/rfc/rfc2822.txt) format.

Returns:



530
531
532
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 530

def date_created
    @properties['date_created']
end

#date_sentTime

Returns The date and time in GMT that the resource was sent specified in [RFC 2822](www.ietf.org/rfc/rfc2822.txt) format. For outgoing messages, this is when we sent the message. For incoming messages, this is when we made the HTTP request to your application.

Returns:

  • (Time)

    The date and time in GMT that the resource was sent specified in [RFC 2822](www.ietf.org/rfc/rfc2822.txt) format. For outgoing messages, this is when we sent the message. For incoming messages, this is when we made the HTTP request to your application.



524
525
526
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 524

def date_sent
    @properties['date_sent']
end

#date_updatedTime

Returns The date and time in GMT that the resource was last updated specified in [RFC 2822](www.ietf.org/rfc/rfc2822.txt) format.

Returns:



470
471
472
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 470

def date_updated
    @properties['date_updated']
end

#deleteBoolean

Delete the MessageInstance

Returns:

  • (Boolean)

    True if delete succeeds, false otherwise



561
562
563
564
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 561

def delete

    context.delete
end

#directionDirection

Returns:

  • (Direction)


452
453
454
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 452

def direction
    @properties['direction']
end

#error_codeString

Returns The error code returned if your message ‘status` is `failed` or `undelivered`. The error_code provides more information about the failure. If the message was successful, this value is null.

Returns:

  • (String)

    The error code returned if your message ‘status` is `failed` or `undelivered`. The error_code provides more information about the failure. If the message was successful, this value is null.



536
537
538
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 536

def error_code
    @properties['error_code']
end

#error_messageString

Returns The description of the ‘error_code` if your message `status` is `failed` or `undelivered`. If the message was successful, this value is null.

Returns:

  • (String)

    The description of the ‘error_code` if your message `status` is `failed` or `undelivered`. If the message was successful, this value is null.



482
483
484
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 482

def error_message
    @properties['error_message']
end

#feedbackfeedback

Access the feedback

Returns:



593
594
595
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 593

def feedback
    context.feedback
end

#fetchMessageInstance

Fetch the MessageInstance

Returns:



569
570
571
572
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 569

def fetch

    context.fetch
end

#fromString

Returns The phone number (in [E.164](en.wikipedia.org/wiki/E.164) format), [alphanumeric sender ID](www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id), or [Wireless SIM](www.twilio.com/docs/wireless/tutorials/communications-guides/how-to-send-and-receive-text-messages) that initiated the message. For incoming messages, this will be the number of the sending phone. For outgoing messages, this value will be one of your Twilio phone numbers or the alphanumeric sender ID used.

Returns:



458
459
460
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 458

def from
    @properties['from']
end

#inspectObject

Provide a detailed, user friendly representation



613
614
615
616
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 613

def inspect
    values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Api.V2010.MessageInstance #{values}>"
end

#mediamedia

Access the media

Returns:



600
601
602
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 600

def media
    context.media
end

#messaging_service_sidString

Returns The SID of the [Messaging Service](www.twilio.com/docs/sms/services/api) used with the message. The value is null if a Messaging Service was not used.

Returns:



512
513
514
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 512

def messaging_service_sid
    @properties['messaging_service_sid']
end

#num_mediaString

Returns The number of media files associated with the message. A message can send up to 10 media files.

Returns:

  • (String)

    The number of media files associated with the message. A message can send up to 10 media files.



500
501
502
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 500

def num_media
    @properties['num_media']
end

#num_segmentsString

Returns The number of segments that make up the complete message. A message body that is too large to be sent in a single SMS message is segmented and charged as multiple messages. Inbound messages over 160 characters are reassembled when the message is received. Note: When using a Messaging Service to send messages, ‘num_segments` will always be 0 in Twilio’s response to your API request.

Returns:

  • (String)

    The number of segments that make up the complete message. A message body that is too large to be sent in a single SMS message is segmented and charged as multiple messages. Inbound messages over 160 characters are reassembled when the message is received. Note: When using a Messaging Service to send messages, ‘num_segments` will always be 0 in Twilio’s response to your API request.



446
447
448
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 446

def num_segments
    @properties['num_segments']
end

#priceString

Returns The amount billed for the message, in the currency specified by ‘price_unit`. Note that your account is charged for each segment we send to the handset. Populated after the message has been sent. May not be immediately available.

Returns:

  • (String)

    The amount billed for the message, in the currency specified by ‘price_unit`. Note that your account is charged for each segment we send to the handset. Populated after the message has been sent. May not be immediately available.



476
477
478
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 476

def price
    @properties['price']
end

#price_unitString

Returns The currency in which ‘price` is measured, in [ISO 4127](www.iso.org/iso/home/standards/currency_codes.htm) format (e.g. `usd`, `eur`, `jpy`).

Returns:



542
543
544
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 542

def price_unit
    @properties['price_unit']
end

#sidString

Returns The unique string that that we created to identify the Message resource.

Returns:

  • (String)

    The unique string that that we created to identify the Message resource.



518
519
520
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 518

def sid
    @properties['sid']
end

#statusStatus

Returns:

  • (Status)


506
507
508
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 506

def status
    @properties['status']
end

#subresource_urisHash

Returns A list of related resources identified by their URIs relative to ‘api.twilio.com`.

Returns:

  • (Hash)

    A list of related resources identified by their URIs relative to ‘api.twilio.com`



554
555
556
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 554

def subresource_uris
    @properties['subresource_uris']
end

#toString

Returns The phone number in [E.164](en.wikipedia.org/wiki/E.164) format that received the message. For incoming messages, this will be one of your Twilio phone numbers. For outgoing messages, this will be the sending phone.

Returns:

  • (String)

    The phone number in [E.164](en.wikipedia.org/wiki/E.164) format that received the message. For incoming messages, this will be one of your Twilio phone numbers. For outgoing messages, this will be the sending phone.



464
465
466
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 464

def to
    @properties['to']
end

#to_sObject

Provide a user friendly representation



606
607
608
609
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 606

def to_s
    values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
    "<Twilio.Api.V2010.MessageInstance #{values}>"
end

#update(body: :unset, status: :unset) ⇒ MessageInstance

Update the MessageInstance

Parameters:

  • body (String) (defaults to: :unset)

    The text of the message you want to send. Can be up to 1,600 characters long.

  • status (UpdateStatus) (defaults to: :unset)

Returns:



579
580
581
582
583
584
585
586
587
588
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 579

def update(
    body: :unset, 
    status: :unset
)

    context.update(
        body: body, 
        status: status, 
    )
end

#uriString

Returns The URI of the resource, relative to ‘api.twilio.com`.

Returns:

  • (String)

    The URI of the resource, relative to ‘api.twilio.com`.



488
489
490
# File 'lib/twilio-ruby/rest/api/v2010/account/message.rb', line 488

def uri
    @properties['uri']
end