opensrs 0.3.4 → 0.3.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: 127ecdac1c36fe084303d59efca748da537ce37a
4
- data.tar.gz: f4018a9dd533a217dcc80f6692e642f28d38cd4d
3
+ metadata.gz: cef55dd62d0db183b1f6e3e85518268695882e8d
4
+ data.tar.gz: 1a195f62bdb2cd02ba0c9d6b4d90a7392ea4c386
5
5
  SHA512:
6
- metadata.gz: 9268aa3a9cca1924ca1b8e40257caaeb630cb3133dd78562ef734ca1e291e0467d4b927ecfac4f0c3698667b7d2772854796ff89f8a8b0c868a80c93d3a4d278
7
- data.tar.gz: e9b96abc301ff7a2f1101374847c44c3b1c5821351e5f7e7bd2fec9bfaaac2508fcb9177c6125b52ea8ca79261fca5ffc49341c483af38273346ad90b7fb872f
6
+ metadata.gz: 09f10fb90e00cc9b43e990a4fa2255b4cd3193533faa5d31064d3197f794f50cf20024f749dbb3a44d954df1d4066075a2e0af2718c4e35e32d2c08a29316d28
7
+ data.tar.gz: 90d8ba319a32a30764a8ccb1456a29286b5ae8ab2448a5f8e6f3c36635a8a79e6c628e3dbdd25dd2a77ac307428867d45893425b2e9926c82e49888652231abc
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.gem
15
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format doc
2
+ --color
3
+ --require spec_helper
data/Gemfile CHANGED
@@ -1,12 +1,3 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "libxml-ruby", "~> 2.6.0"
4
-
5
- group :development do
6
- gem "nokogiri", "~> 1.4.6"
7
- gem "jeweler"
8
- gem "git"
9
- gem "rake"
10
- gem "shoulda"
11
- gem "rspec", "~> 2.0"
12
- end
3
+ gemspec
@@ -1,53 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ opensrs (0.3.5)
5
+ libxml-ruby (~> 2)
6
+
1
7
  GEM
2
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
3
9
  specs:
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)
10
- git (1.2.5)
11
- i18n (0.6.1)
12
- jeweler (1.8.4)
13
- bundler (~> 1.0)
14
- git (>= 1.2.5)
15
- rake
16
- rdoc
17
- json (1.7.7)
18
- libxml-ruby (2.6.0)
19
- metaclass (0.0.1)
20
- mocha (0.10.5)
21
- metaclass (~> 0.0.1)
22
- multi_json (1.7.1)
23
- nokogiri (1.4.7)
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)
10
+ activesupport (4.1.8)
11
+ i18n (~> 0.6, >= 0.6.9)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 1.1)
16
+ diff-lcs (1.2.5)
17
+ i18n (0.6.11)
18
+ json (1.8.1)
19
+ libxml-ruby (2.8.0)
20
+ mini_portile (0.6.1)
21
+ minitest (5.5.0)
22
+ nokogiri (1.6.5)
23
+ mini_portile (~> 0.6.0)
24
+ rake (10.4.2)
25
+ rspec (2.99.0)
26
+ rspec-core (~> 2.99.0)
27
+ rspec-expectations (~> 2.99.0)
28
+ rspec-mocks (~> 2.99.0)
29
+ rspec-core (2.99.2)
30
+ rspec-expectations (2.99.2)
33
31
  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)
32
+ rspec-mocks (2.99.2)
33
+ shoulda (3.5.0)
34
+ shoulda-context (~> 1.0, >= 1.0.1)
35
+ shoulda-matchers (>= 1.4.1, < 3.0)
36
+ shoulda-context (1.2.1)
37
+ shoulda-matchers (2.7.0)
40
38
  activesupport (>= 3.0.0)
41
- bourne (~> 1.1.2)
39
+ thread_safe (0.3.4)
40
+ tzinfo (1.2.2)
41
+ thread_safe (~> 0.1)
42
42
 
43
43
  PLATFORMS
44
44
  ruby
45
45
 
46
46
  DEPENDENCIES
47
- git
48
- jeweler
49
- libxml-ruby (~> 2.6.0)
50
- nokogiri (~> 1.4.6)
47
+ bundler (~> 1.8)
48
+ nokogiri
49
+ opensrs!
51
50
  rake
52
51
  rspec (~> 2.0)
53
52
  shoulda
@@ -1,4 +1,6 @@
1
- Copyright (c) 2010-2011 Josh Delsman
1
+ Copyright (c) 2014 Joshua Delsman
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,129 @@
1
+ # OpenSRS
2
+
3
+ [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/voxxit/opensrs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
5
+ [![Build Status](https://travis-ci.org/voxxit/opensrs.svg?branch=master)](https://travis-ci.org/voxxit/opensrs)
6
+ [![Code Climate](https://codeclimate.com/github/voxxit/opensrs/badges/gpa.svg)](https://codeclimate.com/github/voxxit/opensrs)
7
+ [![Coverage Status](https://img.shields.io/coveralls/voxxit/opensrs.svg)](https://coveralls.io/r/voxxit/opensrs)
8
+
9
+ This (unofficial) OpenSRS gem provides basic support to connect to, and utilize the [OpenSRS API.](http://www.opensrs.com/site/resources/documentation/api) This library has been well-tested in high-performance production
10
+ environments.
11
+
12
+ ### Requirements
13
+
14
+ * Ruby **>= 1.9.2** or **>= 2.0.0** or **>= 2.1.2**
15
+
16
+ ### Installation
17
+
18
+ You can install this gem by doing the following:
19
+
20
+ $ gem install opensrs
21
+
22
+ You can then include it in a Ruby project, like so:
23
+
24
+ require 'opensrs'
25
+
26
+ For Rails 3.x and above, add it to the `Gemfile`:
27
+
28
+ gem "opensrs"
29
+
30
+ ### Usage
31
+
32
+ This library provides basic functionality for interacting with the OpenSRS XML API.
33
+
34
+ - Connection handling
35
+ - Error reporting
36
+ - XML encoding
37
+ - XML decoding
38
+
39
+ Currently, the library supports LibXML and Nokogiri as XML parsers. By default, it uses LibXML to parse and generate XML. If you'd like to use Nokogiri (1.4.7 and below) for parsing XML, then in one of your app initializers add the following line:
40
+
41
+ OpenSRS::Server.xml_processor = :nokogiri
42
+
43
+ To connect, instantiate a new <tt>OpenSRS::Server</tt> object:
44
+
45
+ server = OpenSRS::Server.new(
46
+ server: "https://rr-n1-tor.opensrs.net:55443/",
47
+ username: "testing",
48
+ password: "53cr3t",
49
+ key: "c633be3170c7fb3fb29e2f99b84be2410..."
50
+ )
51
+
52
+ **NOTE:** Connecting to OpenSRS requires that you add the IP(s) you're connecting from to their whitelist. Log in to the testing or production servers, and add your IP(s) under Profile Management > Add IPs for Script/API Access. IP changes take about one hour to take effect.
53
+
54
+ If you would like, you can provide OpenSRS::Server with a logger to write the contents of the requests and responses
55
+ with OpenSRS. The assumption is you are using a Rails-like logger, but as long as your logger has an info method you
56
+ are fine. You can simply assign the logger or pass it in as an initialization option:
57
+
58
+ server = OpenSRS::Server.new(
59
+ server: "https://rr-n1-tor.opensrs.net:55443/",
60
+ username: "testing",
61
+ password: "53cr3t",
62
+ key: "c633be3170c7fb3fb29e2f99b84be2410...",
63
+ logger: Rails.logger
64
+ )
65
+
66
+ or, if you can change it later:
67
+
68
+ server.logger = Rails.logger
69
+
70
+ Once you have a server connection class, you can build from this to create the methods that you need. For instance, let's say we want to grab our account balance. The OpenSRS XML API takes a couple of attributes for all commands. You can include those here:
71
+
72
+ def get_balance
73
+ server.call(
74
+ action: "GET_BALANCE",
75
+ object: "BALANCE"
76
+ )
77
+ end
78
+
79
+ Sometimes you might need to include attributes for the command, such as a cookie, or the data attributes themselves. You can do this, too:
80
+
81
+ def create_nameserver(nameserver)
82
+ server.call(
83
+ action: "CREATE",
84
+ object: "NAMESERVER",
85
+ cookie: "366828736:3210384",
86
+ attributes: {
87
+ name: nameserver.hostname,
88
+ ipaddress: "212.112.123.11"
89
+ }
90
+ )
91
+ end
92
+
93
+ Responses from OpenSRS are returned in an OpenSRS::Response object, which gives you access to a multitude of things.
94
+
95
+ Method | Description
96
+ ---|---
97
+ `response.response` | This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
98
+ `response.response` | This gives you the response in a Hash form, which is highly accessible to most other actions in your application.
99
+ `response.errors` | If there are errors which come back from OpenSRS, they are returned here. If not, it returns nil.
100
+ `response.success?` | Returns true if the response was labeled as successful. If not, it returns false.
101
+ `response.request_xml` | Returns raw request XML.
102
+ `response.response_xml` | Returns raw response XML.
103
+
104
+ ### Bugs/Feature Requests
105
+
106
+ If you have any bugs or feature requests for this gem, feel free to [open an issue.](http://github.com/voxxit/opensrs/issues/new)
107
+
108
+ ### How To Contribute
109
+
110
+ * Fork the project.
111
+ * Make your feature addition or bug fix.
112
+ * Add specs for it.
113
+ * Commit, but **do not mess with Rakefile or version.**
114
+ * Send me a pull request. Bonus points for topic branches!
115
+
116
+ ### Contributors (in order of appearance)
117
+
118
+ * [Joshua Delsman](http://github.com/voxxit)
119
+ * Glenn Roberts
120
+
121
+ ### Copyright
122
+
123
+ Copyright (c) 2010-2014 Joshua Delsman.
124
+
125
+ Distributed under the MIT license. See `LICENSE` for details.
126
+
127
+
128
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/voxxit/opensrs/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
129
+
data/Rakefile CHANGED
@@ -1,40 +1 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- begin
5
- Bundler.setup(:default, :development)
6
- rescue Bundler::BundlerError => e
7
- $stderr.puts e.message
8
- $stderr.puts "Run `bundle install` to install missing gems"
9
- exit e.status_code
10
- end
11
-
12
- $LOAD_PATH.unshift("lib")
13
-
14
- require 'rake'
15
- require 'opensrs'
16
-
17
- begin
18
- require 'jeweler'
19
-
20
- Jeweler::Tasks.new do |gem|
21
- gem.name = "opensrs"
22
- gem.version = OpenSRS::Version::VERSION
23
- gem.summary = "Provides support to utilize the OpenSRS API with Ruby/Rails."
24
- gem.description = "Provides support to utilize the OpenSRS API with Ruby/Rails."
25
- gem.email = "jdelsman@voxxit.com"
26
- gem.homepage = "http://github.com/voxxit/opensrs"
27
- gem.license = "MIT"
28
- gem.authors = ["Josh Delsman"]
29
-
30
- # Requirements are in Gemfile
31
- end
32
- rescue LoadError
33
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
34
- end
35
-
36
- require 'rspec/core/rake_task'
37
-
38
- RSpec::Core::RakeTask.new(:spec)
39
-
40
- task :default => :spec
1
+ require "bundler/gem_tasks"
@@ -4,11 +4,14 @@ require "digest/md5"
4
4
  require "openssl"
5
5
 
6
6
  module OpenSRS
7
- class BadResponse < StandardError; end
8
- class TimeoutError < StandardError; end
7
+ class OpenSRSError < StandardError; end
8
+
9
+ class BadResponse < OpenSRSError; end
10
+ class ConnectionError < OpenSRSError; end
11
+ class TimeoutError < ConnectionError; end
9
12
 
10
13
  class Server
11
- attr_accessor :server, :username, :password, :key, :timeout, :open_timeout
14
+ attr_accessor :server, :username, :password, :key, :timeout, :open_timeout, :logger
12
15
 
13
16
  def initialize(options = {})
14
17
  @server = URI.parse(options[:server] || "https://rr-n1-tor.opensrs.net:55443/")
@@ -17,13 +20,16 @@ module OpenSRS
17
20
  @key = options[:key]
18
21
  @timeout = options[:timeout]
19
22
  @open_timeout = options[:open_timeout]
23
+ @logger = options[:logger]
20
24
  end
21
25
 
22
26
  def call(data = {})
23
27
  xml = xml_processor.build({ :protocol => "XCP" }.merge!(data))
28
+ log('Request', xml, data)
24
29
 
25
30
  begin
26
31
  response = http.post(server_path, xml, headers(xml))
32
+ log('Response', response.body, data)
27
33
  rescue Net::HTTPBadResponse
28
34
  raise OpenSRS::BadResponse, "Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again."
29
35
  end
@@ -32,6 +38,8 @@ module OpenSRS
32
38
  return OpenSRS::Response.new(parsed_response, xml, response.body)
33
39
  rescue Timeout::Error => err
34
40
  raise OpenSRS::TimeoutError, err
41
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED => err
42
+ raise OpenSRS::ConnectionError, err
35
43
  end
36
44
 
37
45
  def xml_processor
@@ -70,6 +78,16 @@ module OpenSRS
70
78
  http
71
79
  end
72
80
 
81
+ def log(type, data, options = {})
82
+ return unless logger
83
+
84
+ message = "[OpenSRS] #{type} XML"
85
+ message = "#{message} for #{options[:object]} #{options[:action]}" if options[:object] && options[:action]
86
+
87
+ line = [message, data].join("\n")
88
+ logger.info(line)
89
+ end
90
+
73
91
  def server_path
74
92
  server.path.empty? ? '/' : server.path
75
93
  end
@@ -1,5 +1,5 @@
1
1
  module OpenSRS
2
2
  class Version
3
- VERSION = "0.3.4"
3
+ VERSION = "0.3.5"
4
4
  end
5
5
  end
@@ -16,44 +16,42 @@ module OpenSRS
16
16
 
17
17
  # Encodes individual elements, and their child elements, for the root XML document.
18
18
  def self.encode_data(data, container = nil)
19
- case data.class.to_s
20
- when "Array" then return encode_dt_array(data, container)
21
- when "Hash" then return encode_dt_assoc(data, container)
22
- when "String", "Numeric", "Date", "Time", "Symbol", "NilClass"
23
- return data.to_s
19
+ case data
20
+ when Array
21
+ encode_dt_array(data, container)
22
+ when Hash
23
+ encode_dt_assoc(data, container)
24
+ when String, Numeric, Date, Time, Symbol, NilClass
25
+ data.to_s
24
26
  else
25
- return data.inspect
27
+ data.inspect
26
28
  end
27
-
28
- return nil
29
29
  end
30
30
 
31
31
  def self.encode_dt_array(data, container)
32
- dt_array = new_element(:dt_array, container)
33
-
34
- data.each_with_index do |item, index|
35
- item_node = new_element(:item, container)
36
- item_node["key"] = index.to_s
37
- item_node << encode_data(item, item_node)
38
-
39
- dt_array << item_node
40
- end
41
-
42
- return dt_array
32
+ build_element(:dt_array, data, container)
43
33
  end
44
34
 
45
35
  def self.encode_dt_assoc(data, container)
46
- dt_assoc = new_element(:dt_assoc, container)
36
+ build_element(:dt_assoc, data, container)
37
+ end
38
+
39
+ def self.build_element(type, data, container)
40
+ element = new_element(type, container)
47
41
 
48
- data.each do |key, value|
42
+ # if array, item = the item
43
+ # if hash, item will be array of the key & value
44
+ data.each_with_index do |item, index|
49
45
  item_node = new_element(:item, container)
50
- item_node["key"] = key.to_s
51
- item_node << encode_data(value, item_node)
46
+ item_node["key"] = item.is_a?(Array) ? item[0].to_s : index.to_s
47
+
48
+ value = item.is_a?(Array) ? item[1] : item
52
49
 
53
- dt_assoc << item_node
50
+ item_node << encode_data(value, item_node)
51
+ element << item_node
54
52
  end
55
53
 
56
- return dt_assoc
54
+ element
57
55
  end
58
56
 
59
57
  # Recursively decodes individual data elements from OpenSRS
@@ -74,4 +72,4 @@ module OpenSRS
74
72
 
75
73
  end
76
74
 
77
- end
75
+ end
@@ -17,8 +17,13 @@ module OpenSRS
17
17
  body = ::Nokogiri::XML::Node.new("body", builder.doc)
18
18
  data_block = ::Nokogiri::XML::Node.new("data_block", builder.doc)
19
19
  other_data = encode_data(data, builder.doc)
20
- builder.doc << envelope << header << version << '0.9'
21
- envelope << body << data_block << other_data
20
+ version << '0.9'
21
+ header << version
22
+ envelope << header
23
+ builder.doc << envelope
24
+ data_block << other_data
25
+ body << data_block
26
+ envelope << body
22
27
  return builder.to_xml
23
28
  end
24
29
 
@@ -1,76 +1,33 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = "opensrs"
8
- s.version = "0.3.4"
3
+ lib = File.expand_path('../lib', __FILE__)
9
4
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Josh Delsman"]
12
- s.date = "2013-04-04"
13
- s.description = "Provides support to utilize the OpenSRS API with Ruby/Rails."
14
- s.email = "jdelsman@voxxit.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "lib/opensrs.rb",
27
- "lib/opensrs/response.rb",
28
- "lib/opensrs/server.rb",
29
- "lib/opensrs/version.rb",
30
- "lib/opensrs/xml_processor.rb",
31
- "lib/opensrs/xml_processor/libxml.rb",
32
- "lib/opensrs/xml_processor/nokogiri.rb",
33
- "opensrs.gemspec",
34
- "spec/opensrs/server_spec.rb",
35
- "spec/opensrs/version_spec.rb",
36
- "spec/opensrs/xml_processor/libxml_spec.rb",
37
- "spec/opensrs/xml_processor/nokogiri_spec.rb",
38
- "spec/spec_helper.rb"
39
- ]
40
- s.homepage = "http://github.com/voxxit/opensrs"
41
- s.licenses = ["MIT"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = "1.8.23"
44
- s.summary = "Provides support to utilize the OpenSRS API with Ruby/Rails."
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
45
6
 
46
- if s.respond_to? :specification_version then
47
- s.specification_version = 3
7
+ require 'opensrs/version'
48
8
 
49
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<libxml-ruby>, ["~> 2.6.0"])
51
- s.add_development_dependency(%q<nokogiri>, ["~> 1.4.6"])
52
- s.add_development_dependency(%q<jeweler>, [">= 0"])
53
- s.add_development_dependency(%q<git>, [">= 0"])
54
- s.add_development_dependency(%q<rake>, [">= 0"])
55
- s.add_development_dependency(%q<shoulda>, [">= 0"])
56
- s.add_development_dependency(%q<rspec>, ["~> 2.0"])
57
- else
58
- s.add_dependency(%q<libxml-ruby>, ["~> 2.6.0"])
59
- s.add_dependency(%q<nokogiri>, ["~> 1.4.6"])
60
- s.add_dependency(%q<jeweler>, [">= 0"])
61
- s.add_dependency(%q<git>, [">= 0"])
62
- s.add_dependency(%q<rake>, [">= 0"])
63
- s.add_dependency(%q<shoulda>, [">= 0"])
64
- s.add_dependency(%q<rspec>, ["~> 2.0"])
65
- end
66
- else
67
- s.add_dependency(%q<libxml-ruby>, ["~> 2.6.0"])
68
- s.add_dependency(%q<nokogiri>, ["~> 1.4.6"])
69
- s.add_dependency(%q<jeweler>, [">= 0"])
70
- s.add_dependency(%q<git>, [">= 0"])
71
- s.add_dependency(%q<rake>, [">= 0"])
72
- s.add_dependency(%q<shoulda>, [">= 0"])
73
- s.add_dependency(%q<rspec>, ["~> 2.0"])
74
- end
75
- end
9
+ Gem::Specification.new do |spec|
10
+
11
+ spec.name = "opensrs"
12
+ spec.version = OpenSRS::Version::VERSION
13
+ spec.authors = [ "Joshua Delsman" ]
14
+ spec.email = [ "j@srv.im" ]
15
+ spec.summary = "OpenSRS API for Ruby"
16
+ spec.description = "Provides support to utilize the OpenSRS API with Ruby."
17
+ spec.homepage = "https://github.com/voxxit/opensrs"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = [ "lib" ]
76
24
 
25
+ spec.add_runtime_dependency "libxml-ruby", "~> 2"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.8"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec", "~> 2.0"
30
+ spec.add_development_dependency "shoulda"
31
+ spec.add_development_dependency "nokogiri"
32
+
33
+ end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe OpenSRS::Server do
4
2
  let(:server) { OpenSRS::Server.new }
5
3
 
@@ -20,6 +18,12 @@ describe OpenSRS::Server do
20
18
  server.timeout.should be_nil
21
19
  server.open_timeout.should be_nil
22
20
  end
21
+
22
+ it 'allows a logger to be set during initialization' do
23
+ logger = double(:info => '')
24
+ server = OpenSRS::Server.new({ :logger => logger })
25
+ server.logger.should eq(logger)
26
+ end
23
27
  end
24
28
 
25
29
  describe ".call" do
@@ -91,6 +95,32 @@ describe OpenSRS::Server do
91
95
  http.should_receive(:post).and_raise err = Timeout::Error.new('test')
92
96
  expect { server.call }.to raise_exception OpenSRS::TimeoutError
93
97
  end
98
+
99
+ it 'wraps connection errors' do
100
+ http.should_receive(:post).and_raise err = Errno::ECONNREFUSED
101
+ expect { server.call }.to raise_exception OpenSRS::ConnectionError
102
+
103
+ http.should_receive(:post).and_raise err = Errno::ECONNRESET
104
+ expect { server.call }.to raise_exception OpenSRS::ConnectionError
105
+ end
106
+
107
+ describe "logger is present" do
108
+ let(:logger) { OpenSRS::TestLogger.new }
109
+ before :each do
110
+ server.logger = logger
111
+ end
112
+
113
+ it "should log the request and the response" do
114
+ xml_processor.should_receive(:build).with(:protocol => "XCP", :some => 'option')
115
+ server.call(:some => 'option')
116
+ logger.messages.length.should eq(2)
117
+ logger.messages.first.should match(/\[OpenSRS\] Request XML/)
118
+ logger.messages.first.should match(/<some xml>/)
119
+ logger.messages.last.should match(/\[OpenSRS\] Response XML/)
120
+ logger.messages.last.should match(/some response/)
121
+ end
122
+
123
+ end
94
124
  end
95
125
 
96
126
  describe "#test xml processor" do
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
2
-
3
1
  describe OpenSRS::Version do
4
2
  describe "VERSION" do
5
3
  it "should return version string" do
6
- OpenSRS::Version::VERSION.should eql("0.3.3")
4
+ OpenSRS::Version::VERSION.should eql("0.3.4")
7
5
  end
8
6
  end
9
7
  end
@@ -1,21 +1,20 @@
1
- require 'spec_helper'
2
1
  require 'date'
3
2
 
4
3
  describe OpenSRS::XmlProcessor::Libxml do
5
- describe ".build" do
4
+ describe ".build" do
6
5
  it "should create XML for a nested hash" do
7
6
  attributes = {:foo => {:bar => 'baz'}}
8
7
  xml = OpenSRS::XmlProcessor::Libxml.build(attributes)
9
8
  xml.should eq %{<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<OPS_envelope>\n <header>\n <version>0.9</version>\n </header>\n <body>\n <data_block>\n <dt_assoc>\n <item key=\"foo\">\n <dt_assoc>\n <item key=\"bar\">baz</item>\n </dt_assoc>\n </item>\n </dt_assoc>\n </data_block>\n </body>\n</OPS_envelope>\n}
10
9
  end
11
10
  end
12
-
11
+
13
12
  describe '.encode_data' do
14
13
  context "on a 3 element array" do
15
14
  before(:each) do
16
15
  @e = OpenSRS::XmlProcessor::Libxml.encode_data([1,2,3])
17
16
  end
18
-
17
+
19
18
  it "is a REXML::Element" do
20
19
  @e.should be_an_instance_of(LibXML::XML::Node)
21
20
  end
@@ -57,12 +56,12 @@ describe OpenSRS::XmlProcessor::Libxml do
57
56
  @e.children[0].attributes["key"].should == 'name'
58
57
  end
59
58
  end
60
-
59
+
61
60
  context "on a nested hash" do
62
61
  before(:each) do
63
62
  @e = OpenSRS::XmlProcessor::Libxml.encode_data({:suggestion => {:maximum => "10"}})
64
63
  end
65
-
64
+
66
65
  it "is a REXML::Element" do
67
66
  @e.should be_an_instance_of(LibXML::XML::Node)
68
67
  end
@@ -70,17 +69,17 @@ describe OpenSRS::XmlProcessor::Libxml do
70
69
  it "is a dt_assoc" do
71
70
  @e.name.should == 'dt_assoc'
72
71
  end
73
-
72
+
74
73
  it "has an <item> child with the correct children" do
75
74
  @e.should have(1).children
76
75
  suggestion = @e.children[0]
77
76
  suggestion.name.should == 'item'
78
77
  suggestion.attributes["key"].should == 'suggestion'
79
-
78
+
80
79
  suggestion.should have(1).children
81
80
  dt_assoc = suggestion.children[0]
82
81
  dt_assoc.name.should == 'dt_assoc'
83
-
82
+
84
83
  dt_assoc.should have(1).children
85
84
  maximum = dt_assoc.children[0]
86
85
  maximum.name.should == 'item'
@@ -131,11 +130,11 @@ describe OpenSRS::XmlProcessor::Libxml do
131
130
  </data_block>
132
131
  </body>
133
132
  </OPS_envelope>}
134
-
133
+
135
134
  resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
136
135
  resp.should == "Tom Jones"
137
136
  end
138
-
137
+
139
138
  it "should handle associate arrays with arrays of values" do
140
139
  xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
141
140
  <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
@@ -153,18 +152,18 @@ describe OpenSRS::XmlProcessor::Libxml do
153
152
  <item key='2'>ns3.example.com</item>
154
153
  </dt_array>
155
154
  </item>
156
- </dt_assoc>
155
+ </dt_assoc>
157
156
  </data_block>
158
157
  </body>
159
158
  </OPS_envelope>}
160
-
159
+
161
160
  resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
162
161
  resp["domain_list"].class.should == Array
163
162
  resp["domain_list"][0].should == "ns1.example.com"
164
163
  resp["domain_list"][1].should == "ns2.example.com"
165
164
  resp["domain_list"][2].should == "ns3.example.com"
166
165
  end
167
-
166
+
168
167
  it "should handle associative arrays containing other associative arrays" do
169
168
  xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
170
169
  <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
@@ -181,7 +180,7 @@ describe OpenSRS::XmlProcessor::Libxml do
181
180
  <dt_assoc>
182
181
  <item key='first_name'>Tom</item>
183
182
  <item key='last_name'>Jones</item>
184
- </dt_assoc>
183
+ </dt_assoc>
185
184
  </item>
186
185
  <item key='tech'>
187
186
  <dt_assoc>
@@ -193,17 +192,17 @@ describe OpenSRS::XmlProcessor::Libxml do
193
192
  </item>
194
193
  </dt_assoc>
195
194
  </data_block>
196
- </body>
195
+ </body>
197
196
  </OPS_envelope>}
198
-
197
+
199
198
  resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
200
-
199
+
201
200
  resp["contact_set"]["owner"]["first_name"].should == "Tom"
202
201
  resp["contact_set"]["owner"]["last_name"].should == "Jones"
203
202
  resp["contact_set"]["tech"]["first_name"].should == "Anne"
204
203
  resp["contact_set"]["tech"]["last_name"].should == "Smith"
205
204
  end
206
-
205
+
207
206
  context "with a balance enquiry example response" do
208
207
  before(:each) do
209
208
  xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
@@ -231,7 +230,7 @@ describe OpenSRS::XmlProcessor::Libxml do
231
230
  </data_block>
232
231
  </body>
233
232
  </OPS_envelope>}
234
-
233
+
235
234
  @resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
236
235
  end
237
236
 
@@ -251,4 +250,4 @@ describe OpenSRS::XmlProcessor::Libxml do
251
250
  end
252
251
  end
253
252
  end
254
- end
253
+ end
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
2
1
  require 'date'
3
2
 
3
+ class OrderedHash < Hash
4
+ end
5
+
4
6
  describe OpenSRS::XmlProcessor::Nokogiri do
5
7
  describe ".build" do
6
8
  it "should create XML for a nested hash" do
@@ -11,7 +13,7 @@ describe OpenSRS::XmlProcessor::Nokogiri do
11
13
  end
12
14
 
13
15
  describe '.encode_data' do
14
-
16
+
15
17
  before(:each) do
16
18
  @builder = ::Nokogiri::XML::Builder.new
17
19
  @doc = @builder.doc
@@ -48,6 +50,22 @@ describe OpenSRS::XmlProcessor::Nokogiri do
48
50
  it { @e.children[0].attributes["key"].value.should eql('name') }
49
51
  end
50
52
 
53
+ context "on a hash subclass" do
54
+ before(:each) do
55
+ ohash = OrderedHash.new
56
+ ohash[:name] = 'kitten'
57
+ @e = OpenSRS::XmlProcessor::Nokogiri.encode_data(ohash, @doc)
58
+ end
59
+
60
+ it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
61
+ it { @e.name.should eql('dt_assoc') }
62
+
63
+ it { @e.should have(1).children }
64
+ it { @e.children[0].name.should eql('item') }
65
+ it { @e.children[0].attributes["key"].value.should eql('name') }
66
+ end
67
+
68
+
51
69
  context "on a nested hash" do
52
70
  before(:each) do
53
71
  @e = OpenSRS::XmlProcessor::Nokogiri.encode_data({:suggestion => {:maximum => "10"}}, @doc)
@@ -92,7 +110,7 @@ describe OpenSRS::XmlProcessor::Nokogiri do
92
110
  end
93
111
 
94
112
  describe '.parse' do
95
-
113
+
96
114
  context "when scaler values" do
97
115
  before(:each) do
98
116
  xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
@@ -225,4 +243,4 @@ describe OpenSRS::XmlProcessor::Nokogiri do
225
243
 
226
244
  end
227
245
  end
228
- end
246
+ end
@@ -1,6 +1,23 @@
1
- require 'opensrs/xml_processor.rb'
2
- require 'opensrs/xml_processor/libxml.rb'
3
- require 'opensrs/xml_processor/nokogiri.rb'
4
- require 'opensrs/server.rb'
5
- require 'opensrs/version.rb'
6
- require 'opensrs/response.rb'
1
+ require 'bundler/setup'
2
+
3
+ Bundler.setup
4
+
5
+ require 'opensrs'
6
+
7
+ RSpec.configure do |config|
8
+ # config for rspec!
9
+ end
10
+
11
+ class OpenSRS::TestLogger
12
+
13
+ attr_reader :messages
14
+
15
+ def initialize
16
+ @messages = []
17
+ end
18
+
19
+ def info(message)
20
+ messages << message
21
+ end
22
+
23
+ end
metadata CHANGED
@@ -1,126 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
- - Josh Delsman
7
+ - Joshua Delsman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libxml-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.6.0
19
+ version: '2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.6.0
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: nokogiri
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.6
33
+ version: '1.8'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.6
40
+ version: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
- name: jeweler
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: git
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: shoulda
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: shoulda
84
+ name: nokogiri
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: '2.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: '2.0'
111
- description: Provides support to utilize the OpenSRS API with Ruby/Rails.
112
- email: jdelsman@voxxit.com
97
+ description: Provides support to utilize the OpenSRS API with Ruby.
98
+ email:
99
+ - j@srv.im
113
100
  executables: []
114
101
  extensions: []
115
- extra_rdoc_files:
116
- - LICENSE
117
- - README.rdoc
102
+ extra_rdoc_files: []
118
103
  files:
119
- - .document
104
+ - ".document"
105
+ - ".gitignore"
106
+ - ".rspec"
120
107
  - Gemfile
121
108
  - Gemfile.lock
122
- - LICENSE
123
- - README.rdoc
109
+ - LICENSE.txt
110
+ - README.md
124
111
  - Rakefile
125
112
  - lib/opensrs.rb
126
113
  - lib/opensrs/response.rb
@@ -135,7 +122,7 @@ files:
135
122
  - spec/opensrs/xml_processor/libxml_spec.rb
136
123
  - spec/opensrs/xml_processor/nokogiri_spec.rb
137
124
  - spec/spec_helper.rb
138
- homepage: http://github.com/voxxit/opensrs
125
+ homepage: https://github.com/voxxit/opensrs
139
126
  licenses:
140
127
  - MIT
141
128
  metadata: {}
@@ -145,18 +132,23 @@ require_paths:
145
132
  - lib
146
133
  required_ruby_version: !ruby/object:Gem::Requirement
147
134
  requirements:
148
- - - '>='
135
+ - - ">="
149
136
  - !ruby/object:Gem::Version
150
137
  version: '0'
151
138
  required_rubygems_version: !ruby/object:Gem::Requirement
152
139
  requirements:
153
- - - '>='
140
+ - - ">="
154
141
  - !ruby/object:Gem::Version
155
142
  version: '0'
156
143
  requirements: []
157
144
  rubyforge_project:
158
- rubygems_version: 2.0.0
145
+ rubygems_version: 2.4.5
159
146
  signing_key:
160
- specification_version: 3
161
- summary: Provides support to utilize the OpenSRS API with Ruby/Rails.
162
- test_files: []
147
+ specification_version: 4
148
+ summary: OpenSRS API for Ruby
149
+ test_files:
150
+ - spec/opensrs/server_spec.rb
151
+ - spec/opensrs/version_spec.rb
152
+ - spec/opensrs/xml_processor/libxml_spec.rb
153
+ - spec/opensrs/xml_processor/nokogiri_spec.rb
154
+ - spec/spec_helper.rb
@@ -1,105 +0,0 @@
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]
5
-
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
7
- environments. More information on the API can be located here:
8
-
9
- http://www.opensrs.com/site/resources/documentation/api
10
-
11
- == Installation
12
-
13
- You can install this gem by doing the following:
14
-
15
- $ gem install opensrs
16
-
17
- You can then include it in a Ruby project, like so:
18
-
19
- require 'opensrs'
20
-
21
- Alternatively, you can include it in a Rails 2.x project in the <tt>environment.rb</tt> file, like so:
22
-
23
- config.gem "opensrs"
24
-
25
- For Rails 3.x, use the <tt>Gemfile</tt>:
26
-
27
- gem "opensrs"
28
-
29
- == Usage
30
-
31
- This library provides basic functionality for interacting with the OpenSRS XML API.
32
-
33
- * Connection handling
34
- * Error reporting
35
- * XML encoding
36
- * XML decoding
37
-
38
- Currently, the library supports LibXML and Nokogiri as XML parsers. By default, it uses LibXML to parse and generate XML. If you'd like to use Nokogiri (1.4.7 and below) for parsing XML, then in one of your app initializers add the following line:
39
-
40
- OpenSRS::Server.xml_processor = :nokogiri
41
-
42
- To connect, instantiate a new <tt>OpenSRS::Server</tt> object:
43
-
44
- server = OpenSRS::Server.new(
45
- :server => "https://rr-n1-tor.opensrs.net:55443/",
46
- :username => "testing",
47
- :password => "53cr3t",
48
- :key => "c633be3170c7fb3fb29e2f99b84be2410..."
49
- )
50
-
51
- NOTE: Connecting to OpenSRS requires that you add the IP(s) you're connecting from to their whitelist. Login to the testing or production servers, and add your IP(s) under Profile Management > Add IPs for Script/API Access. IP changes take about one hour to take effect.
52
-
53
- Once you have a server connection class, you can build from this to create the methods that you need. For instance, let's say we want to grab our account balance. The OpenSRS XML API takes a couple of attributes for all commands. You can include those here:
54
-
55
- def get_balance
56
- server.call(
57
- :action => "GET_BALANCE",
58
- :object => "BALANCE"
59
- )
60
- end
61
-
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:
63
-
64
- def create_nameserver(nameserver)
65
- server.call(
66
- :action => "CREATE",
67
- :object => "NAMESERVER",
68
- :cookie => "366828736:3210384",
69
- :attributes => {
70
- :name => nameserver.hostname,
71
- :ipaddress => "212.112.123.11"
72
- }
73
- )
74
- end
75
-
76
- Responses from OpenSRS are returned in an OpenSRS::Response object, which gives you access to a multitude of things.
77
-
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.
79
- * <tt>response.errors</tt> - If there are errors which come back from OpenSRS, they are returned here. If not, it returns nil.
80
- * <tt>response.success?</tt> - Returns true if the response was labeled as successful. If not, it returns false.
81
- * <tt>response.request_xml</tt> - Returns raw request XML.
82
- * <tt>response.response_xml</tt> - Returns raw response XML.
83
-
84
- == Bugs/Feature Requests
85
-
86
- If you have any bugs or feature requests for this gem, feel free to add them in the Issues portion of the GitHub repository here:
87
-
88
- http://github.com/voxxit/opensrs/issues
89
-
90
- == Note on Patches/Pull Requests
91
-
92
- * Fork the project.
93
- * Make your feature addition or bug fix.
94
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
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.
96
- * Send me a pull request. Bonus points for topic branches.
97
-
98
- == Contributors (in order of appearance)
99
-
100
- * Josh Delsman
101
- * Glenn Roberts
102
-
103
- == Copyright
104
-
105
- Copyright (c) 2010-2013 Josh Delsman. Distributed under the MIT license. See LICENSE for details.