tronzap-sdk 1.0.0 → 1.1.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.
@@ -11,7 +11,7 @@ module Tronzap
11
11
  # @!attribute [r] max_energy
12
12
  # @return [Integer] largest energy amount this rate applies to
13
13
  # @!attribute [r] price
14
- # @return [BigDecimal] price per unit of energy, in TRX
14
+ # @return [BigDecimal] price per 1000 units of energy, in TRX
15
15
  # @!attribute [r] price_32k
16
16
  # @return [BigDecimal] price of 32 000 energy, in TRX
17
17
  # @!attribute [r] price_65k
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Tronzap
4
4
  module Models
5
- # An energy price tier. Energy is priced per unit.
5
+ # An energy price tier. Energy is priced per 1000 units: 65000 energy at a {price} of 0.03 costs 1.95.
6
6
  #
7
7
  # @!attribute [r] duration
8
8
  # @return [Integer] rental duration in hours
@@ -11,11 +11,13 @@ module Tronzap
11
11
  # @!attribute [r] max_amount
12
12
  # @return [Integer] largest amount this tier applies to
13
13
  # @!attribute [r] min_energy
14
- # @return [Integer] smallest energy amount this tier applies to
14
+ # @deprecated Use {#min_amount}.
15
+ # @return [Integer] the same value as {#min_amount}
15
16
  # @!attribute [r] max_energy
16
- # @return [Integer] largest energy amount this tier applies to
17
+ # @deprecated Use {#max_amount}.
18
+ # @return [Integer] the same value as {#max_amount}
17
19
  # @!attribute [r] price
18
- # @return [BigDecimal] price per unit of energy, in TRX
20
+ # @return [BigDecimal] price per 1000 units of energy, in TRX
19
21
  # @!attribute [r] price_32k
20
22
  # @return [BigDecimal] price of 32 000 energy, in TRX
21
23
  # @!attribute [r] price_65k
@@ -27,12 +29,14 @@ module Tronzap
27
29
  # @api private
28
30
  def self.from_api(value)
29
31
  data = Coerce.object(value, "energy rate")
32
+ min_amount = Coerce.integer(data["min_amount"], "min_amount")
33
+ max_amount = Coerce.integer(data["max_amount"], "max_amount")
30
34
  new(
31
35
  duration: Coerce.integer(data["duration"], "duration"),
32
- min_amount: Coerce.integer(data["min_amount"], "min_amount"),
33
- max_amount: Coerce.integer(data["max_amount"], "max_amount"),
34
- min_energy: Coerce.integer(data["min_energy"], "min_energy"),
35
- max_energy: Coerce.integer(data["max_energy"], "max_energy"),
36
+ min_amount: min_amount,
37
+ max_amount: max_amount,
38
+ min_energy: min_amount,
39
+ max_energy: max_amount,
36
40
  price: Coerce.decimal(data["price"], "price"),
37
41
  price_32k: Coerce.decimal(data["price_32k"], "price_32k"),
38
42
  price_65k: Coerce.decimal(data["price_65k"], "price_65k"),
@@ -14,7 +14,9 @@ module Tronzap
14
14
  # What an AML check screens: a wallet address or a transaction hash.
15
15
  AML_CHECK_TYPES = %i[address hash].freeze
16
16
 
17
- # Directions of a screened transaction: incoming (+:deposit+) or outgoing (+:withdrawal+) funds.
17
+ # Which side of a screened transaction you are on; the risk is scored for the counterparty. +:deposit+: the
18
+ # funds were sent to your address, the screened address is yours and the sender is scored. +:withdrawal+: you
19
+ # sent the funds, the screened address is the external recipient's and the recipient is scored.
18
20
  AML_DIRECTIONS = %i[deposit withdrawal].freeze
19
21
 
20
22
  # AML check states.
@@ -22,5 +24,9 @@ module Tronzap
22
24
 
23
25
  # AML risk levels.
24
26
  AML_RISK_LEVELS = %i[low medium high].freeze
27
+
28
+ # Subscription states: +:new+ → +:pending+ → +:active+, then +:stopped+ or +:expired+; +:error+ when it could
29
+ # not be started.
30
+ SUBSCRIPTION_STATUSES = %i[new pending error active stopped expired].freeze
25
31
  end
26
32
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tronzap
4
+ module Models
5
+ # The parameters a subscription was started with.
6
+ #
7
+ # @!attribute [r] address
8
+ # @return [String] the TRON address the subscription serves
9
+ # @!attribute [r] duration_days
10
+ # @return [Integer] how many days the subscription runs, 0 for no time limit
11
+ # @!attribute [r] transactions_limit
12
+ # @return [Integer] how many transactions the subscription covers, 0 for no limit
13
+ # @!attribute [r] activate_address
14
+ # @return [Boolean] whether activating the address was requested
15
+ SubscriptionParams = Data.define(:address, :duration_days, :transactions_limit, :activate_address) do
16
+ # @api private
17
+ def self.from_api(value)
18
+ data = Coerce.object(value, "params")
19
+ new(
20
+ address: Coerce.text(data["address"], "params.address"),
21
+ duration_days: Coerce.integer(data["duration"], "params.duration"),
22
+ transactions_limit: Coerce.integer(data["transactions_limit"], "params.transactions_limit"),
23
+ activate_address: Coerce.boolean(data["activate_address"], "params.activate_address")
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
@@ -9,17 +9,21 @@ module Tronzap
9
9
  # @!attribute [r] network
10
10
  # @return [String] the network code, for example +TRX+, +BTC+ or +ETH+
11
11
  # @!attribute [r] address
12
- # @return [String] the wallet address
12
+ # @return [String] the address to screen; for a hash check, the recipient address of the transaction, where
13
+ # the funds were received
13
14
  # @!attribute [r] transaction_hash
14
15
  # @return [String, nil] the transaction hash, required when {type} is +:hash+
15
16
  # @!attribute [r] direction
16
- # @return [Symbol, nil] the transaction direction for a hash check, one of {Models::AML_DIRECTIONS}
17
+ # @return [Symbol, nil] for a hash check, which side of the transaction you are on, one of
18
+ # {Models::AML_DIRECTIONS}: +:deposit+ if the funds were sent to your address (+address+ is yours),
19
+ # +:withdrawal+ if you sent them (+address+ is the external recipient's). The risk is scored for the
20
+ # counterparty. When omitted for a hash check, the SDK sends +deposit+.
17
21
  AmlCheck = Data.define(:type, :network, :address, :transaction_hash, :direction) do
18
22
  # @param type [Symbol, String] +:address+ or +:hash+
19
23
  # @param network [String]
20
24
  # @param address [String]
21
25
  # @param transaction_hash [String, nil]
22
- # @param direction [Symbol, String, nil] +:deposit+ or +:withdrawal+
26
+ # @param direction [Symbol, String, nil] +:deposit+ or +:withdrawal+; a hash check without one sends +deposit+
23
27
  # @raise [ArgumentError]
24
28
  def initialize(type:, network:, address:, transaction_hash: nil, direction: nil)
25
29
  type = Validation.one_of(type, Models::AML_CHECK_TYPES, "type")
@@ -46,10 +50,16 @@ module Tronzap
46
50
 
47
51
  # Screens a transaction.
48
52
  #
53
+ # +address+ is the recipient address of the transaction, where the funds were received. +direction+ says
54
+ # which side of the transaction you are on: +:deposit+ if the funds were sent to your address (+address+ is
55
+ # yours), +:withdrawal+ if you sent them (+address+ is the external recipient's). The risk is scored for the
56
+ # counterparty: the sender of a deposit, the recipient of a withdrawal. Without a direction the SDK sends
57
+ # +deposit+.
58
+ #
49
59
  # @param network [String] the network code, for example +BTC+
50
- # @param address [String]
60
+ # @param address [String] the recipient address of the transaction
51
61
  # @param transaction_hash [String]
52
- # @param direction [Symbol, String, nil] +:deposit+ or +:withdrawal+
62
+ # @param direction [Symbol, String, nil] +:deposit+ (the default) or +:withdrawal+
53
63
  # @return [AmlCheck]
54
64
  def self.for_hash(network, address, transaction_hash, direction: nil)
55
65
  new(type: :hash, network: network, address: address, transaction_hash: transaction_hash,
@@ -60,7 +70,8 @@ module Tronzap
60
70
  def body
61
71
  body = { "type" => type.name, "network" => network, "address" => address }
62
72
  body["hash"] = transaction_hash if transaction_hash
63
- body["direction"] = direction.name if direction
73
+ sent_direction = direction || (:deposit if type == :hash)
74
+ body["direction"] = sent_direction.name if sent_direction
64
75
  body
65
76
  end
66
77
  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
 
@@ -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 wallet address
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
@@ -11,7 +11,8 @@ module Tronzap
11
11
  # @!attribute [r] amount
12
12
  # @return [Integer] the amount priced
13
13
  # @!attribute [r] energy
14
- # @return [Integer] the energy priced
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: Coerce.integer(data["amount"], "amount"),
31
- energy: Coerce.integer(data["energy"], "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 amount of energy the price applies to
8
+ # @return [Integer] the energy the transfer needs, which the price applies to
9
9
  # @!attribute [r] energy
10
- # @return [Integer] the energy the transfer needs
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: Coerce.integer(data["amount"], "amount"),
32
- energy: Coerce.integer(data["energy"], "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 is priced per unit and bandwidth per 1000 units: {Models::EnergyRate#price} × 65000 is the cost of
8
- # 65000 energy, while 345 bandwidth at a {Models::BandwidthRate#price} of 1 costs 0.345.
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
@@ -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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Tronzap
4
4
  # The SDK version, reported in the default +User-Agent+ header.
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
data/lib/tronzap.rb CHANGED
@@ -17,6 +17,7 @@ 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"
20
21
  require_relative "tronzap/requests/validation"
21
22
  require_relative "tronzap/requests/estimate_energy"
22
23
  require_relative "tronzap/requests/calculate"
@@ -27,6 +28,9 @@ require_relative "tronzap/requests/address_activation"
27
28
  require_relative "tronzap/requests/check_transaction"
28
29
  require_relative "tronzap/requests/aml_check"
29
30
  require_relative "tronzap/requests/aml_history"
31
+ require_relative "tronzap/requests/start_subscription"
32
+ require_relative "tronzap/requests/subscription_lookup"
33
+ require_relative "tronzap/requests/subscription_history"
30
34
  require_relative "tronzap/responses/account_balance"
31
35
  require_relative "tronzap/responses/address_info"
32
36
  require_relative "tronzap/responses/aml_check"
@@ -36,6 +40,9 @@ require_relative "tronzap/responses/calculation"
36
40
  require_relative "tronzap/responses/direct_recharge_info"
37
41
  require_relative "tronzap/responses/energy_estimate"
38
42
  require_relative "tronzap/responses/service_rates"
43
+ require_relative "tronzap/responses/subscription"
44
+ require_relative "tronzap/responses/subscription_history"
45
+ require_relative "tronzap/responses/subscription_plan"
39
46
  require_relative "tronzap/responses/transaction"
40
47
  require_relative "tronzap/http_adapter"
41
48
  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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TronZap
@@ -53,6 +53,7 @@ files:
53
53
  - lib/tronzap/models/energy_rate.rb
54
54
  - lib/tronzap/models/enums.rb
55
55
  - lib/tronzap/models/resource_amounts.rb
56
+ - lib/tronzap/models/subscription_params.rb
56
57
  - lib/tronzap/models/timestamp.rb
57
58
  - lib/tronzap/models/transaction_params.rb
58
59
  - lib/tronzap/requests/address_activation.rb
@@ -64,6 +65,9 @@ files:
64
65
  - lib/tronzap/requests/energy_transaction.rb
65
66
  - lib/tronzap/requests/estimate_energy.rb
66
67
  - lib/tronzap/requests/resource_bundle_transaction.rb
68
+ - lib/tronzap/requests/start_subscription.rb
69
+ - lib/tronzap/requests/subscription_history.rb
70
+ - lib/tronzap/requests/subscription_lookup.rb
67
71
  - lib/tronzap/requests/validation.rb
68
72
  - lib/tronzap/response_decoder.rb
69
73
  - lib/tronzap/responses/account_balance.rb
@@ -75,6 +79,9 @@ files:
75
79
  - lib/tronzap/responses/direct_recharge_info.rb
76
80
  - lib/tronzap/responses/energy_estimate.rb
77
81
  - lib/tronzap/responses/service_rates.rb
82
+ - lib/tronzap/responses/subscription.rb
83
+ - lib/tronzap/responses/subscription_history.rb
84
+ - lib/tronzap/responses/subscription_plan.rb
78
85
  - lib/tronzap/responses/transaction.rb
79
86
  - lib/tronzap/version.rb
80
87
  homepage: https://tronzap.com/