agent_cooper 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "agent_cooper"
16
16
 
17
17
  runtime_dependencies = {
18
+ "eggnog" => "~> 0.0.2",
18
19
  "httpclient" => "~> 2.2.3",
19
20
  "nokogiri" => "~> 1.5.5",
20
21
  "virtus" => "~> 0.5.1"
@@ -1,4 +1,5 @@
1
1
  require 'nokogiri'
2
+ require 'eggnog'
2
3
  require 'httpclient'
3
4
  require 'virtus'
4
5
  require 'cgi'
@@ -11,7 +12,6 @@ end
11
12
 
12
13
  require 'agent_cooper/config'
13
14
  require 'agent_cooper/response'
14
- require 'agent_cooper/utils/hash'
15
15
 
16
16
  require 'agent_cooper/request'
17
17
  require 'agent_cooper/requests/finder'
@@ -11,13 +11,13 @@ module AgentCooper
11
11
  end
12
12
 
13
13
  # @api public
14
- def to_hash(options = {})
15
- AgentCooper::Utils::Hash.from_xml(xml, options)
14
+ def code
15
+ response.code
16
16
  end
17
17
 
18
18
  # @api public
19
- def code
20
- response.code
19
+ def to_hash(options = {})
20
+ xml.to_hash(options)
21
21
  end
22
22
 
23
23
  # @api public
@@ -1,3 +1,3 @@
1
1
  module AgentCooper
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -4,22 +4,14 @@ describe AgentCooper::Response do
4
4
 
5
5
  subject { described_class.new(:response => response) }
6
6
 
7
- let(:body) { "<root><foo>bar</foo></root>" }
7
+ let(:body) { "<root><foo baz="">Some Text</foo></root>" }
8
8
  let(:code) { 200 }
9
9
 
10
10
  let(:response) { mock(:response, :body => body, :code => code) }
11
11
 
12
12
  its(:body) { should eql(body) }
13
13
  its(:code) { should eql(code) }
14
-
15
- its(:to_hash) { should eql({"root" => {"foo" => "bar"}}) }
16
-
17
- context "when options are passed" do
18
- specify "preserve_attributes" do
19
- subject.to_hash(:preserve_attributes => true).should eql({"root" => {"foo" => {"__content__" => "bar"}}})
20
- end
21
- end
22
-
14
+ its(:to_hash) { should be_a(Hash)}
23
15
  its(:xml) { should be_a(Nokogiri::XML::Document) }
24
16
  its(:valid?) { should be_true }
25
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agent_cooper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-01 00:00:00.000000000 Z
12
+ date: 2012-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eggnog
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.2
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: httpclient
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +187,6 @@ files:
171
187
  - lib/agent_cooper/requests/shopper.rb
172
188
  - lib/agent_cooper/response.rb
173
189
  - lib/agent_cooper/synchrony.rb
174
- - lib/agent_cooper/utils/hash.rb
175
190
  - lib/agent_cooper/version.rb
176
191
  - spec/agent_cooper/config_spec.rb
177
192
  - spec/agent_cooper/request_spec.rb
@@ -1,94 +0,0 @@
1
- module AgentCooper
2
- module Utils
3
- class Hash
4
- def self.from_xml(xml, options)
5
- unless xml.is_a?(Nokogiri::XML::Node)
6
- raise ArgumentError, "`xml` must be an instance of Nokogiri::XML::Node"
7
- end
8
-
9
- doc = XMLDocumentDecorator.new(xml, options)
10
-
11
- doc.to_hash
12
- end
13
-
14
- class XMLDocumentDecorator
15
- def initialize(document, options)
16
- @document, @options = document, options
17
- end
18
-
19
- def to_hash
20
- root.to_hash
21
- end
22
-
23
- def root
24
- XMLNodeDecorator.new(document.root, options)
25
- end
26
-
27
- def method_missing(m, *args)
28
- document.send(m, *args)
29
- end
30
-
31
- private
32
-
33
- attr_reader :document, :options
34
- end
35
-
36
- class XMLNodeDecorator
37
- CONTENT_ROOT = '__content__'.freeze
38
-
39
- def initialize(node, options)
40
- @node, @options = node, options
41
- end
42
-
43
- def to_hash(hash = {})
44
- node_hash = {}
45
-
46
- # Insert node hash into parent hash correctly
47
- case hash[name]
48
- when Array then hash[name] << node_hash
49
- when Hash then hash[name] = [hash[name], node_hash]
50
- when nil then hash[name] = node_hash
51
- end
52
-
53
- # Handle child elements
54
- children.each do |c|
55
- child = XMLNodeDecorator.new(c, options)
56
-
57
- if child.element?
58
- child.to_hash(node_hash)
59
- elsif child.text? || child.cdata?
60
- unless preserve_attributes?
61
- hash[name] = child.content
62
- else
63
- node_hash[CONTENT_ROOT] ||= ''
64
- node_hash[CONTENT_ROOT] << child.content
65
- end
66
- end
67
- end
68
-
69
- # Remove content node if it is blank and there are child tags
70
- if node_hash.length > 1 && node_hash[CONTENT_ROOT].empty?
71
- node_hash.delete(CONTENT_ROOT)
72
- end
73
-
74
- # Handle attributes
75
- attribute_nodes.each {|a| node_hash[a.node_name] = a.value }
76
-
77
- hash
78
- end
79
-
80
- def method_missing(m, *args)
81
- node.send(m, *args)
82
- end
83
-
84
- private
85
-
86
- def preserve_attributes?
87
- options.fetch(:preserve_attributes) { false }
88
- end
89
-
90
- attr_reader :node, :options
91
- end
92
- end
93
- end
94
- end