Class: Courier::NotificationsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ NotificationsClient

Parameters:



19
20
21
22
# File 'lib/trycourier/notifications/client.rb', line 19

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



15
16
17
# File 'lib/trycourier/notifications/client.rb', line 15

def request_client
  @request_client
end

Instance Method Details

#cancel_submission(id:, submission_id:, request_options: nil) ⇒ Void

Parameters:

  • id (String)
  • submission_id (String)
  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


173
174
175
176
177
178
179
180
181
182
# File 'lib/trycourier/notifications/client.rb', line 173

def cancel_submission(id:, submission_id:, request_options: nil)
  @request_client.conn.delete("/notifications/#{id}/#{submission_id}/checks") 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_content(id:, request_options: nil) ⇒ Notifications::NotificationGetContentResponse

Parameters:

Returns:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trycourier/notifications/client.rb', line 43

def get_content(id:, request_options: nil)
  response = @request_client.conn.get("/notifications/#{id}/content") 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
  Notifications::NotificationGetContentResponse.from_json(json_object: response.body)
end

#get_draft_content(id:, request_options: nil) ⇒ Notifications::NotificationGetContentResponse

Parameters:

Returns:



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/trycourier/notifications/client.rb', line 58

def get_draft_content(id:, request_options: nil)
  response = @request_client.conn.get("/notifications/#{id}/draft/content") 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
  Notifications::NotificationGetContentResponse.from_json(json_object: response.body)
end

#get_submission_checks(id:, submission_id:, request_options: nil) ⇒ Notifications::SubmissionChecksGetResponse

Parameters:

  • id (String)
  • submission_id (String)
  • request_options (RequestOptions) (defaults to: nil)

Returns:



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

def get_submission_checks(id:, submission_id:, request_options: nil)
  response = @request_client.conn.get("/notifications/#{id}/#{submission_id}/checks") 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
  Notifications::SubmissionChecksGetResponse.from_json(json_object: response.body)
end

#list(cursor: nil, request_options: nil) ⇒ Notifications::NotificationListResponse

Parameters:

  • cursor (String) (defaults to: nil)
  • request_options (RequestOptions) (defaults to: nil)

Returns:



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

def list(cursor: nil, request_options: nil)
  response = @request_client.conn.get("/notifications") 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
  Notifications::NotificationListResponse.from_json(json_object: response.body)
end

#replace_submission_checks(id:, submission_id:, checks:, request_options: nil) ⇒ Notifications::SubmissionChecksReplaceResponse

Parameters:

  • id (String)
  • submission_id (String)
  • checks (Array<Hash>)

    Request of type Array<Notifications::BaseCheck>, as a Hash

    • :id (String)

    • :status (Notifications::CheckStatus)

    • :type (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/trycourier/notifications/client.rb', line 156

def replace_submission_checks(id:, submission_id:, checks:, request_options: nil)
  response = @request_client.conn.put("/notifications/#{id}/#{submission_id}/checks") 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 || {}), checks: checks }.compact
  end
  Notifications::SubmissionChecksReplaceResponse.from_json(json_object: response.body)
end

#update_draft_variations(id:, blocks: nil, channels: nil, request_options: nil) ⇒ Void

Parameters:

  • id (String)
  • blocks (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationBlock>, as a Hash

    • :alias_ (String)

    • :context (String)

    • :id (String)

    • :type (Notifications::BlockType)

    • :content (Hash)

    • :locales (Hash=> String)

    • :checksum (String)

  • channels (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationChannel>, as a Hash

    • :id (String)

    • :type (String)

    • :content (Hash)

      • :subject (String)

      • :title (String)

    • :locales (Hash=> String)

    • :checksum (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


120
121
122
123
124
125
126
127
128
129
130
# File 'lib/trycourier/notifications/client.rb', line 120

def update_draft_variations(id:, blocks: nil, channels: nil, request_options: nil)
  @request_client.conn.post("/notifications/#{id}/draft/variations") 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 || {}), blocks: blocks, channels: channels }.compact
  end
end

#update_variations(id:, blocks: nil, channels: nil, request_options: nil) ⇒ Void

Parameters:

  • id (String)
  • blocks (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationBlock>, as a Hash

    • :alias_ (String)

    • :context (String)

    • :id (String)

    • :type (Notifications::BlockType)

    • :content (Hash)

    • :locales (Hash=> String)

    • :checksum (String)

  • channels (Array<Hash>) (defaults to: nil)

    Request of type Array<Notifications::NotificationChannel>, as a Hash

    • :id (String)

    • :type (String)

    • :content (Hash)

      • :subject (String)

      • :title (String)

    • :locales (Hash=> String)

    • :checksum (String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


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

def update_variations(id:, blocks: nil, channels: nil, request_options: nil)
  @request_client.conn.post("/notifications/#{id}/variations") 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 || {}), blocks: blocks, channels: channels }.compact
  end
end