nis-ruby

Ruby client library for the NEM Infrastructure Server(NIS) API.
The gem is under development. Incompatible changes can be made.
Do a thorough test on testnet before you use this gem on production.
Installation
$ gem install nis-ruby
Or add this line to your application's Gemfile:
gem 'nis-ruby'
Usage
Examples
More specific example codes are in examples/ directory.
Methods
require 'rubygems'
require 'nis'
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,
1, # send 1xem
'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 = Nis.new(host: '104.128.226.60')
# nis.transaction_announce(req)
Requesting
require 'rubygems'
require 'nis'
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 choose nodes from NEM Node Rewards.
Hash
# Passing hostname
Nis.new(host: '104.128.226.60')
# Passing url
Nis.new(url: 'http://104.128.226.60:7890')
Environment Variable
$ export NIS_URL=http://104.128.226.60:7890
$ nis heartbeat # => {"code":1,"type":2,"message":"ok"}
Environment variable used as default value.
For More Information
Contact
Feel free to ask me if you have any questions.
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.