server-registry-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +12 -0
- data/bin/srctool +8 -0
- data/lib/server-registry-client/cli.rb +94 -0
- data/lib/server-registry-client/client.rb +37 -0
- data/lib/server-registry-client/errors.rb +4 -0
- data/lib/server-registry-client/models/server.rb +58 -0
- data/lib/server-registry-client/models.rb +3 -0
- data/lib/server-registry-client/server_processor/base.rb +77 -0
- data/lib/server-registry-client/server_processor/v1.rb +98 -0
- data/lib/server-registry-client/server_processor.rb +6 -0
- data/lib/server-registry-client/version.rb +3 -0
- data/lib/server-registry-client.rb +5 -0
- data/server-registry-client.gemspec +28 -0
- data/spec/client_spec.rb +16 -0
- data/spec/server_spec.rb +96 -0
- data/spec/spec_helper.rb +1 -0
- metadata +136 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michael James
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Server::Registry::Client
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'server-registry-client'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install server-registry-client
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:test) do |t|
|
6
|
+
t.rspec_opts = "--color --format nested --backtrace"
|
7
|
+
end
|
8
|
+
|
9
|
+
# desc "Run all tests"
|
10
|
+
# task :test do |t|
|
11
|
+
# sh %{ ruby -S rspec --color --format nested --backtrace }
|
12
|
+
# end
|
data/bin/srctool
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
|
4
|
+
module ServerRegistryClient
|
5
|
+
class CLI < ::Thor
|
6
|
+
class_option :server, :type => :string, :banner => "URL of the server registry"
|
7
|
+
|
8
|
+
option :hostname, :banner => "server hostname"
|
9
|
+
option :ip_address, :banner => "server IP address"
|
10
|
+
option :port, :type => :numeric, :banner => "server port"
|
11
|
+
option :categories, :required => true, :banner => "comma-separated string of category names"
|
12
|
+
desc "add_server", "add server to registry server"
|
13
|
+
def add_server
|
14
|
+
require_server_option
|
15
|
+
require_server_hostname_or_ip_address
|
16
|
+
|
17
|
+
server = construct_server_from_options
|
18
|
+
|
19
|
+
categories = parse_csv(options[:categories])
|
20
|
+
|
21
|
+
client = construct_client
|
22
|
+
client.add_server_to_categories(server, categories)
|
23
|
+
end
|
24
|
+
|
25
|
+
option :hostname, :banner => "server hostname"
|
26
|
+
option :ip_address, :banner => "server IP address"
|
27
|
+
option :port, :type => :numeric, :banner => "server port"
|
28
|
+
option :categories, :required => true, :banner => "comma-separated string of category names"
|
29
|
+
desc "remove_server_from_category", "remove server from categories on registry server"
|
30
|
+
def remove_server_from_category
|
31
|
+
require_server_option
|
32
|
+
require_server_hostname_or_ip_address
|
33
|
+
|
34
|
+
server = construct_server_from_options
|
35
|
+
|
36
|
+
categories = parse_csv(options[:categories])
|
37
|
+
|
38
|
+
client = construct_client
|
39
|
+
categories.each do |category_name|
|
40
|
+
client.remove_server_from_category(server, category_name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
option :hostname, :banner => "server hostname"
|
45
|
+
option :ip_address, :banner => "server IP address"
|
46
|
+
option :port, :type => :numeric, :banner => "server port"
|
47
|
+
desc "remove_server", "remove all entries with the specified server attributes"
|
48
|
+
def remove_server
|
49
|
+
require_server_option
|
50
|
+
require_server_hostname_or_ip_address
|
51
|
+
|
52
|
+
server = construct_server_from_options
|
53
|
+
|
54
|
+
client = construct_client
|
55
|
+
client.remove_servers_like(server)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def construct_client
|
61
|
+
return ServerRegistryClient::Client.new(options[:server])
|
62
|
+
end
|
63
|
+
|
64
|
+
def construct_server_from_options
|
65
|
+
server = ServerRegistryClient::Server.new
|
66
|
+
server.hostname = options[:hostname]
|
67
|
+
server.ip_address = options[:ip_address]
|
68
|
+
server.port = (options[:port].to_i > 0 ? options[:port].to_i : nil)
|
69
|
+
|
70
|
+
return server
|
71
|
+
end
|
72
|
+
|
73
|
+
def parse_csv(value)
|
74
|
+
categories = []
|
75
|
+
|
76
|
+
categories << value.to_s.split(",")
|
77
|
+
categories.flatten!
|
78
|
+
|
79
|
+
return categories
|
80
|
+
end
|
81
|
+
|
82
|
+
def require_server_hostname_or_ip_address
|
83
|
+
if options[:hostname].blank? && options[:ip_address].blank?
|
84
|
+
raise ::Thor::RequiredArgumentMissingError, "--hostname or --ip_address option must not be blank"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def require_server_option
|
89
|
+
if options[:server].blank?
|
90
|
+
raise ::Thor::RequiredArgumentMissingError, "--server options must not be blank"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ServerRegistryClient
|
2
|
+
class Client
|
3
|
+
attr_accessor :server_processor
|
4
|
+
|
5
|
+
def initialize(server_registry_url, version_number=1)
|
6
|
+
use_version(server_registry_url, version_number)
|
7
|
+
end
|
8
|
+
|
9
|
+
def servers_in_category(category)
|
10
|
+
return server_processor.servers_in_category(category)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_server_to_categories(server, category_names)
|
14
|
+
return server_processor.add_server_to_categories(server, category_names)
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove_server_from_category(server, category_name)
|
18
|
+
return server_processor.remove_server_from_category(server, category_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def remove_servers_like(server)
|
22
|
+
return server_processor.remove_servers_like(server)
|
23
|
+
end
|
24
|
+
|
25
|
+
def server_registry_url
|
26
|
+
return server_processor.server_registry_url_root
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def use_version(server_registry_url, version_number)
|
32
|
+
raise "version number must be a number greater than zero" if version_number.to_i <= 0
|
33
|
+
|
34
|
+
self.server_processor = ServerRegistryClient::ServerProcessor.const_get("V#{version_number}".to_sym).new(server_registry_url)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
|
3
|
+
module ServerRegistryClient
|
4
|
+
class Server
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :hostname
|
7
|
+
attr_accessor :ip_address
|
8
|
+
attr_accessor :port
|
9
|
+
|
10
|
+
def initialize(id=nil, hostname=nil, ip_address=nil, port=nil)
|
11
|
+
@id = id
|
12
|
+
@hostname = hostname
|
13
|
+
@ip_address = ip_address
|
14
|
+
@port = port
|
15
|
+
end
|
16
|
+
|
17
|
+
def matches?(server)
|
18
|
+
result = false
|
19
|
+
|
20
|
+
we_have_hostname = !self.hostname.blank?
|
21
|
+
we_have_ip_address = !self.ip_address.blank?
|
22
|
+
we_have_port = !self.port.blank?
|
23
|
+
|
24
|
+
they_have_hostname = !server.hostname.blank?
|
25
|
+
they_have_ip_address = !server.ip_address.blank?
|
26
|
+
they_have_port = !server.port.blank?
|
27
|
+
|
28
|
+
ip_address_matches = (we_have_ip_address && they_have_ip_address && self.ip_address == server.ip_address)
|
29
|
+
hostname_matches = (we_have_hostname && they_have_hostname && self.hostname == server.hostname)
|
30
|
+
|
31
|
+
port_matches = if we_have_port && they_have_port && self.port == server.port && (ip_address_matches || hostname_matches)
|
32
|
+
true
|
33
|
+
elsif they_have_port && !we_have_port && (ip_address_matches || hostname_matches)
|
34
|
+
true
|
35
|
+
elsif !they_have_port && !we_have_port && (ip_address_matches || hostname_matches)
|
36
|
+
true
|
37
|
+
elsif we_have_port && they_have_port && self.port == server.port && (!we_have_hostname && they_have_hostname)
|
38
|
+
true
|
39
|
+
else
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
if self.id == server.id
|
44
|
+
result = true
|
45
|
+
else
|
46
|
+
if ip_address_matches
|
47
|
+
result = (true && port_matches)
|
48
|
+
elsif hostname_matches
|
49
|
+
result = (true && port_matches)
|
50
|
+
else
|
51
|
+
result = port_matches
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
return result
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'uri'
|
3
|
+
require 'yajl'
|
4
|
+
|
5
|
+
module ServerRegistryClient
|
6
|
+
module ServerProcessor
|
7
|
+
class Base
|
8
|
+
attr_reader :server_registry_url_root
|
9
|
+
attr_reader :last_response
|
10
|
+
attr_reader :api_version
|
11
|
+
|
12
|
+
def initialize(server_registry_url_root)
|
13
|
+
@server_registry_url_root = server_registry_url_root
|
14
|
+
@hydra = ::Typhoeus::Hydra.new
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
attr_reader :hydra
|
20
|
+
attr_writer :api_version
|
21
|
+
|
22
|
+
def default_typhoeus_options
|
23
|
+
{
|
24
|
+
:timeout => 5000
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def make_web_request(api_fragment, options={}, &block)
|
29
|
+
typhoeus_options = default_typhoeus_options.merge(options)
|
30
|
+
|
31
|
+
request = ::Typhoeus::Request.new(URI.join(self.server_registry_url_root, api_fragment).to_s, typhoeus_options)
|
32
|
+
response_body = nil
|
33
|
+
|
34
|
+
request.on_complete do |response|
|
35
|
+
if response.timed_out?
|
36
|
+
raise ServerRegistryClient::ServerCommunicationError, "Request to #{request.url} timed out"
|
37
|
+
elsif response.success?
|
38
|
+
if response.headers["Content-Type"].include?("application/json")
|
39
|
+
response_body = parse_json(response.body)
|
40
|
+
else
|
41
|
+
response_body = response.body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
self.hydra.queue(request)
|
47
|
+
self.hydra.run
|
48
|
+
|
49
|
+
@last_response = request.response
|
50
|
+
|
51
|
+
unless block.nil?
|
52
|
+
block.call(self.last_response, response_body)
|
53
|
+
end
|
54
|
+
|
55
|
+
return response_body
|
56
|
+
end
|
57
|
+
|
58
|
+
def print_typhoeus_response(response)
|
59
|
+
return <<-EOF
|
60
|
+
#{response.code} #{response.status_message}
|
61
|
+
#{response.headers}
|
62
|
+
|
63
|
+
#{response.body}
|
64
|
+
EOF
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_json(data)
|
68
|
+
json = Yajl::Parser.parse(data, :symbolize_keys => true)
|
69
|
+
return json
|
70
|
+
end
|
71
|
+
|
72
|
+
def jsonify(data)
|
73
|
+
return Yajl::Encoder.encode(data, :pretty => true)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module ServerRegistryClient
|
2
|
+
module ServerProcessor
|
3
|
+
class V1 < Base
|
4
|
+
def initialize(server_registry_url)
|
5
|
+
super
|
6
|
+
self.api_version = "v1"
|
7
|
+
end
|
8
|
+
|
9
|
+
def servers_in_category(category)
|
10
|
+
response_json = make_web_request("/api/#{api_version}/category/#{category}")
|
11
|
+
|
12
|
+
if response_json.nil? || last_response.response_code == 404
|
13
|
+
return []
|
14
|
+
else
|
15
|
+
return response_json[:servers].map do |server_json|
|
16
|
+
server_from_json(server_json)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_all_servers
|
22
|
+
response_json = make_web_request("/api/#{api_version}/servers")
|
23
|
+
|
24
|
+
return response_json.map do |server_json|
|
25
|
+
server_from_json(server_json)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_server_to_categories(server, category_names)
|
30
|
+
server_json_hash = server_to_json_hash(server)
|
31
|
+
server_json_hash[:categories] = (category_names.kind_of?(Array) ? category_names : [category_names])
|
32
|
+
|
33
|
+
server_json = jsonify(server_json_hash)
|
34
|
+
|
35
|
+
make_web_request("/api/#{api_version}/servers", {
|
36
|
+
:method => :post,
|
37
|
+
:body => server_json
|
38
|
+
}) do |response, response_body|
|
39
|
+
unless response.success?
|
40
|
+
raise ServerRegistryClient::ServerCommunicationError, "Server responded: #{print_typhoeus_response(response)}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_server_from_category(server, category_name)
|
46
|
+
server_name = server.hostname || server.ip_address
|
47
|
+
server_removed = true
|
48
|
+
|
49
|
+
make_web_request("/api/#{api_version}/category/#{category_name}/server/#{server_name}", {
|
50
|
+
:method => :delete
|
51
|
+
}) do |response, response_body|
|
52
|
+
unless response.success?
|
53
|
+
server_removed = false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
return server_removed
|
58
|
+
end
|
59
|
+
|
60
|
+
def remove_servers_like(server_to_match)
|
61
|
+
all_servers = get_all_servers
|
62
|
+
|
63
|
+
servers_to_delete = all_servers.find_all do |server|
|
64
|
+
server_to_match.matches?(server)
|
65
|
+
end
|
66
|
+
|
67
|
+
servers_to_delete.each do |server|
|
68
|
+
make_web_request("/api/#{api_version}/server/#{server.id}", {
|
69
|
+
:method => :delete
|
70
|
+
})
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def server_from_json(server_json)
|
77
|
+
server = ::ServerRegistryClient::Server.new
|
78
|
+
|
79
|
+
server.id = server_json[:id]
|
80
|
+
server.hostname = server_json[:hostname]
|
81
|
+
server.ip_address = server_json[:ip_address]
|
82
|
+
server.port = server_json[:port]
|
83
|
+
|
84
|
+
return server
|
85
|
+
end
|
86
|
+
|
87
|
+
def server_to_json_hash(server)
|
88
|
+
json = {}
|
89
|
+
|
90
|
+
json[:hostname] = server.hostname
|
91
|
+
json[:ip_address] = server.ip_address
|
92
|
+
json[:port] = server.port
|
93
|
+
|
94
|
+
return json
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/server-registry-client/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michael James"]
|
6
|
+
gem.email = ["umjames29@gmail.com"]
|
7
|
+
gem.description = %q{Client library and command-line tools for interacting with the server registry (https://github.com/umjames/server-registry)}
|
8
|
+
gem.summary = %q{Client library and command-line tools for interacting with the server registry (https://github.com/umjames/server-registry)}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\) - [".gitignore"]
|
12
|
+
gem.executables = %w(srctool) #gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "server-registry-client"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ServerRegistryClient::VERSION
|
17
|
+
|
18
|
+
gem.required_ruby_version = ">= 1.9.1"
|
19
|
+
gem.required_rubygems_version = ">= 1.8.5"
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
|
24
|
+
gem.add_runtime_dependency 'typhoeus', '0.5.3'
|
25
|
+
gem.add_runtime_dependency 'yajl-ruby', '~> 1.1'
|
26
|
+
gem.add_runtime_dependency 'thor', '~> 0.16'
|
27
|
+
gem.add_runtime_dependency 'activesupport', '~> 3.2'
|
28
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe ServerRegistryClient::Client do
|
4
|
+
it "should be able to create a client with a valid URL" do
|
5
|
+
expect do
|
6
|
+
client = ServerRegistryClient::Client.new("http://www.apple.com")
|
7
|
+
end.to_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should recognize localhost URLs" do
|
11
|
+
expect do
|
12
|
+
client = ServerRegistryClient::Client.new("http://localhost:3000/api/")
|
13
|
+
end.to_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/spec/server_spec.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe ServerRegistryClient::Server do
|
4
|
+
context "matching algorithm" do
|
5
|
+
before(:each) do
|
6
|
+
@test_server = ServerRegistryClient::Server.new
|
7
|
+
@test_server.id = 1
|
8
|
+
@test_server.hostname = "localhost"
|
9
|
+
@test_server.ip_address = "127.0.0.1"
|
10
|
+
@test_server.port = 3000
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should match if ids are the same" do
|
14
|
+
server = ServerRegistryClient::Server.new
|
15
|
+
server.id = 1
|
16
|
+
server.hostname = "www.example.com"
|
17
|
+
server.ip_address = "1.2.3.4"
|
18
|
+
server.port = @test_server.port + 1
|
19
|
+
|
20
|
+
@test_server.matches?(server).should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not match if the ports are different" do
|
24
|
+
server = ServerRegistryClient::Server.new
|
25
|
+
server.port = @test_server.port + 1
|
26
|
+
|
27
|
+
@test_server.matches?(server).should_not be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not match less specific server attributes" do
|
31
|
+
server = ServerRegistryClient::Server.new
|
32
|
+
server.hostname = @test_server.hostname
|
33
|
+
|
34
|
+
@test_server.matches?(server).should_not be_true
|
35
|
+
|
36
|
+
server.hostname = nil
|
37
|
+
server.ip_address = @test_server.ip_address
|
38
|
+
|
39
|
+
@test_server.matches?(server).should_not be_true
|
40
|
+
|
41
|
+
server.hostname = @test_server.hostname
|
42
|
+
|
43
|
+
@test_server.matches?(server).should_not be_true
|
44
|
+
|
45
|
+
server.port = @test_server.port
|
46
|
+
|
47
|
+
@test_server.matches?(server).should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should match more specific server attributes" do
|
51
|
+
server = ServerRegistryClient::Server.new
|
52
|
+
server.hostname = @test_server.hostname
|
53
|
+
|
54
|
+
server.matches?(@test_server).should be_true
|
55
|
+
@test_server.matches?(server).should_not be_true
|
56
|
+
|
57
|
+
server.hostname = nil
|
58
|
+
server.ip_address = @test_server.ip_address
|
59
|
+
|
60
|
+
server.matches?(@test_server).should be_true
|
61
|
+
@test_server.matches?(server).should_not be_true
|
62
|
+
|
63
|
+
server.hostname = nil
|
64
|
+
server.ip_address = nil
|
65
|
+
server.port = @test_server.port
|
66
|
+
|
67
|
+
server.matches?(@test_server).should be_true
|
68
|
+
@test_server.matches?(server).should_not be_true
|
69
|
+
|
70
|
+
server.hostname = @test_server.hostname
|
71
|
+
server.ip_address = @test_server.ip_address
|
72
|
+
|
73
|
+
@test_server.matches?(server).should be_true
|
74
|
+
server.matches?(@test_server).should be_true
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be able to find the correct servers" do
|
78
|
+
servers = []
|
79
|
+
|
80
|
+
server_to_match = ServerRegistryClient::Server.new(nil, "www.example.com")
|
81
|
+
|
82
|
+
servers << ServerRegistryClient::Server.new(3, "stage.shindig.io", "4.3.2.1", 345)
|
83
|
+
servers << ServerRegistryClient::Server.new(1, "www.apple.com", "1.2.3.4")
|
84
|
+
servers << ServerRegistryClient::Server.new(8, "www.example.com")
|
85
|
+
servers << ServerRegistryClient::Server.new(9, "www.example.com", nil, 80)
|
86
|
+
servers << ServerRegistryClient::Server.new(10, "www.example.com", nil, 1221)
|
87
|
+
servers << ServerRegistryClient::Server.new(2, "www.test.com", "1.2.3.4")
|
88
|
+
|
89
|
+
found_servers = servers.find_all do |server|
|
90
|
+
server_to_match.matches?(server)
|
91
|
+
end
|
92
|
+
|
93
|
+
found_servers.map(&:id).should == [8, 9, 10]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "server-registry-client"
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: server-registry-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael James
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70335946949280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70335946949280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70335946948820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70335946948820
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: typhoeus
|
38
|
+
requirement: &70335946948320 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - =
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.5.3
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70335946948320
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: yajl-ruby
|
49
|
+
requirement: &70335946947780 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70335946947780
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: thor
|
60
|
+
requirement: &70335946947320 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0.16'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70335946947320
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: &70335946946860 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.2'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70335946946860
|
80
|
+
description: Client library and command-line tools for interacting with the server
|
81
|
+
registry (https://github.com/umjames/server-registry)
|
82
|
+
email:
|
83
|
+
- umjames29@gmail.com
|
84
|
+
executables:
|
85
|
+
- srctool
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- bin/srctool
|
94
|
+
- lib/server-registry-client.rb
|
95
|
+
- lib/server-registry-client/cli.rb
|
96
|
+
- lib/server-registry-client/client.rb
|
97
|
+
- lib/server-registry-client/errors.rb
|
98
|
+
- lib/server-registry-client/models.rb
|
99
|
+
- lib/server-registry-client/models/server.rb
|
100
|
+
- lib/server-registry-client/server_processor.rb
|
101
|
+
- lib/server-registry-client/server_processor/base.rb
|
102
|
+
- lib/server-registry-client/server_processor/v1.rb
|
103
|
+
- lib/server-registry-client/version.rb
|
104
|
+
- server-registry-client.gemspec
|
105
|
+
- spec/client_spec.rb
|
106
|
+
- spec/server_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage: ''
|
109
|
+
licenses: []
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 1.9.1
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.8.5
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 1.8.5
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: Client library and command-line tools for interacting with the server registry
|
132
|
+
(https://github.com/umjames/server-registry)
|
133
|
+
test_files:
|
134
|
+
- spec/client_spec.rb
|
135
|
+
- spec/server_spec.rb
|
136
|
+
- spec/spec_helper.rb
|