nis-ruby 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75af8135685c901f2173ab165c56ac71cf17381a
4
- data.tar.gz: e4aaa4ac65642edd9da3e9efe7bc0ce8bdf0f670
3
+ metadata.gz: 243cf43c7f000b402bc53492589b09e6fcace49d
4
+ data.tar.gz: da5160e721669987b8c75e4edb47c9504882150c
5
5
  SHA512:
6
- metadata.gz: b8e1129782915ad5aa4ebf07ad93e0bb4c0f86c320c94b1f780c8b0b0b505fbb5ce0c08038275a89d95079168610f3b2a6613cb62e9c042e46b6d979ff5aa9f8
7
- data.tar.gz: 131ed553ec7a65721fc5bb293e41639cf13218363249051fe405df811225f0a545b16bd40a43e1f7d468caa0a6f19daabd79c666b78561ed2a0dc30c6ea6b895
6
+ metadata.gz: b7905478e1bc79efc732b110aa97bde382f0c530d57e3d54b3901cbcc54e9ee1a3519e43db1272f79da7d9f8b37ce1911c6c43404a4702ab6e3b251cd587789d
7
+ data.tar.gz: ccff172070610b806ad272f50a4ef42bd7262caa4f30f58db63c52208254d542810896e27f12066e88a9e4a46216c380b3d681da2e35d0dcf629fa28953a0a07
data/.travis.yml CHANGED
@@ -4,8 +4,6 @@ rvm:
4
4
  - 2.4.0
5
5
  - 2.3.0
6
6
  - 2.2.0
7
- - 2.1.0
8
- - 2.0.0
9
7
 
10
8
  branches:
11
9
  only:
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # nis-ruby
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/nis-ruby.svg)](https://badge.fury.io/rb/nis-ruby)
3
4
  [![Build Status](https://travis-ci.org/44uk/nis-ruby.svg?branch=master)](https://travis-ci.org/44uk/nis-ruby)
5
+ [![Code Climate](https://codeclimate.com/github/44uk/nis-ruby/badges/gpa.svg)](https://codeclimate.com/github/44uk/nis-ruby)
6
+ [![Join the chat at https://gitter.im/44uk/nis-ruby](https://badges.gitter.im/44uk/nis-ruby.svg)](https://gitter.im/44uk/nis-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
7
 
5
8
  <img src="https://cloud.githubusercontent.com/assets/370508/24320282/a332d238-1175-11e7-96dc-75bc30e562d2.png" width="320" height="320" alt="NEM" align="right" />
6
9
 
@@ -12,22 +15,14 @@ Ruby client library for the NEM Infrastructure Server API
12
15
 
13
16
  ## Installation
14
17
 
15
- Add this line to your application's Gemfile:
16
-
17
- ```ruby
18
- gem 'nis-ruby'
19
- ```
20
-
21
- And then execute:
22
-
23
18
  ```bash
24
- $ bundle install
19
+ $ gem install nis-ruby
25
20
  ```
26
21
 
27
- Or install it yourself as:
22
+ Or add this line to your application's Gemfile:
28
23
 
29
- ```bash
30
- $ gem specific_install -l 'git://github.com/44uk/nis-ruby.git'
24
+ ```ruby
25
+ gem 'nis-ruby'
31
26
  ```
32
27
 
33
28
 
@@ -58,6 +53,11 @@ nis.request(:post, '/account/unlock',
58
53
  ```
59
54
 
60
55
 
56
+ ## Documentation
57
+
58
+ Available at [rubydoc.info](http://www.rubydoc.info/gems/nis-ruby).
59
+
60
+
61
61
  ## Commandline
62
62
 
63
63
  ```bash
data/lib/nis.rb CHANGED
@@ -1,16 +1,16 @@
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"
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
8
 
9
9
  # API Ruby Wrapper for NEM Infrastructure Server
10
10
  class Nis
11
11
  extend Forwardable
12
12
 
13
- def_delegators :@client, :request
13
+ def_delegators :@client, :request, :request!
14
14
 
15
15
  # @param [hash] options HTTP Client connection information
16
16
  # @option options [Symbol] :url URL
data/lib/nis/client.rb CHANGED
@@ -29,11 +29,22 @@ class Nis::Client
29
29
  # @param [Hash] params API Parameters
30
30
  # @return [Hash] Hash converted API Response
31
31
  def request(method, path, params = nil, &block)
32
+ params.reject! { |_, value| value.nil? } unless params.nil?
32
33
  body = connection.send(method, path, params).body
33
34
  hash = parse_body(body) unless body.size == 0
34
35
  block_given? ? yield(hash) : hash
35
36
  end
36
37
 
38
+ # @param [Symbol] method HTTP Method(GET or POST)
39
+ # @param [String] path API Path
40
+ # @param [Hash] params API Parameters
41
+ # @return [Hash] Hash converted API Response
42
+ def request!(method, path, params = nil, &block)
43
+ hash = request(method, path, params)
44
+ raise Nis::Util.error_handling(hash) if hash.has_key?(:error)
45
+ block_given? ? yield(hash) : hash
46
+ end
47
+
37
48
  private
38
49
 
39
50
  def connection
@@ -65,7 +76,7 @@ class Nis::Client
65
76
 
66
77
  if url
67
78
  uri = URI(url)
68
- if uri.scheme == "http"
79
+ if uri.scheme == 'http'
69
80
  defaults[:scheme] = uri.scheme
70
81
  defaults[:host] = uri.host
71
82
  defaults[:port] = uri.port
data/lib/nis/endpoint.rb CHANGED
@@ -1,2 +1,2 @@
1
- Dir[File.expand_path('../endpoint/*.rb', __FILE__)].each{|f| require f}
2
- Dir[File.expand_path('../endpoint/**/*.rb', __FILE__)].each{|f| require f}
1
+ Dir[File.expand_path('../endpoint/*.rb', __FILE__)].each { |f| require f }
2
+ Dir[File.expand_path('../endpoint/**/*.rb', __FILE__)].each { |f| require f }
data/lib/nis/error.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  class Nis
2
2
  class Error < StandardError; end
3
+ class BadRequestError < StandardError; end
3
4
  end
data/lib/nis/struct.rb CHANGED
@@ -1 +1 @@
1
- Dir[File.expand_path('../struct/*.rb', __FILE__)].each{|f| require f}
1
+ Dir[File.expand_path('../struct/*.rb', __FILE__)].each { |f| require f }
data/lib/nis/unit.rb CHANGED
@@ -1 +1 @@
1
- Dir[File.expand_path('../unit/*.rb', __FILE__)].each{|f| require f}
1
+ Dir[File.expand_path('../unit/*.rb', __FILE__)].each { |f| require f }
@@ -2,7 +2,7 @@ module Nis::Unit
2
2
  # @attr [String] value
3
3
  # @attr [String] first_char
4
4
  class Address
5
- attr :value, :first_char
5
+ attr_accessor :value, :first_char
6
6
 
7
7
  def initialize(value)
8
8
  @value = value
@@ -1,8 +1,7 @@
1
1
  module Nis::Unit
2
2
  # @attr [String] value
3
- # @attr [String] value_in_nem
4
3
  class Balance
5
- attr :value
4
+ attr_accessor :value
6
5
 
7
6
  def initialize(value)
8
7
  @value = value.to_i
@@ -13,14 +12,17 @@ module Nis::Unit
13
12
  @value_in_nem ||= @value.to_f / 1_000_000
14
13
  end
15
14
 
15
+ # @return [String]
16
16
  def to_s
17
17
  @value.to_s
18
18
  end
19
19
 
20
+ # @return [Integer]
20
21
  def to_i
21
22
  @value
22
23
  end
23
24
 
25
+ # @return [Boolean]
24
26
  def ==(other)
25
27
  @value == other.value
26
28
  end
data/lib/nis/unit/code.rb CHANGED
@@ -2,20 +2,18 @@ module Nis::Unit
2
2
  # @attr [String] value
3
3
  # @attr [String] message
4
4
  class Code
5
- attr :value, :message
5
+ attr_accessor :value, :message
6
6
 
7
7
  def initialize(value)
8
8
  @value = value
9
9
  end
10
10
 
11
- def message
12
- @message
13
- end
14
-
11
+ # @return [String]
15
12
  def to_s
16
13
  @message
17
14
  end
18
15
 
16
+ # @return [Boolean]
19
17
  def ==(other)
20
18
  @value == other.value
21
19
  end
data/lib/nis/unit/hash.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Nis::Unit
2
2
  # @attr [String] value
3
3
  class Hash
4
- attr :value
4
+ attr_accessor :value
5
5
 
6
6
  def initialize(value)
7
7
  @value = value
@@ -12,10 +12,12 @@ module Nis::Unit
12
12
  !!(@value =~ /[0-9a-f]{64}/)
13
13
  end
14
14
 
15
+ # @return [String]
15
16
  def to_s
16
17
  @value
17
18
  end
18
19
 
20
+ # @return [Boolean]
19
21
  def ==(other)
20
22
  @value == other.value
21
23
  end
@@ -1,13 +1,13 @@
1
1
  module Nis::Unit
2
2
  # @attr [String] value
3
3
  class Status
4
- attr :value
4
+ attr_accessor :value
5
5
 
6
6
  def initialize(value)
7
7
  @value = value
8
8
  end
9
9
 
10
- %w[
10
+ %w(
11
11
  UNKNOWN
12
12
  LOCKED
13
13
  UNLOCKED
@@ -16,16 +16,18 @@ module Nis::Unit
16
16
  ACTIVE
17
17
  DEACTIVATING
18
18
  INACTIVE
19
- ].each do |status|
19
+ ).each do |status|
20
20
  define_method "#{status.downcase}?" do
21
21
  instance_variable_get(:@value) == status
22
22
  end
23
23
  end
24
24
 
25
+ # @return [String]
25
26
  def to_s
26
27
  @value
27
28
  end
28
29
 
30
+ # @return [Boolean]
29
31
  def ==(other)
30
32
  @value == other.value
31
33
  end
data/lib/nis/unit/type.rb CHANGED
@@ -2,20 +2,20 @@ module Nis::Unit
2
2
  # @attr [String] value
3
3
  # @attr [String] message
4
4
  class Type
5
- attr :value, :message
5
+ attr_accessor :value, :message
6
6
 
7
7
  def initialize(value)
8
8
  @value = value
9
9
  end
10
10
 
11
- def message
12
- @message
13
- end
11
+ attr_reader :message
14
12
 
13
+ # @return [String]
15
14
  def to_s
16
15
  @message
17
16
  end
18
17
 
18
+ # @return [Boolean]
19
19
  def ==(other)
20
20
  @value == other.value
21
21
  end
@@ -1,10 +1,10 @@
1
1
  module Nis::Unit
2
2
  # @attr [String] value
3
3
  class Version
4
- MAINNET = 1744830465
5
- TESTNET = -1744830463
4
+ MAINNET = 1_744_830_465
5
+ TESTNET = -1_744_830_463
6
6
 
7
- attr :value
7
+ attr_accessor :value
8
8
 
9
9
  def initialize(value)
10
10
  @value = value
@@ -20,12 +20,14 @@ module Nis::Unit
20
20
  @value == TESTNET
21
21
  end
22
22
 
23
+ # @return [String]
23
24
  def to_s
24
25
  testnet? ? 'testnet' :
25
26
  mainnet? ? 'mainnet' :
26
27
  'unexpected'
27
28
  end
28
29
 
30
+ # @return [Boolean]
29
31
  def ==(other)
30
32
  @value == other.value
31
33
  end
data/lib/nis/util.rb CHANGED
@@ -1 +1,11 @@
1
- Dir[File.expand_path('../util/*.rb', __FILE__)].each{|f| require f}
1
+ module Nis::Util
2
+ def self.error_handling(hash)
3
+ error_klass = case hash[:error]
4
+ when 'Bad Request' then Nis::BadRequestError
5
+ else Nis::Error
6
+ end
7
+ error_klass.new(hash[:message])
8
+ end
9
+ end
10
+
11
+ Dir[File.expand_path('../util/*.rb', __FILE__)].each { |f| require f }
data/lib/nis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Nis
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
data/nis.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/44uk/nis-ruby'
15
15
  spec.license = 'MIT'
16
16
 
17
+ spec.required_ruby_version = '>= 2.2'
17
18
  spec.metadata['yard.run'] = 'yri'
18
19
 
19
20
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nis-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Ieyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-01 00:00:00.000000000 Z
11
+ date: 2017-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="
187
187
  - !ruby/object:Gem::Version
188
- version: '0'
188
+ version: '2.2'
189
189
  required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - ">="