Class: Reach::REST::Api::Messaging::MessagingItemList
- Inherits:
-
ListResource
- Object
- ListResource
- Reach::REST::Api::Messaging::MessagingItemList
- Defined in:
- lib/reach-ruby/rest/api/messaging/messaging_item.rb
Instance Method Summary collapse
-
#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.
-
#each ⇒ Object
When passed a block, yields MessagingItemInstance records from the API.
-
#get_page(target_url) ⇒ Page
Retrieve a single page of MessagingItemInstance records from the API.
-
#initialize(version) ⇒ MessagingItemList
constructor
Initialize the MessagingItemList.
-
#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.
-
#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.
-
#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.
-
#to_s ⇒ Object
Provide a user friendly representation.
Constructor Details
#initialize(version) ⇒ MessagingItemList
Initialize the MessagingItemList
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
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 |
#each ⇒ Object
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.
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.
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.
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.
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_s ⇒ Object
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 |