opensrs 0.3.5 → 0.3.6

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: cef55dd62d0db183b1f6e3e85518268695882e8d
4
- data.tar.gz: 1a195f62bdb2cd02ba0c9d6b4d90a7392ea4c386
3
+ metadata.gz: 859e3e67b33ab3a4c5f7c071531a409e16048650
4
+ data.tar.gz: ca25ef41d7a29a3f8bd1b491a022c4af1135caf1
5
5
  SHA512:
6
- metadata.gz: 09f10fb90e00cc9b43e990a4fa2255b4cd3193533faa5d31064d3197f794f50cf20024f749dbb3a44d954df1d4066075a2e0af2718c4e35e32d2c08a29316d28
7
- data.tar.gz: 90d8ba319a32a30764a8ccb1456a29286b5ae8ab2448a5f8e6f3c36635a8a79e6c628e3dbdd25dd2a77ac307428867d45893425b2e9926c82e49888652231abc
6
+ metadata.gz: 783c86e4637b6f6ba6f4c12e4519118e42e3c4e700c2ccf2ad702021ebe569d3a62e419f167827e74176ea1b2892cbd78d6768fcf94f73ee88c4fd8180d093ed
7
+ data.tar.gz: 8d271520d7d262eb3c11cf5645d3849e1f03ebfcf727fe4c1f2043d800a9dfdac745dd7d4f7b04d6d2fd9152daa05f7d1c630ade248d6a8f32c6b12b07916503
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "opensrs"
5
+
6
+ require "pry"
7
+ Pry.start
8
+
9
+ require "irb"
10
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -1,8 +1,8 @@
1
- require File.dirname(__FILE__) + '/opensrs/xml_processor'
2
- require File.dirname(__FILE__) + '/opensrs/xml_processor/libxml.rb'
3
- require File.dirname(__FILE__) + '/opensrs/server.rb'
4
- require File.dirname(__FILE__) + '/opensrs/response.rb'
5
- require File.dirname(__FILE__) + '/opensrs/version.rb'
1
+ require "opensrs/xml_processor"
2
+ require "opensrs/xml_processor/libxml"
3
+ require "opensrs/server"
4
+ require "opensrs/response"
5
+ require "opensrs/version"
6
6
 
7
7
  module OpenSRS
8
- end
8
+ end
@@ -2,28 +2,30 @@ module OpenSRS
2
2
  class Response
3
3
  attr_reader :request_xml, :response_xml
4
4
  attr_accessor :response, :success
5
-
5
+
6
6
  def initialize(parsed_response, request_xml, response_xml)
7
7
  @response = parsed_response
8
8
  @request_xml = request_xml
9
9
  @response_xml = response_xml
10
10
  @success = success?
11
11
  end
12
-
12
+
13
13
  # We need to return the error message unless the
14
14
  # response is successful.
15
15
  def errors
16
- if !success?
17
- if response["response_text"] and response["response_code"]
18
- "#{response["response_text"]} (Code #{response["response_code"]})"
19
- else
20
- "Unknown error"
21
- end
16
+ unless success?
17
+ msg = @response["response_text"]
18
+ code = @response["response_code"]
19
+
20
+ return msg && code ? "#{msg} (Code #{code})" : "Unknown error"
22
21
  end
23
22
  end
24
-
23
+
24
+ # If 'is_success' is returned, the API is letting us know that they
25
+ # will explicitly tell us whether something has succeeded or not.
26
+ # Otherwise, just assume it is successful.
25
27
  def success?
26
- response["is_success"] ? response["is_success"].to_s == "1" : true
28
+ @response["is_success"] && @response["is_success"] == "1" ? true : false
27
29
  end
28
30
  end
29
- end
31
+ end
@@ -19,7 +19,7 @@ module OpenSRS
19
19
  @password = options[:password]
20
20
  @key = options[:key]
21
21
  @timeout = options[:timeout]
22
- @open_timeout = options[:open_timeout]
22
+ @open_timeout = options[:open_timeout]
23
23
  @logger = options[:logger]
24
24
  end
25
25
 
@@ -47,7 +47,7 @@ module OpenSRS
47
47
  end
48
48
 
49
49
  def self.xml_processor=(name)
50
- require File.dirname(__FILE__) + "/xml_processor/#{name.to_s.downcase}"
50
+ require "opensrs/xml_processor/#{name.to_s.downcase}"
51
51
  @@xml_processor = OpenSRS::XmlProcessor.const_get("#{name.to_s.capitalize}")
52
52
  end
53
53
 
@@ -56,7 +56,8 @@ module OpenSRS
56
56
  private
57
57
 
58
58
  def headers(request)
59
- { "Content-Length" => request.length.to_s,
59
+ {
60
+ "Content-Length" => request.length.to_s,
60
61
  "Content-Type" => "text/xml",
61
62
  "X-Username" => username,
62
63
  "X-Signature" => signature(request)
@@ -64,9 +65,7 @@ module OpenSRS
64
65
  end
65
66
 
66
67
  def signature(request)
67
- signature = Digest::MD5.hexdigest(request + key)
68
- signature = Digest::MD5.hexdigest(signature + key)
69
- signature
68
+ Digest::MD5.hexdigest(Digest::MD5.hexdigest(request + key) + key)
70
69
  end
71
70
 
72
71
  def http
@@ -1,5 +1,3 @@
1
1
  module OpenSRS
2
- class Version
3
- VERSION = "0.3.5"
4
- end
2
+ VERSION = "0.3.6"
5
3
  end
@@ -1,5 +1,4 @@
1
1
  module OpenSRS
2
-
3
2
  class XmlProcessor
4
3
 
5
4
  # Parses the main data block from OpenSRS and discards
@@ -71,5 +70,4 @@ module OpenSRS
71
70
  end
72
71
 
73
72
  end
74
-
75
73
  end
@@ -1,60 +1,67 @@
1
- require "libxml"
1
+ begin
2
+ require 'libxml'
3
+ rescue LoadError => e
4
+ $stderr.puts "Cannot find `libxml` gem. Please install it before using it as the XML processor"
5
+ raise e
6
+ end
2
7
 
3
8
  module OpenSRS
4
- class XmlProcessor::Libxml < OpenSRS::XmlProcessor
5
- include ::LibXML::XML
6
-
7
- # First, builds REXML elements for the inputted data. Then, it will
8
- # go ahead and build the entire XML document to send to OpenSRS.
9
- def self.build(data)
10
- xml = Document.new
11
- xml.root = envelope = Node.new("OPS_envelope")
12
-
13
- envelope << header = Node.new("header")
14
- envelope << body = Node.new("body")
15
- header << Node.new("version", "0.9")
16
- body << data_block = Node.new("data_block")
17
-
18
- data_block << encode_data(data, data_block)
19
-
20
- return xml.to_s
21
- end
9
+ class XmlProcessor
10
+ class Libxml < OpenSRS::XmlProcessor
11
+ include ::LibXML::XML
22
12
 
23
- protected
13
+ # First, builds REXML elements for the inputted data. Then, it will
14
+ # go ahead and build the entire XML document to send to OpenSRS.
15
+ def self.build(data)
16
+ xml = Document.new
17
+ xml.root = envelope = Node.new("OPS_envelope")
24
18
 
25
- def self.data_block_element(response)
26
- doc = Parser.string(response).parse
27
- return doc.find("//OPS_envelope/body/data_block/*")
28
- end
19
+ envelope << header = Node.new("header")
20
+ envelope << body = Node.new("body")
21
+ header << Node.new("version", "0.9")
22
+ body << data_block = Node.new("data_block")
29
23
 
30
- def self.decode_dt_array_data(element)
31
- dt_array = []
24
+ data_block << encode_data(data, data_block)
32
25
 
33
- element.children.each do |item|
34
- next if item.empty?
35
- dt_array[item.attributes["key"].to_i] = decode_data(item)
26
+ return xml.to_s
36
27
  end
37
28
 
38
- return dt_array
39
- end
29
+ protected
40
30
 
41
- def self.decode_dt_assoc_data(element)
42
- dt_assoc = {}
31
+ def self.data_block_element(response)
32
+ doc = Parser.string(response).parse
33
+ return doc.find("//OPS_envelope/body/data_block/*")
34
+ end
43
35
 
44
- element.children.each do |item|
45
- next if item.content.strip.empty?
46
- dt_assoc[item.attributes["key"]] = decode_data(item)
36
+ def self.decode_dt_array_data(element)
37
+ dt_array = []
38
+
39
+ element.children.each do |item|
40
+ next if item.empty?
41
+ dt_array[item.attributes["key"].to_i] = decode_data(item)
42
+ end
43
+
44
+ return dt_array
47
45
  end
48
46
 
49
- return dt_assoc
50
- end
47
+ def self.decode_dt_assoc_data(element)
48
+ dt_assoc = {}
51
49
 
52
- # Accepts two parameters but uses only one; to keep the interface same as other xml parser classes
53
- # Is that a side effect of Template pattern?
54
- #
55
- def self.new_element(element_name, container)
56
- return Node.new(element_name.to_s)
57
- end
50
+ element.children.each do |item|
51
+ next if item.content.strip.empty?
52
+ dt_assoc[item.attributes["key"]] = decode_data(item)
53
+ end
54
+
55
+ return dt_assoc
56
+ end
58
57
 
58
+ # Accepts two parameters but uses only one; to keep the interface same as other xml parser classes
59
+ # Is that a side effect of Template pattern?
60
+ #
61
+ def self.new_element(element_name, container)
62
+ return Node.new(element_name.to_s)
63
+ end
64
+
65
+ end
59
66
  end
60
- end
67
+ end
@@ -1,64 +1,66 @@
1
1
  begin
2
2
  require 'nokogiri'
3
3
  rescue LoadError => e
4
- $stderr.puts "Cannot find Nokogiri gem. Please install Nokogiri before using it as the xml processor\n\n"
4
+ $stderr.puts "Cannot find `nokogiri` gem. Please install it before using it as the XML processor"
5
5
  raise e
6
6
  end
7
7
 
8
8
  module OpenSRS
9
- class XmlProcessor::Nokogiri < OpenSRS::XmlProcessor
9
+ class XmlProcessor
10
+ class Nokogiri < OpenSRS::XmlProcessor
10
11
 
11
- def self.build(data)
12
- builder = ::Nokogiri::XML::Builder.new
12
+ def self.build(data)
13
+ builder = ::Nokogiri::XML::Builder.new
13
14
 
14
- envelope = ::Nokogiri::XML::Node.new("OPS_envelope", builder.doc)
15
- header = ::Nokogiri::XML::Node.new("header", builder.doc)
16
- version = ::Nokogiri::XML::Node.new("version", builder.doc)
17
- body = ::Nokogiri::XML::Node.new("body", builder.doc)
18
- data_block = ::Nokogiri::XML::Node.new("data_block", builder.doc)
19
- other_data = encode_data(data, builder.doc)
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
27
- return builder.to_xml
28
- end
15
+ envelope = ::Nokogiri::XML::Node.new("OPS_envelope", builder.doc)
16
+ header = ::Nokogiri::XML::Node.new("header", builder.doc)
17
+ version = ::Nokogiri::XML::Node.new("version", builder.doc)
18
+ body = ::Nokogiri::XML::Node.new("body", builder.doc)
19
+ data_block = ::Nokogiri::XML::Node.new("data_block", builder.doc)
20
+ other_data = encode_data(data, builder.doc)
21
+ version << '0.9'
22
+ header << version
23
+ envelope << header
24
+ builder.doc << envelope
25
+ data_block << other_data
26
+ body << data_block
27
+ envelope << body
28
+ return builder.to_xml
29
+ end
29
30
 
30
- protected
31
+ protected
31
32
 
32
- def self.data_block_element(response)
33
- doc = ::Nokogiri::XML(response)
34
- return doc.xpath('//OPS_envelope/body/data_block/*')
35
- end
33
+ def self.data_block_element(response)
34
+ doc = ::Nokogiri::XML(response)
35
+ return doc.xpath('//OPS_envelope/body/data_block/*')
36
+ end
37
+
38
+ def self.decode_dt_array_data(element)
39
+ dt_array = []
36
40
 
37
- def self.decode_dt_array_data(element)
38
- dt_array = []
41
+ element.children.each do |item|
42
+ next if item.content.strip.empty?
43
+ dt_array[item.attributes["key"].value.to_i] = decode_data(item.children)
44
+ end
39
45
 
40
- element.children.each do |item|
41
- next if item.content.strip.empty?
42
- dt_array[item.attributes["key"].value.to_i] = decode_data(item.children)
46
+ return dt_array
43
47
  end
44
48
 
45
- return dt_array
46
- end
49
+ def self.decode_dt_assoc_data(element)
50
+ dt_assoc = {}
47
51
 
48
- def self.decode_dt_assoc_data(element)
49
- dt_assoc = {}
52
+ element.children.each do |item|
53
+ next if item.content.strip.empty?
54
+ dt_assoc[item.attributes["key"].value] = decode_data(item.children)
55
+ end
50
56
 
51
- element.children.each do |item|
52
- next if item.content.strip.empty?
53
- dt_assoc[item.attributes["key"].value] = decode_data(item.children)
57
+ return dt_assoc
54
58
  end
55
59
 
56
- return dt_assoc
57
- end
60
+ def self.new_element(element_name, container)
61
+ return ::Nokogiri::XML::Node.new(element_name.to_s, container)
62
+ end
58
63
 
59
- def self.new_element(element_name, container)
60
- return ::Nokogiri::XML::Node.new(element_name.to_s, container)
61
64
  end
62
-
63
65
  end
64
66
  end
@@ -1,15 +1,12 @@
1
1
  # coding: utf-8
2
-
3
2
  lib = File.expand_path('../lib', __FILE__)
4
-
5
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
-
7
- require 'opensrs/version'
4
+ require "opensrs/version"
8
5
 
9
6
  Gem::Specification.new do |spec|
10
7
 
11
8
  spec.name = "opensrs"
12
- spec.version = OpenSRS::Version::VERSION
9
+ spec.version = OpenSRS::VERSION
13
10
  spec.authors = [ "Joshua Delsman" ]
14
11
  spec.email = [ "j@srv.im" ]
15
12
  spec.summary = "OpenSRS API for Ruby"
@@ -17,17 +14,18 @@ Gem::Specification.new do |spec|
17
14
  spec.homepage = "https://github.com/voxxit/opensrs"
18
15
  spec.license = "MIT"
19
16
 
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" ]
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
24
21
 
25
22
  spec.add_runtime_dependency "libxml-ruby", "~> 2"
26
23
 
27
- spec.add_development_dependency "bundler", "~> 1.8"
24
+ spec.add_development_dependency "bundler"
28
25
  spec.add_development_dependency "rake"
29
- spec.add_development_dependency "rspec", "~> 2.0"
26
+ spec.add_development_dependency "rspec"
30
27
  spec.add_development_dependency "shoulda"
31
28
  spec.add_development_dependency "nokogiri"
29
+ spec.add_development_dependency "pry"
32
30
 
33
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Delsman
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libxml-ruby
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.8'
33
+ version: '0'
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.8'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '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: '2.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: shoulda
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Provides support to utilize the OpenSRS API with Ruby.
98
112
  email:
99
113
  - j@srv.im
@@ -109,6 +123,8 @@ files:
109
123
  - LICENSE.txt
110
124
  - README.md
111
125
  - Rakefile
126
+ - bin/console
127
+ - bin/setup
112
128
  - lib/opensrs.rb
113
129
  - lib/opensrs/response.rb
114
130
  - lib/opensrs/server.rb
@@ -117,11 +133,6 @@ files:
117
133
  - lib/opensrs/xml_processor/libxml.rb
118
134
  - lib/opensrs/xml_processor/nokogiri.rb
119
135
  - opensrs.gemspec
120
- - spec/opensrs/server_spec.rb
121
- - spec/opensrs/version_spec.rb
122
- - spec/opensrs/xml_processor/libxml_spec.rb
123
- - spec/opensrs/xml_processor/nokogiri_spec.rb
124
- - spec/spec_helper.rb
125
136
  homepage: https://github.com/voxxit/opensrs
126
137
  licenses:
127
138
  - MIT
@@ -146,9 +157,4 @@ rubygems_version: 2.4.5
146
157
  signing_key:
147
158
  specification_version: 4
148
159
  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
160
+ test_files: []
@@ -1,139 +0,0 @@
1
- describe OpenSRS::Server do
2
- let(:server) { OpenSRS::Server.new }
3
-
4
- describe '#new' do
5
- it 'allows timeouts to be set' do
6
- server = OpenSRS::Server.new({ :timeout => 90 })
7
- server.timeout.should == 90
8
- server.open_timeout.should be_nil
9
- end
10
-
11
- it 'allows open timeouts to be set' do
12
- server = OpenSRS::Server.new({ :timeout => 90, :open_timeout => 10 })
13
- server.timeout.should eq(90)
14
- server.open_timeout.should eq(10)
15
- end
16
-
17
- it 'leaves it up to Net::HTTP if no timeouts given' do
18
- server.timeout.should be_nil
19
- server.open_timeout.should be_nil
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
27
- end
28
-
29
- describe ".call" do
30
- let(:response) { double(:body => 'some response') }
31
- let(:header) { {"some" => "header" } }
32
- let(:xml) { '<some xml></some xml>' }
33
- let(:response_xml) { xml }
34
- let(:xml_processor) { double OpenSRS::XmlProcessor }
35
- let(:http) { double(Net::HTTP, :use_ssl= => true, :verify_mode= => true) }
36
-
37
- before :each do
38
- server.stub(:headers).and_return header
39
- xml_processor.stub(:build).and_return xml
40
- xml_processor.stub(:parse).and_return response_xml
41
- server.stub(:xml_processor).and_return xml_processor
42
- http.stub(:post).and_return response
43
- Net::HTTP.stub(:new).and_return http
44
- end
45
-
46
- it "builds XML request" do
47
- xml_processor.should_receive(:build).with(:protocol => "XCP", :some => 'option')
48
- server.call(:some => 'option')
49
- end
50
-
51
- it "posts to given path" do
52
- server.server = URI.parse 'http://with-path.com/endpoint'
53
- http.should_receive(:post).with('/endpoint', xml, header).and_return double.as_null_object
54
- server.call
55
- end
56
-
57
- it "parses the response" do
58
- xml_processor.should_receive(:parse).with(response.body)
59
- server.call(:some => 'option')
60
- end
61
-
62
- it "posts to root path" do
63
- server.server = URI.parse 'http://root-path.com/'
64
- http.should_receive(:post).with('/', xml, header).and_return double.as_null_object
65
- server.call
66
- end
67
-
68
- it "defaults path to '/'" do
69
- server.server = URI.parse 'http://no-path.com'
70
- http.should_receive(:post).with('/', xml, header).and_return double.as_null_object
71
- server.call
72
- end
73
-
74
- it 'allows overriding of default (Net:HTTP) timeouts' do
75
- server.timeout = 90
76
-
77
- http.should_receive(:open_timeout=).with(90)
78
- http.should_receive(:read_timeout=).with(90)
79
-
80
- server.call( { :some => 'data' } )
81
- end
82
-
83
- it 'allows overriding of default (Net:HTTP) timeouts' do
84
- server.timeout = 180
85
- server.open_timeout = 30
86
-
87
- http.should_receive(:read_timeout=).with(180)
88
- http.should_receive(:open_timeout=).with(180)
89
- http.should_receive(:open_timeout=).with(30)
90
-
91
- server.call( { :some => 'data' } )
92
- end
93
-
94
- it 're-raises Net:HTTP timeouts' do
95
- http.should_receive(:post).and_raise err = Timeout::Error.new('test')
96
- expect { server.call }.to raise_exception OpenSRS::TimeoutError
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
124
- end
125
-
126
- describe "#test xml processor" do
127
- context "on class initialization" do
128
- it { server.xml_processor.should eql(OpenSRS::XmlProcessor::Libxml) }
129
- end
130
-
131
- context "on changing xml processor" do
132
- before(:each) do
133
- OpenSRS::Server.xml_processor = :nokogiri
134
- end
135
-
136
- it { server.xml_processor.should eql(OpenSRS::XmlProcessor::Nokogiri) }
137
- end
138
- end
139
- end
@@ -1,7 +0,0 @@
1
- describe OpenSRS::Version do
2
- describe "VERSION" do
3
- it "should return version string" do
4
- OpenSRS::Version::VERSION.should eql("0.3.4")
5
- end
6
- end
7
- end
@@ -1,253 +0,0 @@
1
- require 'date'
2
-
3
- describe OpenSRS::XmlProcessor::Libxml do
4
- describe ".build" do
5
- it "should create XML for a nested hash" do
6
- attributes = {:foo => {:bar => 'baz'}}
7
- xml = OpenSRS::XmlProcessor::Libxml.build(attributes)
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}
9
- end
10
- end
11
-
12
- describe '.encode_data' do
13
- context "on a 3 element array" do
14
- before(:each) do
15
- @e = OpenSRS::XmlProcessor::Libxml.encode_data([1,2,3])
16
- end
17
-
18
- it "is a REXML::Element" do
19
- @e.should be_an_instance_of(LibXML::XML::Node)
20
- end
21
-
22
- it "is a dt_array" do
23
- @e.name.should == 'dt_array'
24
- end
25
-
26
- it "has 3 children all called <item>" do
27
- @e.should have(3).children
28
- @e.children[0].name.should == "item"
29
- @e.children[1].name.should == "item"
30
- @e.children[2].name.should == "item"
31
- end
32
-
33
- it "has children with keys 0, 1 and 2" do
34
- @e.children[0].attributes["key"].should == "0"
35
- @e.children[1].attributes["key"].should == "1"
36
- @e.children[2].attributes["key"].should == "2"
37
- end
38
- end
39
-
40
- context "on a hash" do
41
- before(:each) do
42
- @e = OpenSRS::XmlProcessor::Libxml.encode_data({:name => "kitteh"})
43
- end
44
-
45
- it "is a REXML::Element" do
46
- @e.should be_an_instance_of(LibXML::XML::Node)
47
- end
48
-
49
- it "is a dt_assoc" do
50
- @e.name.should == 'dt_assoc'
51
- end
52
-
53
- it "has an <item> child with the right key" do
54
- @e.should have(1).children
55
- @e.children[0].name.should == 'item'
56
- @e.children[0].attributes["key"].should == 'name'
57
- end
58
- end
59
-
60
- context "on a nested hash" do
61
- before(:each) do
62
- @e = OpenSRS::XmlProcessor::Libxml.encode_data({:suggestion => {:maximum => "10"}})
63
- end
64
-
65
- it "is a REXML::Element" do
66
- @e.should be_an_instance_of(LibXML::XML::Node)
67
- end
68
-
69
- it "is a dt_assoc" do
70
- @e.name.should == 'dt_assoc'
71
- end
72
-
73
- it "has an <item> child with the correct children" do
74
- @e.should have(1).children
75
- suggestion = @e.children[0]
76
- suggestion.name.should == 'item'
77
- suggestion.attributes["key"].should == 'suggestion'
78
-
79
- suggestion.should have(1).children
80
- dt_assoc = suggestion.children[0]
81
- dt_assoc.name.should == 'dt_assoc'
82
-
83
- dt_assoc.should have(1).children
84
- maximum = dt_assoc.children[0]
85
- maximum.name.should == 'item'
86
- maximum.attributes["key"].should == 'maximum'
87
- end
88
- end
89
-
90
- context "produces a scalar" do
91
- it "from a string" do
92
- OpenSRS::XmlProcessor::Libxml.encode_data("cheezburger").to_s.should == "cheezburger"
93
- end
94
-
95
- it "from a string with XML characters" do
96
- OpenSRS::XmlProcessor::Libxml.encode_data("<smile>").to_s.should == "<smile>"
97
- end
98
-
99
- it "from an integer" do
100
- OpenSRS::XmlProcessor::Libxml.encode_data(12345).to_s.should == "12345"
101
- end
102
-
103
- it "from a date" do
104
- date = Date.parse("2010/02/12")
105
- OpenSRS::XmlProcessor::Libxml.encode_data(date).to_s.should == "2010-02-12"
106
- end
107
-
108
- it "from a symbol" do
109
- OpenSRS::XmlProcessor::Libxml.encode_data(:name).to_s.should == "name"
110
- end
111
-
112
- it "from true or false" do
113
- OpenSRS::XmlProcessor::Libxml.encode_data(true).to_s.should == "true"
114
- OpenSRS::XmlProcessor::Libxml.encode_data(false).to_s.should == "false"
115
- end
116
- end
117
- end
118
-
119
- describe '.parse' do
120
- it "should handle scalar values" do
121
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
122
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
123
- <OPS_envelope>
124
- <header>
125
- <version>1.0</version>
126
- </header>
127
- <body>
128
- <data_block>
129
- <dt_scalar>Tom Jones</dt_scalar>
130
- </data_block>
131
- </body>
132
- </OPS_envelope>}
133
-
134
- resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
135
- resp.should == "Tom Jones"
136
- end
137
-
138
- it "should handle associate arrays with arrays of values" do
139
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
140
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
141
- <OPS_envelope>
142
- <header>
143
- <version>1.0</version>
144
- </header>
145
- <body>
146
- <data_block>
147
- <dt_assoc>
148
- <item key='domain_list'>
149
- <dt_array>
150
- <item key='0'>ns1.example.com</item>
151
- <item key='1'>ns2.example.com</item>
152
- <item key='2'>ns3.example.com</item>
153
- </dt_array>
154
- </item>
155
- </dt_assoc>
156
- </data_block>
157
- </body>
158
- </OPS_envelope>}
159
-
160
- resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
161
- resp["domain_list"].class.should == Array
162
- resp["domain_list"][0].should == "ns1.example.com"
163
- resp["domain_list"][1].should == "ns2.example.com"
164
- resp["domain_list"][2].should == "ns3.example.com"
165
- end
166
-
167
- it "should handle associative arrays containing other associative arrays" do
168
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
169
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
170
- <OPS_envelope>
171
- <header>
172
- <version>1.0</version>
173
- </header>
174
- <body>
175
- <data_block>
176
- <dt_assoc>
177
- <item key="contact_set">
178
- <dt_assoc>
179
- <item key='owner'>
180
- <dt_assoc>
181
- <item key='first_name'>Tom</item>
182
- <item key='last_name'>Jones</item>
183
- </dt_assoc>
184
- </item>
185
- <item key='tech'>
186
- <dt_assoc>
187
- <item key='first_name'>Anne</item>
188
- <item key='last_name'>Smith</item>
189
- </dt_assoc>
190
- </item>
191
- </dt_assoc>
192
- </item>
193
- </dt_assoc>
194
- </data_block>
195
- </body>
196
- </OPS_envelope>}
197
-
198
- resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
199
-
200
- resp["contact_set"]["owner"]["first_name"].should == "Tom"
201
- resp["contact_set"]["owner"]["last_name"].should == "Jones"
202
- resp["contact_set"]["tech"]["first_name"].should == "Anne"
203
- resp["contact_set"]["tech"]["last_name"].should == "Smith"
204
- end
205
-
206
- context "with a balance enquiry example response" do
207
- before(:each) do
208
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
209
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
210
- <OPS_envelope>
211
- <header>
212
- <version>0.9</version>
213
- </header>
214
- <body>
215
- <data_block>
216
- <dt_assoc>
217
- <item key="protocol">XCP</item>
218
- <item key="action">REPLY</item>
219
- <item key="object">BALANCE</item>
220
- <item key="is_success">1</item>
221
- <item key="response_code">200</item>
222
- <item key="response_text">Command successful</item>
223
- <item key="attributes">
224
- <dt_assoc>
225
- <item key="balance">8549.18</item>
226
- <item key="hold_balance">1676.05</item>
227
- </dt_assoc>
228
- </item>
229
- </dt_assoc>
230
- </data_block>
231
- </body>
232
- </OPS_envelope>}
233
-
234
- @resp = OpenSRS::XmlProcessor::Libxml.parse(xml)
235
- end
236
-
237
- it "produces a hash" do
238
- @resp.should be_an_instance_of(Hash)
239
- end
240
-
241
- it "has top level keys" do
242
- @resp["protocol"].should == "XCP"
243
- @resp["action"].should == "REPLY"
244
- @resp["object"].should == "BALANCE"
245
- end
246
-
247
- it "has second level keys" do
248
- @resp["attributes"]["balance"].should == "8549.18"
249
- @resp["attributes"]["hold_balance"].should == "1676.05"
250
- end
251
- end
252
- end
253
- end
@@ -1,246 +0,0 @@
1
- require 'date'
2
-
3
- class OrderedHash < Hash
4
- end
5
-
6
- describe OpenSRS::XmlProcessor::Nokogiri do
7
- describe ".build" do
8
- it "should create XML for a nested hash" do
9
- attributes = {:foo => {:bar => 'baz'}}
10
- xml = OpenSRS::XmlProcessor::Nokogiri.build(attributes)
11
- xml.should eq %{<?xml version=\"1.0\"?>\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}
12
- end
13
- end
14
-
15
- describe '.encode_data' do
16
-
17
- before(:each) do
18
- @builder = ::Nokogiri::XML::Builder.new
19
- @doc = @builder.doc
20
- end
21
-
22
- context "on a 3 element array" do
23
- before(:each) do
24
- @e = OpenSRS::XmlProcessor::Nokogiri.encode_data([1,2,3], @doc)
25
- end
26
-
27
- it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
28
- it { @e.name.should eql('dt_array') }
29
-
30
- it { @e.should have(3).children }
31
- it { @e.children[0].name.should eql("item") }
32
- it { @e.children[1].name.should eql("item") }
33
- it { @e.children[2].name.should eql("item") }
34
-
35
- it { @e.children[0].attributes["key"].value.should eql("0") }
36
- it { @e.children[1].attributes["key"].value.should eql("1") }
37
- it { @e.children[2].attributes["key"].value.should eql("2") }
38
- end
39
-
40
- context "on a hash" do
41
- before(:each) do
42
- @e = OpenSRS::XmlProcessor::Nokogiri.encode_data({:name => "kitteh"}, @doc)
43
- end
44
-
45
- it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
46
- it { @e.name.should eql('dt_assoc') }
47
-
48
- it { @e.should have(1).children }
49
- it { @e.children[0].name.should eql('item') }
50
- it { @e.children[0].attributes["key"].value.should eql('name') }
51
- end
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
-
69
- context "on a nested hash" do
70
- before(:each) do
71
- @e = OpenSRS::XmlProcessor::Nokogiri.encode_data({:suggestion => {:maximum => "10"}}, @doc)
72
- @suggestion = @e.children[0]
73
- @dt_assoc = @suggestion.children[0]
74
- end
75
-
76
- it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
77
- it { @e.name.should == 'dt_assoc' }
78
-
79
- context "<item> child" do
80
- it { @e.should have(1).children }
81
- it { @suggestion.name.should eql('item') }
82
- it { @suggestion.attributes["key"].value.should eql('suggestion') }
83
- end
84
-
85
- context "suggesion children" do
86
- it { @suggestion.should have(1).children }
87
- it { @dt_assoc.name.should eql('dt_assoc') }
88
- end
89
-
90
- context "dt_assoc children" do
91
- before(:each) do
92
- @maximum = @dt_assoc.children[0]
93
- end
94
- it { @dt_assoc.should have(1).children }
95
- it { @maximum.name.should eql('item') }
96
- it { @maximum.attributes["key"].value.should eql('maximum') }
97
- end
98
- end
99
-
100
- context "produces a scalar" do
101
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data("cheezburger").to_s.should eql("cheezburger") }
102
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data("<smile>").to_s.should eql("<smile>") }
103
-
104
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(12345).to_s.should eql("12345") }
105
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(Date.parse("2010/02/12")).to_s.should eql("2010-02-12") }
106
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(:name).to_s.should eql("name") }
107
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(true).to_s.should eql("true") }
108
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(false).to_s.should eql("false") }
109
- end
110
- end
111
-
112
- describe '.parse' do
113
-
114
- context "when scaler values" do
115
- before(:each) do
116
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
117
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
118
- <OPS_envelope>
119
- <header>
120
- <version>1.0</version>
121
- </header>
122
- <body>
123
- <data_block>
124
- <dt_scalar>Tom Jones</dt_scalar>
125
- </data_block>
126
- </body>
127
- </OPS_envelope>}
128
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
129
- end
130
-
131
- it { @response.should eql("Tom Jones") }
132
- end
133
-
134
- context "when associative arrays with arrays of values" do
135
- before(:each) do
136
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
137
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
138
- <OPS_envelope>
139
- <header>
140
- <version>1.0</version>
141
- </header>
142
- <body>
143
- <data_block>
144
- <dt_assoc>
145
- <item key='domain_list'>
146
- <dt_array>
147
- <item key='0'>ns1.example.com</item>
148
- <item key='1'>ns2.example.com</item>
149
- <item key='2'>ns3.example.com</item>
150
- </dt_array>
151
- </item>
152
- </dt_assoc>
153
- </data_block>
154
- </body>
155
- </OPS_envelope>}
156
-
157
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
158
- end
159
-
160
- it { @response["domain_list"].class.should eql(Array) }
161
- it { @response["domain_list"][0].should eql("ns1.example.com") }
162
- it { @response["domain_list"][1].should eql("ns2.example.com") }
163
- it { @response["domain_list"][2].should eql("ns3.example.com") }
164
- end
165
-
166
- context "when associative arrays containing other associative arrays" do
167
- before(:each) do
168
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
169
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
170
- <OPS_envelope>
171
- <header>
172
- <version>1.0</version>
173
- </header>
174
- <body>
175
- <data_block>
176
- <dt_assoc>
177
- <item key="contact_set">
178
- <dt_assoc>
179
- <item key='owner'>
180
- <dt_assoc>
181
- <item key='first_name'>Tom</item>
182
- <item key='last_name'>Jones</item>
183
- </dt_assoc>
184
- </item>
185
- <item key='tech'>
186
- <dt_assoc>
187
- <item key='first_name'>Anne</item>
188
- <item key='last_name'>Smith</item>
189
- </dt_assoc>
190
- </item>
191
- </dt_assoc>
192
- </item>
193
- </dt_assoc>
194
- </data_block>
195
- </body>
196
- </OPS_envelope>}
197
-
198
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
199
- end
200
- it { @response["contact_set"]["owner"]["first_name"].should eql("Tom") }
201
- it { @response["contact_set"]["owner"]["last_name"].should eql("Jones") }
202
- it { @response["contact_set"]["tech"]["first_name"].should eql("Anne") }
203
- it { @response["contact_set"]["tech"]["last_name"].should eql("Smith") }
204
- end
205
-
206
- context "with a balance enquiry example response" do
207
- before(:each) do
208
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
209
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
210
- <OPS_envelope>
211
- <header>
212
- <version>0.9</version>
213
- </header>
214
- <body>
215
- <data_block>
216
- <dt_assoc>
217
- <item key="protocol">XCP</item>
218
- <item key="action">REPLY</item>
219
- <item key="object">BALANCE</item>
220
- <item key="is_success">1</item>
221
- <item key="response_code">200</item>
222
- <item key="response_text">Command successful</item>
223
- <item key="attributes">
224
- <dt_assoc>
225
- <item key="balance">8549.18</item>
226
- <item key="hold_balance">1676.05</item>
227
- </dt_assoc>
228
- </item>
229
- </dt_assoc>
230
- </data_block>
231
- </body>
232
- </OPS_envelope>}
233
-
234
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
235
- end
236
-
237
- it { @response.should be_an_instance_of(Hash) }
238
- it { @response["protocol"].should eql("XCP") }
239
- it { @response["action"].should eql("REPLY") }
240
- it { @response["object"].should eql("BALANCE") }
241
- it { @response["attributes"]["balance"].should eql("8549.18") }
242
- it { @response["attributes"]["hold_balance"].should eql("1676.05") }
243
-
244
- end
245
- end
246
- end
@@ -1,23 +0,0 @@
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