ripple-rest 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ripple-rest.rb CHANGED
@@ -3,7 +3,6 @@ module RippleRest; end
3
3
  require 'json'
4
4
  require 'cgi'
5
5
  require 'bigdecimal'
6
- require 'autoparse'
7
6
  require 'rest-client'
8
7
  require 'ripple-rest/version'
9
8
  require 'ripple-rest/errors'
@@ -13,23 +12,61 @@ require 'ripple-rest/schemas/account_settings'
13
12
  require 'ripple-rest/schemas/trustlines'
14
13
  require 'ripple-rest/schemas/balance'
15
14
  require 'ripple-rest/schemas/notifications'
16
- require 'ripple-rest/schemas/order'
17
15
  require 'ripple-rest/schemas/amount'
18
16
  require 'ripple-rest/schemas/payments'
19
17
 
20
18
  class << RippleRest
19
+ # Set endpoint URI
20
+ # @param endpoint [String] "http://localhost:5990/"
21
21
  def setup endpoint
22
22
  @endpoint = endpoint.gsub %r|/$|, ""
23
23
  end
24
24
 
25
+ # Retrieve the details of a transaction in the standard Ripple JSON format.
26
+ # @return [Hash] See the Ripple Wiki page on [Transaction Formats](https://ripple.com/wiki/Transactions) for more information.
27
+ # @raise [RippleRestError] if RippleRest server returns an error
28
+ # @raise [ProtocolError] if protocol is wrong or network is down
29
+ def get_transaction hash
30
+ get("v1/transactions/#{hash}")["transaction"]
31
+ end
32
+
33
+ # A simple endpoint that can be used to check if ripple-rest is connected to a rippled and is ready to serve. If used before querying the other endpoints this can be used to centralize the logic to handle if rippled is disconnected from the Ripple Network and unable to process transactions.
34
+ # @return [Boolean] true if `ripple-rest` is ready to serve
35
+ # @raise [RippleRestError] if RippleRest server returns an error
36
+ # @raise [ProtocolError] if protocol is wrong or network is down
37
+ def server_connected?
38
+ get("v1/server/connected")["connected"]
39
+ end
40
+
41
+ # Retrieve information about the ripple-rest and connected rippled's current status.
42
+ # @return [Hash] https://github.com/ripple/ripple-rest/blob/develop/docs/api-reference.md#get-server-info
43
+ # @raise [RippleRestError] if RippleRest server returns an error
44
+ # @raise [ProtocolError] if protocol is wrong or network is down
45
+ def server_info
46
+ get("v1/server")
47
+ end
48
+
49
+ # A UUID v4 generator.
50
+ # @return [String] "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
51
+ # @raise [RippleRestError] if RippleRest server returns an error
52
+ # @raise [ProtocolError] if protocol is wrong or network is down
53
+ def next_uuid
54
+ get("v1/uuid")["uuid"]
55
+ end
56
+
57
+ # @!group Private APIs
58
+
59
+ # @api private
25
60
  def get uri, args = {}
26
61
  wrap_error { RestClient.get "#{@endpoint}/#{uri}", args }
27
62
  end
28
63
 
64
+ # @api private
29
65
  def post uri, args = {}
30
66
  wrap_error { RestClient.post "#{@endpoint}/#{uri}", args, :content_type => :json }
31
67
  end
32
68
 
69
+ # @api private
33
70
  def wrap_error
34
71
  unless @endpoint
35
72
  raise ArgumentError.new "You have to setup RippleRest first."
@@ -53,20 +90,6 @@ class << RippleRest
53
90
  json || response.to_str
54
91
  end
55
92
 
56
- def get_transaction hash
57
- get("v1/transactions/#{hash}")["transaction"]
58
- end
59
-
60
- def server_connected?
61
- get("v1/server/connected")["connected"]
62
- end
63
-
64
- def server_info
65
- get("v1/server")
66
- end
67
-
68
- def next_uuid
69
- get("v1/uuid")["uuid"]
70
- end
93
+ #@!endgroup
71
94
  end
72
95
 
@@ -1,5 +1,6 @@
1
1
  module RippleRest
2
2
  class ProtocolError < RuntimeError
3
+ # @return [RestClient::Response]
3
4
  attr_accessor :response
4
5
  def initialize message, response
5
6
  super message
@@ -8,6 +9,7 @@ module RippleRest
8
9
  end
9
10
 
10
11
  class RippleRestError < RuntimeError
12
+ # @return [String, Hash]
11
13
  attr_accessor :response
12
14
  def initialize message, response
13
15
  super message
@@ -1,6 +1,11 @@
1
1
  module RippleRest
2
2
  class Account
3
+ # Account's Address (rXXXXXX...)
4
+ # @return [String]
3
5
  attr_accessor :address
6
+
7
+ # Account's secret
8
+ # @return [String]
4
9
  attr_accessor :secret
5
10
 
6
11
  def initialize address, secret = nil
@@ -8,12 +13,21 @@ module RippleRest
8
13
  @secret = secret
9
14
  end
10
15
 
16
+ # Get an account's existing balances.
17
+ # This includes XRP balance (which does not include a counterparty) and trustline balances.
18
+ # @return [Array<Balance>]
19
+ # @raise [RippleRestError] if RippleRest server returns an error
20
+ # @raise [ProtocolError] if protocol is wrong or network is down
11
21
  def balances
12
22
  RippleRest
13
23
  .get("v1/accounts/#{@address}/balances")["balances"]
14
24
  .map(&Balance.method(:new))
15
25
  end
16
26
 
27
+ # Returns a Trustlines object for this account.
28
+ # @return [Trustlines]
29
+ # @raise [RippleRestError] if RippleRest server returns an error
30
+ # @raise [ProtocolError] if protocol is wrong or network is down
17
31
  def trustlines
18
32
  data = RippleRest
19
33
  .get("v1/accounts/#{@address}/trustlines")["trustlines"]
@@ -23,6 +37,10 @@ module RippleRest
23
37
  obj
24
38
  end
25
39
 
40
+ # Returns a AccountSettings object for this account.
41
+ # @return [AccountSettings]
42
+ # @raise [RippleRestError] if RippleRest server returns an error
43
+ # @raise [ProtocolError] if protocol is wrong or network is down
26
44
  def settings
27
45
  data = RippleRest.get("v1/accounts/#{@address}/settings")["settings"]
28
46
  obj = AccountSettings.new data
@@ -30,6 +48,8 @@ module RippleRest
30
48
  obj
31
49
  end
32
50
 
51
+ # Returns a Notifications object for this account.
52
+ # @return [Notifications]
33
53
  def notifications
34
54
  @notifications ||= lambda {
35
55
  obj = Notifications.new
@@ -37,11 +57,9 @@ module RippleRest
37
57
  obj
38
58
  }.call
39
59
  end
40
-
41
- def require_secret
42
- raise ArgumentError.new("Secret is required for this operation.") unless secret
43
- end
44
60
 
61
+ # Returns a Payments object for this account.
62
+ # @return [Payments]
45
63
  def payments
46
64
  payments ||= lambda {
47
65
  obj = Payments.new
@@ -50,8 +68,17 @@ module RippleRest
50
68
  }.call
51
69
  end
52
70
 
71
+ # Returns the address of attribute address.
72
+ # @return [String]
53
73
  def to_s
54
74
  address
55
75
  end
76
+
77
+ # @!group Private APIs
78
+ # @api private
79
+ def require_secret
80
+ raise ArgumentError.new("Secret is required for this operation.") unless secret
81
+ end
82
+ # @!endgroup
56
83
  end
57
84
  end
@@ -1,9 +1,13 @@
1
1
  module RippleRest
2
- generate_schema :AccountSettings
3
-
4
2
  class AccountSettings
3
+ # @return [Account]
5
4
  attr_accessor :account
6
5
 
6
+ # Save the account settings
7
+ # @raise [ArgumentError] if secret is missing from the Account object
8
+ # @raise [RippleRestError] if RippleRest server returns an error
9
+ # @raise [ProtocolError] if protocol is wrong or network is down
10
+ # @return [void]
7
11
  def save
8
12
  raise ArgumentError.new("Account is missing.") unless account
9
13
 
@@ -1,11 +1,12 @@
1
1
  module RippleRest
2
- generate_schema :Amount
3
-
4
2
  class Amount
3
+ # @return [String]
5
4
  def to_s
6
5
  "#{value}+#{currency}#{issuer.to_s.size > 0 ? ("+" + issuer) : ""}"
7
6
  end
8
7
 
8
+ # @param s [String, Amount] an Amount object or a String like "1+XRP" or "1+USD+r..."
9
+ # @return [Amount]
9
10
  def self.from_string s
10
11
  return s if s.is_a?(Amount)
11
12
 
@@ -1,7 +1,6 @@
1
1
  module RippleRest
2
- generate_schema :Balance
3
-
4
2
  class Balance
3
+ # @return [String]
5
4
  def inspect
6
5
  "#{value.to_s} #{currency}#{counterparty.to_s.size > 0 ? " (#{counterparty})" : ""}"
7
6
  end
@@ -1,9 +1,12 @@
1
+ require 'autoparse'
2
+
1
3
  module RippleRest
2
- SCHEMA_ROOT = File.join(File.dirname(__FILE__), "json")
3
-
4
+ # @!group Private APIs
5
+ # @api private
4
6
  def self.generate_schema(fn)
5
- RippleRest.const_set fn, AutoParse.generate(JSON.parse(File.read(File.join(SCHEMA_ROOT, "#{fn}.json"))), :uri => "#{fn}")
7
+ RippleRest.const_set fn, AutoParse.generate(JSON.parse(File.read(File.join(File.join(File.dirname(__FILE__), "json"), "#{fn}.json"))), :uri => "#{fn}")
6
8
  end
9
+ # @!endgroup
7
10
 
8
11
  generate_schema :Currency
9
12
  generate_schema :FloatString
@@ -13,5 +16,435 @@ module RippleRest
13
16
  generate_schema :RippleAddress
14
17
  generate_schema :Timestamp
15
18
  generate_schema :UINT32
16
- generate_schema :URL
17
- end
19
+ generate_schema :URL
20
+
21
+ generate_schema :Order
22
+ generate_schema :Balance
23
+ generate_schema :Notification
24
+ generate_schema :Payment
25
+ generate_schema :Trustline
26
+ generate_schema :AccountSettings
27
+ generate_schema :Amount
28
+
29
+ # A
30
+ class Notification < AutoParse::Instance
31
+ # @!attribute account
32
+ # The Ripple address of the account to which the notification pertains
33
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
34
+
35
+
36
+ # @!attribute type
37
+ # The resource type this notification corresponds to. Possible values are "payment", "order", "trustline", "accountsettings"
38
+ # @return [String] +"^payment|order|trustline|accountsettings$"+
39
+
40
+
41
+ # @!attribute direction
42
+ # The direction of the transaction, from the perspective of the account being queried. Possible values are "incoming", "outgoing", and "passthrough"
43
+ # @return [String] +"^incoming|outgoing|passthrough$"+
44
+
45
+
46
+ # @!attribute state
47
+ # The state of the transaction from the perspective of the Ripple Ledger. Possible values are "validated" and "failed"
48
+ # @return [String] +"^validated|failed$"+
49
+
50
+
51
+ # @!attribute result
52
+ # The rippled code indicating the success or failure type of the transaction. The code "tesSUCCESS" indicates that the transaction was successfully validated and written into the Ripple Ledger. All other codes will begin with the following prefixes: "tec", "tef", "tel", or "tej"
53
+ # @return [String] +"te[cfjlms][A-Za-z_]+"+
54
+
55
+
56
+ # @!attribute ledger
57
+ # The string representation of the index number of the ledger containing the validated or failed transaction. Failed payments will only be written into the Ripple Ledger if they fail after submission to a rippled and a Ripple Network fee is claimed
58
+ # @return [String] +"^[0-9]+$"+
59
+
60
+
61
+ # @!attribute hash
62
+ # The 256-bit hash of the transaction. This is used throughout the Ripple protocol as the unique identifier for the transaction
63
+ # @return [String<Hash256>] +"^$|^[A-Fa-f0-9]{64}$"+
64
+
65
+
66
+ # @!attribute timestamp
67
+ # The timestamp representing when the transaction was validated and written into the Ripple ledger
68
+ # @return [String<Timestamp>] +"^$|^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](Z|[+](2[0-3]|[01][0-9]):[0-5][0-9])$"+
69
+
70
+
71
+ # @!attribute transaction_url
72
+ # A URL that can be used to fetch the full resource this notification corresponds to
73
+ # @return [String]
74
+
75
+
76
+ # @!attribute previous_notification_url
77
+ # A URL that can be used to fetch the notification that preceded this one chronologically
78
+ # @return [String]
79
+
80
+
81
+ # @!attribute next_notification_url
82
+ # A URL that can be used to fetch the notification that followed this one chronologically
83
+ # @return [String]
84
+
85
+
86
+ end
87
+ # A simplified Order object used by the ripple-rest API (note that "orders" are referred to elsewhere in the Ripple protocol as "offers")
88
+ class Order < AutoParse::Instance
89
+ # @!attribute account
90
+ # The Ripple account address of the order's creator
91
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
92
+
93
+
94
+ # @!attribute buy
95
+ # If set to true the order it indicates that the creator is looking to receive the base_amount in exchange for the counter_amount. If undefined or set to false it indicates that the creator is looking to sell the base_amount to receive the counter_amount
96
+ # @return [Boolean]
97
+
98
+
99
+ # @!attribute base_amount
100
+ # The amount of currency the seller_account is seeking to buy. If other orders take part of this one, this value will change to represent the amount left in the order. This may be specified along with the counter_amount OR exchange_rate but not both. When the order is parsed from the Ripple Ledger the base currency will be determined according to the Priority Ranking of Currencies (XRP,EUR,GBP,AUD,NZD,USD,CAD,CHF,JPY,CNY) and if neither currency is listed in the ranking the base currency will be the one that is alphabetically first
101
+ # @return [Amount]
102
+
103
+
104
+ # @!attribute counter_amount
105
+ # The amount of currency being sold. If other orders take part of this one, this value will change to represent the amount left in the order. This may be specified along with the base_amount OR the exchange_rate but not both
106
+ # @return [Amount]
107
+
108
+
109
+ # @!attribute exchange_rate
110
+ # A string representation of the order price, defined as the cost one unit of the base currency in terms of the counter currency. This may be specified along with the base_amount OR the counter_amount but not both. If it is unspecified it will be computed automatically based on the counter_amount divided by the base_amount
111
+ # @return [String<FloatString>]
112
+
113
+
114
+ # @!attribute expiration_timestamp
115
+ # The ISO combined date and time string representing the point beyond which the order will no longer be considered active or valid
116
+ # @return [String<Timestamp>] +"^$|^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](Z|[+](2[0-3]|[01][0-9]):[0-5][0-9])$"+
117
+
118
+
119
+ # @!attribute ledger_timeout
120
+ # A string representation of the number of ledger closes after submission during which the order should be considered active
121
+ # @return [String] +"^[0-9]*$"+
122
+
123
+
124
+ # @!attribute immediate_or_cancel
125
+ # If set to true this order will only take orders that are available at the time of execution and will not create an entry in the Ripple Ledger
126
+ # @return [Boolean]
127
+
128
+
129
+ # @!attribute fill_or_kill
130
+ # If set to true this order will only take orders that fill the base_amount and are available at the time of execution and will not create an entry in the Ripple Ledger
131
+ # @return [Boolean]
132
+
133
+
134
+ # @!attribute maximize_buy_or_sell
135
+ # If set to true and it is a buy order it will buy up to the base_amount even if the counter_amount is exceeded, if it is a sell order it will sell up to the counter_amount even if the base_amount is exceeded
136
+ # @return [Boolean]
137
+
138
+
139
+ # @!attribute cancel_replace
140
+ # If this is set to the sequence number of an outstanding order, that order will be cancelled and replaced with this one
141
+ # @return [String] +"^d*$"+
142
+
143
+
144
+ # @!attribute sequence
145
+ # The sequence number of this order from the perspective of the seller_account. The seller_account and the sequence number uniquely identify the order in the Ripple Ledger
146
+ # @return [String] +"^[0-9]*$"+
147
+
148
+
149
+ # @!attribute fee
150
+ # The Ripple Network transaction fee, represented in whole XRP (NOT "drops", or millionths of an XRP, which is used elsewhere in the Ripple protocol) used to create the order
151
+ # @return [String<FloatString>]
152
+
153
+
154
+ # @!attribute state
155
+ # If the order is active the state will be "active". If this object represents a historical order the state will be "validated", "filled" if the order was removed because it was fully filled, "cancelled" if it was deleted by the owner, "expired" if it reached the expiration_timestamp, or "failed" if there was an error with the initial attempt to place the order
156
+ # @return [String] +"^active|validated|filled|cancelled|expired|failed$"+
157
+
158
+
159
+ # @!attribute ledger
160
+ # The string representation of the index number of the ledger containing this order or, in the case of historical queries, of the transaction that modified this Order.
161
+ # @return [String] +"^[0-9]+$"+
162
+
163
+
164
+ # @!attribute hash
165
+ # When returned as the result of a historical query this will be the hash of Ripple transaction that created, modified, or deleted this order. The transaction hash is used throughout the Ripple Protocol to uniquely identify a particular transaction
166
+ # @return [String<Hash256>] +"^$|^[A-Fa-f0-9]{64}$"+
167
+
168
+
169
+ # @!attribute previous
170
+ # If the order was modified or partially filled this will be a full Order object. If the previous object also had a previous object that will be removed to reduce data complexity. Order changes can be walked backwards by querying the API for previous.hash repeatedly
171
+ # @return [Order]
172
+
173
+
174
+ end
175
+ # An object
176
+ class AccountSettings < AutoParse::Instance
177
+ # @!attribute account
178
+ # The Ripple address of the account in question
179
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
180
+
181
+
182
+ # @!attribute regular_key
183
+ # The hash of an optional additional public key that can be used for signing and verifying transactions
184
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
185
+
186
+
187
+ # @!attribute url
188
+ # The domain associated with this account. The ripple.txt file can be looked up to verify this information
189
+ # @return [String<URL>] +"^(ftp://|http://|https://)?([A-Za-z0-9_]+:{0,1}[A-Za-z0-9_]*@)?(^([ \\t\\r\\n\\f])+)(:[0-9]+)?(/|/([[A-Za-z0-9_]#!:.?+=&%@!-\\/]))?$"+
190
+
191
+
192
+ # @!attribute email_hash
193
+ # The MD5 128-bit hash of the account owner's email address
194
+ # @return [String<Hash128>] +"^$|^[A-Fa-f0-9]{32}$"+
195
+
196
+
197
+ # @!attribute message_key
198
+ # An optional public key, represented as hex, that can be set to allow others to send encrypted messages to the account owner
199
+ # @return [String] +"^([0-9a-fA-F]{2}){0,33}$"+
200
+
201
+
202
+ # @!attribute transfer_rate
203
+ # A number representation of the rate charged each time a holder of currency issued by this account transfers it. By default the rate is 100. A rate of 101 is a 1% charge on top of the amount being transferred. Up to nine decimal places are supported
204
+ # @return [Float]
205
+
206
+
207
+ # @!attribute require_destination_tag
208
+ # If set to true incoming payments will only be validated if they include a destination_tag. This may be used primarily by gateways that operate exclusively with hosted wallets
209
+ # @return [Boolean]
210
+
211
+
212
+ # @!attribute require_authorization
213
+ # If set to true incoming trustlines will only be validated if this account first creates a trustline to the counterparty with the authorized flag set to true. This may be used by gateways to prevent accounts unknown to them from holding currencies they issue
214
+ # @return [Boolean]
215
+
216
+
217
+ # @!attribute disallow_xrp
218
+ # If set to true incoming XRP payments will be allowed
219
+ # @return [Boolean]
220
+
221
+
222
+ # @!attribute transaction_sequence
223
+ # A string representation of the last sequence number of a validated transaction created by this account
224
+ # @return [String<UINT32>] +"^$|^(429496729[0-5]|42949672[0-8][0-9]|4294967[01][0-9]{2}|429496[0-6][0-9]{3}|42949[0-5][0-9]{4}|4294[0-8][0-9]{5}|429[0-3][0-9]{6}|42[0-8][0-9]{7}|4[01][0-9]{8}|[1-3][0-9]{9}|[1-9][0-9]{8}|[1-9][0-9]{7}|[1-9][0-9]{6}|[1-9][0-9]{5}|[1-9][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])$"+
225
+
226
+
227
+ # @!attribute trustline_count
228
+ # The number of trustlines owned by this account. This value does not include incoming trustlines where this account has not explicitly reciprocated trust
229
+ # @return [String<UINT32>] +"^$|^(429496729[0-5]|42949672[0-8][0-9]|4294967[01][0-9]{2}|429496[0-6][0-9]{3}|42949[0-5][0-9]{4}|4294[0-8][0-9]{5}|429[0-3][0-9]{6}|42[0-8][0-9]{7}|4[01][0-9]{8}|[1-3][0-9]{9}|[1-9][0-9]{8}|[1-9][0-9]{7}|[1-9][0-9]{6}|[1-9][0-9]{5}|[1-9][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])$"+
230
+
231
+
232
+ # @!attribute ledger
233
+ # The string representation of the index number of the ledger containing these account settings or, in the case of historical queries, of the transaction that modified these settings
234
+ # @return [String] +"^[0-9]+$"+
235
+
236
+
237
+ # @!attribute hash
238
+ # If this object was returned by a historical query this value will be the hash of the transaction that modified these settings. The transaction hash is used throughout the Ripple Protocol to uniquely identify a particular transaction
239
+ # @return [String<Hash256>] +"^$|^[A-Fa-f0-9]{64}$"+
240
+
241
+
242
+ end
243
+ # A flattened Payment object used by the ripple-rest API
244
+ class Payment < AutoParse::Instance
245
+ # @!attribute source_account
246
+ # The Ripple account address of the Payment sender
247
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
248
+
249
+
250
+ # @!attribute source_tag
251
+ # A string representing an unsigned 32-bit integer most commonly used to refer to a sender's hosted account at a Ripple gateway
252
+ # @return [String<UINT32>] +"^$|^(429496729[0-5]|42949672[0-8][0-9]|4294967[01][0-9]{2}|429496[0-6][0-9]{3}|42949[0-5][0-9]{4}|4294[0-8][0-9]{5}|429[0-3][0-9]{6}|42[0-8][0-9]{7}|4[01][0-9]{8}|[1-3][0-9]{9}|[1-9][0-9]{8}|[1-9][0-9]{7}|[1-9][0-9]{6}|[1-9][0-9]{5}|[1-9][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])$"+
253
+
254
+
255
+ # @!attribute source_amount
256
+ # An optional amount that can be specified to constrain cross-currency payments
257
+ # @return [Amount]
258
+
259
+
260
+ # @!attribute source_slippage
261
+ # An optional cushion for the source_amount to increase the likelihood that the payment will succeed. The source_account will never be charged more than source_amount.value + source_slippage
262
+ # @return [String<FloatString>]
263
+
264
+
265
+ # @!attribute destination_account
266
+ #
267
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
268
+
269
+
270
+ # @!attribute destination_tag
271
+ # A string representing an unsigned 32-bit integer most commonly used to refer to a receiver's hosted account at a Ripple gateway
272
+ # @return [String<UINT32>] +"^$|^(429496729[0-5]|42949672[0-8][0-9]|4294967[01][0-9]{2}|429496[0-6][0-9]{3}|42949[0-5][0-9]{4}|4294[0-8][0-9]{5}|429[0-3][0-9]{6}|42[0-8][0-9]{7}|4[01][0-9]{8}|[1-3][0-9]{9}|[1-9][0-9]{8}|[1-9][0-9]{7}|[1-9][0-9]{6}|[1-9][0-9]{5}|[1-9][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])$"+
273
+
274
+
275
+ # @!attribute destination_amount
276
+ # The amount the destination_account will receive
277
+ # @return [Amount]
278
+
279
+
280
+ # @!attribute invoice_id
281
+ # A 256-bit hash that can be used to identify a particular payment
282
+ # @return [String<Hash256>] +"^$|^[A-Fa-f0-9]{64}$"+
283
+
284
+
285
+ # @!attribute paths
286
+ # A "stringified" version of the Ripple PathSet structure that users should treat as opaque
287
+ # @return [String]
288
+
289
+
290
+ # @!attribute partial_payment
291
+ # A boolean that, if set to true, indicates that this payment should go through even if the whole amount cannot be delivered because of a lack of liquidity or funds in the source_account account
292
+ # @return [Boolean]
293
+
294
+
295
+ # @!attribute no_direct_ripple
296
+ # A boolean that can be set to true if paths are specified and the sender would like the Ripple Network to disregard any direct paths from the source_account to the destination_account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet
297
+ # @return [Boolean]
298
+
299
+
300
+ # @!attribute direction
301
+ # The direction of the payment, from the perspective of the account being queried. Possible values are "incoming", "outgoing", and "passthrough"
302
+ # @return [String] +"^incoming|outgoing|passthrough$"+
303
+
304
+
305
+ # @!attribute state
306
+ # The state of the payment from the perspective of the Ripple Ledger. Possible values are "validated" and "failed" and "new" if the payment has not been submitted yet
307
+ # @return [String] +"^validated|failed|new$"+
308
+
309
+
310
+ # @!attribute result
311
+ # The rippled code indicating the success or failure type of the payment. The code "tesSUCCESS" indicates that the payment was successfully validated and written into the Ripple Ledger. All other codes will begin with the following prefixes: "tec", "tef", "tel", or "tej"
312
+ # @return [String] +"te[cfjlms][A-Za-z_]+"+
313
+
314
+
315
+ # @!attribute ledger
316
+ # The string representation of the index number of the ledger containing the validated or failed payment. Failed payments will only be written into the Ripple Ledger if they fail after submission to a rippled and a Ripple Network fee is claimed
317
+ # @return [String] +"^[0-9]+$"+
318
+
319
+
320
+ # @!attribute hash
321
+ # The 256-bit hash of the payment. This is used throughout the Ripple protocol as the unique identifier for the transaction
322
+ # @return [String<Hash256>] +"^$|^[A-Fa-f0-9]{64}$"+
323
+
324
+
325
+ # @!attribute timestamp
326
+ # The timestamp representing when the payment was validated and written into the Ripple ledger
327
+ # @return [String<Timestamp>] +"^$|^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](Z|[+](2[0-3]|[01][0-9]):[0-5][0-9])$"+
328
+
329
+
330
+ # @!attribute fee
331
+ # The Ripple Network transaction fee, represented in whole XRP (NOT "drops", or millionths of an XRP, which is used elsewhere in the Ripple protocol)
332
+ # @return [String<FloatString>]
333
+
334
+
335
+ # @!attribute source_balance_changes
336
+ # Parsed from the validated transaction metadata, this array represents all of the changes to balances held by the source_account. Most often this will have one amount representing the Ripple Network fee and, if the source_amount was not XRP, one amount representing the actual source_amount that was sent
337
+ # @return [array]
338
+
339
+
340
+ # @!attribute destination_balance_changes
341
+ # Parsed from the validated transaction metadata, this array represents the changes to balances held by the destination_account. For those receiving payments this is important to check because if the partial_payment flag is set this value may be less than the destination_amount
342
+ # @return [array]
343
+
344
+
345
+ end
346
+ # A simplified representation of an account Balance
347
+ class Balance < AutoParse::Instance
348
+ # @!attribute value
349
+ # The quantity of the currency, denoted as a string to retain floating point precision
350
+ # @return [String]
351
+
352
+
353
+ # @!attribute currency
354
+ # The currency expressed as a three-character code
355
+ # @return [String<Currency>] +"^([a-zA-Z0-9]{3}|[A-Fa-f0-9]{40})$"+
356
+
357
+
358
+ # @!attribute counterparty
359
+ # The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP
360
+ # @return [String] +"^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
361
+
362
+
363
+ end
364
+ # An Amount on the Ripple Protocol, used also for XRP in the ripple-rest API
365
+ class Amount < AutoParse::Instance
366
+ # @!attribute value
367
+ # The quantity of the currency, denoted as a string to retain floating point precision
368
+ # @return [String]
369
+
370
+
371
+ # @!attribute currency
372
+ # The currency expressed as a three-character code
373
+ # @return [String<Currency>] +"^([a-zA-Z0-9]{3}|[A-Fa-f0-9]{40})$"+
374
+
375
+
376
+ # @!attribute issuer
377
+ # The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP
378
+ # @return [String] +"^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
379
+
380
+
381
+ # @!attribute counterparty
382
+ # The Ripple account address of the currency's issuer or gateway, or an empty string if the currency is XRP
383
+ # @return [String] +"^$|^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
384
+
385
+
386
+ end
387
+ # A simplified Trustline object used by the ripple-rest API
388
+ class Trustline < AutoParse::Instance
389
+ # @!attribute account
390
+ # The account from whose perspective this trustline is being viewed
391
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
392
+
393
+
394
+ # @!attribute counterparty
395
+ # The other party in this trustline
396
+ # @return [String<RippleAddress>] +"^r[1-9A-HJ-NP-Za-km-z]{25,33}$"+
397
+
398
+
399
+ # @!attribute currency
400
+ # The code of the currency in which this trustline denotes trust
401
+ # @return [String<Currency>] +"^([a-zA-Z0-9]{3}|[A-Fa-f0-9]{40})$"+
402
+
403
+
404
+ # @!attribute limit
405
+ # The maximum value of the currency that the account may hold issued by the counterparty
406
+ # @return [String<FloatString>]
407
+
408
+
409
+ # @!attribute reciprocated_limit
410
+ # The maximum value of the currency that the counterparty may hold issued by the account
411
+ # @return [String<FloatString>]
412
+
413
+
414
+ # @!attribute authorized_by_account
415
+ # Set to true if the account has explicitly authorized the counterparty to hold currency it issues. This is only necessary if the account's settings include require_authorization_for_incoming_trustlines
416
+ # @return [Boolean]
417
+
418
+
419
+ # @!attribute authorized_by_counterparty
420
+ # Set to true if the counterparty has explicitly authorized the account to hold currency it issues. This is only necessary if the counterparty's settings include require_authorization_for_incoming_trustlines
421
+ # @return [Boolean]
422
+
423
+
424
+ # @!attribute account_allows_rippling
425
+ # If true it indicates that the account allows pairwise rippling out through this trustline
426
+ # @return [Boolean]
427
+
428
+
429
+ # @!attribute counterparty_allows_rippling
430
+ # If true it indicates that the counterparty allows pairwise rippling out through this trustline
431
+ # @return [Boolean]
432
+
433
+
434
+ # @!attribute ledger
435
+ # The string representation of the index number of the ledger containing this trustline or, in the case of historical queries, of the transaction that modified this Trustline
436
+ # @return [String] +"^[0-9]+$"+
437
+
438
+
439
+ # @!attribute hash
440
+ # If this object was returned by a historical query this value will be the hash of the transaction that modified this Trustline. The transaction hash is used throughout the Ripple Protocol to uniquely identify a particular transaction
441
+ # @return [String<Hash256>] +"^$|^[A-Fa-f0-9]{64}$"+
442
+
443
+
444
+ # @!attribute previous
445
+ # If the trustline was changed this will be a full Trustline object representing the previous values. If the previous object also had a previous object that will be removed to reduce data complexity. Trustline changes can be walked backwards by querying the API for previous.hash repeatedly
446
+ # @return [Trustline]
447
+
448
+
449
+ end
450
+ end
@@ -3,5 +3,5 @@
3
3
  "title": "URL",
4
4
  "description": "A standard URL",
5
5
  "type": "string",
6
- "pattern": "^(ftp:\/\/|http:\/\/|https:\/\/)?([A-Za-z0-9_]+:{0,1}[A-Za-z0-9_]*@)?(^([ \t\r\n\f])+)(:[0-9]+)?(\/|\/([[A-Za-z0-9_]#!:.?+=&%@!-\/]))?$"
6
+ "pattern": "^(ftp:\/\/|http:\/\/|https:\/\/)?([A-Za-z0-9_]+:{0,1}[A-Za-z0-9_]*@)?(^([ \\t\\r\\n\\f])+)(:[0-9]+)?(\/|\/([[A-Za-z0-9_]#!:.?+=&%@!-\\/]))?$"
7
7
  }
@@ -0,0 +1,73 @@
1
+ require 'json'
2
+ schemas = {}
3
+ Dir["*.json"].each do |i|
4
+ key = File.basename(i, ".json")
5
+ schemas[key] = JSON.parse File.read i
6
+ end
7
+
8
+ puts <<'EOF'
9
+ require 'autoparse'
10
+
11
+ module RippleRest
12
+ # @!group Private APIs
13
+ # @api private
14
+ def self.generate_schema(fn)
15
+ RippleRest.const_set fn, AutoParse.generate(JSON.parse(File.read(File.join(File.join(File.dirname(__FILE__), "json"), "#{fn}.json"))), :uri => "#{fn}")
16
+ end
17
+ # @!endgroup
18
+
19
+ generate_schema :Currency
20
+ generate_schema :FloatString
21
+ generate_schema :Hash128
22
+ generate_schema :Hash256
23
+ generate_schema :ResourceId
24
+ generate_schema :RippleAddress
25
+ generate_schema :Timestamp
26
+ generate_schema :UINT32
27
+ generate_schema :URL
28
+
29
+ generate_schema :Order
30
+ generate_schema :Balance
31
+ generate_schema :Notification
32
+ generate_schema :Payment
33
+ generate_schema :Trustline
34
+ generate_schema :AccountSettings
35
+ generate_schema :Amount
36
+
37
+ EOF
38
+ schemas.values.select{|i|i["type"] == "object"}.each do |json|
39
+ key = json["title"]
40
+ puts " # #{json["description"]}"
41
+ puts " class #{key} < AutoParse::Instance"
42
+
43
+ json["properties"].each do |k, v|
44
+ type = ""
45
+ if v["type"] == "string" && v["pattern"]
46
+ type = "[String] +#{v["pattern"].inspect}+"
47
+ elsif v["type"] == "string"
48
+ type = "[String]"
49
+ elsif v["type"] == "boolean"
50
+ type = "[Boolean]"
51
+ elsif v["type"] == "float"
52
+ type = "[Float]"
53
+ elsif v["$ref"] == "FloatString"
54
+ type = "[String<FloatString>]" # BigDecimal
55
+ elsif v["$ref"] == "UInt32"
56
+ type = "[UInt32]"
57
+ elsif v["$ref"] && schemas[v["$ref"]]["type"] == "string"
58
+ type = "[String<#{v["$ref"]}>] +#{schemas[v["$ref"]]["pattern"].inspect}+"
59
+ elsif v["$ref"]
60
+ type = "[#{v["$ref"]}]"
61
+ elsif
62
+ type = "[#{v["type"]}]"
63
+ end
64
+
65
+ puts " # @!attribute #{k}"
66
+ puts " # #{v["description"]}"
67
+ puts " # @return #{type}"
68
+ puts
69
+ puts
70
+ end
71
+ puts " end"
72
+ end
73
+ puts "end"
@@ -1,9 +1,16 @@
1
1
  module RippleRest
2
- generate_schema :Notification
3
-
4
2
  class Notifications
3
+ # @return [Account]
5
4
  attr_accessor :account
6
5
 
6
+ # Get notifications.
7
+ #
8
+ # Clients using notifications to monitor their account activity should pay particular attention to the `state` and `result` fields. The `state` field will either be `validated` or `failed` and represents the finalized status of that transaction. The `result` field will be `tesSUCCESS` if the `state` was validated. If the transaction failed, `result` will contain the `rippled` or `ripple-lib` error code.
9
+ #
10
+ # Notifications have `next_notification_url` and `previous_notification_url`'s. Account notifications can be polled by continuously following the `next_notification_url`, and handling the resultant notifications, until the `next_notification_url` is an empty string. This means that there are no new notifications but, as soon as there are, querying the same URL that produced this notification in the first place will return the same notification but with the `next_notification_url` set.
11
+ # @raise [RippleRestError] if RippleRest server returns an error
12
+ # @raise [ProtocolError] if protocol is wrong or network is down
13
+ # @return [Notification]
7
14
  def [] hash
8
15
  Notification.new RippleRest
9
16
  .get("v1/accounts/#{account.address}/notifications/#{hash}")["notification"]
@@ -1,16 +1,22 @@
1
1
  module RippleRest
2
- generate_schema :Payment
3
-
4
2
  class Payment
3
+ # Gets Account object of this Payment's source account
5
4
  def account
6
5
  @account
7
6
  end
8
7
 
8
+ # Sets source account and secret for this Payment
9
+ # @param val [Account]
9
10
  def account= val
10
11
  @account = val
11
12
  self.source_account = val.address
12
13
  end
13
14
 
15
+ # Submits a payment
16
+ # @return [String] Client resource ID
17
+ # @raise [ArgumentError] if secret is missing from the Account object
18
+ # @raise [RippleRestError] if RippleRest server returns an error
19
+ # @raise [ProtocolError] if protocol is wrong or network is down
14
20
  def submit
15
21
  @account.require_secret
16
22
 
@@ -22,17 +28,31 @@ module RippleRest
22
28
  RippleRest.post("v1/payments", hash)["client_resource_id"]
23
29
  end
24
30
 
31
+ # @return [String]
25
32
  attr_accessor :client_resource_id
26
33
  end
27
34
 
28
35
  class Payments
36
+ # @return [Account]
29
37
  attr_accessor :account
30
38
 
39
+ # Returns an individual payment.
40
+ # @param hash [String] Payment hash or client resource ID
41
+ # @raise [RippleRestError] if RippleRest server returns an error
42
+ # @raise [ProtocolError] if protocol is wrong or network is down
43
+ # @return [Payment]
31
44
  def [] hash
32
45
  Payment.new RippleRest
33
46
  .get("v1/accounts/#{account.address}/payments/#{hash}")["payment"]
34
47
  end
35
48
 
49
+ # Query `rippled` for possible payment "paths" through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency.
50
+ # @param destination_account [String, Account] destination account
51
+ # @param destination_amount [String, Amount] destination amount
52
+ # @param source_currencies [Array<String>] an array of source currencies that can be used to constrain the results returned (e.g. `["XRP", "USD+r...", "BTC+r..."]`) Currencies can be denoted by their currency code (e.g. USD) or by their currency code and issuer (e.g. `USD+r...`). If no issuer is specified for a currency other than XRP, the results will be limited to the specified currencies but any issuer for that currency will do.
53
+ # @raise [RippleRestError] if RippleRest server returns an error
54
+ # @raise [ProtocolError] if protocol is wrong or network is down
55
+ # @return [Array<Payment>]
36
56
  def find_path destination_account, destination_amount, source_currencies = nil
37
57
  uri = "v1/accounts/#{account.address}/payments/paths/#{destination_account.to_s}/#{destination_amount.to_s}"
38
58
 
@@ -46,6 +66,8 @@ module RippleRest
46
66
  end
47
67
  end
48
68
 
69
+ # Create a Payment object with some field filled.
70
+ # @return [Payment]
49
71
  def create destination_account, destination_amount
50
72
  payment = Payment.new
51
73
  payment.account = account
@@ -54,6 +76,18 @@ module RippleRest
54
76
  payment
55
77
  end
56
78
 
79
+ # Browse historical payments in bulk.
80
+ # @option options [String, Account] :source_account If specified, limit the results to payments initiated by a particular account
81
+ # @option options [String, Account] :destination_account If specified, limit the results to payments made to a particular account
82
+ # @option options [Boolean] :exclude_failed if set to true, this will return only payment that were successfully validated and written into the Ripple Ledger
83
+ # @option options [String] :start_ledger If earliest_first is set to true this will be the index number of the earliest ledger queried, or the most recent one if earliest_first is set to false. Defaults to the first ledger the rippled has in its complete ledger. An error will be returned if this value is outside the rippled's complete ledger set
84
+ # @option options [String] :end_ledger If earliest_first is set to true this will be the index number of the most recent ledger queried, or the earliest one if earliest_first is set to false. Defaults to the last ledger the rippled has in its complete ledger. An error will be returned if this value is outside the rippled's complete ledger set
85
+ # @option options [Boolean] :earliest_first Determines the order in which the results should be displayed. Defaults to true
86
+ # @option options [Fixnum] :results_per_page Limits the number of resources displayed per page. Defaults to 20
87
+ # @option options [Fixnum] :page The page to be displayed. If there are fewer than the results_per_page number displayed, this indicates that this is the last page
88
+ # @raise [RippleRestError] if RippleRest server returns an error
89
+ # @raise [ProtocolError] if protocol is wrong or network is down
90
+ # @return [Array<Payment>]
57
91
  def query options = {}
58
92
  qs = ""
59
93
  if options && options.size > 0
@@ -1,24 +1,31 @@
1
1
  module RippleRest
2
-
3
- generate_schema :Trustline
4
2
  class Trustlines
5
3
  include Enumerable
6
4
 
5
+ # @return [Account]
7
6
  attr_accessor :account
8
7
 
9
8
  def initialize data
10
9
  @data = data
11
10
  end
12
11
 
12
+ # Use with Enumerable
13
13
  def each *args, &block
14
14
  @data.each *args, &block
15
15
  end
16
16
 
17
- def add obj
17
+ # Add trustline
18
+ # @param obj [String, Hash] Either a string representation of trustline limit, Hash containing value, currency, counterparty or a string form value/currency/counterparty.
19
+ # @param allow_rippling [Boolean] See [here](https://ripple.com/wiki/No_Ripple) for details
20
+ # @raise [ArgumentError] if secret is missing from the Account object
21
+ # @raise [RippleRestError] if RippleRest server returns an error
22
+ # @raise [ProtocolError] if protocol is wrong or network is down
23
+ def add obj, allow_rippling = true
18
24
  raise ArgumentError.new("Account is missing.") unless account
19
25
  account.require_secret
20
26
 
21
27
  hash = {}
28
+ hash["allow_rippling"] = allow_rippling
22
29
  hash["secret"] = account.secret
23
30
 
24
31
  if obj.is_a? String
@@ -1,3 +1,3 @@
1
1
  module RippleRest
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripple-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -49,6 +49,7 @@ executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
+ - lib/ripple-rest/schemas/json/_generate.rb
52
53
  - lib/ripple-rest/schemas/json.rb
53
54
  - lib/ripple-rest/schemas/trustlines.rb
54
55
  - lib/ripple-rest/schemas/payments.rb
@@ -56,7 +57,6 @@ files:
56
57
  - lib/ripple-rest/schemas/account_settings.rb
57
58
  - lib/ripple-rest/schemas/balance.rb
58
59
  - lib/ripple-rest/schemas/notifications.rb
59
- - lib/ripple-rest/schemas/order.rb
60
60
  - lib/ripple-rest/schemas/account.rb
61
61
  - lib/ripple-rest/version.rb
62
62
  - lib/ripple-rest/errors.rb
@@ -95,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  segments:
97
97
  - 0
98
- hash: -284765535
98
+ hash: 9938735
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
@@ -1,6 +0,0 @@
1
- module RippleRest
2
- generate_schema :Order
3
-
4
- class Order
5
- end
6
- end