Class: Courier::AudiencesClient

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:) ⇒ AudiencesClient

Parameters:



17
18
19
20
# File 'lib/trycourier/audiences/client.rb', line 17

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



13
14
15
# File 'lib/trycourier/audiences/client.rb', line 13

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)


70
71
72
73
74
75
76
77
78
79
# File 'lib/trycourier/audiences/client.rb', line 70

def delete(audience_id:, request_options: nil)
  @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

#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:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/trycourier/audiences/client.rb', line 27

def get(audience_id:, request_options: nil)
  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

#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:



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/trycourier/audiences/client.rb', line 105

def list_audiences(cursor: nil, request_options: nil)
  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

#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:



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/trycourier/audiences/client.rb', line 87

def list_members(audience_id:, cursor: nil, request_options: nil)
  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

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

Creates or updates audience.

Parameters:

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/trycourier/audiences/client.rb', line 47

def update(audience_id:, name: nil, description: nil, filter: nil, request_options: nil)
  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