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,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Responses
|
|
5
|
+
# An energy subscription for an address.
|
|
6
|
+
#
|
|
7
|
+
# {Client#start_subscription}, {Client#check_subscription} and {Client#stop_subscription} report the IDs,
|
|
8
|
+
# status, dates and {params}. {Client#get_subscription_history} reports the usage counters
|
|
9
|
+
# ({transactions_limit}, {transactions_used}, {energy_used}, {total_price}) instead of {params}. A field the
|
|
10
|
+
# response does not carry is +nil+.
|
|
11
|
+
#
|
|
12
|
+
# @!attribute [r] id
|
|
13
|
+
# @return [String] the subscription ID assigned by TronZap
|
|
14
|
+
# @!attribute [r] subscription_id
|
|
15
|
+
# @return [String] the plan the subscription belongs to, such as +unlimited_energy+
|
|
16
|
+
# @!attribute [r] external_id
|
|
17
|
+
# @return [String, nil] the ID you passed when starting the subscription
|
|
18
|
+
# @!attribute [r] address
|
|
19
|
+
# @return [String, nil] the TRON address the subscription serves, +nil+ when the API did not report it, as
|
|
20
|
+
# in the response of {Client#stop_subscription}; {params} still holds it there
|
|
21
|
+
# @!attribute [r] status
|
|
22
|
+
# @return [Symbol] the current state, one of {Models::SUBSCRIPTION_STATUSES} or +:unknown+
|
|
23
|
+
# @!attribute [r] params
|
|
24
|
+
# @return [Models::SubscriptionParams, nil] the parameters the subscription was started with, +nil+ in the
|
|
25
|
+
# history
|
|
26
|
+
# @!attribute [r] transactions_limit
|
|
27
|
+
# @return [Integer, nil] how many transactions the subscription covers, 0 for no limit
|
|
28
|
+
# @!attribute [r] transactions_used
|
|
29
|
+
# @return [Integer, nil] how many transactions the subscription has served
|
|
30
|
+
# @!attribute [r] energy_used
|
|
31
|
+
# @return [Integer, nil] how much energy the subscription has delegated
|
|
32
|
+
# @!attribute [r] total_price
|
|
33
|
+
# @return [BigDecimal, nil] the amount charged for the subscription so far, in TRX
|
|
34
|
+
# @!attribute [r] created_at
|
|
35
|
+
# @return [Models::Timestamp, nil] when the subscription was created
|
|
36
|
+
# @!attribute [r] started_at
|
|
37
|
+
# @return [Models::Timestamp, nil] when the subscription started
|
|
38
|
+
# @!attribute [r] renewed_at
|
|
39
|
+
# @return [Models::Timestamp, nil] when the subscription was last renewed
|
|
40
|
+
# @!attribute [r] stopped_at
|
|
41
|
+
# @return [Models::Timestamp, nil] when the subscription was stopped
|
|
42
|
+
# @!attribute [r] expire_at
|
|
43
|
+
# @return [Models::Timestamp, nil] when the subscription ends, +nil+ when it has no time limit
|
|
44
|
+
Subscription = Data.define(:id, :subscription_id, :external_id, :address, :status, :params,
|
|
45
|
+
:transactions_limit, :transactions_used, :energy_used, :total_price,
|
|
46
|
+
:created_at, :started_at, :renewed_at, :stopped_at, :expire_at) do
|
|
47
|
+
# @api private
|
|
48
|
+
def self.from_api(value)
|
|
49
|
+
data = Coerce.object(value, "subscription")
|
|
50
|
+
new(
|
|
51
|
+
id: Coerce.text(data["id"], "id"),
|
|
52
|
+
subscription_id: Coerce.text(data["subscription_id"], "subscription_id"),
|
|
53
|
+
external_id: Coerce.optional_text(data["external_id"], "external_id"),
|
|
54
|
+
address: Coerce.optional_text(data["address"], "address"),
|
|
55
|
+
status: Coerce.enum(data["status"], Models::SUBSCRIPTION_STATUSES, "status"),
|
|
56
|
+
params: data["params"].nil? ? nil : Models::SubscriptionParams.from_api(data["params"]),
|
|
57
|
+
transactions_limit: Coerce.optional_integer(data["transactions_limit"], "transactions_limit"),
|
|
58
|
+
transactions_used: Coerce.optional_integer(data["transactions_used"], "transactions_used"),
|
|
59
|
+
energy_used: Coerce.optional_integer(data["energy_used"], "energy_used"),
|
|
60
|
+
total_price: Coerce.optional_decimal(data["total_price"], "total_price"),
|
|
61
|
+
**timestamps(data)
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.timestamps(data)
|
|
66
|
+
%w[created_at started_at renewed_at stopped_at expire_at].to_h do |name|
|
|
67
|
+
[name.to_sym, Coerce.timestamp(data[name], name)]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
private_class_method :timestamps
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Responses
|
|
5
|
+
# One page of your subscriptions, 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 subscriptions across all pages
|
|
13
|
+
# @!attribute [r] items
|
|
14
|
+
# @return [Array<Subscription>] the subscriptions on this page, with usage counters and without params
|
|
15
|
+
SubscriptionHistory = 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") { Subscription.from_api(_1) }
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tronzap
|
|
4
|
+
module Responses
|
|
5
|
+
# A subscription plan on sale.
|
|
6
|
+
#
|
|
7
|
+
# @!attribute [r] subscription_id
|
|
8
|
+
# @return [String] the plan's key, such as +unlimited_energy+. Pass it to {Client#start_subscription}.
|
|
9
|
+
# @!attribute [r] id
|
|
10
|
+
# @return [Integer] the plan's numeric ID
|
|
11
|
+
# @!attribute [r] name
|
|
12
|
+
# @return [String] the human-readable plan name
|
|
13
|
+
# @!attribute [r] activation_fee
|
|
14
|
+
# @return [BigDecimal] the one-time fee charged when a subscription starts, in TRX
|
|
15
|
+
# @!attribute [r] initial_price
|
|
16
|
+
# @return [BigDecimal] the amount charged when a subscription starts, in TRX
|
|
17
|
+
# @!attribute [r] price
|
|
18
|
+
# @return [BigDecimal] the price of each transaction the subscription serves, in TRX
|
|
19
|
+
# @!attribute [r] transactions_limit
|
|
20
|
+
# @return [Integer] how many transactions the plan covers, 0 for no limit
|
|
21
|
+
# @!attribute [r] duration_days
|
|
22
|
+
# @return [Integer] how many days the plan runs, 0 for no time limit
|
|
23
|
+
SubscriptionPlan = Data.define(:subscription_id, :id, :name, :activation_fee, :initial_price, :price,
|
|
24
|
+
:transactions_limit, :duration_days) do
|
|
25
|
+
# @api private
|
|
26
|
+
def self.from_api(value, key = nil)
|
|
27
|
+
data = Coerce.object(value, "subscription plan")
|
|
28
|
+
new(
|
|
29
|
+
subscription_id: Coerce.text(key || data["subscription_id"], "subscription_id"),
|
|
30
|
+
id: Coerce.integer(data["id"], "id"),
|
|
31
|
+
name: Coerce.text(data["name"], "name"),
|
|
32
|
+
activation_fee: Coerce.decimal(data["activation_fee"], "activation_fee"),
|
|
33
|
+
initial_price: Coerce.decimal(data["initial_price"], "initial_price"),
|
|
34
|
+
price: Coerce.decimal(data["price"], "price"),
|
|
35
|
+
transactions_limit: Coerce.integer(data["transactions_limit"], "transactions_limit"),
|
|
36
|
+
duration_days: Coerce.integer(data["duration_days"], "duration_days")
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The API lists plans as an object keyed by plan; an empty list arrives as [].
|
|
41
|
+
#
|
|
42
|
+
# @api private
|
|
43
|
+
def self.list_from_api(value)
|
|
44
|
+
case value
|
|
45
|
+
when Hash then value.map { |key, plan| from_api(plan, key) }.freeze
|
|
46
|
+
when Array then value.map { from_api(_1) }.freeze
|
|
47
|
+
else raise Coerce::Error, "result is not an object"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/tronzap/version.rb
CHANGED
data/lib/tronzap.rb
CHANGED
|
@@ -17,6 +17,8 @@ require_relative "tronzap/models/bandwidth_rate"
|
|
|
17
17
|
require_relative "tronzap/models/activate_address_rate"
|
|
18
18
|
require_relative "tronzap/models/direct_recharge_rate"
|
|
19
19
|
require_relative "tronzap/models/aml_risk_factor"
|
|
20
|
+
require_relative "tronzap/models/subscription_params"
|
|
21
|
+
require_relative "tronzap/models/bulk_rejected_row"
|
|
20
22
|
require_relative "tronzap/requests/validation"
|
|
21
23
|
require_relative "tronzap/requests/estimate_energy"
|
|
22
24
|
require_relative "tronzap/requests/calculate"
|
|
@@ -27,15 +29,30 @@ require_relative "tronzap/requests/address_activation"
|
|
|
27
29
|
require_relative "tronzap/requests/check_transaction"
|
|
28
30
|
require_relative "tronzap/requests/aml_check"
|
|
29
31
|
require_relative "tronzap/requests/aml_history"
|
|
32
|
+
require_relative "tronzap/requests/start_subscription"
|
|
33
|
+
require_relative "tronzap/requests/subscription_lookup"
|
|
34
|
+
require_relative "tronzap/requests/subscription_history"
|
|
35
|
+
require_relative "tronzap/requests/bulk_item"
|
|
36
|
+
require_relative "tronzap/requests/bulk_calculate"
|
|
37
|
+
require_relative "tronzap/requests/bulk_create"
|
|
38
|
+
require_relative "tronzap/requests/bulk_lookup"
|
|
39
|
+
require_relative "tronzap/requests/bulk_report"
|
|
40
|
+
require_relative "tronzap/requests/bulk_history"
|
|
30
41
|
require_relative "tronzap/responses/account_balance"
|
|
31
42
|
require_relative "tronzap/responses/address_info"
|
|
32
43
|
require_relative "tronzap/responses/aml_check"
|
|
33
44
|
require_relative "tronzap/responses/aml_history"
|
|
34
45
|
require_relative "tronzap/responses/aml_service"
|
|
46
|
+
require_relative "tronzap/responses/bulk_calculation"
|
|
47
|
+
require_relative "tronzap/responses/bulk_history"
|
|
48
|
+
require_relative "tronzap/responses/bulk_order"
|
|
35
49
|
require_relative "tronzap/responses/calculation"
|
|
36
50
|
require_relative "tronzap/responses/direct_recharge_info"
|
|
37
51
|
require_relative "tronzap/responses/energy_estimate"
|
|
38
52
|
require_relative "tronzap/responses/service_rates"
|
|
53
|
+
require_relative "tronzap/responses/subscription"
|
|
54
|
+
require_relative "tronzap/responses/subscription_history"
|
|
55
|
+
require_relative "tronzap/responses/subscription_plan"
|
|
39
56
|
require_relative "tronzap/responses/transaction"
|
|
40
57
|
require_relative "tronzap/http_adapter"
|
|
41
58
|
require_relative "tronzap/response_decoder"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tronzap-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- TronZap
|
|
@@ -49,21 +49,32 @@ files:
|
|
|
49
49
|
- lib/tronzap/models/address_resources.rb
|
|
50
50
|
- lib/tronzap/models/aml_risk_factor.rb
|
|
51
51
|
- lib/tronzap/models/bandwidth_rate.rb
|
|
52
|
+
- lib/tronzap/models/bulk_rejected_row.rb
|
|
52
53
|
- lib/tronzap/models/direct_recharge_rate.rb
|
|
53
54
|
- lib/tronzap/models/energy_rate.rb
|
|
54
55
|
- lib/tronzap/models/enums.rb
|
|
55
56
|
- lib/tronzap/models/resource_amounts.rb
|
|
57
|
+
- lib/tronzap/models/subscription_params.rb
|
|
56
58
|
- lib/tronzap/models/timestamp.rb
|
|
57
59
|
- lib/tronzap/models/transaction_params.rb
|
|
58
60
|
- lib/tronzap/requests/address_activation.rb
|
|
59
61
|
- lib/tronzap/requests/aml_check.rb
|
|
60
62
|
- lib/tronzap/requests/aml_history.rb
|
|
61
63
|
- lib/tronzap/requests/bandwidth_transaction.rb
|
|
64
|
+
- lib/tronzap/requests/bulk_calculate.rb
|
|
65
|
+
- lib/tronzap/requests/bulk_create.rb
|
|
66
|
+
- lib/tronzap/requests/bulk_history.rb
|
|
67
|
+
- lib/tronzap/requests/bulk_item.rb
|
|
68
|
+
- lib/tronzap/requests/bulk_lookup.rb
|
|
69
|
+
- lib/tronzap/requests/bulk_report.rb
|
|
62
70
|
- lib/tronzap/requests/calculate.rb
|
|
63
71
|
- lib/tronzap/requests/check_transaction.rb
|
|
64
72
|
- lib/tronzap/requests/energy_transaction.rb
|
|
65
73
|
- lib/tronzap/requests/estimate_energy.rb
|
|
66
74
|
- lib/tronzap/requests/resource_bundle_transaction.rb
|
|
75
|
+
- lib/tronzap/requests/start_subscription.rb
|
|
76
|
+
- lib/tronzap/requests/subscription_history.rb
|
|
77
|
+
- lib/tronzap/requests/subscription_lookup.rb
|
|
67
78
|
- lib/tronzap/requests/validation.rb
|
|
68
79
|
- lib/tronzap/response_decoder.rb
|
|
69
80
|
- lib/tronzap/responses/account_balance.rb
|
|
@@ -71,10 +82,16 @@ files:
|
|
|
71
82
|
- lib/tronzap/responses/aml_check.rb
|
|
72
83
|
- lib/tronzap/responses/aml_history.rb
|
|
73
84
|
- lib/tronzap/responses/aml_service.rb
|
|
85
|
+
- lib/tronzap/responses/bulk_calculation.rb
|
|
86
|
+
- lib/tronzap/responses/bulk_history.rb
|
|
87
|
+
- lib/tronzap/responses/bulk_order.rb
|
|
74
88
|
- lib/tronzap/responses/calculation.rb
|
|
75
89
|
- lib/tronzap/responses/direct_recharge_info.rb
|
|
76
90
|
- lib/tronzap/responses/energy_estimate.rb
|
|
77
91
|
- lib/tronzap/responses/service_rates.rb
|
|
92
|
+
- lib/tronzap/responses/subscription.rb
|
|
93
|
+
- lib/tronzap/responses/subscription_history.rb
|
|
94
|
+
- lib/tronzap/responses/subscription_plan.rb
|
|
78
95
|
- lib/tronzap/responses/transaction.rb
|
|
79
96
|
- lib/tronzap/version.rb
|
|
80
97
|
homepage: https://tronzap.com/
|