Class: Reach::REST::Api::Messaging::MessagingItemList

Inherits:
ListResource
  • Object
show all
Defined in:
lib/reach-ruby/rest/api/messaging/messaging_item.rb

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ MessagingItemList

Initialize the MessagingItemList

Parameters:

  • version (Version)

    Version that contains the resource



26
27
28
29
30
31
32
33
34
35
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 26

def initialize(version)
    super(version)
    # Path Solution
    @solution = {  }
    @uri = { 
        "read" => "/messaging/v1/list", 
        "dispatch" => "/messaging/v1/create"
    }
    
end

Instance Method Details

#dispatch(dest: nil, src: nil, body: nil, bulk_identifier: :unset, scheduled_time: :unset, status_callback: :unset, max_price: :unset, validity_period: :unset) ⇒ MessagingItemInstance

Dispatch the MessagingItemInstance

Parameters:

  • dest (String) (defaults to: nil)

    The destination phone number in E.164 format of the message.

  • src (String) (defaults to: nil)

    The phone number (in E.164 format), or the alphanumeric sender ID that initiated the message.

  • body (String) (defaults to: nil)

    The text of the message to send. It can be up to 1,600 GSM-7 characters in length. That limit varies if your message is not made of only GSM-7 characters. More generally, the message body should not exceed 10 segments.

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

    The identifier of the bulk operation this message belongs to.

  • scheduled_time (Time) (defaults to: :unset)

    The datetime at which the message will be sent. Must be in ISO 8601 format. A message must be scheduled at least 15 min in advance of message send time and cannot be scheduled more than 5 days in advance of the request.

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

    The URL that will be called to send status information of your message. If provided, the API POST these message status changes to the URL: ‘queued`, `failed`, `sent`, `canceled`, `delivered`, or `undelivered`. URLs must contain a valid hostname and underscores are not allowed.

  • max_price (Float) (defaults to: :unset)

    The maximum total price in the applet currency that should be paid for the message to be delivered. If the cost exceeds ‘maxPrice`, the message will fail and a status of `failed` is sent to the status callback.

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

    It represents how long, in seconds, the message can remain in the queue. After this period elapses, the message fails and the status callback is called. After a message has been accepted by a carrier, however, there is no guarantee that the message will not be queued after this period. It is recommended that this value be at least 5 seconds. The maximum allowed value is 14,400 which corresponds to 4 hours.

Returns:



47
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
74
75
76
77
78
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 47

def dispatch(
    dest: nil, 
    src: nil, 
    body: nil, 
    bulk_identifier: :unset, 
    scheduled_time: :unset, 
    status_callback: :unset, 
    max_price: :unset, 
    validity_period: :unset
)

    baseParams = {
    }
    data = Reach::Values.of(baseParams.merge({                        
        'dest' => dest,
        'src' => src,
        'body' => body,
        'bulkIdentifier' => bulk_identifier,
        'scheduledTime' => Reach.serialize_iso8601_datetime(scheduled_time),
        'statusCallback' => status_callback,
        'maxPrice' => max_price,
        'validityPeriod' => validity_period,
    }))

    
    
    payload = @version.dispatch('POST', @uri["dispatch"], data: data)
    MessagingItemInstance.new(
        @version,
        payload,
    )
end

#eachObject

When passed a block, yields MessagingItemInstance records from the API. This operation lazily loads records as efficiently as possible until the limit is reached.



147
148
149
150
151
152
153
154
155
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 147

def each
    limits = @version.read_limits

    page = self.page(page_size: limits[:page_size], )

    @version.stream(page,
        limit: limits[:limit],
        page_limit: limits[:page_limit]).each {|x| yield x}
end

#get_page(target_url) ⇒ Page

Retrieve a single page of MessagingItemInstance records from the API. Request is executed immediately.

Parameters:

  • target_url (String)

    API-generated URL for the requested results page

Returns:

  • (Page)

    Page of MessagingItemInstance



199
200
201
202
203
204
205
206
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 199

def get_page(target_url)
    baseUrl = @version.url_without_pagination_info(target_url)
    response = @version.domain.request(
        'GET',
        target_url
    )
MessagingItemPage.new(baseUrl, @version, response, @solution)
end

#list(dest: :unset, src: :unset, bulk_identifier: :unset, sent_at: :unset, sent_after: :unset, sent_before: :unset, limit: nil, page_size: nil) ⇒ Array

Lists MessagingItemInstance records from the API as a list. Unlike stream(), this operation is eager and will load ‘limit` records into memory before returning.

Parameters:

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

    Retrieve messages sent to only this phone number. The phone number in E.164 format of the message.

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

    Retrieve messages sent from only this phone number, in E.164 format, or alphanumeric sender ID.

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

    Retrieve only messages that are assocaited with this ‘bulkIdentifier`.

  • sent_at (Time) (defaults to: :unset)

    Retrieve only messages sent at the specified date. Must be in ISO 8601 format.

  • sent_after (Time) (defaults to: :unset)

    Retrieve only messages sent after the specified datetime. Must be in ISO 8601 format.

  • sent_before (Time) (defaults to: :unset)

    Retrieve only messages sent before the specified datetime. Must be in ISO 8601 format.

  • limit (Integer) (defaults to: nil)

    Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit

  • page_size (Integer) (defaults to: nil)

    Number of records to fetch per request, when not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)

Returns:

  • (Array)

    Array of up to limit results



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 98

def list(dest: :unset, src: :unset, bulk_identifier: :unset, sent_at: :unset, sent_after: :unset, sent_before: :unset, limit: nil, page_size: nil)
    self.stream(
        dest: dest,
        src: src,
        bulk_identifier: bulk_identifier,
        sent_at: sent_at,
        sent_after: sent_after,
        sent_before: sent_before,
        limit: limit,
        page_size: page_size
    ).entries
end

#page(dest: :unset, src: :unset, bulk_identifier: :unset, sent_at: :unset, sent_after: :unset, sent_before: :unset, page_token: :unset, page_number: :unset, page_size: :unset) ⇒ Page

Retrieve a single page of MessagingItemInstance records from the API. Request is executed immediately.

Parameters:

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

    Retrieve messages sent to only this phone number. The phone number in E.164 format of the message.

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

    Retrieve messages sent from only this phone number, in E.164 format, or alphanumeric sender ID.

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

    Retrieve only messages that are assocaited with this ‘bulkIdentifier`.

  • sent_at (Time) (defaults to: :unset)

    Retrieve only messages sent at the specified date. Must be in ISO 8601 format.

  • sent_after (Time) (defaults to: :unset)

    Retrieve only messages sent after the specified datetime. Must be in ISO 8601 format.

  • sent_before (Time) (defaults to: :unset)

    Retrieve only messages sent before the specified datetime. Must be in ISO 8601 format.

  • page_number (Integer) (defaults to: :unset)

    Page Number, this value is simply for client state

  • page_size (Integer) (defaults to: :unset)

    Number of records to return, defaults to 20

Returns:

  • (Page)

    Page of MessagingItemInstance



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 169

def page(dest: :unset, src: :unset, bulk_identifier: :unset, sent_at: :unset, sent_after: :unset, sent_before: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
    params = Reach::Values.of({
        
        'dest' => dest,
        
        'src' => src,
        
        'bulkIdentifier' => bulk_identifier,
        
        'sentAt' =>  Reach.serialize_iso8601_datetime(sent_at),
        
        'sentAfter' =>  Reach.serialize_iso8601_datetime(sent_after),
        
        'sentBefore' =>  Reach.serialize_iso8601_datetime(sent_before),
        
        'page' => page_number,
        'pageSize' => page_size,
    })

    baseUrl = @version.url_without_pagination_info(@version.absolute_url(@uri["read"]), params)
    response = @version.page('GET', @uri["read"], params: params)

    MessagingItemPage.new(baseUrl, @version, response, @solution)
end

#stream(dest: :unset, src: :unset, bulk_identifier: :unset, sent_at: :unset, sent_after: :unset, sent_before: :unset, limit: nil, page_size: nil) ⇒ Enumerable

Streams Instance records from the API as an Enumerable. This operation lazily loads records as efficiently as possible until the limit is reached.

Parameters:

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

    Retrieve messages sent to only this phone number. The phone number in E.164 format of the message.

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

    Retrieve messages sent from only this phone number, in E.164 format, or alphanumeric sender ID.

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

    Retrieve only messages that are assocaited with this ‘bulkIdentifier`.

  • sent_at (Time) (defaults to: :unset)

    Retrieve only messages sent at the specified date. Must be in ISO 8601 format.

  • sent_after (Time) (defaults to: :unset)

    Retrieve only messages sent after the specified datetime. Must be in ISO 8601 format.

  • sent_before (Time) (defaults to: :unset)

    Retrieve only messages sent before the specified datetime. Must be in ISO 8601 format.

  • limit (Integer) (defaults to: nil)

    Upper limit for the number of records to return. stream() guarantees to never return more than limit. Default is no limit

  • page_size (Integer) (defaults to: nil)

    Number of records to fetch per request, when not set will use the default value of 50 records. If no page_size is defined but a limit is defined, stream() will attempt to read the limit with the most efficient page size, i.e. min(limit, 1000)

Returns:

  • (Enumerable)

    Enumerable that will yield up to limit results



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 128

def stream(dest: :unset, src: :unset, bulk_identifier: :unset, sent_at: :unset, sent_after: :unset, sent_before: :unset, limit: nil, page_size: nil)
    limits = @version.read_limits(limit, page_size)

    page = self.page(
        dest: dest,
        src: src,
        bulk_identifier: bulk_identifier,
        sent_at: sent_at,
        sent_after: sent_after,
        sent_before: sent_before,
        page_size: limits[:page_size], )

    @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
end

#to_sObject

Provide a user friendly representation



211
212
213
# File 'lib/reach-ruby/rest/api/messaging/messaging_item.rb', line 211

def to_s
    '#<Reach.Api.Messaging.MessagingItemList>'
end