Class: Courier::AsyncClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorization_token:, environment: Environment::PRODUCTION, max_retries: nil, timeout_in_seconds: nil) ⇒ AsyncClient

Parameters:

  • environment (Environment) (defaults to: Environment::PRODUCTION)
  • max_retries (Long) (defaults to: nil)

    The number of times to retry a failed request, defaults to 2.

  • timeout_in_seconds (Long) (defaults to: nil)
  • authorization_token (String)


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/trycourier.rb', line 85

def initialize(authorization_token:, environment: Environment::PRODUCTION, max_retries: nil,
               timeout_in_seconds: nil)
  @async_request_client = AsyncRequestClient.new(environment: environment, max_retries: max_retries,
                                                 timeout_in_seconds: timeout_in_seconds, authorization_token: authorization_token)
  @audiences = AsyncAudiencesClient.new(request_client: @async_request_client)
  @audit_events = AsyncAuditEventsClient.new(request_client: @async_request_client)
  @auth_tokens = AsyncAuthTokensClient.new(request_client: @async_request_client)
  @automations = AsyncAutomationsClient.new(request_client: @async_request_client)
  @brands = AsyncBrandsClient.new(request_client: @async_request_client)
  @bulk = AsyncBulkClient.new(request_client: @async_request_client)
  @lists = AsyncListsClient.new(request_client: @async_request_client)
  @messages = AsyncMessagesClient.new(request_client: @async_request_client)
  @notifications = AsyncNotificationsClient.new(request_client: @async_request_client)
  @profiles = AsyncProfilesClient.new(request_client: @async_request_client)
  @templates = AsyncTemplatesClient.new(request_client: @async_request_client)
  @tenants = AsyncTenantsClient.new(request_client: @async_request_client)
  @translations = AsyncTranslationsClient.new(request_client: @async_request_client)
  @users = Users::AsyncClient.new(request_client: @async_request_client)
end

Instance Attribute Details

#audiencesObject (readonly)

Returns the value of attribute audiences.



77
78
79
# File 'lib/trycourier.rb', line 77

def audiences
  @audiences
end

#audit_eventsObject (readonly)

Returns the value of attribute audit_events.



77
78
79
# File 'lib/trycourier.rb', line 77

def audit_events
  @audit_events
end

#auth_tokensObject (readonly)

Returns the value of attribute auth_tokens.



77
78
79
# File 'lib/trycourier.rb', line 77

def auth_tokens
  @auth_tokens
end

#automationsObject (readonly)

Returns the value of attribute automations.



77
78
79
# File 'lib/trycourier.rb', line 77

def automations
  @automations
end

#brandsObject (readonly)

Returns the value of attribute brands.



77
78
79
# File 'lib/trycourier.rb', line 77

def brands
  @brands
end

#bulkObject (readonly)

Returns the value of attribute bulk.



77
78
79
# File 'lib/trycourier.rb', line 77

def bulk
  @bulk
end

#listsObject (readonly)

Returns the value of attribute lists.



77
78
79
# File 'lib/trycourier.rb', line 77

def lists
  @lists
end

#messagesObject (readonly)

Returns the value of attribute messages.



77
78
79
# File 'lib/trycourier.rb', line 77

def messages
  @messages
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



77
78
79
# File 'lib/trycourier.rb', line 77

def notifications
  @notifications
end

#profilesObject (readonly)

Returns the value of attribute profiles.



77
78
79
# File 'lib/trycourier.rb', line 77

def profiles
  @profiles
end

#templatesObject (readonly)

Returns the value of attribute templates.



77
78
79
# File 'lib/trycourier.rb', line 77

def templates
  @templates
end

#tenantsObject (readonly)

Returns the value of attribute tenants.



77
78
79
# File 'lib/trycourier.rb', line 77

def tenants
  @tenants
end

#translationsObject (readonly)

Returns the value of attribute translations.



77
78
79
# File 'lib/trycourier.rb', line 77

def translations
  @translations
end

#usersObject (readonly)

Returns the value of attribute users.



77
78
79
# File 'lib/trycourier.rb', line 77

def users
  @users
end

Instance Method Details

#send(message:, request_options: nil) ⇒ SendMessageResponse

Use the send API to send a message to one or more recipients.

Parameters:

Returns:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/trycourier.rb', line 110

def send(message:, request_options: nil)
  response = @async_request_client.conn.post("/send") 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["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
    unless request_options&.idempotency_expiry.nil?
      req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = { **(request_options&.additional_body_parameters || {}), message: message }.compact
  end
  SendMessageResponse.from_json(json_object: response.body)
end