Class: Courier::AsyncAudiencesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/audiences/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AsyncAudiencesClient

Parameters:



124
125
126
127
# File 'lib/trycourier/audiences/client.rb', line 124

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



120
121
122
# File 'lib/trycourier/audiences/client.rb', line 120

def request_client
  @request_client
end

Instance Method Details

#delete(audience_id:, request_options: nil) ⇒ Void

Deletes the specified audience.

Parameters:

  • audience_id (String)

    A unique identifier representing the audience id

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/trycourier/audiences/client.rb', line 181

def delete(audience_id:, request_options: nil)
  Async do
    @request_client.conn.delete("/audiences/#{audience_id}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
  end
end

#get(audience_id:, request_options: nil) ⇒ Audiences::Audience

Returns the specified audience by id.

Parameters:

  • audience_id (String)

    A unique identifier representing the audience_id

  • request_options (RequestOptions) (defaults to: nil)

Returns:



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/trycourier/audiences/client.rb', line 134

def get(audience_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/audiences/#{audience_id}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Audiences::Audience.from_json(json_object: response.body)
  end
end

#list_audiences(cursor: nil, request_options: nil) ⇒ Audiences::AudienceListResponse

Get the audiences associated with the authorization token.

Parameters:

  • cursor (String) (defaults to: nil)

    A unique identifier that allows for fetching the next set of audiences

  • request_options (RequestOptions) (defaults to: nil)

Returns:



220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/trycourier/audiences/client.rb', line 220

def list_audiences(cursor: nil, request_options: nil)
  Async do
    response = @request_client.conn.get("/audiences") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.params = { **(request_options&.additional_query_parameters || {}), "cursor": cursor }.compact
    end
    Audiences::AudienceListResponse.from_json(json_object: response.body)
  end
end

#list_members(audience_id:, cursor: nil, request_options: nil) ⇒ Audiences::AudienceMemberListResponse

Get list of members of an audience.

Parameters:

  • audience_id (String)

    A unique identifier representing the audience id

  • cursor (String) (defaults to: nil)

    A unique identifier that allows for fetching the next set of members

  • request_options (RequestOptions) (defaults to: nil)

Returns:



200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/trycourier/audiences/client.rb', line 200

def list_members(audience_id:, cursor: nil, request_options: nil)
  Async do
    response = @request_client.conn.get("/audiences/#{audience_id}/members") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.params = { **(request_options&.additional_query_parameters || {}), "cursor": cursor }.compact
    end
    Audiences::AudienceMemberListResponse.from_json(json_object: response.body)
  end
end

#update(audience_id:, name: nil, description: nil, filter: nil, request_options: nil) ⇒ Audiences::AudienceUpdateResponse

Creates or updates audience.

Parameters:

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/trycourier/audiences/client.rb', line 156

def update(audience_id:, name: nil, description: nil, filter: nil, request_options: nil)
  Async do
    response = @request_client.conn.put("/audiences/#{audience_id}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        name: name,
        description: description,
        filter: filter
      }.compact
    end
    Audiences::AudienceUpdateResponse.from_json(json_object: response.body)
  end
end