tronzap-sdk 1.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +70 -0
- data/README.es.md +145 -15
- data/README.md +143 -14
- data/README.pt-br.md +145 -14
- data/README.ru.md +141 -13
- data/lib/tronzap/client.rb +157 -6
- data/lib/tronzap/coerce.rb +8 -0
- data/lib/tronzap/errors.rb +74 -17
- data/lib/tronzap/models/bulk_rejected_row.rb +30 -0
- data/lib/tronzap/models/direct_recharge_rate.rb +1 -1
- data/lib/tronzap/models/energy_rate.rb +12 -8
- data/lib/tronzap/models/enums.rb +15 -1
- data/lib/tronzap/models/subscription_params.rb +28 -0
- data/lib/tronzap/requests/aml_check.rb +17 -6
- data/lib/tronzap/requests/bulk_calculate.rb +40 -0
- data/lib/tronzap/requests/bulk_create.rb +52 -0
- data/lib/tronzap/requests/bulk_history.rb +28 -0
- data/lib/tronzap/requests/bulk_item.rb +29 -0
- data/lib/tronzap/requests/bulk_lookup.rb +48 -0
- data/lib/tronzap/requests/bulk_report.rb +55 -0
- data/lib/tronzap/requests/start_subscription.rb +54 -0
- data/lib/tronzap/requests/subscription_history.rb +35 -0
- data/lib/tronzap/requests/subscription_lookup.rb +48 -0
- data/lib/tronzap/requests/validation.rb +8 -0
- data/lib/tronzap/response_decoder.rb +53 -15
- data/lib/tronzap/responses/aml_check.rb +1 -1
- data/lib/tronzap/responses/bulk_calculation.rb +44 -0
- data/lib/tronzap/responses/bulk_history.rb +28 -0
- data/lib/tronzap/responses/bulk_order.rb +87 -0
- data/lib/tronzap/responses/calculation.rb +5 -3
- data/lib/tronzap/responses/energy_estimate.rb +6 -4
- data/lib/tronzap/responses/service_rates.rb +3 -2
- data/lib/tronzap/responses/subscription.rb +73 -0
- data/lib/tronzap/responses/subscription_history.rb +28 -0
- data/lib/tronzap/responses/subscription_plan.rb +52 -0
- data/lib/tronzap/version.rb +1 -1
- data/lib/tronzap.rb +17 -0
- metadata +18 -1
|
@@ -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
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Requests
|
|
5
|
+
# A subscription to start for an address.
|
|
6
|
+
#
|
|
7
|
+
# @!attribute [r] subscription_id
|
|
8
|
+
# @return [String] the plan to subscribe to, the {Responses::SubscriptionPlan#subscription_id} of a plan from
|
|
9
|
+
# {Client#get_subscriptions}, such as +unlimited_energy+. Not the plan's numeric
|
|
10
|
+
# {Responses::SubscriptionPlan#id}.
|
|
11
|
+
# @!attribute [r] address
|
|
12
|
+
# @return [String] the TRON address the subscription serves
|
|
13
|
+
# @!attribute [r] duration_days
|
|
14
|
+
# @return [Integer] how many days the subscription runs, 0 for no time limit
|
|
15
|
+
# @!attribute [r] transactions_limit
|
|
16
|
+
# @return [Integer] how many transactions the subscription covers, 0 for no limit
|
|
17
|
+
# @!attribute [r] external_id
|
|
18
|
+
# @return [String, nil] your own ID for the subscription, to look it up with
|
|
19
|
+
# {SubscriptionLookup.by_external_id}
|
|
20
|
+
# @!attribute [r] activate_address
|
|
21
|
+
# @return [Boolean] whether to also activate the address if it is not active yet
|
|
22
|
+
StartSubscription = Data.define(:subscription_id, :address, :duration_days, :transactions_limit, :external_id,
|
|
23
|
+
:activate_address) do
|
|
24
|
+
# @param subscription_id [String]
|
|
25
|
+
# @param address [String]
|
|
26
|
+
# @param duration_days [Integer]
|
|
27
|
+
# @param transactions_limit [Integer]
|
|
28
|
+
# @param external_id [String, nil]
|
|
29
|
+
# @param activate_address [Boolean]
|
|
30
|
+
# @raise [ArgumentError]
|
|
31
|
+
def initialize(subscription_id:, address:, duration_days: 0, transactions_limit: 0, external_id: nil,
|
|
32
|
+
activate_address: false)
|
|
33
|
+
super(
|
|
34
|
+
subscription_id: Validation.string(subscription_id, "subscription_id"),
|
|
35
|
+
address: Validation.string(address, "address"),
|
|
36
|
+
duration_days: Validation.non_negative_integer(duration_days, "duration_days"),
|
|
37
|
+
transactions_limit: Validation.non_negative_integer(transactions_limit, "transactions_limit"),
|
|
38
|
+
external_id: Validation.optional_string(external_id, "external_id"),
|
|
39
|
+
activate_address: Validation.boolean(activate_address, "activate_address")
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @api private
|
|
44
|
+
def body
|
|
45
|
+
params = { "address" => address, "duration" => duration_days, "transactions_limit" => transactions_limit }
|
|
46
|
+
params["activate_address"] = true if activate_address
|
|
47
|
+
body = { "subscription_id" => subscription_id }
|
|
48
|
+
body["external_id"] = external_id if external_id
|
|
49
|
+
body["params"] = params
|
|
50
|
+
body
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Requests
|
|
5
|
+
# A page of subscription history 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
|
+
# @!attribute [r] status
|
|
12
|
+
# @return [Symbol, nil] only subscriptions in this state, one of {Models::SUBSCRIPTION_STATUSES}, or all
|
|
13
|
+
# subscriptions when +nil+
|
|
14
|
+
SubscriptionHistory = Data.define(:page, :per_page, :status) do
|
|
15
|
+
# @param page [Integer]
|
|
16
|
+
# @param per_page [Integer]
|
|
17
|
+
# @param status [Symbol, String, nil]
|
|
18
|
+
# @raise [ArgumentError]
|
|
19
|
+
def initialize(page: 1, per_page: 10, status: nil)
|
|
20
|
+
super(
|
|
21
|
+
page: Validation.positive_integer(page, "page"),
|
|
22
|
+
per_page: Validation.positive_integer(per_page, "per_page"),
|
|
23
|
+
status: Validation.optional_one_of(status, Models::SUBSCRIPTION_STATUSES, "status")
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @api private
|
|
28
|
+
def body
|
|
29
|
+
body = { "page" => page, "per_page" => per_page }
|
|
30
|
+
body["status"] = status.name if status
|
|
31
|
+
body
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Requests
|
|
5
|
+
# The subscription to check or stop, by its TronZap ID, your external ID, or both.
|
|
6
|
+
#
|
|
7
|
+
# @!attribute [r] id
|
|
8
|
+
# @return [String, nil] the subscription ID assigned by TronZap
|
|
9
|
+
# @!attribute [r] external_id
|
|
10
|
+
# @return [String, nil] the external ID you passed when starting the subscription
|
|
11
|
+
SubscriptionLookup = 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 subscription up by its TronZap ID.
|
|
24
|
+
#
|
|
25
|
+
# @param id [String]
|
|
26
|
+
# @return [SubscriptionLookup]
|
|
27
|
+
def self.by_id(id)
|
|
28
|
+
new(id: id)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Looks a subscription up by the external ID you passed when starting it.
|
|
32
|
+
#
|
|
33
|
+
# @param external_id [String]
|
|
34
|
+
# @return [SubscriptionLookup]
|
|
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
|
|
@@ -29,6 +29,14 @@ module Tronzap
|
|
|
29
29
|
value
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
def non_negative_integer(value, name)
|
|
33
|
+
unless value.is_a?(Integer) && !value.negative?
|
|
34
|
+
raise ArgumentError, "#{name} must be a non-negative Integer, got #{value.inspect}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
value
|
|
38
|
+
end
|
|
39
|
+
|
|
32
40
|
def boolean(value, name)
|
|
33
41
|
raise ArgumentError, "#{name} must be true or false, got #{value.inspect}" unless [true, false].include?(value)
|
|
34
42
|
|
|
@@ -20,8 +20,9 @@ module Tronzap
|
|
|
20
20
|
body = text(response.body)
|
|
21
21
|
document, parse_error = parse(body)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
retry_after = retry_after(response.headers, parse_error ? nil : document)
|
|
24
|
+
check_api_error(document, status, body, retry_after) unless parse_error
|
|
25
|
+
raise http_error(status, body, retry_after) unless (200..299).cover?(status)
|
|
25
26
|
|
|
26
27
|
result = result(document, parse_error, status, body)
|
|
27
28
|
begin
|
|
@@ -55,7 +56,14 @@ module Tronzap
|
|
|
55
56
|
[nil, e]
|
|
56
57
|
end
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
# @param response [#status, #headers, #body]
|
|
60
|
+
# @return [Boolean] whether the status is 2xx and the body is +text/csv+
|
|
61
|
+
def csv?(response)
|
|
62
|
+
(200..299).cover?(response.status.to_i) &&
|
|
63
|
+
header(response.headers, "content-type").to_s.split(";").first.to_s.strip.casecmp?("text/csv")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def check_api_error(document, status, body, retry_after)
|
|
59
67
|
unless document.is_a?(Hash)
|
|
60
68
|
raise ApiError.new(UNKNOWN_API_ERROR, code: ErrorCode::AUTH_ERROR, status: status, response_body: body)
|
|
61
69
|
end
|
|
@@ -63,16 +71,35 @@ module Tronzap
|
|
|
63
71
|
code = code(document["code"])
|
|
64
72
|
return if code&.zero?
|
|
65
73
|
|
|
66
|
-
raise
|
|
74
|
+
raise api_error(
|
|
67
75
|
string(document["error"]) || UNKNOWN_API_ERROR,
|
|
68
76
|
code: code || ErrorCode::AUTH_ERROR,
|
|
69
77
|
status: status,
|
|
70
78
|
response_body: body,
|
|
71
79
|
error_key: string(document["key"]),
|
|
72
|
-
request_id: string(document["request_id"])
|
|
80
|
+
request_id: string(document["request_id"]),
|
|
81
|
+
result: document["result"],
|
|
82
|
+
retry_after: retry_after
|
|
73
83
|
)
|
|
74
84
|
end
|
|
75
85
|
|
|
86
|
+
def api_error(message, **details)
|
|
87
|
+
result = details[:result]
|
|
88
|
+
if result.is_a?(Hash)
|
|
89
|
+
case details[:code]
|
|
90
|
+
when ErrorCode::BULK_PRICE_CHANGED
|
|
91
|
+
return BulkPriceChangedError.new(message, calculation: Responses::BulkCalculation.from_api(result),
|
|
92
|
+
**details)
|
|
93
|
+
when ErrorCode::BULK_NO_VALID_ITEMS
|
|
94
|
+
return BulkNoValidItemsError.new(message, rejected: Models::BulkRejectedRow.list_from_api(result["rejected"]),
|
|
95
|
+
**details)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
ApiError.new(message, **details)
|
|
99
|
+
rescue Coerce::Error
|
|
100
|
+
ApiError.new(message, **details)
|
|
101
|
+
end
|
|
102
|
+
|
|
76
103
|
def code(value)
|
|
77
104
|
case value
|
|
78
105
|
when Integer then value
|
|
@@ -88,20 +115,21 @@ module Tronzap
|
|
|
88
115
|
end
|
|
89
116
|
end
|
|
90
117
|
|
|
91
|
-
def http_error(status, body,
|
|
118
|
+
def http_error(status, body, retry_after)
|
|
119
|
+
details = { status: status, response_body: body, retry_after: retry_after }
|
|
92
120
|
case status
|
|
93
|
-
when 429
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
when 500.. then ServerError.new("Server error (HTTP #{status})", status: status, response_body: body)
|
|
98
|
-
else HttpError.new("HTTP error #{status}", status: status, response_body: body)
|
|
121
|
+
when 429 then RateLimitError.new("Too many requests (HTTP 429)", **details)
|
|
122
|
+
when 401, 403 then UnauthorizedError.new("Unauthorized (HTTP #{status})", **details)
|
|
123
|
+
when 500.. then ServerError.new("Server error (HTTP #{status})", **details)
|
|
124
|
+
else HttpError.new("HTTP error #{status}", **details)
|
|
99
125
|
end
|
|
100
126
|
end
|
|
101
127
|
|
|
102
|
-
def retry_after(headers)
|
|
103
|
-
|
|
104
|
-
|
|
128
|
+
def retry_after(headers, document)
|
|
129
|
+
retry_after_header(header(headers, "retry-after")) || retry_after_field(document)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def retry_after_header(value)
|
|
105
133
|
return nil unless value.is_a?(String)
|
|
106
134
|
|
|
107
135
|
value = value.strip
|
|
@@ -111,5 +139,15 @@ module Tronzap
|
|
|
111
139
|
rescue ArgumentError
|
|
112
140
|
nil
|
|
113
141
|
end
|
|
142
|
+
|
|
143
|
+
def retry_after_field(document)
|
|
144
|
+
value = document["retry_after"] if document.is_a?(Hash)
|
|
145
|
+
value.to_f if value.is_a?(Integer) && !value.negative?
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def header(headers, name)
|
|
149
|
+
value = headers.to_h.find { |key, _| key.to_s.casecmp?(name) }&.last
|
|
150
|
+
value.is_a?(Array) ? value.first : value
|
|
151
|
+
end
|
|
114
152
|
end
|
|
115
153
|
end
|
|
@@ -9,7 +9,7 @@ module Tronzap
|
|
|
9
9
|
# @!attribute [r] type
|
|
10
10
|
# @return [Symbol] what is screened, one of {Models::AML_CHECK_TYPES} or +:unknown+
|
|
11
11
|
# @!attribute [r] address
|
|
12
|
-
# @return [String] the screened
|
|
12
|
+
# @return [String] the screened address; for a hash check, the recipient address of the transaction
|
|
13
13
|
# @!attribute [r] transaction_hash
|
|
14
14
|
# @return [String, nil] the screened transaction hash, +nil+ for an address check
|
|
15
15
|
# @!attribute [r] direction
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Responses
|
|
5
|
+
# The price of a bulk energy order. Nothing is charged until the order is started with {Client#bulk_create}.
|
|
6
|
+
#
|
|
7
|
+
# @!attribute [r] id
|
|
8
|
+
# @return [String] the calculation ID to pass to {Client#bulk_create}
|
|
9
|
+
# @!attribute [r] status
|
|
10
|
+
# @return [Symbol] +:draft+, or another of {Models::BULK_STATUSES} or +:unknown+
|
|
11
|
+
# @!attribute [r] resource
|
|
12
|
+
# @return [String] the resource ordered, +energy+
|
|
13
|
+
# @!attribute [r] duration
|
|
14
|
+
# @return [Integer] rental duration in hours
|
|
15
|
+
# @!attribute [r] total_amount
|
|
16
|
+
# @return [BigDecimal] the price of the accepted rows, in TRX
|
|
17
|
+
# @!attribute [r] accepted
|
|
18
|
+
# @return [Integer] how many rows will be ordered
|
|
19
|
+
# @!attribute [r] rejected_count
|
|
20
|
+
# @return [Integer] how many rows were rejected
|
|
21
|
+
# @!attribute [r] rejected
|
|
22
|
+
# @return [Array<Models::BulkRejectedRow>] the rejected rows with their row numbers and reasons
|
|
23
|
+
# @!attribute [r] expires_at
|
|
24
|
+
# @return [Models::Timestamp, nil] when the calculation expires, 10 minutes after it was made
|
|
25
|
+
BulkCalculation = Data.define(:id, :status, :resource, :duration, :total_amount, :accepted, :rejected_count,
|
|
26
|
+
:rejected, :expires_at) do
|
|
27
|
+
# @api private
|
|
28
|
+
def self.from_api(value)
|
|
29
|
+
data = Coerce.object(value, "result")
|
|
30
|
+
new(
|
|
31
|
+
id: Coerce.text(data["id"], "id"),
|
|
32
|
+
status: Coerce.enum(data["status"], Models::BULK_STATUSES, "status"),
|
|
33
|
+
resource: Coerce.text(data["resource"], "resource"),
|
|
34
|
+
duration: Coerce.integer(data["duration"], "duration"),
|
|
35
|
+
total_amount: Coerce.decimal(data["total_amount"], "total_amount"),
|
|
36
|
+
accepted: Coerce.integer(data["accepted"], "accepted"),
|
|
37
|
+
rejected_count: Coerce.integer(data["rejected_count"], "rejected_count"),
|
|
38
|
+
rejected: Models::BulkRejectedRow.list_from_api(data["rejected"]),
|
|
39
|
+
expires_at: Coerce.timestamp(data["expires_at"], "expires_at")
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Responses
|
|
5
|
+
# One page of your bulk orders, newest first.
|
|
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
|
|
11
|
+
# @!attribute [r] total
|
|
12
|
+
# @return [Integer] the number of bulk orders across all pages
|
|
13
|
+
# @!attribute [r] items
|
|
14
|
+
# @return [Array<BulkOrder>] the orders on this page
|
|
15
|
+
BulkHistory = Data.define(:page, :per_page, :total, :items) do
|
|
16
|
+
# @api private
|
|
17
|
+
def self.from_api(value)
|
|
18
|
+
data = Coerce.object(value, "result")
|
|
19
|
+
new(
|
|
20
|
+
page: Coerce.integer(data["page"], "page"),
|
|
21
|
+
per_page: Coerce.integer(data["per_page"], "per_page"),
|
|
22
|
+
total: Coerce.integer(data["total"], "total"),
|
|
23
|
+
items: Coerce.list(data["items"], "items") { BulkOrder.from_api(_1) }
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Responses
|
|
5
|
+
# A bulk energy order and its progress.
|
|
6
|
+
#
|
|
7
|
+
# @!attribute [r] id
|
|
8
|
+
# @return [String] the bulk order ID assigned by TronZap
|
|
9
|
+
# @!attribute [r] external_id
|
|
10
|
+
# @return [String, nil] the ID you passed when starting the order
|
|
11
|
+
# @!attribute [r] status
|
|
12
|
+
# @return [Symbol] the current state, one of {Models::BULK_STATUSES} or +:unknown+. +:completed+, +:partial+
|
|
13
|
+
# and +:failed+ are final.
|
|
14
|
+
# @!attribute [r] resource
|
|
15
|
+
# @return [String] the resource ordered, +energy+
|
|
16
|
+
# @!attribute [r] duration
|
|
17
|
+
# @return [Integer] rental duration in hours
|
|
18
|
+
# @!attribute [r] force
|
|
19
|
+
# @return [Boolean] whether rows are bought even if the price rose, within {max_price_increase}
|
|
20
|
+
# @!attribute [r] max_price_increase
|
|
21
|
+
# @return [Integer] the allowed price increase in percent
|
|
22
|
+
# @!attribute [r] webhook_url
|
|
23
|
+
# @return [String, nil] the URL called when the order becomes final
|
|
24
|
+
# @!attribute [r] total
|
|
25
|
+
# @return [Integer] how many rows the order has
|
|
26
|
+
# @!attribute [r] processed
|
|
27
|
+
# @return [Integer] how many rows are processed
|
|
28
|
+
# @!attribute [r] delivered
|
|
29
|
+
# @return [Integer] how many rows received energy
|
|
30
|
+
# @!attribute [r] failed
|
|
31
|
+
# @return [Integer] how many rows failed
|
|
32
|
+
# @!attribute [r] in_review
|
|
33
|
+
# @return [Integer] how many rows wait for a manual check
|
|
34
|
+
# @!attribute [r] skipped
|
|
35
|
+
# @return [Integer] how many rows were skipped without a charge
|
|
36
|
+
# @!attribute [r] skipped_by_reason
|
|
37
|
+
# @return [Hash{String => Integer}] the skipped rows by reason, for example +address_not_activated+ or
|
|
38
|
+
# +price_increased+
|
|
39
|
+
# @!attribute [r] rejected_count
|
|
40
|
+
# @return [Integer] how many rows the calculation rejected
|
|
41
|
+
# @!attribute [r] total_amount
|
|
42
|
+
# @return [BigDecimal] the calculated price of the order, in TRX
|
|
43
|
+
# @!attribute [r] charged_amount
|
|
44
|
+
# @return [BigDecimal] the amount charged so far, in TRX
|
|
45
|
+
# @!attribute [r] created_at
|
|
46
|
+
# @return [Models::Timestamp, nil] when the order was created
|
|
47
|
+
# @!attribute [r] started_at
|
|
48
|
+
# @return [Models::Timestamp, nil] when processing started
|
|
49
|
+
# @!attribute [r] finalized_at
|
|
50
|
+
# @return [Models::Timestamp, nil] when the order became final, +nil+ while it runs
|
|
51
|
+
BulkOrder = Data.define(:id, :external_id, :status, :resource, :duration, :force, :max_price_increase,
|
|
52
|
+
:webhook_url, :total, :processed, :delivered, :failed, :in_review, :skipped,
|
|
53
|
+
:skipped_by_reason, :rejected_count, :total_amount, :charged_amount, :created_at,
|
|
54
|
+
:started_at, :finalized_at) do
|
|
55
|
+
# @api private
|
|
56
|
+
def self.from_api(value)
|
|
57
|
+
data = Coerce.object(value, "bulk order")
|
|
58
|
+
new(
|
|
59
|
+
id: Coerce.text(data["id"], "id"),
|
|
60
|
+
external_id: Coerce.optional_text(data["external_id"], "external_id"),
|
|
61
|
+
status: Coerce.enum(data["status"], Models::BULK_STATUSES, "status"),
|
|
62
|
+
resource: Coerce.text(data["resource"], "resource"),
|
|
63
|
+
duration: Coerce.integer(data["duration"], "duration"),
|
|
64
|
+
force: Coerce.boolean(data["force"], "force"),
|
|
65
|
+
max_price_increase: Coerce.integer(data["max_price_increase"], "max_price_increase"),
|
|
66
|
+
webhook_url: Coerce.optional_text(data["webhook_url"], "webhook_url"),
|
|
67
|
+
**counters(data),
|
|
68
|
+
skipped_by_reason: Coerce.integer_map(data["skipped_by_reason"], "skipped_by_reason"),
|
|
69
|
+
total_amount: Coerce.decimal(data["total_amount"], "total_amount"),
|
|
70
|
+
charged_amount: Coerce.decimal(data["charged_amount"], "charged_amount"),
|
|
71
|
+
**timestamps(data)
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.timestamps(data)
|
|
76
|
+
%w[created_at started_at finalized_at].to_h { |name| [name.to_sym, Coerce.timestamp(data[name], name)] }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def self.counters(data)
|
|
80
|
+
%w[total processed delivered failed in_review skipped rejected_count].to_h do |name|
|
|
81
|
+
[name.to_sym, Coerce.integer(data[name], name)]
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
private_class_method :counters, :timestamps
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -11,7 +11,8 @@ module Tronzap
|
|
|
11
11
|
# @!attribute [r] amount
|
|
12
12
|
# @return [Integer] the amount priced
|
|
13
13
|
# @!attribute [r] energy
|
|
14
|
-
# @
|
|
14
|
+
# @deprecated Use {#amount}.
|
|
15
|
+
# @return [Integer] the same value as {#amount}
|
|
15
16
|
# @!attribute [r] duration
|
|
16
17
|
# @return [Integer] rental duration in hours
|
|
17
18
|
# @!attribute [r] price
|
|
@@ -24,11 +25,12 @@ module Tronzap
|
|
|
24
25
|
# @api private
|
|
25
26
|
def self.from_api(value)
|
|
26
27
|
data = Coerce.object(value, "result")
|
|
28
|
+
amount = Coerce.integer(data["amount"], "amount")
|
|
27
29
|
new(
|
|
28
30
|
address: Coerce.text(data["address"], "address"),
|
|
29
31
|
service: Coerce.enum(data["type"], Models::SERVICES, "type"),
|
|
30
|
-
amount:
|
|
31
|
-
energy:
|
|
32
|
+
amount: amount,
|
|
33
|
+
energy: amount,
|
|
32
34
|
duration: Coerce.integer(data["duration"], "duration"),
|
|
33
35
|
price: Coerce.decimal(data["price"], "price"),
|
|
34
36
|
activation_fee: Coerce.decimal(data["activation_fee"], "activation_fee"),
|
|
@@ -5,9 +5,10 @@ module Tronzap
|
|
|
5
5
|
# The energy a token transfer needs and what that energy costs.
|
|
6
6
|
#
|
|
7
7
|
# @!attribute [r] amount
|
|
8
|
-
# @return [Integer] the
|
|
8
|
+
# @return [Integer] the energy the transfer needs, which the price applies to
|
|
9
9
|
# @!attribute [r] energy
|
|
10
|
-
# @
|
|
10
|
+
# @deprecated Use {#amount}.
|
|
11
|
+
# @return [Integer] the same value as {#amount}
|
|
11
12
|
# @!attribute [r] duration
|
|
12
13
|
# @return [Integer] rental duration in hours
|
|
13
14
|
# @!attribute [r] price
|
|
@@ -27,9 +28,10 @@ module Tronzap
|
|
|
27
28
|
# @api private
|
|
28
29
|
def self.from_api(value)
|
|
29
30
|
data = Coerce.object(value, "result")
|
|
31
|
+
amount = Coerce.integer(data["amount"], "amount")
|
|
30
32
|
new(
|
|
31
|
-
amount:
|
|
32
|
-
energy:
|
|
33
|
+
amount: amount,
|
|
34
|
+
energy: amount,
|
|
33
35
|
duration: Coerce.integer(data["duration"], "duration"),
|
|
34
36
|
price: Coerce.decimal(data["price"], "price"),
|
|
35
37
|
activation_fee: Coerce.decimal(data["activation_fee"], "activation_fee"),
|
|
@@ -4,8 +4,9 @@ module Tronzap
|
|
|
4
4
|
module Responses
|
|
5
5
|
# The resources on sale and their current prices.
|
|
6
6
|
#
|
|
7
|
-
# Energy
|
|
8
|
-
#
|
|
7
|
+
# Energy and bandwidth are both priced per 1000 units, so a purchase costs price × amount / 1000: 65000 energy
|
|
8
|
+
# at a {Models::EnergyRate#price} of 0.03 costs 1.95, and 345 bandwidth at a {Models::BandwidthRate#price} of 1
|
|
9
|
+
# costs 0.345.
|
|
9
10
|
#
|
|
10
11
|
# @!attribute [r] energy
|
|
11
12
|
# @return [Array<Models::EnergyRate>] energy price tiers
|