yetis_node 0.0.2 → 0.1.1

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: 41ed3c76fab85cda7f767da3c395a93cb7ba874f
4
- data.tar.gz: b5b20ee35b9aad8fa92bd5966597b45baf63fd2e
3
+ metadata.gz: 73cc4c5a4c2931c35f55b526115b79619ccc596d
4
+ data.tar.gz: ba9ebf51cc5f23ad6f632c3339bf6cc83c281377
5
5
  SHA512:
6
- metadata.gz: c7b95d2ca78890e4011a1c6e9af8ee17734b84c410a6393dcfcc8ea8294c94d69145501a064a22c7c4970dab5ebc6fc91abe95d7de3bbefb7afa9f0b978ededa
7
- data.tar.gz: f8169c46cb7f6a0ac827ed27d1422ee0d8a363f4e308a73c2998fc3fdd24aaf1c2841695ec3727b9bdd4fa3a7585184ed2a8bb1cfeed78504450f4c120e17c8f
6
+ metadata.gz: 1dc1ebfe06f54f42d22eac5379bf2e05bdbc29ac23856658f53d7642f1aa4cdf1aab82fb6998ea87947e33b6b36d4e800588741104647e16382ed878608cc290
7
+ data.tar.gz: 294dd20cfbebec68d4b28ab19693fb82589ca97104788b5cd6ba881c7626a0c065a5859aa75049d39607b6f43a283ae7e1d61e0a98c39f92f960dc8ae34b6096
@@ -2,23 +2,23 @@
2
2
 
3
3
  require "xmlrpc/client"
4
4
 
5
- if(ARGV.empty?)
6
- puts "usage: #{$0} host:port"
7
- exit
5
+ if (ARGV.empty?)
6
+ puts "usage: #{$0} host:port"
7
+ exit
8
8
  end
9
9
 
10
- (host,port) = ARGV[0].split(':')
10
+ (host, port) = ARGV[0].split(':')
11
11
  $s = XMLRPC::Client.new(host, "/", port)
12
12
 
13
13
  def f(*args)
14
- puts args.take(args.size-1).join(' ')
15
- r = $s.call("di","yeti", *args)
16
- return if !r.kind_of?(Array)
17
- r.each do |e|
18
- if e.kind_of?(Array)
19
- f(*args.first(args.size - 1), e[0],'_list')
20
- end
21
- end
14
+ puts args.take(args.size-1).join(' ')
15
+ r = $s.call("di", "yeti", *args)
16
+ return if !r.kind_of?(Array)
17
+ r.each do |e|
18
+ if e.kind_of?(Array)
19
+ f(*args.first(args.size - 1), e[0], '_list')
20
+ end
21
+ end
22
22
  end
23
23
 
24
24
  begin
@@ -1,9 +1,12 @@
1
- require "yetis_node/version"
1
+ require 'yetis_node/version'
2
2
  require 'yetis_node/cmd/base'
3
3
  require 'yetis_node/cmd/show'
4
4
  require 'yetis_node/cmd/set'
5
5
  require 'yetis_node/cmd/request'
6
6
  require 'yetis_node/error'
7
+ require 'yetis_node/base_transport'
8
+ require 'yetis_node/xml_rpc_transport'
9
+ require 'yetis_node/json_rpc_transport'
7
10
  require 'yetis_node/client'
8
11
 
9
12
  module YetisNode
@@ -0,0 +1,12 @@
1
+ module YetisNode
2
+ class BaseTransport
3
+ attr_reader :uri, :options
4
+ DEFAULT_TIMEOUT = 5
5
+
6
+ def initialize(uri, options = {})
7
+ @uri = uri
8
+ @options = options
9
+ end
10
+
11
+ end
12
+ end
@@ -1,4 +1,4 @@
1
- require 'xmlrpc/client'
1
+ require 'forwardable'
2
2
  module YetisNode
3
3
 
4
4
 
@@ -7,13 +7,16 @@ module YetisNode
7
7
  # node.calls_count
8
8
  # => "10"
9
9
  class Client
10
- attr_reader :uri
10
+ extend Forwardable
11
11
 
12
- DEFAULT_TIMEOUT = 10
12
+ attr_reader :uri, :options, :transport
13
+
14
+ def_delegators :@transport, :rpc_send
13
15
 
14
16
  def initialize(uri, options = {})
15
17
  @uri = uri
16
18
  @options = options
19
+ select_transport!
17
20
  end
18
21
 
19
22
  include Cmd::Base
@@ -21,15 +24,22 @@ module YetisNode
21
24
  include Cmd::Request
22
25
  include Cmd::Set
23
26
 
24
-
25
27
  protected :invoke_show, :invoke_request, :invoke_set
26
28
 
27
- protected
29
+ private
28
30
 
29
- def xml_rpc
30
- @xml_rpc ||= XMLRPC::Client.new2(uri, @options.fetch(:proxy, nil), @options.fetch(:timeout, DEFAULT_TIMEOUT))
31
- end
31
+ def select_transport!
32
+ transport_klass = case @options.fetch(:transport, :xml_rpc)
33
+ when :xml_rpc
34
+ XmlRpcTransport
35
+ when :json_rpc
36
+ JsonRpcTransport
37
+ else
38
+ raise Error.new('invalid transport')
39
+ end
32
40
 
41
+ @transport = transport_klass.new(@uri, @options)
42
+ end
33
43
 
34
44
  end
35
45
  end
@@ -2,19 +2,10 @@ module YetisNode
2
2
  module Cmd
3
3
  module Base
4
4
 
5
-
6
5
  def invoke(method, prefix, args = [])
7
- rpc_send(*([prefix] + method.to_s.split("_") + args.compact))
8
- end
9
-
10
- def rpc_send(*args)
11
- begin
12
- xml_rpc.call_async('di', 'yeti', *args)
13
- rescue XMLRPC::FaultException => e
14
- raise Error.new(e.message)
15
- end
6
+ rpc_send(*([prefix] + method.to_s.split('_') + args.compact))
16
7
  end
17
8
 
18
9
  end
19
10
  end
20
- end
11
+ end
@@ -76,7 +76,7 @@ module YetisNode
76
76
 
77
77
  def resource_state(type_id, id = nil)
78
78
  invoke_show([type_id, id || :all])
79
- end
79
+ end
80
80
 
81
81
  def invoke_show(args = [])
82
82
  invoke(caller_locations(1, 1)[0].label, 'show', args)
@@ -1,4 +1,11 @@
1
1
  module YetisNode
2
2
  class Error < RuntimeError
3
- end
3
+ attr_reader :original
4
+
5
+ def initialize(msg, original=$!)
6
+ super(msg)
7
+ @original = original
8
+ end
9
+
10
+ end
4
11
  end
@@ -0,0 +1,23 @@
1
+ require 'jrpc'
2
+ module YetisNode
3
+ class JsonRpcTransport < BaseTransport
4
+
5
+ def rpc_send(*args)
6
+ begin
7
+ json_rpc.connect if json_rpc.closed?
8
+ result = json_rpc.invoke_request(*args)
9
+ json_rpc.close
10
+ result
11
+ rescue ::JRPC::Error => e
12
+ raise Error.new("JSON RPC Error: #{"(#{e.code}) " if e.respond_to?(:code)}#{e.message}")
13
+ end
14
+ end
15
+
16
+ def json_rpc
17
+ @json_rpc ||= ::JRPC::TcpClient.new uri,
18
+ namespace: 'yeti.',
19
+ timeout: options.fetch(:timeout, BaseTransport::DEFAULT_TIMEOUT)
20
+ end
21
+
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module YetisNode
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,17 @@
1
+ require 'xmlrpc/client'
2
+ module YetisNode
3
+ class XmlRpcTransport < BaseTransport
4
+
5
+
6
+ def rpc_send(*args)
7
+ xml_rpc.call_async('di', 'yeti', *args)
8
+ rescue XMLRPC::FaultException => e
9
+ raise Error.new(e.message)
10
+ end
11
+
12
+ def xml_rpc
13
+ @xml_rpc ||= XMLRPC::Client.new2 uri, options.fetch(:timeout, BaseTransport::DEFAULT_TIMEOUT)
14
+ end
15
+
16
+ end
17
+ end
@@ -4,20 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'yetis_node/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "yetis_node"
7
+ spec.name = 'yetis_node'
8
8
  spec.version = YetisNode::VERSION
9
- spec.authors = ["Igor Fedoronchuk"]
10
- spec.email = ["igor.f@didww.com"]
9
+ spec.authors = ['Igor Fedoronchuk']
10
+ spec.email = ['igor.f@didww.com']
11
11
  spec.summary = %q{XMLRPC client for YETI switch.}
12
12
  spec.description = %q{XMLRPC client for YETI switch. http://yeti-switch.org }
13
- spec.homepage = "http://yeti-switch.org"
14
- spec.license = "MIT"
13
+ spec.homepage = 'http://yeti-switch.org'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_runtime_dependency 'jrpc', '~> 0.4', '>= 0.4.6'
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
23
24
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yetis_node
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Fedoronchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-01 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jrpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.6
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.4'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.6
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: bundler
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -53,13 +73,16 @@ files:
53
73
  - Rakefile
54
74
  - bin/yetis_cmd_list.rb
55
75
  - lib/yetis_node.rb
76
+ - lib/yetis_node/base_transport.rb
56
77
  - lib/yetis_node/client.rb
57
78
  - lib/yetis_node/cmd/base.rb
58
79
  - lib/yetis_node/cmd/request.rb
59
80
  - lib/yetis_node/cmd/set.rb
60
81
  - lib/yetis_node/cmd/show.rb
61
82
  - lib/yetis_node/error.rb
83
+ - lib/yetis_node/json_rpc_transport.rb
62
84
  - lib/yetis_node/version.rb
85
+ - lib/yetis_node/xml_rpc_transport.rb
63
86
  - yetis_node.gemspec
64
87
  homepage: http://yeti-switch.org
65
88
  licenses:
@@ -81,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
104
  version: '0'
82
105
  requirements: []
83
106
  rubyforge_project:
84
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.5.0
85
108
  signing_key:
86
109
  specification_version: 4
87
110
  summary: XMLRPC client for YETI switch.