nis-ruby 0.0.16 → 0.0.17

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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -33
  3. data/examples/account/generate.rb +29 -0
  4. data/examples/account/get.rb +26 -0
  5. data/examples/account/harvests.rb +8 -0
  6. data/examples/account/historical.rb +13 -0
  7. data/examples/account/importances.rb +8 -0
  8. data/examples/account/lock.rb +8 -0
  9. data/examples/account/mosaic.rb +9 -0
  10. data/examples/account/namespace.rb +8 -0
  11. data/examples/account/status.rb +8 -0
  12. data/examples/account/transfers.rb +16 -0
  13. data/examples/account/unconfirmed_transactions.rb +8 -0
  14. data/examples/account/unlock.rb +8 -0
  15. data/examples/account/unlocked.rb +8 -0
  16. data/examples/block/at_public.rb +4 -0
  17. data/examples/block/get.rb +4 -0
  18. data/examples/debug/connections.rb +13 -0
  19. data/examples/debug/time_synchronization.rb +6 -0
  20. data/examples/local/account_transfers.rb +20 -0
  21. data/examples/local/chain_blocks_after.rb +8 -0
  22. data/examples/namespace/mosaic_definition.rb +6 -0
  23. data/examples/namespace/root.rb +6 -0
  24. data/examples/nis.rb +11 -7
  25. data/examples/node/active_peers.rb +6 -0
  26. data/examples/node/boot.rb +25 -0
  27. data/examples/node/info.rb +8 -0
  28. data/examples/node/peerlist.rb +14 -0
  29. data/examples/time_sync/network_time.rb +6 -0
  30. data/examples/transactions/get.rb +42 -0
  31. data/examples/transactions/importance_transfer.rb +6 -4
  32. data/examples/transactions/mosaic_definition_creation.rb +6 -4
  33. data/examples/transactions/mosaic_supply_change.rb +6 -4
  34. data/examples/transactions/multisig.rb +6 -4
  35. data/examples/transactions/multisig_add_cosignatory.rb +3 -1
  36. data/examples/transactions/multisig_aggregate_modification.rb +6 -4
  37. data/examples/transactions/multisig_signature.rb +6 -3
  38. data/examples/transactions/provision_namespace.rb +6 -4
  39. data/examples/transactions/transfer.rb +14 -7
  40. data/examples/transactions/transfer_mosaic.rb +5 -3
  41. data/examples/transactions/transfer_remote.rb +6 -4
  42. data/lib/nis.rb +6 -0
  43. data/lib/nis/client.rb +11 -0
  44. data/lib/nis/configuration.rb +23 -0
  45. data/lib/nis/endpoint/account/transfers.rb +24 -0
  46. data/lib/nis/endpoint/debug/connections.rb +17 -0
  47. data/lib/nis/endpoint/local/account/transfers.rb +14 -0
  48. data/lib/nis/endpoint/node/peer_list.rb +20 -0
  49. data/lib/nis/endpoint/time_sync.rb +4 -0
  50. data/lib/nis/endpoint/time_sync/network_time.rb +10 -0
  51. data/lib/nis/endpoint/transaction/get.rb +12 -0
  52. data/lib/nis/keypair.rb +13 -7
  53. data/lib/nis/struct.rb +1 -0
  54. data/lib/nis/struct/importance_transfer_transaction.rb +10 -0
  55. data/lib/nis/struct/message.rb +9 -2
  56. data/lib/nis/struct/mosaic_definition_creation_transaction.rb +15 -0
  57. data/lib/nis/struct/mosaic_supply_change_transaction.rb +12 -0
  58. data/lib/nis/struct/multisig_aggregate_modification_transaction.rb +10 -0
  59. data/lib/nis/struct/multisig_signature_transaction.rb +12 -0
  60. data/lib/nis/struct/multisig_transaction.rb +15 -0
  61. data/lib/nis/struct/network_time.rb +17 -0
  62. data/lib/nis/struct/provision_namespace_transaction.rb +16 -0
  63. data/lib/nis/struct/transaction.rb +4 -81
  64. data/lib/nis/struct/transaction_meta_data_pair.rb +17 -1
  65. data/lib/nis/struct/transfer_transaction.rb +11 -0
  66. data/lib/nis/unit/address.rb +11 -4
  67. data/lib/nis/util.rb +3 -1
  68. data/lib/nis/util/convert.rb +44 -51
  69. data/lib/nis/util/deserializer.rb +62 -77
  70. data/lib/nis/util/ed25519.rb +10 -12
  71. data/lib/nis/util/serializer.rb +117 -185
  72. data/lib/nis/version.rb +1 -1
  73. data/nis.gemspec +0 -3
  74. metadata +43 -26
  75. data/bin/nis +0 -60
  76. data/examples/account.rb +0 -44
  77. data/examples/block.rb +0 -9
  78. data/examples/debug.rb +0 -33
  79. data/examples/local.rb +0 -19
  80. data/examples/namespace.rb +0 -9
  81. data/examples/node.rb +0 -44
  82. data/examples/shutdown.rb +0 -6
@@ -0,0 +1,6 @@
1
+ require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new(host: '23.228.67.85')
5
+
6
+ p nis.node_active_peers_max_chain_height
@@ -0,0 +1,25 @@
1
+ require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
5
+
6
+ bnr = Nis::Struct::BootNodeRequest.new(
7
+ metaData: {
8
+ application: 'NIS'
9
+ },
10
+ endpoint: {
11
+ protocol: 'http',
12
+ port: 7890,
13
+ host: 'localhost'
14
+ },
15
+ identity: {
16
+ 'private-key': 'a6cbd01d04edecfaef51df9486c111abb6299c764a00206eb1d01f4587491b3f',
17
+ name: 'Alice'
18
+ }
19
+ )
20
+
21
+ begin
22
+ p nis.node_boot(boot_node_request: bnr)
23
+ rescue => ex
24
+ p ex
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new(host: '23.228.67.85')
5
+
6
+ p nis.node_info
7
+ p nis.node_extended_info
8
+ p nis.node_experiences
@@ -0,0 +1,14 @@
1
+ require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new(host: '23.228.67.85')
5
+
6
+ # mapped methods
7
+ p nis.node_peerlist_all
8
+ p nis.node_peerlist_reachable
9
+ p nis.node_peerlist_active
10
+
11
+ # another way
12
+ p nis.node_peerlist(:all)
13
+ p nis.node_peerlist(:reachable)
14
+ p nis.node_peerlist(:active)
@@ -0,0 +1,6 @@
1
+ require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new(host: '23.228.67.85')
5
+
6
+ p nis.time_sync_network_time
@@ -0,0 +1,42 @@
1
+ require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ A_ADDRESS = 'TDPP2C4XQLMESBMCYGWN4NRAJAKZEYRV75KGYSOB'
5
+
6
+ nis = Nis.new(host: '23.228.67.85')
7
+
8
+ # transfer
9
+ hash = 'a7131c0836da45e72f61ac6e76259d7200a85f0d2cf38f79f223b2c366673b08'
10
+ p nis.transaction_get(hash: hash)
11
+
12
+ # important transfer
13
+ hash = '0765dbe0e79c2a57f2f71ae77f915d67b66290b2f72db5b3537bb32a1b09e2bf'
14
+ p nis.transaction_get(hash: hash)
15
+
16
+ # multisig aggregate modification
17
+ hash = '9593e7846c01a3a8c00363af9ae7a333cc11e266eb88636957578ae0d9f495a3'
18
+ p nis.transaction_get(hash: hash)
19
+
20
+ # multisig signature
21
+ # hash = ''
22
+ # p nis.transaction_get(hash: hash)
23
+
24
+ # transfer (multisig)
25
+ hash = '4185cad053f0bc7a2b3b9e5adc493e81a5af2f0a431f3d34ba2a25c937731629'
26
+ p nis.transaction_get(hash: hash)
27
+
28
+ # aggregate (multisig)
29
+ hash = 'f7d385a4c8b78d8a6a91c7b778df4ae793394c9c8bfeeca1393bf43770328a06'
30
+ p nis.transaction_get(hash: hash)
31
+
32
+ # provision namespace
33
+ hash = '63a3982228b68de56c73896d394cfa3698d7d81e7aec89ea1a77a6d68d103d22'
34
+ p nis.transaction_get(hash: hash)
35
+
36
+ # mosaic definition creation
37
+ hash = '0a16d30f57d65c5241cb0894a50fee51efbf6ff25a7a605de10423819234ab5d'
38
+ p nis.transaction_get(hash: hash)
39
+
40
+ # mosaic supply change
41
+ hash = '7d2c7f4c2895075a4c1bf2fdceba3781c3a80313e6979c29f1cd83277fe64ded'
42
+ p nis.transaction_get(hash: hash)
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # sender
4
7
  A_PRIVATE_KEY = '260206d683962350532408e8774fd14870a173b7fba17f6b504da3dbc5f1cc9f'
@@ -9,11 +12,10 @@ B_PUBLIC_KEY = 'cc6c9485d15b992501e57fe3799487e99de272f79c5442de94eeb998b45e0144
9
12
  kp = Nis::Keypair.new(A_PRIVATE_KEY)
10
13
 
11
14
  tx = Nis::Transaction::ImportanceTransfer.new(B_PUBLIC_KEY, :activate)
12
- puts "Fee: #{tx.fee.to_i}"
15
+ p "Fee: #{tx.fee.to_i}"
13
16
 
14
- nis = Nis.new
15
17
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
16
18
  res = nis.transaction_prepare_announce(req)
17
19
 
18
- puts "Message: #{res.message}"
19
- puts "TransactionHash: #{res.transaction_hash}"
20
+ p "Message: #{res.message}"
21
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # mosaic creator
4
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -37,11 +40,10 @@ definition = Nis::Struct::MosaicDefinition.new(
37
40
  )
38
41
 
39
42
  tx = Nis::Transaction::MosaicDefinitionCreation.new(definition)
40
- puts "Fee: #{tx.fee.to_i}"
43
+ p "Fee: #{tx.fee.to_i}"
41
44
 
42
- nis = Nis.new
43
45
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
44
46
  res = nis.transaction_prepare_announce(req)
45
47
 
46
- puts "Message: #{res.message}"
47
- puts "TransactionHash: #{res.transaction_hash}"
48
+ p "Message: #{res.message}"
49
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # mosaic owner
4
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -11,11 +14,10 @@ mosaic_id = Nis::Struct::MosaicId.new(
11
14
  )
12
15
 
13
16
  tx = Nis::Transaction::MosaicSupplyChange.new(mosaic_id, :increase, 1_000)
14
- puts "Fee: #{tx.fee.to_i}"
17
+ p "Fee: #{tx.fee.to_i}"
15
18
 
16
- nis = Nis.new
17
19
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
18
20
  res = nis.transaction_prepare_announce(req)
19
21
 
20
- puts "Message: #{res.message}"
21
- puts "TransactionHash: #{res.transaction_hash}"
22
+ p "Message: #{res.message}"
23
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # multisig
4
7
  M_PUBLIC_KEY = '00f077782658ae91b77f238ba5fcd7ef110564b5c189072e4d4590d9b17f9d76f3'
@@ -13,11 +16,10 @@ kp = Nis::Keypair.new(A_PRIVATE_KEY)
13
16
 
14
17
  ttx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
15
18
  tx = Nis::Transaction::Multisig.new(ttx, M_PUBLIC_KEY)
16
- puts "Fee: #{tx.fee.to_i}"
19
+ p "Fee: #{tx.fee.to_i}"
17
20
 
18
- nis = Nis.new
19
21
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
20
22
  res = nis.transaction_prepare_announce(req)
21
23
 
22
- puts "Message: #{res.message}"
23
- puts "TransactionHash: #{res.transaction_hash}"
24
+ p "Message: #{res.message}"
25
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # multisig
4
7
  M_PUBLIC_KEY = '6d72b57d2bc199d328e7ea3e24775f7f614760bc18f3f8501cd3daa9870cc40c'
@@ -20,7 +23,6 @@ min_cosigs = 1
20
23
  mtx = Nis::Transaction::MultisigAggregateModification.new([mcm], min_cosigs)
21
24
  tx = Nis::Transaction::Multisig.new(mtx, M_PUBLIC_KEY)
22
25
 
23
- nis = Nis.new
24
26
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
25
27
  res = nis.transaction_prepare_announce(req)
26
28
 
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # multisig
4
7
  M_PRIVATE_KEY = '00f077782658ae91b77f238ba5fcd7ef110564b5c189072e4d4590d9b17f9d76f3'
@@ -16,11 +19,10 @@ mcm = Nis::Struct::MultisigCosignatoryModification.new(
16
19
  min_cosigs = 1
17
20
 
18
21
  tx = Nis::Transaction::MultisigAggregateModification.new([mcm], min_cosigs)
19
- puts "Fee: #{tx.fee.to_i}"
22
+ p "Fee: #{tx.fee.to_i}"
20
23
 
21
- nis = Nis.new
22
24
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
23
25
  res = nis.transaction_prepare_announce(req)
24
26
 
25
- puts "Message: #{res.message}"
26
- puts "TransactionHash: #{res.transaction_hash}"
27
+ p "Message: #{res.message}"
28
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # multisig
4
7
  M_PUBLIC_KEY = '6d72b57d2bc199d328e7ea3e24775f7f614760bc18f3f8501cd3daa9870cc40c'
@@ -24,12 +27,12 @@ unless txes.size > 0
24
27
  end
25
28
 
26
29
  hash = txes.first.meta.data
27
- puts "Unconfirmed Transaction Hash: #{hash}"
30
+ p "Unconfirmed Transaction Hash: #{hash}"
28
31
 
29
32
  tx = Nis::Transaction::MultisigSignature.new(hash, M_ADDRESS, B_PUBLIC_KEY)
30
33
 
31
34
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
32
35
  res = nis.transaction_prepare_announce(req)
33
36
 
34
- puts "Message: #{res.message}"
35
- puts "TransactionHash: #{res.transaction_hash}"
37
+ p "Message: #{res.message}"
38
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # namespace creator
4
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -6,11 +9,10 @@ A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b83421
6
9
  kp = Nis::Keypair.new(A_PRIVATE_KEY)
7
10
 
8
11
  tx = Nis::Transaction::ProvisionNamespace.new('sushi')
9
- puts "Fee: #{tx.fee.to_i}"
12
+ p "Fee: #{tx.fee.to_i}"
10
13
 
11
- nis = Nis.new
12
14
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
13
15
  res = nis.transaction_prepare_announce(req)
14
16
 
15
- puts "Message: #{res.message}"
16
- puts "TransactionHash: #{res.transaction_hash}"
17
+ p "Message: #{res.message}"
18
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,13 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ # output debug log example
5
+ # Nis.configure do |conf|
6
+ # conf.logger = Logger.new('./nis-ruby.log')
7
+ # conf.logger.level = Logger::DEBUG
8
+ # end
9
+
10
+ nis = Nis.new
2
11
 
3
12
  # sender
4
13
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -9,17 +18,15 @@ B_PUBLIC_KEY = '9e7ab2924cd1a3482df784db190614cfc8a33671f5d80a5b15a9c9e8b4d13933
9
18
 
10
19
  kp = Nis::Keypair.new(A_PRIVATE_KEY)
11
20
  tx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
12
- puts "Fee: #{tx.fee.to_i}"
21
+ p "Fee: #{tx.fee.to_i}"
13
22
 
14
- nis = Nis.new
15
23
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
16
24
  res = nis.transaction_prepare_announce(req)
17
25
 
18
- puts "Message: #{res.message}"
19
- puts "TransactionHash: #{res.transaction_hash}"
26
+ p "Message: #{res.message}"
27
+ p "TransactionHash: #{res.transaction_hash}"
20
28
 
21
29
  # with encrypted message
22
-
23
30
  message = Nis::Struct::Message.new('Good luck!', type: :encrypted,
24
31
  private_key: kp.private,
25
32
  public_key: B_PUBLIC_KEY
@@ -30,5 +37,5 @@ puts "Fee: #{tx.fee.to_i}"
30
37
 
31
38
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
32
39
  res = nis.transaction_prepare_announce(req)
33
- puts "Message: #{res.message}"
34
- puts "TransactionHash: #{res.transaction_hash}"
40
+ p "Message: #{res.message}"
41
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new
2
5
 
3
6
  # sender
4
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -9,7 +12,6 @@ B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
9
12
  kp = Nis::Keypair.new(A_PRIVATE_KEY)
10
13
 
11
14
  # fetch mosaic definition
12
- nis = Nis.new
13
15
  mo_dmdps = nis.namespace_mosaic_definition_page(namespace: 'kon')
14
16
  mo_def = mo_dmdps.first.mosaic
15
17
 
@@ -48,5 +50,5 @@ tx.mosaics << Nis::Struct::MosaicAttachment.new(mo_def, 1)
48
50
  req = Nis::Request::PrepareAnnounce.new(tx, kp)
49
51
  res = nis.transaction_prepare_announce(req)
50
52
 
51
- puts "Message: #{res.message}"
52
- puts "TransactionHash: #{res.transaction_hash}"
53
+ p "Message: #{res.message}"
54
+ p "TransactionHash: #{res.transaction_hash}"
@@ -1,4 +1,7 @@
1
1
  require 'nis'
2
+ Nis.logger.level = Logger::DEBUG
3
+
4
+ nis = Nis.new(host: '23.228.67.85')
2
5
 
3
6
  # sender
4
7
  A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
@@ -9,11 +12,10 @@ B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
9
12
  kp = Nis::Keypair.new(A_PRIVATE_KEY)
10
13
 
11
14
  tx = Nis::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
12
- puts "Fee: #{tx.fee.to_i}"
15
+ p "Fee: #{tx.fee.to_i}"
13
16
 
14
- nis = Nis.new(host: '104.128.226.60')
15
17
  req = Nis::Request::Announce.new(tx, kp)
16
18
  res = nis.transaction_announce(req)
17
19
 
18
- puts "Message: #{res.message}"
19
- puts "TransactionHash: #{res.transaction_hash}"
20
+ p "Message: #{res.message}"
21
+ p "TransactionHash: #{res.transaction_hash}"
data/lib/nis.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'nis/version'
2
+ require 'nis/configuration'
2
3
  require 'nis/mixin'
3
4
  require 'nis/util'
4
5
  require 'nis/keypair'
@@ -13,6 +14,8 @@ require 'nis/error'
13
14
 
14
15
  # API Ruby Wrapper for NEM Infrastructure Server
15
16
  class Nis
17
+ extend Nis::Configuration
18
+
16
19
  extend Forwardable
17
20
 
18
21
  def_delegators :@client, :request, :request!
@@ -56,6 +59,7 @@ class Nis
56
59
  include Nis::Endpoint::Block::At
57
60
  include Nis::Endpoint::Block::Get
58
61
 
62
+ include Nis::Endpoint::Transaction::Get
59
63
  include Nis::Endpoint::Transaction::PrepareAnnounce
60
64
  include Nis::Endpoint::Transaction::Announce
61
65
 
@@ -69,6 +73,8 @@ class Nis
69
73
  include Nis::Endpoint::Node::Info
70
74
  include Nis::Endpoint::Node::PeerList
71
75
 
76
+ include Nis::Endpoint::TimeSync::NetworkTime
77
+
72
78
  include Nis::Endpoint::Debug::Connections
73
79
  include Nis::Endpoint::Debug::TimeSynchronization
74
80
  end
@@ -15,6 +15,7 @@ class Nis::Client
15
15
  }.freeze
16
16
 
17
17
  LOCAL_ONLY_PATHES = [
18
+ '/account/generate',
18
19
  '/local/account/transfers/incoming',
19
20
  '/local/account/transfers/outgoing',
20
21
  '/local/account/transfers/all',
@@ -40,6 +41,7 @@ class Nis::Client
40
41
  # @param [Hash] params API Parameters
41
42
  # @return [Hash] Hash converted API Response
42
43
  def request(method, path, params = {})
44
+ log(method, path, params)
43
45
  if connection.remote? && local_only?(path)
44
46
  raise Nis::Error, "The request (#{method} #{path}) is only permitted to local NIS."
45
47
  end
@@ -120,6 +122,15 @@ class Nis::Client
120
122
  options
121
123
  end
122
124
 
125
+ def log(method, path, params)
126
+ Nis.logger.debug "host:%s\tmethod:%s\tpath:%s\tparams:%s" % [
127
+ connection.url_prefix,
128
+ method,
129
+ path,
130
+ params.to_hash
131
+ ]
132
+ end
133
+
123
134
  module Local
124
135
  def local?
125
136
  host == '127.0.0.1' || host == 'localhost'
@@ -0,0 +1,23 @@
1
+ require 'logger'
2
+
3
+ class Nis
4
+ module Configuration
5
+ # Logger for {#debug}, default is `Nis::Logger.new(STDOUT)`
6
+ # @return [Logger]
7
+ attr_accessor :logger
8
+
9
+ def self.extended(base)
10
+ base.logger = Logger.new($stdout).tap { |logger| logger.level = Logger::INFO }
11
+ end
12
+
13
+ # @yield [self]
14
+ # @example
15
+ # Nis.configure do |conf|
16
+ # conf.logger = Logger.new('path/to/nis-ruby.log')
17
+ # conf.logger.level = Logger::DEBUG
18
+ # end
19
+ def configure
20
+ yield self
21
+ end
22
+ end
23
+ end