Module: RippleRest

Defined in:
lib/ripple-rest.rb,
lib/ripple-rest/errors.rb,
lib/ripple-rest/schemas.rb,
lib/ripple-rest/version.rb,
lib/ripple-rest/helpers.rb,
lib/ripple-rest/rest-object.rb,
lib/ripple-rest/generated-schemas.rb

Defined Under Namespace

Modules: RestTypeHelper Classes: Account, AccountSettings, Amount, Balance, Notification, Notifications, Order, Payment, Payments, ProtocolError, RestObject, RippleRestError, Trustline, Trustlines

Constant Summary collapse

VERSION =
"1.0.3"

Private APIs collapse

Class Method Summary collapse

Class Method Details

.get(uri, args = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


56
57
58
# File 'lib/ripple-rest.rb', line 56

def get uri, args = {}
  wrap_error { RestClient.get "#{@endpoint}/#{uri}", args }
end

.get_transaction(hash) ⇒ Hash

Retrieve the details of a transaction in the standard Ripple JSON format.

Raises:


25
26
27
# File 'lib/ripple-rest.rb', line 25

def get_transaction hash
  get("v1/transactions/#{hash}")["transaction"]
end

.next_uuidString

A UUID v4 generator.

Raises:


49
50
51
# File 'lib/ripple-rest.rb', line 49

def next_uuid
  get("v1/uuid")["uuid"]
end

.post(uri, args = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


61
62
63
# File 'lib/ripple-rest.rb', line 61

def post uri, args = {}
  wrap_error { RestClient.post "#{@endpoint}/#{uri}", args.to_json, :content_type => :json }
end

.server_connected?Boolean

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.

Raises:


33
34
35
# File 'lib/ripple-rest.rb', line 33

def server_connected?
  get("v1/server/connected")["connected"]
end

.server_infoHash

Retrieve information about the ripple-rest and connected rippled's current status.

Raises:


41
42
43
# File 'lib/ripple-rest.rb', line 41

def server_info
  get("v1/server")
end

.setup(endpoint) ⇒ Object

Set endpoint URI


17
18
19
# File 'lib/ripple-rest.rb', line 17

def setup endpoint
  @endpoint = endpoint.gsub %r|/$|, ""
end

.wrap_errorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ripple-rest.rb', line 66

def wrap_error
  unless @endpoint
    raise ArgumentError.new "You have to setup RippleRest first."
  end
  
  begin
    response = yield
  rescue => e
    response = e.response if e.respond_to? :response
  end
  
  json = JSON.parse response.to_str rescue nil
  if json
    raise RippleRest::RippleRestError.new(json["message"] || json["error"] || json.to_json, json) unless json["success"]
  end

  if !response || response.code != 200
    raise RippleRest::ProtocolError.new "Protocol is wrong or network is down", response
  end
  
  json || response.to_str
end