nis-ruby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adebde300e51f8f5c6fb4e8ab89b1576f1da53ce
4
- data.tar.gz: dba85ef747580684ac4033edd2f7176d60bc4c27
3
+ metadata.gz: 5b9bc79d0376d239e28cf6c5e8fc77e828e93f19
4
+ data.tar.gz: 0d0d828ae81680a4835070dbad7fec4dbd07a3e9
5
5
  SHA512:
6
- metadata.gz: 32f3f47e8e3a7a1469349289bb5c3d4c70380f3c22d4eb91b257affd5a1acb87ad131194c51062cf29082037c24e0d9fd8698adcfaef64052ed20ec16c5a363e
7
- data.tar.gz: fad93a592a019513e28d9cca729d481b3bd6c8e0d29fa0873e5647fcf12b93a47012e32304af6dcd5ce03d2f402eef07e4a04ac3f190273a2901565bc7f71774
6
+ metadata.gz: 45407f6af5215dedc762e96d5fad0b1a8704986a6515cc5d3d4e9f3568dc844b3b8f1ccc29175a617b025ab7f8c0f3907b2e6a37f36eb5761153858333c4c350
7
+ data.tar.gz: 349d2f09004e8035a438766cb3e48d8aef07dc3a100b9b07e1fdb12900f3fe6da8d23db0d32e986225a4384c80af063d47cb0956fd45c4ebe5d81e5a93699e69
data/README.md CHANGED
@@ -50,21 +50,46 @@ nis.request(:post, '/account/unlock',
50
50
  )
51
51
  # => Nothing
52
52
  # See http://bob.nem.ninja/docs/#locking-and-unlocking-accounts
53
- ```
54
-
55
53
 
56
- ## Documentation
57
-
58
- Available at [rubydoc.info](http://www.rubydoc.info/gems/nis-ruby).
54
+ t = {
55
+ amount: 10_000_000,
56
+ fee: 3_000_000,
57
+ recipient: 'TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS',
58
+ signer: 'a1aaca6c17a24252e674d155713cdf55996ad00175be4af02a20c67b59f9fe8a',
59
+ message: {
60
+ payload: '',
61
+ type: 1
62
+ },
63
+ type: 0x0101, # 257
64
+ timeStamp: (Time.now.to_i - 1_427_587_585),
65
+ deadline: (Time.now.to_i - 1_427_587_585) + 43_200,
66
+ version: -1_744_830_463 # testnet version 1
67
+ }
68
+ puts nis.request! :post, 'transaction/prepare-announce', {
69
+ transaction: t,
70
+ privateKey: '68e4f79f886927de698df4f857de2aada41ccca6617e56bb0d61623b35b08cc0'
71
+ }
72
+ # => {innerTransactionHash: {}, code: 1, type: 1, message: "SUCCESS", transactionHash: {data: "9da41fd6c6886740ae6a15c869df0470015d78103e5b216971aa09fdbcce9cde"}}
73
+ # See http://bob.nem.ninja/docs/#initiating-a-transfer-transaction
74
+ ```
59
75
 
60
76
 
61
77
  ## Commandline
62
78
 
63
79
  ```bash
64
- $ nis status # => {"code":6,"type":4,"message":"status"}
65
- $ nis heartbeat # => {"code":1,"type":2,"message":"ok"}
80
+ $ nis status
81
+ # => {"code":6,"type":4,"message":"status"}
82
+
83
+ $ nis heartbeat
84
+ # => {"code":1,"type":2,"message":"ok"}
85
+
66
86
  $ nis request get account/get --params=address:TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS
67
87
  # => [AccountMetaDataPair structure]
88
+
89
+ $ nis request get account/harvests --params=address:TALICELCD3XPH4FFI5STGGNSNSWPOTG5E4DS2TOS hash:81d52a7df4abba8bb1613bcc42b6b93cf3114524939035d88ae8e864cd2c34c8
90
+ # => [Array <HervestInfo structure>]
91
+
92
+
68
93
  ```
69
94
 
70
95
 
@@ -93,6 +118,11 @@ Nis.new(url: 'http://bigalice3.nem.ninja:7890')
93
118
  - Do more improvements.
94
119
 
95
120
 
121
+ ## Documentation
122
+
123
+ Available at [rubydoc.info](http://www.rubydoc.info/gems/nis-ruby).
124
+
125
+
96
126
  ## Contributing
97
127
 
98
128
  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.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/lib/nis/client.rb CHANGED
@@ -1,18 +1,19 @@
1
1
  require 'faraday'
2
+ require 'faraday_middleware'
2
3
  require 'json'
3
4
  require 'uri'
4
5
 
5
6
  # @attr [Hash] options connection options
6
7
  class Nis::Client
7
8
  DEFAULTS = {
8
- url: -> {ENV['NIS_URL']},
9
+ url: -> { ENV['NIS_URL'] },
9
10
  scheme: 'http',
10
11
  host: '127.0.0.1',
11
12
  port: 7890,
12
13
  timeout: 5
13
- }
14
+ }.freeze
14
15
 
15
- attr :options
16
+ attr_reader :options
16
17
 
17
18
  # @param [hash] options HTTP Client connection information
18
19
  # @option options [Symbol] :url URL
@@ -28,10 +29,11 @@ class Nis::Client
28
29
  # @param [String] path API Path
29
30
  # @param [Hash] params API Parameters
30
31
  # @return [Hash] Hash converted API Response
31
- def request(method, path, params = nil, &block)
32
- params.reject! { |_, value| value.nil? } unless params.nil?
33
- body = connection.send(method, path, params).body
34
- hash = parse_body(body) unless body.size == 0
32
+ def request(method, path, params = {})
33
+ params.reject! { |_, value| value.nil? } unless params.empty?
34
+ res = connection.send(method, path, params)
35
+ body = res.body
36
+ hash = parse_body(body) unless body.empty?
35
37
  block_given? ? yield(hash) : hash
36
38
  end
37
39
 
@@ -39,9 +41,10 @@ class Nis::Client
39
41
  # @param [String] path API Path
40
42
  # @param [Hash] params API Parameters
41
43
  # @return [Hash] Hash converted API Response
42
- def request!(method, path, params = nil, &block)
44
+ # @raise [Nis::Error] NIS error
45
+ def request!(method, path, params = {})
43
46
  hash = request(method, path, params)
44
- raise Nis::Util.error_handling(hash) if hash.has_key?(:error)
47
+ raise Nis::Util.error_handling(hash) if hash.key?(:error)
45
48
  block_given? ? yield(hash) : hash
46
49
  end
47
50
 
@@ -50,11 +53,11 @@ class Nis::Client
50
53
  def connection
51
54
  @connection ||= Faraday.new(url: @options[:url]) do |f|
52
55
  f.options[:timeout] = @options[:timeout]
53
- f.request :url_encoded
54
- f.adapter Faraday.default_adapter
56
+ f.request :json
55
57
  # f.response :logger do | logger |
56
58
  # logger.filter(/(privateKey=)(\w+)/,'\1[FILTERED]')
57
59
  # end
60
+ f.adapter Faraday.default_adapter
58
61
  end
59
62
  end
60
63
 
@@ -69,7 +72,7 @@ class Nis::Client
69
72
  defaults[:url] = defaults[:url].call if defaults[:url].respond_to?(:call)
70
73
 
71
74
  defaults.keys.each do |key|
72
- options[key] = options[key.to_s] if options.has_key?(key.to_s)
75
+ options[key] = options[key.to_s] if options.key?(key.to_s)
73
76
  end
74
77
 
75
78
  url = options[:url] || defaults[:url]
data/lib/nis/error.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  class Nis
2
2
  class Error < StandardError; end
3
- class BadRequestError < StandardError; end
3
+ class BadRequestError < Error; end
4
+ class InternalServerError < Error; end
4
5
  end
@@ -1,12 +1,14 @@
1
1
  class Nis::Struct
2
+ # @attr [Integer] type
3
+ # @attr [String] code
4
+ # @attr [String] message
2
5
  # @see http://bob.nem.ninja/docs/#nemRequestResult
3
6
  class NemRequestResult
4
7
  include Nis::Util::Assignable
5
-
6
8
  attr_accessor :type, :code, :message
7
9
 
8
- def self.build(json)
9
- new(json)
10
+ def self.build(attrs)
11
+ new(attrs)
10
12
  end
11
13
 
12
14
  # @return [Boolean]
@@ -24,6 +26,7 @@ class Nis::Struct
24
26
  @type == 4
25
27
  end
26
28
 
29
+ # @return [String]
27
30
  def to_s
28
31
  @message
29
32
  end
@@ -1,8 +1,7 @@
1
1
  module Nis::Unit
2
2
  # @attr [String] value
3
- # @attr [String] first_char
4
3
  class Address
5
- attr_accessor :value, :first_char
4
+ attr_accessor :value
6
5
 
7
6
  def initialize(value)
8
7
  @value = value
@@ -24,10 +23,12 @@ module Nis::Unit
24
23
  @first_char == 'T'
25
24
  end
26
25
 
26
+ # @return [String]
27
27
  def to_s
28
28
  @value
29
29
  end
30
30
 
31
+ # @return [Boolean]
31
32
  def ==(other)
32
33
  @value == other.value
33
34
  end
@@ -1,6 +1,8 @@
1
1
  module Nis::Unit
2
2
  # @attr [String] value
3
3
  class Balance
4
+ include Comparable
5
+
4
6
  attr_accessor :value
5
7
 
6
8
  def initialize(value)
@@ -9,7 +11,7 @@ module Nis::Unit
9
11
 
10
12
  # @return [Float]
11
13
  def in_nem
12
- @value_in_nem ||= @value.to_f / 1_000_000
14
+ @value.to_f / 1_000_000
13
15
  end
14
16
 
15
17
  # @return [String]
@@ -23,8 +25,16 @@ module Nis::Unit
23
25
  end
24
26
 
25
27
  # @return [Boolean]
26
- def ==(other)
27
- @value == other.value
28
+ def <=>(other)
29
+ @value <=> other.to_i
30
+ end
31
+
32
+ %w(+ -).each do |op|
33
+ define_method op do |other|
34
+ a = instance_variable_get('@value')
35
+ b = other.to_i
36
+ self.class.new(a.send(op, b))
37
+ end
28
38
  end
29
39
  end
30
40
  end
data/lib/nis/unit/type.rb CHANGED
@@ -8,8 +8,6 @@ module Nis::Unit
8
8
  @value = value
9
9
  end
10
10
 
11
- attr_reader :message
12
-
13
11
  # @return [String]
14
12
  def to_s
15
13
  @message
data/lib/nis/util.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Nis::Util
2
2
  def self.error_handling(hash)
3
3
  error_klass = case hash[:error]
4
- when 'Bad Request' then Nis::BadRequestError
5
- else Nis::Error
6
- end
4
+ when 'Bad Request' then Nis::BadRequestError
5
+ when 'Internal Server Error' then Nis::InternalServerError
6
+ else Nis::Error
7
+ end
7
8
  error_klass.new(hash[:message])
8
9
  end
9
10
  end
@@ -16,7 +16,7 @@ module Nis::Util
16
16
  # @return [Hash] Attribute and value pairs
17
17
  def to_hash
18
18
  instance_variables.each_with_object({}) do |var, hash|
19
- hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
19
+ hash[var.to_s.delete('@').to_sym] = instance_variable_get(var)
20
20
  end
21
21
  end
22
22
 
data/lib/nis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Nis
2
- VERSION = '0.0.4'.freeze
2
+ VERSION = '0.0.5'.freeze
3
3
  end
data/nis.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'nis/version'
@@ -9,15 +10,15 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ['Yoshiyuki Ieyama']
10
11
  spec.email = ['yukku0423@gmail.com']
11
12
 
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}
13
+ spec.summary = 'Ruby client library for the NEM Infrastructure Server API'
14
+ spec.description = 'Ruby client library for the NEM Infrastructure Server API'
14
15
  spec.homepage = 'https://github.com/44uk/nis-ruby'
15
16
  spec.license = 'MIT'
16
17
 
17
18
  spec.required_ruby_version = '>= 2.2'
18
19
  spec.metadata['yard.run'] = 'yri'
19
20
 
20
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
22
  f.match(%r{^(test|spec|features)/})
22
23
  end
23
24
  spec.bindir = 'bin'
@@ -33,5 +34,6 @@ Gem::Specification.new do |spec|
33
34
  spec.add_development_dependency 'pry', '~> 0.10'
34
35
 
35
36
  spec.add_dependency 'faraday', '~> 0.11'
37
+ spec.add_dependency 'faraday_middleware', '~> 0.11'
36
38
  spec.add_dependency 'thor', '~> 0.19'
37
39
  end
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.4
4
+ version: 0.0.5
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-04 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.11'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday_middleware
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.11'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.11'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: thor
127
141
  requirement: !ruby/object:Gem::Requirement