nis-ruby 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/README.md +81 -0
- data/Rakefile +6 -0
- data/bin/nis +59 -0
- data/lib/nis.rb +27 -0
- data/lib/nis/client.rb +89 -0
- data/lib/nis/endpoint.rb +2 -0
- data/lib/nis/endpoint/heartbeat.rb +10 -0
- data/lib/nis/endpoint/status.rb +10 -0
- data/lib/nis/error.rb +3 -0
- data/lib/nis/struct.rb +1 -0
- data/lib/nis/struct/nem_request_result.rb +31 -0
- data/lib/nis/unit.rb +1 -0
- data/lib/nis/unit/address.rb +35 -0
- data/lib/nis/unit/balance.rb +28 -0
- data/lib/nis/unit/code.rb +23 -0
- data/lib/nis/unit/hash.rb +23 -0
- data/lib/nis/unit/status.rb +33 -0
- data/lib/nis/unit/type.rb +23 -0
- data/lib/nis/unit/version.rb +33 -0
- data/lib/nis/util.rb +1 -0
- data/lib/nis/util/assignable.rb +28 -0
- data/lib/nis/version.rb +3 -0
- data/nis.gemspec +36 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75af8135685c901f2173ab165c56ac71cf17381a
|
4
|
+
data.tar.gz: e4aaa4ac65642edd9da3e9efe7bc0ce8bdf0f670
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8e1129782915ad5aa4ebf07ad93e0bb4c0f86c320c94b1f780c8b0b0b505fbb5ce0c08038275a89d95079168610f3b2a6613cb62e9c042e46b6d979ff5aa9f8
|
7
|
+
data.tar.gz: 131ed553ec7a65721fc5bb293e41639cf13218363249051fe405df811225f0a545b16bd40a43e1f7d468caa0a6f19daabd79c666b78561ed2a0dc30c6ea6b895
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at yukku0423@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# nis-ruby
|
2
|
+
|
3
|
+
[](https://travis-ci.org/44uk/nis-ruby)
|
4
|
+
|
5
|
+
<img src="https://cloud.githubusercontent.com/assets/370508/24320282/a332d238-1175-11e7-96dc-75bc30e562d2.png" width="320" height="320" alt="NEM" align="right" />
|
6
|
+
|
7
|
+
Ruby client library for the NEM Infrastructure Server API
|
8
|
+
|
9
|
+
- [NEM \- Distributed Ledger Technology \(Blockchain\)](https://www.nem.io/)
|
10
|
+
- [NEM NIS API Documentation](http://bob.nem.ninja/docs/)
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'nis-ruby'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ bundle install
|
25
|
+
```
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
$ gem specific_install -l 'git://github.com/44uk/nis-ruby.git'
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
nis = Nis.new
|
38
|
+
|
39
|
+
nis.heartbeat
|
40
|
+
# => {code: 1, type: 2, message: "ok"}
|
41
|
+
# See http://bob.nem.ninja/docs/#heart-beat-request
|
42
|
+
|
43
|
+
nis.status
|
44
|
+
# => {code: 6, type: 4, message: "status"}
|
45
|
+
# See http://bob.nem.ninja/docs/#status-request
|
46
|
+
|
47
|
+
nis.request(:get, '/account/get',
|
48
|
+
address: 'TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS'
|
49
|
+
)
|
50
|
+
# => [AccountMetaDataPair structure]
|
51
|
+
# See http://bob.nem.ninja/docs/#accountMetaDataPair
|
52
|
+
|
53
|
+
nis.request(:post, '/account/unlock',
|
54
|
+
privateKey: '00983bb01d05edecfaef55df9486c111abb6299c754a002069b1d0ef4537441bda'
|
55
|
+
)
|
56
|
+
# => Nothing
|
57
|
+
# See http://bob.nem.ninja/docs/#locking-and-unlocking-accounts
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
## Commandline
|
62
|
+
|
63
|
+
```bash
|
64
|
+
$ nis status # => {"code":6,"type":4,"message":"status"}
|
65
|
+
$ nis heartbeat # => {"code":1,"type":2,"message":"ok"}
|
66
|
+
```
|
67
|
+
|
68
|
+
|
69
|
+
## TODO
|
70
|
+
|
71
|
+
- Do more improvements.
|
72
|
+
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
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](http://contributor-covenant.org) code of conduct.
|
77
|
+
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/nis
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'thor'
|
5
|
+
require 'nis'
|
6
|
+
require 'nis/version'
|
7
|
+
|
8
|
+
class Nis
|
9
|
+
class CLI < Thor
|
10
|
+
class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
|
11
|
+
class_option :version, type: :boolean, desc: 'version'
|
12
|
+
class_option :debug, type: :boolean, aliases: '-d', desc: 'debug mode'
|
13
|
+
|
14
|
+
desc 'heartbeat', 'Get NIS heartbeat'
|
15
|
+
def heartbeat
|
16
|
+
puts Nis.new.heartbeat.to_json
|
17
|
+
setting_debug_mode
|
18
|
+
rescue => e
|
19
|
+
output_error_if_debug_mode(e)
|
20
|
+
exit(false)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'status', 'Get NIS status'
|
24
|
+
def status
|
25
|
+
puts Nis.new.status.to_json
|
26
|
+
setting_debug_mode
|
27
|
+
rescue => e
|
28
|
+
output_error_if_debug_mode(e)
|
29
|
+
exit(false)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'request', 'Send request to NIS'
|
33
|
+
def request(method, path, params = nil)
|
34
|
+
puts Nis.new.request(method, path, params)
|
35
|
+
setting_debug_mode
|
36
|
+
rescue => e
|
37
|
+
output_error_if_debug_mode(e)
|
38
|
+
exit(false)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'version', 'version'
|
42
|
+
def version
|
43
|
+
puts Nis::VERSION
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def setting_debug_mode
|
49
|
+
$DEBUG = options[:debug]
|
50
|
+
end
|
51
|
+
|
52
|
+
def output_error_if_debug_mode(e)
|
53
|
+
return unless options[:debug]
|
54
|
+
STDERR.puts(e.backtrace)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Nis::CLI.start(ARGV)
|
data/lib/nis.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "nis/version"
|
2
|
+
require "nis/util"
|
3
|
+
require "nis/client"
|
4
|
+
require "nis/endpoint"
|
5
|
+
require "nis/struct"
|
6
|
+
require "nis/unit"
|
7
|
+
require "nis/error"
|
8
|
+
|
9
|
+
# API Ruby Wrapper for NEM Infrastructure Server
|
10
|
+
class Nis
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators :@client, :request
|
14
|
+
|
15
|
+
# @param [hash] options HTTP Client connection information
|
16
|
+
# @option options [Symbol] :url URL
|
17
|
+
# @option options [Symbol] :scheme default http (http only)
|
18
|
+
# @option options [Symbol] :host default 127.0.0.1
|
19
|
+
# @option options [Symbol] :port default 7890
|
20
|
+
# @option options [Symbol] :timeout default 5
|
21
|
+
def initialize(options = {})
|
22
|
+
@client = Client.new(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
include Nis::Endpoint::Heartbeat
|
26
|
+
include Nis::Endpoint::Status
|
27
|
+
end
|
data/lib/nis/client.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
# @attr [Hash] options connection options
|
6
|
+
class Nis::Client
|
7
|
+
DEFAULTS = {
|
8
|
+
url: -> {ENV['NIS_URL']},
|
9
|
+
scheme: 'http',
|
10
|
+
host: '127.0.0.1',
|
11
|
+
port: 7890,
|
12
|
+
timeout: 5
|
13
|
+
}
|
14
|
+
|
15
|
+
attr :options
|
16
|
+
|
17
|
+
# @param [hash] options HTTP Client connection information
|
18
|
+
# @option options [Symbol] :url URL
|
19
|
+
# @option options [Symbol] :scheme default http (http only)
|
20
|
+
# @option options [Symbol] :host default 127.0.0.1
|
21
|
+
# @option options [Symbol] :port default 7890
|
22
|
+
# @option options [Symbol] :timeout default 5
|
23
|
+
def initialize(options = {})
|
24
|
+
@options = parse_options(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param [Symbol] method HTTP Method(GET or POST)
|
28
|
+
# @param [String] path API Path
|
29
|
+
# @param [Hash] params API Parameters
|
30
|
+
# @return [Hash] Hash converted API Response
|
31
|
+
def request(method, path, params = nil, &block)
|
32
|
+
body = connection.send(method, path, params).body
|
33
|
+
hash = parse_body(body) unless body.size == 0
|
34
|
+
block_given? ? yield(hash) : hash
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def connection
|
40
|
+
@connection ||= Faraday.new(url: @options[:url]) do |f|
|
41
|
+
f.options[:timeout] = @options[:timeout]
|
42
|
+
f.request :url_encoded
|
43
|
+
f.adapter Faraday.default_adapter
|
44
|
+
# f.response :logger do | logger |
|
45
|
+
# logger.filter(/(privateKey=)(\w+)/,'\1[FILTERED]')
|
46
|
+
# end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_body(body)
|
51
|
+
JSON.parse(body, symbolize_names: true)
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_options(options = {})
|
55
|
+
defaults = DEFAULTS.dup
|
56
|
+
options = options.dup
|
57
|
+
|
58
|
+
defaults[:url] = defaults[:url].call if defaults[:url].respond_to?(:call)
|
59
|
+
|
60
|
+
defaults.keys.each do |key|
|
61
|
+
options[key] = options[key.to_s] if options.has_key?(key.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
url = options[:url] || defaults[:url]
|
65
|
+
|
66
|
+
if url
|
67
|
+
uri = URI(url)
|
68
|
+
if uri.scheme == "http"
|
69
|
+
defaults[:scheme] = uri.scheme
|
70
|
+
defaults[:host] = uri.host
|
71
|
+
defaults[:port] = uri.port
|
72
|
+
else
|
73
|
+
raise ArgumentError, "invalid URI scheme '#{uri.scheme}'"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
defaults.keys.each do |key|
|
78
|
+
options[key] = defaults[key] if options[key].nil?
|
79
|
+
end
|
80
|
+
|
81
|
+
options[:url] = URI::Generic.build(
|
82
|
+
scheme: options[:scheme],
|
83
|
+
host: options[:host],
|
84
|
+
port: options[:port]
|
85
|
+
).to_s
|
86
|
+
|
87
|
+
options
|
88
|
+
end
|
89
|
+
end
|
data/lib/nis/endpoint.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Nis::Endpoint
|
2
|
+
module Heartbeat
|
3
|
+
# Determines if NIS is up and responsive.
|
4
|
+
# @return [Nis::Struct::NemRequestResult] NIS Heartbeat
|
5
|
+
# @see http://bob.nem.ninja/docs/#heart-beat-request
|
6
|
+
def heartbeat
|
7
|
+
Nis::Struct::NemRequestResult.build request(:get, '/heartbeat')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Nis::Endpoint
|
2
|
+
module Status
|
3
|
+
# Determines the status of NIS.
|
4
|
+
# @return [Nis::Struct::NemRequestResult] NIS status
|
5
|
+
# @see http://bob.nem.ninja/docs/#status-request
|
6
|
+
def status
|
7
|
+
Nis::Struct::NemRequestResult.build request(:get, '/status')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/nis/error.rb
ADDED
data/lib/nis/struct.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.expand_path('../struct/*.rb', __FILE__)].each{|f| require f}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Nis::Struct
|
2
|
+
# @see http://bob.nem.ninja/docs/#nemRequestResult
|
3
|
+
class NemRequestResult
|
4
|
+
include Nis::Util::Assignable
|
5
|
+
|
6
|
+
attr_accessor :type, :code, :message
|
7
|
+
|
8
|
+
def self.build(json)
|
9
|
+
new(json)
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Boolean]
|
13
|
+
def validation?
|
14
|
+
@type == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Boolean]
|
18
|
+
def heartbeat?
|
19
|
+
@type == 2
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Boolean]
|
23
|
+
def status?
|
24
|
+
@type == 4
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
@message
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/nis/unit.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.expand_path('../unit/*.rb', __FILE__)].each{|f| require f}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Nis::Unit
|
2
|
+
# @attr [String] value
|
3
|
+
# @attr [String] first_char
|
4
|
+
class Address
|
5
|
+
attr :value, :first_char
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@value = value
|
9
|
+
@first_char = @value[0]
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Boolean]
|
13
|
+
def valid?
|
14
|
+
!!(@value =~ /[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{40}/)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Boolean]
|
18
|
+
def mainnet?
|
19
|
+
@first_char == 'N'
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Boolean]
|
23
|
+
def testnet?
|
24
|
+
@first_char == 'T'
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
@value
|
29
|
+
end
|
30
|
+
|
31
|
+
def ==(other)
|
32
|
+
@value == other.value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Nis::Unit
|
2
|
+
# @attr [String] value
|
3
|
+
# @attr [String] value_in_nem
|
4
|
+
class Balance
|
5
|
+
attr :value
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@value = value.to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Float]
|
12
|
+
def in_nem
|
13
|
+
@value_in_nem ||= @value.to_f / 1_000_000
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
@value.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_i
|
21
|
+
@value
|
22
|
+
end
|
23
|
+
|
24
|
+
def ==(other)
|
25
|
+
@value == other.value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Nis::Unit
|
2
|
+
# @attr [String] value
|
3
|
+
# @attr [String] message
|
4
|
+
class Code
|
5
|
+
attr :value, :message
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
@message
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
@message
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
@value == other.value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Nis::Unit
|
2
|
+
# @attr [String] value
|
3
|
+
class Hash
|
4
|
+
attr :value
|
5
|
+
|
6
|
+
def initialize(value)
|
7
|
+
@value = value
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Boolean]
|
11
|
+
def valid?
|
12
|
+
!!(@value =~ /[0-9a-f]{64}/)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
@value
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
@value == other.value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Nis::Unit
|
2
|
+
# @attr [String] value
|
3
|
+
class Status
|
4
|
+
attr :value
|
5
|
+
|
6
|
+
def initialize(value)
|
7
|
+
@value = value
|
8
|
+
end
|
9
|
+
|
10
|
+
%w[
|
11
|
+
UNKNOWN
|
12
|
+
LOCKED
|
13
|
+
UNLOCKED
|
14
|
+
REMOTE
|
15
|
+
ACTIVATING
|
16
|
+
ACTIVE
|
17
|
+
DEACTIVATING
|
18
|
+
INACTIVE
|
19
|
+
].each do |status|
|
20
|
+
define_method "#{status.downcase}?" do
|
21
|
+
instance_variable_get(:@value) == status
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
@value
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other)
|
30
|
+
@value == other.value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Nis::Unit
|
2
|
+
# @attr [String] value
|
3
|
+
# @attr [String] message
|
4
|
+
class Type
|
5
|
+
attr :value, :message
|
6
|
+
|
7
|
+
def initialize(value)
|
8
|
+
@value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
@message
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
@message
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
@value == other.value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Nis::Unit
|
2
|
+
# @attr [String] value
|
3
|
+
class Version
|
4
|
+
MAINNET = 1744830465
|
5
|
+
TESTNET = -1744830463
|
6
|
+
|
7
|
+
attr :value
|
8
|
+
|
9
|
+
def initialize(value)
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Boolean]
|
14
|
+
def mainnet?
|
15
|
+
@value == MAINNET
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Boolean]
|
19
|
+
def testnet?
|
20
|
+
@value == TESTNET
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
testnet? ? 'testnet' :
|
25
|
+
mainnet? ? 'mainnet' :
|
26
|
+
'unexpected'
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other)
|
30
|
+
@value == other.value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/nis/util.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.expand_path('../util/*.rb', __FILE__)].each{|f| require f}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Nis::Util
|
2
|
+
module Assignable
|
3
|
+
def initialize(attributes = {})
|
4
|
+
attributes.each do |k, v|
|
5
|
+
send("#{k.to_s}=", v) if respond_to?("#{k.to_s}=")
|
6
|
+
end if attributes
|
7
|
+
yield self if block_given?
|
8
|
+
end
|
9
|
+
|
10
|
+
# @param [Symbol, String] attr Attribute name
|
11
|
+
# @return [Any] Attribute value
|
12
|
+
def [](attr)
|
13
|
+
send(attr)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Hash] Attribute and value pairs
|
17
|
+
def to_hash
|
18
|
+
instance_variables.each_with_object({}) do |var, hash|
|
19
|
+
hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [String] JSON formatted structure
|
24
|
+
def to_json
|
25
|
+
to_hash.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/nis/version.rb
ADDED
data/nis.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nis/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'nis-ruby'
|
8
|
+
spec.version = Nis::VERSION
|
9
|
+
spec.authors = ['Yoshiyuki Ieyama']
|
10
|
+
spec.email = ['yukku0423@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby client library for the NEM Infrastructure Server API}
|
13
|
+
spec.description = %q{Ruby client library for the NEM Infrastructure Server API}
|
14
|
+
spec.homepage = 'https://github.com/44uk/nis-ruby'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.metadata['yard.run'] = 'yri'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'bin'
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.47'
|
30
|
+
spec.add_development_dependency 'timecop', '~> 0.8'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 2.3'
|
32
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
33
|
+
|
34
|
+
spec.add_dependency 'faraday', '~> 0.11'
|
35
|
+
spec.add_dependency 'thor', '~> 0.19'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nis-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoshiyuki Ieyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.47'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.47'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: faraday
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.11'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.11'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: thor
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.19'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.19'
|
139
|
+
description: Ruby client library for the NEM Infrastructure Server API
|
140
|
+
email:
|
141
|
+
- yukku0423@gmail.com
|
142
|
+
executables:
|
143
|
+
- nis
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".travis.yml"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- bin/nis
|
155
|
+
- lib/nis.rb
|
156
|
+
- lib/nis/client.rb
|
157
|
+
- lib/nis/endpoint.rb
|
158
|
+
- lib/nis/endpoint/heartbeat.rb
|
159
|
+
- lib/nis/endpoint/status.rb
|
160
|
+
- lib/nis/error.rb
|
161
|
+
- lib/nis/struct.rb
|
162
|
+
- lib/nis/struct/nem_request_result.rb
|
163
|
+
- lib/nis/unit.rb
|
164
|
+
- lib/nis/unit/address.rb
|
165
|
+
- lib/nis/unit/balance.rb
|
166
|
+
- lib/nis/unit/code.rb
|
167
|
+
- lib/nis/unit/hash.rb
|
168
|
+
- lib/nis/unit/status.rb
|
169
|
+
- lib/nis/unit/type.rb
|
170
|
+
- lib/nis/unit/version.rb
|
171
|
+
- lib/nis/util.rb
|
172
|
+
- lib/nis/util/assignable.rb
|
173
|
+
- lib/nis/version.rb
|
174
|
+
- nis.gemspec
|
175
|
+
homepage: https://github.com/44uk/nis-ruby
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
metadata:
|
179
|
+
yard.run: yri
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.5.1
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: Ruby client library for the NEM Infrastructure Server API
|
200
|
+
test_files: []
|