nis-ruby

Ruby client library for the NEM Infrastructure Server API
The gem is under development. Incompatible changes can be made.
Installation
$ gem install nis-ruby
Or add this line to your application's Gemfile:
gem 'nis-ruby'
Usage
More specific example codes are in examples/ directory.
Methods
nis = Nis.new
nis.heartbeat
# => {code: 1, type: 2, message: "ok"}
# See https://nemproject.github.io/#heart-beat-request
nis.status
# => {code: 6, type: 4, message: "status"}
# See https://nemproject.github.io/#status-request
kp = Nis::Keypair.new(SENDER_PRIV_KEY)
tx = Nis::Transaction::Transfer.new(
RECIPIENT_ADDRESS,
10_000_000,
'Message'
)
req = Nis::Request::PrepareAnnounce.new(tx, kp)
# Request to local node.
nis.transaction_prepare_announce(req)
# See https://nemproject.github.io/#initiating-a-transfer-transaction
# => {innerTransactionHash: {}, code: 1, type: 1, message: "SUCCESS", transactionHash: {data: "9da41fd6c6886740ae6a15c869df0470015d78103e5b216971aa09fdbcce9cde"}}
# Request to remote node.
# nis.transaction_announce(req)
Requesting
nis = Nis.new
nis.request(:get, '/account/get',
address: 'TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS'
)
# => [AccountMetaDataPair structure]
# See https://nemproject.github.io/#accountMetaDataPair
nis.request(:post, '/account/unlock',
privateKey: '00983bb01d05edecfaef55df9486c111abb6299c754a002069b1d0ef4537441bda'
)
# => Nothing
# See https://nemproject.github.io/#locking-and-unlocking-accounts
Commandline
$ nis status
# => {"code":6,"type":4,"message":"status"}
$ nis heartbeat
# => {"code":1,"type":2,"message":"ok"}
$ nis request get account/get --params=address:TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS
# => [AccountMetaDataPair structure]
$ nis request get account/harvests --params=address:TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS hash:81d52a7df4abba8bb1613bcc42b6b93cf3114524939035d88ae8e864cd2c34c8
# => [Array <HervestInfo structure>]
Connection
You can find nodes here.
Hash
# Passing hostname
Nis.new(host: 'bigalice3.nem.ninja')
# Passing url
Nis.new(url: 'http://bigalice3.nem.ninja:7890')
Environment Variable
$ export NIS_URL=http://bigalice3.nem.ninja:7890
$ nis heartbeat # => {"code":1,"type":2,"message":"ok"}
Environment variable used as default value.
TODO
- Do more improvements
- Mosaic transferring
- Encryption message
- Be more easy to use
Documentation
Available at rubydoc.info.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nis-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.