tronzap-sdk 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,11 @@
2
2
 
3
3
  require "digest"
4
4
  require "json"
5
+ require "openssl"
5
6
 
6
7
  module Tronzap
7
8
  # Client for the {https://docs.tronzap.com/ TronZap API}: buy TRON energy and bandwidth, activate addresses, run
8
- # AML checks and manage energy subscriptions.
9
+ # AML checks, manage energy subscriptions and place bulk energy orders.
9
10
  #
10
11
  # A client is immutable and safe to share between threads. Create one per set of credentials.
11
12
  #
@@ -250,6 +251,91 @@ module Tronzap
250
251
  post("/v1/subscriptions/history", body) { Responses::SubscriptionHistory.from_api(_1) }
251
252
  end
252
253
 
254
+ # Validates and prices the rows of a bulk energy order. The calculation is valid for 10 minutes; nothing is
255
+ # charged. Invalid rows do not fail the request: they come back in {Responses::BulkCalculation#rejected} with
256
+ # their row number. When no row is valid, the call raises {BulkNoValidItemsError}.
257
+ #
258
+ # @overload bulk_calculate(request)
259
+ # @param request [Requests::BulkCalculate]
260
+ # @overload bulk_calculate(items:, duration: 1)
261
+ # @param items [Array<Requests::BulkItem, Hash>] at most 10 000 rows with +address+ and +amount+
262
+ # @return [Responses::BulkCalculation]
263
+ # @raise [ArgumentError, Error]
264
+ def bulk_calculate(request = nil, **params)
265
+ body = build(Requests::BulkCalculate, request, params).body
266
+ post("/v1/bulk/calculate", body) { Responses::BulkCalculation.from_api(_1) }
267
+ end
268
+
269
+ # Starts a bulk order from a calculation. Each address is charged when it is processed, and inactive addresses
270
+ # are skipped without a charge. If the price changed since the calculation, the order is not started and the
271
+ # call raises {BulkPriceChangedError}: confirm the new total of its calculation, then start the order with that
272
+ # calculation's ID. Repeating a call with the same ID or external ID returns the order already started.
273
+ #
274
+ # @overload bulk_create(request)
275
+ # @param request [Requests::BulkCreate]
276
+ # @overload bulk_create(id:, external_id: nil, force: false, max_price_increase: nil, webhook_url: nil)
277
+ # @return [Responses::BulkOrder]
278
+ # @raise [ArgumentError, Error]
279
+ def bulk_create(request = nil, **params)
280
+ body = build(Requests::BulkCreate, request, params).body
281
+ post("/v1/bulk/create", body) { Responses::BulkOrder.from_api(_1) }
282
+ end
283
+
284
+ # The status and progress of a bulk order, by its TronZap ID or by your external ID.
285
+ #
286
+ # @overload bulk_check(request)
287
+ # @param request [Requests::BulkLookup]
288
+ # @overload bulk_check(id: nil, external_id: nil)
289
+ # @return [Responses::BulkOrder]
290
+ # @raise [ArgumentError, Error]
291
+ def bulk_check(request = nil, **params)
292
+ body = build(Requests::BulkLookup, request, params).body
293
+ post("/v1/bulk/check", body) { Responses::BulkOrder.from_api(_1) }
294
+ end
295
+
296
+ # One page of your bulk orders, newest first.
297
+ #
298
+ # @overload get_bulk_history(request)
299
+ # @param request [Requests::BulkHistory]
300
+ # @overload get_bulk_history(page: 1, per_page: 10)
301
+ # @return [Responses::BulkHistory]
302
+ # @raise [ArgumentError, Error]
303
+ def get_bulk_history(request = nil, **params)
304
+ body = build(Requests::BulkHistory, request, params).body
305
+ post("/v1/bulk/history", body) { Responses::BulkHistory.from_api(_1) }
306
+ end
307
+
308
+ # The per-address report of a bulk order as CSV with a header line and the columns +row+, +address+, +amount+,
309
+ # +status+, +reason+, +charged+ and +transaction_id+. Rows the calculation rejected are not included.
310
+ #
311
+ # @overload bulk_report(request)
312
+ # @param request [Requests::BulkReport]
313
+ # @overload bulk_report(id: nil, external_id: nil, status: nil)
314
+ # @return [String] the CSV, in UTF-8
315
+ # @raise [ArgumentError, Error]
316
+ def bulk_report(request = nil, **params)
317
+ response = request(post_request("/v1/bulk/report", build(Requests::BulkReport, request, params).body))
318
+ return ResponseDecoder.text(response.body) if ResponseDecoder.csv?(response)
319
+
320
+ ResponseDecoder.decode(response) { nil }
321
+ raise InvalidResponseError.new("Expected a CSV report", status: response.status.to_i,
322
+ response_body: ResponseDecoder.text(response.body))
323
+ end
324
+
325
+ # Checks the +X-Signature+ header of a bulk order webhook: the SHA-256 of the raw body followed by your API
326
+ # secret, in hex.
327
+ #
328
+ # @param body [String] the raw request body, exactly as received
329
+ # @param signature [String, nil] the value of the +X-Signature+ header
330
+ # @return [Boolean] whether the signature matches the body and your API secret
331
+ def verify_webhook_signature(body, signature)
332
+ raise ArgumentError, "body must be a String" unless body.is_a?(String)
333
+ return false unless signature.is_a?(String)
334
+
335
+ expected = Digest::SHA256.hexdigest(body.b + config.api_secret.b)
336
+ OpenSSL.secure_compare(expected, signature.strip.downcase)
337
+ end
338
+
253
339
  # @return [String] a description that leaves out the credentials
254
340
  def inspect
255
341
  "#<#{self.class.name} base_url=#{config.base_url.inspect}>"
@@ -273,16 +359,22 @@ module Tronzap
273
359
  end
274
360
 
275
361
  def post(path, payload, &)
362
+ ResponseDecoder.decode(request(post_request(path, payload)), &)
363
+ end
364
+
365
+ def post_request(path, payload)
276
366
  body = JSON.generate(payload)
277
- request = HttpAdapter::Request.new(
367
+ HttpAdapter::Request.new(
278
368
  http_method: :post,
279
369
  url: "#{config.base_url}#{path}",
280
370
  headers: headers(body),
281
371
  body: body,
282
372
  timeout: config.timeout
283
373
  )
284
- response = HttpAdapter.translate_errors { config.adapter.call(request) }
285
- ResponseDecoder.decode(response, &)
374
+ end
375
+
376
+ def request(http_request)
377
+ HttpAdapter.translate_errors { config.adapter.call(http_request) }
286
378
  end
287
379
 
288
380
  def headers(body)
@@ -109,6 +109,10 @@ module Tronzap
109
109
  object(value, name).to_h { |key, amount| [key.to_s.freeze, to_decimal(amount, "#{name}.#{key}")] }.freeze
110
110
  end
111
111
 
112
+ def integer_map(value, name)
113
+ object(value, name).to_h { |key, count| [key.to_s.freeze, integer(count, "#{name}.#{key}")] }.freeze
114
+ end
115
+
112
116
  def timestamp(value, name)
113
117
  case value
114
118
  when nil then nil
@@ -27,19 +27,62 @@ module Tronzap
27
27
  # @return [String] the raw response body
28
28
  attr_reader :response_body
29
29
 
30
+ # @return [Object, nil] the +result+ the API sent along with the error, as parsed JSON (numbers as +Integer+ or
31
+ # +BigDecimal+), or +nil+. {ErrorCode::BULK_PRICE_CHANGED} and {ErrorCode::BULK_NO_VALID_ITEMS} carry it;
32
+ # {BulkPriceChangedError} and {BulkNoValidItemsError} also expose it typed.
33
+ attr_reader :result
34
+
35
+ # @return [Float, nil] seconds to wait before retrying, from the +Retry-After+ header or the +retry_after+ field,
36
+ # or +nil+ when the API sent neither. {ErrorCode::RATE_LIMITED} carries it.
37
+ attr_reader :retry_after
38
+
30
39
  # @param message [String] the error message from the API
31
40
  # @param code [Integer] the numeric error code
32
41
  # @param status [Integer] the HTTP status of the response
33
42
  # @param response_body [String] the raw response body
34
43
  # @param error_key [String, nil] the error key
35
44
  # @param request_id [String, nil] the request ID
36
- def initialize(message, code:, status:, response_body:, error_key: nil, request_id: nil)
45
+ # @param result [Object, nil] the +result+ sent with the error
46
+ # @param retry_after [Float, nil] seconds to wait before retrying
47
+ def initialize(message, code:, status:, response_body:, error_key: nil, request_id: nil, result: nil,
48
+ retry_after: nil)
37
49
  super(message)
38
50
  @code = code
39
51
  @status = status
40
52
  @response_body = response_body
41
53
  @error_key = error_key
42
54
  @request_id = request_id
55
+ @result = result
56
+ @retry_after = retry_after
57
+ end
58
+ end
59
+
60
+ # The price of a bulk order changed since its calculation, so the order was not started:
61
+ # {ErrorCode::BULK_PRICE_CHANGED}. Confirm the new total of {#calculation}, then start the order with its ID.
62
+ class BulkPriceChangedError < ApiError
63
+ # @return [Responses::BulkCalculation] the new calculation, valid for 10 minutes
64
+ attr_reader :calculation
65
+
66
+ # @param message [String] the error message from the API
67
+ # @param calculation [Responses::BulkCalculation] the new calculation
68
+ # @param options [Hash] the keyword arguments of {ApiError#initialize}
69
+ def initialize(message, calculation:, **)
70
+ super(message, **)
71
+ @calculation = calculation
72
+ end
73
+ end
74
+
75
+ # No row of a bulk calculation is valid: {ErrorCode::BULK_NO_VALID_ITEMS}. Fix the rows in {#rejected}.
76
+ class BulkNoValidItemsError < ApiError
77
+ # @return [Array<Models::BulkRejectedRow>] the rejected rows with their row numbers and reasons
78
+ attr_reader :rejected
79
+
80
+ # @param message [String] the error message from the API
81
+ # @param rejected [Array<Models::BulkRejectedRow>] the rejected rows
82
+ # @param options [Hash] the keyword arguments of {ApiError#initialize}
83
+ def initialize(message, rejected:, **)
84
+ super(message, **)
85
+ @rejected = rejected
43
86
  end
44
87
  end
45
88
 
@@ -51,19 +94,8 @@ module Tronzap
51
94
  # @return [String] the raw response body
52
95
  attr_reader :response_body
53
96
 
54
- # @param message [String] the error message
55
- # @param status [Integer] the HTTP status of the response
56
- # @param response_body [String] the raw response body
57
- def initialize(message, status:, response_body:)
58
- super(message)
59
- @status = status
60
- @response_body = response_body
61
- end
62
- end
63
-
64
- # The API answered with HTTP 429: too many requests. Back off and retry.
65
- class RateLimitError < HttpError
66
- # @return [Float, nil] seconds the API asked to wait before retrying, from the +Retry-After+ header
97
+ # @return [Float, nil] seconds to wait before retrying, from the +Retry-After+ header or the +retry_after+ field,
98
+ # or +nil+ when the server sent neither
67
99
  attr_reader :retry_after
68
100
 
69
101
  # @param message [String] the error message
@@ -71,11 +103,18 @@ module Tronzap
71
103
  # @param response_body [String] the raw response body
72
104
  # @param retry_after [Float, nil] seconds to wait before retrying
73
105
  def initialize(message, status:, response_body:, retry_after: nil)
74
- super(message, status: status, response_body: response_body)
106
+ super(message)
107
+ @status = status
108
+ @response_body = response_body
75
109
  @retry_after = retry_after
76
110
  end
77
111
  end
78
112
 
113
+ # HTTP 429 without an API payload, for example from a proxy. Back off and retry.
114
+ #
115
+ # A rate limit reported by the API arrives as {ApiError} with {ErrorCode::RATE_LIMITED}.
116
+ class RateLimitError < HttpError; end
117
+
79
118
  # The API answered with HTTP 401 or 403: check the API token and secret.
80
119
  class UnauthorizedError < HttpError; end
81
120
 
@@ -145,6 +184,23 @@ module Tronzap
145
184
  SERVICE_NOT_AVAILABLE = 35
146
185
  # Invalid bandwidth amount.
147
186
  INVALID_BANDWIDTH_AMOUNT = 50
187
+ # Bulk order not found: check the order ID or external ID. A calculation that was never started is not an order.
188
+ BULK_NOT_FOUND = 90
189
+ # Bulk calculation expired: call {Client#bulk_calculate} again; a calculation is valid for 10 minutes.
190
+ BULK_EXPIRED = 91
191
+ # The price changed since the calculation: confirm the new total of {BulkPriceChangedError#calculation}, then
192
+ # start the order with its ID.
193
+ BULK_PRICE_CHANGED = 92
194
+ # Too many items: send at most 10 000 rows in one calculation.
195
+ BULK_TOO_MANY_ITEMS = 93
196
+ # No valid items: fix the rows in {BulkNoValidItemsError#rejected}.
197
+ BULK_NO_VALID_ITEMS = 94
198
+ # The resource cannot be ordered in bulk: only energy can.
199
+ BULK_RESOURCE_NOT_SUPPORTED = 95
200
+ # The request body is too large (HTTP 413): send fewer rows in one calculation.
201
+ PAYLOAD_TOO_LARGE = 96
202
+ # Too many requests (HTTP 429): wait {ApiError#retry_after} seconds, when given, and retry.
203
+ RATE_LIMITED = 429
148
204
  # Internal server error. Contact support if it persists.
149
205
  INTERNAL_SERVER_ERROR = 500
150
206
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Models
5
+ # A row of a bulk calculation that was rejected and will not be ordered.
6
+ #
7
+ # @!attribute [r] row
8
+ # @return [Integer] the position of the row in the request, starting at 1
9
+ # @!attribute [r] address
10
+ # @return [String] the address as it was sent
11
+ # @!attribute [r] reason
12
+ # @return [String] why the row was rejected, for example +invalid_address+, +invalid_amount+ or +duplicate+
13
+ BulkRejectedRow = Data.define(:row, :address, :reason) do
14
+ # @api private
15
+ def self.from_api(value)
16
+ data = Coerce.object(value, "rejected row")
17
+ new(
18
+ row: Coerce.integer(data["row"], "row"),
19
+ address: Coerce.text(data["address"], "address"),
20
+ reason: Coerce.text(data["reason"], "reason")
21
+ )
22
+ end
23
+
24
+ # @api private
25
+ def self.list_from_api(value)
26
+ Coerce.list(value, "rejected") { from_api(_1) }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -28,5 +28,13 @@ module Tronzap
28
28
  # Subscription states: +:new+ → +:pending+ → +:active+, then +:stopped+ or +:expired+; +:error+ when it could
29
29
  # not be started.
30
30
  SUBSCRIPTION_STATUSES = %i[new pending error active stopped expired].freeze
31
+
32
+ # Bulk order states: a calculation is +:draft+; a started order is +:processing+, then +:completed+ (every row
33
+ # delivered), +:partial+ (some rows delivered) or +:failed+ (none delivered).
34
+ BULK_STATUSES = %i[draft processing completed partial failed].freeze
35
+
36
+ # Row results in a bulk order report. +:in_review+ rows wait for a manual check; +:pending+ rows are not
37
+ # processed yet.
38
+ BULK_ROW_STATUSES = %i[delivered failed in_review skipped pending].freeze
31
39
  end
32
40
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Requests
5
+ # The rows of a bulk energy order to validate and price.
6
+ #
7
+ # @!attribute [r] items
8
+ # @return [Array<BulkItem>] the rows, at most 10 000
9
+ # @!attribute [r] duration
10
+ # @return [Integer] rental duration in hours, one of the durations {Client#get_services} lists
11
+ BulkCalculate = Data.define(:items, :duration) do
12
+ # @param items [Array<BulkItem, Hash>] the rows, as {BulkItem}s or hashes with +address+ and +amount+
13
+ # @param duration [Integer]
14
+ # @raise [ArgumentError]
15
+ def initialize(items:, duration: 1)
16
+ raise ArgumentError, "items is required" unless items.is_a?(Array) && !items.empty?
17
+
18
+ super(
19
+ items: items.map { |item| item(item) }.freeze,
20
+ duration: Validation.positive_integer(duration, "duration")
21
+ )
22
+ end
23
+
24
+ # @api private
25
+ def body
26
+ { "resource" => "energy", "duration" => duration, "items" => items.map(&:body) }
27
+ end
28
+
29
+ private
30
+
31
+ def item(value)
32
+ case value
33
+ when BulkItem then value
34
+ when Hash then BulkItem.new(**value.transform_keys(&:to_sym))
35
+ else raise ArgumentError, "items must hold BulkItems or hashes, got #{value.inspect}"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Requests
5
+ # A bulk order to start from a calculation.
6
+ #
7
+ # @!attribute [r] id
8
+ # @return [String] the {Responses::BulkCalculation#id} of the calculation to start
9
+ # @!attribute [r] external_id
10
+ # @return [String, nil] your own ID for the order, unique per account. Starting an order again with the same
11
+ # external ID returns the order already started.
12
+ # @!attribute [r] force
13
+ # @return [Boolean] whether to buy even if the price rises while the order runs, within {max_price_increase}.
14
+ # When +false+, an address whose price rose is skipped.
15
+ # @!attribute [r] max_price_increase
16
+ # @return [Integer, nil] the allowed price increase in percent, 0 to 100, used only with {force}. The API
17
+ # default of 20 applies when it is +nil+.
18
+ # @!attribute [r] webhook_url
19
+ # @return [String, nil] a public +https+ URL called once when the order becomes final. Check its
20
+ # +X-Signature+ header with {Client#verify_webhook_signature}.
21
+ BulkCreate = Data.define(:id, :external_id, :force, :max_price_increase, :webhook_url) do
22
+ # @param id [String]
23
+ # @param external_id [String, nil]
24
+ # @param force [Boolean]
25
+ # @param max_price_increase [Integer, nil]
26
+ # @param webhook_url [String, nil]
27
+ # @raise [ArgumentError]
28
+ def initialize(id:, external_id: nil, force: false, max_price_increase: nil, webhook_url: nil)
29
+ unless max_price_increase.nil?
30
+ max_price_increase = Validation.non_negative_integer(max_price_increase, "max_price_increase")
31
+ end
32
+ super(
33
+ id: Validation.string(id, "id"),
34
+ external_id: Validation.optional_string(external_id, "external_id"),
35
+ force: Validation.boolean(force, "force"),
36
+ max_price_increase: max_price_increase,
37
+ webhook_url: Validation.optional_string(webhook_url, "webhook_url")
38
+ )
39
+ end
40
+
41
+ # @api private
42
+ def body
43
+ body = { "id" => id }
44
+ body["force"] = true if force
45
+ body["max_price_increase"] = max_price_increase if max_price_increase
46
+ body["webhook_url"] = webhook_url if webhook_url
47
+ body["external_id"] = external_id if external_id
48
+ body
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Requests
5
+ # A page of bulk orders to return.
6
+ #
7
+ # @!attribute [r] page
8
+ # @return [Integer] the page number, starting at 1
9
+ # @!attribute [r] per_page
10
+ # @return [Integer] the page size, at most 50
11
+ BulkHistory = Data.define(:page, :per_page) do
12
+ # @param page [Integer]
13
+ # @param per_page [Integer]
14
+ # @raise [ArgumentError]
15
+ def initialize(page: 1, per_page: 10)
16
+ super(
17
+ page: Validation.positive_integer(page, "page"),
18
+ per_page: Validation.positive_integer(per_page, "per_page")
19
+ )
20
+ end
21
+
22
+ # @api private
23
+ def body
24
+ { "page" => page, "per_page" => per_page }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Requests
5
+ # One row of a bulk energy order. The SDK does not check the address or the amount: the calculation rejects
6
+ # invalid rows and reports them with their row number.
7
+ #
8
+ # @!attribute [r] address
9
+ # @return [String] the TRON address that receives the energy
10
+ # @!attribute [r] amount
11
+ # @return [Integer] the amount of energy
12
+ BulkItem = Data.define(:address, :amount) do
13
+ # @param address [String]
14
+ # @param amount [Integer]
15
+ # @raise [ArgumentError] when the address is not a String or the amount not an Integer
16
+ def initialize(address:, amount:)
17
+ raise ArgumentError, "address must be a String, got #{address.inspect}" unless address.is_a?(String)
18
+ raise ArgumentError, "amount must be an Integer, got #{amount.inspect}" unless amount.is_a?(Integer)
19
+
20
+ super(address: address.dup.freeze, amount: amount)
21
+ end
22
+
23
+ # @api private
24
+ def body
25
+ { "address" => address, "amount" => amount }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Requests
5
+ # The bulk order to check, by its TronZap ID, your external ID, or both.
6
+ #
7
+ # @!attribute [r] id
8
+ # @return [String, nil] the bulk order ID assigned by TronZap
9
+ # @!attribute [r] external_id
10
+ # @return [String, nil] the external ID you passed when starting the order
11
+ BulkLookup = Data.define(:id, :external_id) do
12
+ # @param id [String, nil]
13
+ # @param external_id [String, nil]
14
+ # @raise [ArgumentError] when neither is given
15
+ def initialize(id: nil, external_id: nil)
16
+ id = Validation.optional_string(id, "id")
17
+ external_id = Validation.optional_string(external_id, "external_id")
18
+ raise ArgumentError, "either id or external_id is required" if id.nil? && external_id.nil?
19
+
20
+ super
21
+ end
22
+
23
+ # Looks a bulk order up by its TronZap ID.
24
+ #
25
+ # @param id [String]
26
+ # @return [BulkLookup]
27
+ def self.by_id(id)
28
+ new(id: id)
29
+ end
30
+
31
+ # Looks a bulk order up by the external ID you passed when starting it.
32
+ #
33
+ # @param external_id [String]
34
+ # @return [BulkLookup]
35
+ def self.by_external_id(external_id)
36
+ new(external_id: external_id)
37
+ end
38
+
39
+ # @api private
40
+ def body
41
+ body = {}
42
+ body["id"] = id if id
43
+ body["external_id"] = external_id if external_id
44
+ body
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Requests
5
+ # The bulk order whose report to download, by its TronZap ID, your external ID, or both.
6
+ #
7
+ # @!attribute [r] id
8
+ # @return [String, nil] the bulk order ID assigned by TronZap
9
+ # @!attribute [r] external_id
10
+ # @return [String, nil] the external ID you passed when starting the order
11
+ # @!attribute [r] status
12
+ # @return [Symbol, nil] only rows with this result, one of {Models::BULK_ROW_STATUSES}, or every row when +nil+
13
+ BulkReport = Data.define(:id, :external_id, :status) do
14
+ # @param id [String, nil]
15
+ # @param external_id [String, nil]
16
+ # @param status [Symbol, String, nil]
17
+ # @raise [ArgumentError]
18
+ def initialize(id: nil, external_id: nil, status: nil)
19
+ id = Validation.optional_string(id, "id")
20
+ external_id = Validation.optional_string(external_id, "external_id")
21
+ raise ArgumentError, "either id or external_id is required" if id.nil? && external_id.nil?
22
+
23
+ super(id: id, external_id: external_id,
24
+ status: Validation.optional_one_of(status, Models::BULK_ROW_STATUSES, "status"))
25
+ end
26
+
27
+ # Downloads the report of a bulk order by its TronZap ID.
28
+ #
29
+ # @param id [String]
30
+ # @param status [Symbol, String, nil]
31
+ # @return [BulkReport]
32
+ def self.by_id(id, status: nil)
33
+ new(id: id, status: status)
34
+ end
35
+
36
+ # Downloads the report of a bulk order by the external ID you passed when starting it.
37
+ #
38
+ # @param external_id [String]
39
+ # @param status [Symbol, String, nil]
40
+ # @return [BulkReport]
41
+ def self.by_external_id(external_id, status: nil)
42
+ new(external_id: external_id, status: status)
43
+ end
44
+
45
+ # @api private
46
+ def body
47
+ body = {}
48
+ body["id"] = id if id
49
+ body["external_id"] = external_id if external_id
50
+ body["status"] = status.name if status
51
+ body
52
+ end
53
+ end
54
+ end
55
+ end