opensrs 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +1,44 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.2)
4
+ activesupport (3.2.13)
5
+ i18n (= 0.6.1)
6
+ multi_json (~> 1.0)
7
+ bourne (1.1.2)
8
+ mocha (= 0.10.5)
9
+ diff-lcs (1.2.1)
5
10
  git (1.2.5)
6
- jeweler (1.6.4)
11
+ i18n (0.6.1)
12
+ jeweler (1.8.4)
7
13
  bundler (~> 1.0)
8
14
  git (>= 1.2.5)
9
15
  rake
16
+ rdoc
17
+ json (1.7.7)
10
18
  libxml-ruby (2.1.2)
19
+ metaclass (0.0.1)
20
+ mocha (0.10.5)
21
+ metaclass (~> 0.0.1)
22
+ multi_json (1.7.1)
11
23
  nokogiri (1.4.7)
12
- rake (0.9.2)
13
- rspec (2.6.0)
14
- rspec-core (~> 2.6.0)
15
- rspec-expectations (~> 2.6.0)
16
- rspec-mocks (~> 2.6.0)
17
- rspec-core (2.6.4)
18
- rspec-expectations (2.6.0)
19
- diff-lcs (~> 1.1.2)
20
- rspec-mocks (2.6.0)
21
- shoulda (2.11.3)
24
+ rake (10.0.3)
25
+ rdoc (4.0.0)
26
+ json (~> 1.4)
27
+ rspec (2.13.0)
28
+ rspec-core (~> 2.13.0)
29
+ rspec-expectations (~> 2.13.0)
30
+ rspec-mocks (~> 2.13.0)
31
+ rspec-core (2.13.1)
32
+ rspec-expectations (2.13.0)
33
+ diff-lcs (>= 1.1.3, < 2.0)
34
+ rspec-mocks (2.13.0)
35
+ shoulda (3.3.2)
36
+ shoulda-context (~> 1.0.1)
37
+ shoulda-matchers (~> 1.4.1)
38
+ shoulda-context (1.0.2)
39
+ shoulda-matchers (1.4.2)
40
+ activesupport (>= 3.0.0)
41
+ bourne (~> 1.1.2)
22
42
 
23
43
  PLATFORMS
24
44
  ruby
@@ -1,24 +1,27 @@
1
- = OpenSRS http://travis-ci.org/voxxit/opensrs.png
1
+ = OpenSRS
2
+
3
+ {<img src="https://travis-ci.org/voxxit/opensrs.png" />}[https://travis-ci.org/voxxit/opensrs]
4
+ {<img src="https://codeclimate.com/github/voxxit/opensrs.png" />}[https://codeclimate.com/github/voxxit/opensrs]
2
5
 
3
6
  This (unofficial) OpenSRS gem provides basic support to connect to, and utilize the OpenSRS API. This library has been well-tested in high-performance production
4
7
  environments. More information on the API can be located here:
5
8
 
6
- http://opensrs.com/resources/documentation/opensrs_xmlapi.pdf
9
+ http://www.opensrs.com/site/resources/documentation/api
7
10
 
8
11
  == Installation
9
12
 
10
13
  You can install this gem by doing the following:
11
14
 
12
15
  $ gem install opensrs
13
-
16
+
14
17
  You can then include it in a Ruby project, like so:
15
18
 
16
19
  require 'opensrs'
17
-
20
+
18
21
  Alternatively, you can include it in a Rails 2.x project in the <tt>environment.rb</tt> file, like so:
19
22
 
20
23
  config.gem "opensrs"
21
-
24
+
22
25
  For Rails 3.x, use the <tt>Gemfile</tt>:
23
26
 
24
27
  gem "opensrs"
@@ -55,7 +58,7 @@ Once you have a server connection class, you can build from this to create the m
55
58
  :object => "BALANCE"
56
59
  )
57
60
  end
58
-
61
+
59
62
  Sometimes you might need to include attributes for the command, such as a cookie, or the data attributes themselves. You can do this, too:
60
63
 
61
64
  def create_nameserver(nameserver)
@@ -69,7 +72,7 @@ Sometimes you might need to include attributes for the command, such as a cookie
69
72
  }
70
73
  )
71
74
  end
72
-
75
+
73
76
  Responses from OpenSRS are returned in an OpenSRS::Response object, which gives you access to a multitude of things.
74
77
 
75
78
  * <tt>response.response</tt> - This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
@@ -92,6 +95,11 @@ http://github.com/voxxit/opensrs/issues
92
95
  * Commit, do not mess with rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull.
93
96
  * Send me a pull request. Bonus points for topic branches.
94
97
 
98
+ == Contributors (in order of appearance)
99
+
100
+ * Josh Delsman
101
+ * Glenn Roberts
102
+
95
103
  == Copyright
96
104
 
97
- Copyright (c) 2010-2011 Josh Delsman. Distributed under the MIT license. See LICENSE for details.
105
+ Copyright (c) 2010-2013 Josh Delsman. Distributed under the MIT license. See LICENSE for details.
@@ -5,30 +5,33 @@ require "openssl"
5
5
 
6
6
  module OpenSRS
7
7
  class BadResponse < StandardError; end
8
-
8
+ class TimeoutError < StandardError; end
9
+
9
10
  class Server
10
- attr_accessor :server, :username, :password, :key
11
+ attr_accessor :server, :username, :password, :key, :timeout, :open_timeout
11
12
 
12
13
  def initialize(options = {})
13
14
  @server = URI.parse(options[:server] || "https://rr-n1-tor.opensrs.net:55443/")
14
15
  @username = options[:username]
15
16
  @password = options[:password]
16
17
  @key = options[:key]
18
+ @timeout = options[:timeout]
19
+ @open_timeout = options[:open_timeout]
17
20
  end
18
21
 
19
- def call(options = {})
20
- attributes = {
21
- :protocol => "XCP"
22
- }
23
-
24
- xml = xml_processor.build(attributes.merge!(options))
22
+ def call(data = {})
23
+ xml = xml_processor.build({ :protocol => "XCP" }.merge!(data))
24
+
25
+ begin
26
+ response = http.post(server_path, xml, headers(xml))
27
+ rescue Net::HTTPBadResponse
28
+ raise OpenSRS::BadResponse, "Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again."
29
+ end
25
30
 
26
- response = http.post(server.path, xml, headers(xml))
27
31
  parsed_response = xml_processor.parse(response.body)
28
-
29
32
  return OpenSRS::Response.new(parsed_response, xml, response.body)
30
- rescue Net::HTTPBadResponse
31
- raise OpenSRS::BadResponse, "Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again."
33
+ rescue Timeout::Error => err
34
+ raise OpenSRS::TimeoutError, err
32
35
  end
33
36
 
34
37
  def xml_processor
@@ -41,31 +44,34 @@ module OpenSRS
41
44
  end
42
45
 
43
46
  OpenSRS::Server.xml_processor = :libxml
44
-
47
+
45
48
  private
46
-
49
+
47
50
  def headers(request)
48
- headers = {
49
- "Content-Length" => request.length.to_s,
51
+ { "Content-Length" => request.length.to_s,
50
52
  "Content-Type" => "text/xml",
51
53
  "X-Username" => username,
52
54
  "X-Signature" => signature(request)
53
55
  }
54
-
55
- return headers
56
56
  end
57
-
57
+
58
58
  def signature(request)
59
59
  signature = Digest::MD5.hexdigest(request + key)
60
60
  signature = Digest::MD5.hexdigest(signature + key)
61
61
  signature
62
62
  end
63
-
63
+
64
64
  def http
65
65
  http = Net::HTTP.new(server.host, server.port)
66
66
  http.use_ssl = (server.scheme == "https")
67
67
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
68
+ http.read_timeout = http.open_timeout = @timeout if @timeout
69
+ http.open_timeout = @open_timeout if @open_timeout
68
70
  http
69
71
  end
72
+
73
+ def server_path
74
+ server.path.empty? ? '/' : server.path
75
+ end
70
76
  end
71
77
  end
@@ -1,5 +1,5 @@
1
1
  module OpenSRS
2
2
  class Version
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
5
5
  end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{opensrs}
8
- s.version = "0.3.2"
7
+ s.name = "opensrs"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Delsman"]
12
- s.date = %q{2011-08-08}
13
- s.description = %q{Provides support to utilize the OpenSRS API with Ruby/Rails.}
14
- s.email = %q{jdelsman@voxxit.com}
12
+ s.date = "2013-03-18"
13
+ s.description = "Provides support to utilize the OpenSRS API with Ruby/Rails."
14
+ s.email = "jdelsman@voxxit.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -37,18 +37,18 @@ Gem::Specification.new do |s|
37
37
  "spec/opensrs/xml_processor/nokogiri_spec.rb",
38
38
  "spec/spec_helper.rb"
39
39
  ]
40
- s.homepage = %q{http://github.com/voxxit/opensrs}
40
+ s.homepage = "http://github.com/voxxit/opensrs"
41
41
  s.licenses = ["MIT"]
42
42
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.6.2}
44
- s.summary = %q{Provides support to utilize the OpenSRS API with Ruby/Rails.}
43
+ s.rubygems_version = "1.8.23"
44
+ s.summary = "Provides support to utilize the OpenSRS API with Ruby/Rails."
45
45
 
46
46
  if s.respond_to? :specification_version then
47
47
  s.specification_version = 3
48
48
 
49
49
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
50
  s.add_runtime_dependency(%q<libxml-ruby>, ["~> 2.1.2"])
51
- s.add_development_dependency(%q<nokogiri>, [">= 0"])
51
+ s.add_development_dependency(%q<nokogiri>, ["~> 1.4.6"])
52
52
  s.add_development_dependency(%q<jeweler>, [">= 0"])
53
53
  s.add_development_dependency(%q<git>, [">= 0"])
54
54
  s.add_development_dependency(%q<rake>, [">= 0"])
@@ -56,7 +56,7 @@ Gem::Specification.new do |s|
56
56
  s.add_development_dependency(%q<rspec>, ["~> 2.0"])
57
57
  else
58
58
  s.add_dependency(%q<libxml-ruby>, ["~> 2.1.2"])
59
- s.add_dependency(%q<nokogiri>, [">= 0"])
59
+ s.add_dependency(%q<nokogiri>, ["~> 1.4.6"])
60
60
  s.add_dependency(%q<jeweler>, [">= 0"])
61
61
  s.add_dependency(%q<git>, [">= 0"])
62
62
  s.add_dependency(%q<rake>, [">= 0"])
@@ -65,7 +65,7 @@ Gem::Specification.new do |s|
65
65
  end
66
66
  else
67
67
  s.add_dependency(%q<libxml-ruby>, ["~> 2.1.2"])
68
- s.add_dependency(%q<nokogiri>, [">= 0"])
68
+ s.add_dependency(%q<nokogiri>, ["~> 1.4.6"])
69
69
  s.add_dependency(%q<jeweler>, [">= 0"])
70
70
  s.add_dependency(%q<git>, [">= 0"])
71
71
  s.add_dependency(%q<rake>, [">= 0"])
@@ -1,13 +1,101 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OpenSRS::Server do
4
- before(:each) do
5
- @server = OpenSRS::Server.new
4
+ let(:server) { OpenSRS::Server.new }
5
+
6
+ describe '#new' do
7
+ it 'allows timeouts to be set' do
8
+ server = OpenSRS::Server.new({ :timeout => 90 })
9
+ server.timeout.should == 90
10
+ server.open_timeout.should be_nil
11
+ end
12
+
13
+ it 'allows open timeouts to be set' do
14
+ server = OpenSRS::Server.new({ :timeout => 90, :open_timeout => 10 })
15
+ server.timeout.should eq(90)
16
+ server.open_timeout.should eq(10)
17
+ end
18
+
19
+ it 'leaves it up to Net::HTTP if no timeouts given' do
20
+ server.timeout.should be_nil
21
+ server.open_timeout.should be_nil
22
+ end
23
+ end
24
+
25
+ describe ".call" do
26
+ let(:response) { double(:body => 'some response') }
27
+ let(:header) { {"some" => "header" } }
28
+ let(:xml) { '<some xml></some xml>' }
29
+ let(:response_xml) { xml }
30
+ let(:xml_processor) { double OpenSRS::XmlProcessor }
31
+ let(:http) { double(Net::HTTP, :use_ssl= => true, :verify_mode= => true) }
32
+
33
+ before :each do
34
+ server.stub(:headers).and_return header
35
+ xml_processor.stub(:build).and_return xml
36
+ xml_processor.stub(:parse).and_return response_xml
37
+ server.stub(:xml_processor).and_return xml_processor
38
+ http.stub(:post).and_return response
39
+ Net::HTTP.stub(:new).and_return http
40
+ end
41
+
42
+ it "builds XML request" do
43
+ xml_processor.should_receive(:build).with(:protocol => "XCP", :some => 'option')
44
+ server.call(:some => 'option')
45
+ end
46
+
47
+ it "posts to given path" do
48
+ server.server = URI.parse 'http://with-path.com/endpoint'
49
+ http.should_receive(:post).with('/endpoint', xml, header).and_return double.as_null_object
50
+ server.call
51
+ end
52
+
53
+ it "parses the response" do
54
+ xml_processor.should_receive(:parse).with(response.body)
55
+ server.call(:some => 'option')
56
+ end
57
+
58
+ it "posts to root path" do
59
+ server.server = URI.parse 'http://root-path.com/'
60
+ http.should_receive(:post).with('/', xml, header).and_return double.as_null_object
61
+ server.call
62
+ end
63
+
64
+ it "defaults path to '/'" do
65
+ server.server = URI.parse 'http://no-path.com'
66
+ http.should_receive(:post).with('/', xml, header).and_return double.as_null_object
67
+ server.call
68
+ end
69
+
70
+ it 'allows overriding of default (Net:HTTP) timeouts' do
71
+ server.timeout = 90
72
+
73
+ http.should_receive(:open_timeout=).with(90)
74
+ http.should_receive(:read_timeout=).with(90)
75
+
76
+ server.call( { :some => 'data' } )
77
+ end
78
+
79
+ it 'allows overriding of default (Net:HTTP) timeouts' do
80
+ server.timeout = 180
81
+ server.open_timeout = 30
82
+
83
+ http.should_receive(:read_timeout=).with(180)
84
+ http.should_receive(:open_timeout=).with(180)
85
+ http.should_receive(:open_timeout=).with(30)
86
+
87
+ server.call( { :some => 'data' } )
88
+ end
89
+
90
+ it 're-raises Net:HTTP timeouts' do
91
+ http.should_receive(:post).and_raise err = Timeout::Error.new('test')
92
+ expect { server.call }.to raise_exception OpenSRS::TimeoutError
93
+ end
6
94
  end
7
95
 
8
96
  describe "#test xml processor" do
9
97
  context "on class initialization" do
10
- it { @server.xml_processor.should eql(OpenSRS::XmlProcessor::Libxml) }
98
+ it { server.xml_processor.should eql(OpenSRS::XmlProcessor::Libxml) }
11
99
  end
12
100
 
13
101
  context "on changing xml processor" do
@@ -15,7 +103,7 @@ describe OpenSRS::Server do
15
103
  OpenSRS::Server.xml_processor = :nokogiri
16
104
  end
17
105
 
18
- it { @server.xml_processor.should eql(OpenSRS::XmlProcessor::Nokogiri) }
106
+ it { server.xml_processor.should eql(OpenSRS::XmlProcessor::Nokogiri) }
19
107
  end
20
108
  end
21
- end
109
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe OpenSRS::Version do
4
4
  describe "VERSION" do
5
5
  it "should return version string" do
6
- OpenSRS::Version::VERSION.should eql("0.3.2")
6
+ OpenSRS::Version::VERSION.should eql("0.3.3")
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -2,4 +2,5 @@ require 'opensrs/xml_processor.rb'
2
2
  require 'opensrs/xml_processor/libxml.rb'
3
3
  require 'opensrs/xml_processor/nokogiri.rb'
4
4
  require 'opensrs/server.rb'
5
- require 'opensrs/version.rb'
5
+ require 'opensrs/version.rb'
6
+ require 'opensrs/response.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-08 00:00:00.000000000 +08:00
13
- default_executable:
12
+ date: 2013-03-18 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: libxml-ruby
17
- requirement: &70360313048380 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,15 @@ dependencies:
22
21
  version: 2.1.2
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *70360313048380
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.2
26
30
  - !ruby/object:Gem::Dependency
27
31
  name: nokogiri
28
- requirement: &70360313047860 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
29
33
  none: false
30
34
  requirements:
31
35
  - - ~>
@@ -33,10 +37,15 @@ dependencies:
33
37
  version: 1.4.6
34
38
  type: :development
35
39
  prerelease: false
36
- version_requirements: *70360313047860
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.4.6
37
46
  - !ruby/object:Gem::Dependency
38
47
  name: jeweler
39
- requirement: &70360313047260 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
40
49
  none: false
41
50
  requirements:
42
51
  - - ! '>='
@@ -44,10 +53,15 @@ dependencies:
44
53
  version: '0'
45
54
  type: :development
46
55
  prerelease: false
47
- version_requirements: *70360313047260
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: git
50
- requirement: &70360313046700 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
51
65
  none: false
52
66
  requirements:
53
67
  - - ! '>='
@@ -55,10 +69,15 @@ dependencies:
55
69
  version: '0'
56
70
  type: :development
57
71
  prerelease: false
58
- version_requirements: *70360313046700
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
59
78
  - !ruby/object:Gem::Dependency
60
79
  name: rake
61
- requirement: &70360313046180 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
62
81
  none: false
63
82
  requirements:
64
83
  - - ! '>='
@@ -66,10 +85,15 @@ dependencies:
66
85
  version: '0'
67
86
  type: :development
68
87
  prerelease: false
69
- version_requirements: *70360313046180
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
70
94
  - !ruby/object:Gem::Dependency
71
95
  name: shoulda
72
- requirement: &70360313045600 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
73
97
  none: false
74
98
  requirements:
75
99
  - - ! '>='
@@ -77,10 +101,15 @@ dependencies:
77
101
  version: '0'
78
102
  type: :development
79
103
  prerelease: false
80
- version_requirements: *70360313045600
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
81
110
  - !ruby/object:Gem::Dependency
82
111
  name: rspec
83
- requirement: &70360313021400 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
84
113
  none: false
85
114
  requirements:
86
115
  - - ~>
@@ -88,7 +117,12 @@ dependencies:
88
117
  version: '2.0'
89
118
  type: :development
90
119
  prerelease: false
91
- version_requirements: *70360313021400
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '2.0'
92
126
  description: Provides support to utilize the OpenSRS API with Ruby/Rails.
93
127
  email: jdelsman@voxxit.com
94
128
  executables: []
@@ -116,7 +150,6 @@ files:
116
150
  - spec/opensrs/xml_processor/libxml_spec.rb
117
151
  - spec/opensrs/xml_processor/nokogiri_spec.rb
118
152
  - spec/spec_helper.rb
119
- has_rdoc: true
120
153
  homepage: http://github.com/voxxit/opensrs
121
154
  licenses:
122
155
  - MIT
@@ -130,9 +163,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
163
  - - ! '>='
131
164
  - !ruby/object:Gem::Version
132
165
  version: '0'
133
- segments:
134
- - 0
135
- hash: 3837143162391248904
136
166
  required_rubygems_version: !ruby/object:Gem::Requirement
137
167
  none: false
138
168
  requirements:
@@ -141,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
171
  version: '0'
142
172
  requirements: []
143
173
  rubyforge_project:
144
- rubygems_version: 1.6.2
174
+ rubygems_version: 1.8.23
145
175
  signing_key:
146
176
  specification_version: 3
147
177
  summary: Provides support to utilize the OpenSRS API with Ruby/Rails.