Class: Courier::BulkClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ BulkClient

Parameters:



17
18
19
20
# File 'lib/trycourier/bulk/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/bulk/client.rb', line 13

def request_client
  @request_client
end

Instance Method Details

#create_job(message:, request_options: nil) ⇒ Bulk::BulkCreateJobResponse

Parameters:

  • message (Hash)

    Request of type Bulk::InboundBulkMessage, as a Hash

    • :message (Hash)

    • :brand (String)

    • :data (Hash=> String)

    • :event (String)

    • :locale (Hash=> String)

    • :override (Object)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/trycourier/bulk/client.rb', line 31

def create_job(message:, request_options: nil)
  response = @request_client.conn.post("/bulk") 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
  Bulk::BulkCreateJobResponse.from_json(json_object: response.body)
end

#get_job(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobResponse

Get a bulk job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request_options (RequestOptions) (defaults to: nil)

Returns:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/trycourier/bulk/client.rb', line 96

def get_job(job_id:, request_options: nil)
  response = @request_client.conn.get("/bulk/#{job_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
  Bulk::BulkGetJobResponse.from_json(json_object: response.body)
end

#get_users(job_id:, request_options: nil) ⇒ Bulk::BulkGetJobUsersResponse

Get Bulk Job Users

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request_options (RequestOptions) (defaults to: nil)

Returns:



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/trycourier/bulk/client.rb', line 113

def get_users(job_id:, request_options: nil)
  response = @request_client.conn.get("/bulk/#{job_id}/users") 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
  Bulk::BulkGetJobUsersResponse.from_json(json_object: response.body)
end

#ingest_users(job_id:, request:, request_options: nil) ⇒ Void

Ingest user data into a Bulk Job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request (Hash)

    Request of type Bulk::BulkIngestUsersParams, as a Hash

    • :users (Array<Bulk::InboundBulkMessageUser>)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:

  • (Void)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/trycourier/bulk/client.rb', line 55

def ingest_users(job_id:, request:, request_options: nil)
  @request_client.conn.post("/bulk/#{job_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["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 || {}), **(request_options&.additional_body_parameters || {}) }.compact
  end
end

#run_job(job_id:, request_options: nil) ⇒ Void

Run a bulk job

Parameters:

  • job_id (String)

    A unique identifier representing the bulk job

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:

  • (Void)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/trycourier/bulk/client.rb', line 76

def run_job(job_id:, request_options: nil)
  @request_client.conn.post("/bulk/#{job_id}/run") 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
  end
end