maremma 3.1.5 → 3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +2 -2
- data/lib/maremma.rb +2 -0
- data/lib/maremma/hash.rb +63 -0
- data/lib/maremma/version.rb +1 -1
- data/spec/maremma_spec.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeb93b6fbd1989f0b9e4fa2ff44208c4be9df6ab
|
4
|
+
data.tar.gz: e3222f0a8c5325ffdba5c1062ff8a8371f195d64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d75cc7a087ea4251fc4a8a94ffbe93b697479c94094bfd5ad6d2024faa2899550c980707747abdd6ba94fab7f8ff6302e37f22c461a9824ebf8ea2449e1619
|
7
|
+
data.tar.gz: 59287bb7153af851dfb492ebc6cee926df4dc38c5a2e9ff4d7da204658ad08ae6f0d3dba81ddb853f71491d83abb5ef7d4855514d261d910438c470bf2842d5a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## v.3.5 (February 14, 2017)
|
2
|
+
|
3
|
+
[maremma 3.5](https://github.com/datacite/maremma/releases/tag/v.3.5) was released on February 14, 2017:
|
4
|
+
|
5
|
+
* breaking change: include attributes when parsing XML (use "text" key for node content)
|
6
|
+
|
1
7
|
## v.3.1.2 (January 29, 2017)
|
2
8
|
|
3
9
|
[maremma 3.1.2](https://github.com/datacite/maremma/releases/tag/v.3.1.2) was released on January 29, 2017:
|
data/Gemfile.lock
CHANGED
data/lib/maremma.rb
CHANGED
@@ -7,6 +7,7 @@ require 'faraday/encoding'
|
|
7
7
|
require 'excon'
|
8
8
|
require 'uri'
|
9
9
|
require 'addressable/uri'
|
10
|
+
require 'maremma/hash'
|
10
11
|
|
11
12
|
DEFAULT_TIMEOUT = 60
|
12
13
|
NETWORKABLE_EXCEPTIONS = [Faraday::ClientError,
|
@@ -254,6 +255,7 @@ module Maremma
|
|
254
255
|
(headers["X-Rate-Limit-Remaining"] || headers["X-RateLimit-Remaining"] || 100).to_i
|
255
256
|
end
|
256
257
|
|
258
|
+
# keep XML attributes, http://stackoverflow.com/a/10794044
|
257
259
|
def self.from_xml(string)
|
258
260
|
if Nokogiri::XML(string).errors.empty?
|
259
261
|
Hash.from_xml(string)
|
data/lib/maremma/hash.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#123129
|
2
|
+
# https://gist.github.com/huy/819999
|
3
|
+
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
ActiveSupport::XmlMini.backend = 'Nokogiri'
|
7
|
+
|
8
|
+
class Hash
|
9
|
+
class << self
|
10
|
+
def from_xml(xml_io)
|
11
|
+
begin
|
12
|
+
result = Nokogiri::XML(xml_io)
|
13
|
+
return { result.root.name => xml_node_to_hash(result.root)}
|
14
|
+
rescue Exception => e
|
15
|
+
# raise your custom exception here
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def xml_node_to_hash(node)
|
20
|
+
# If we are at the root of the document, start the hash
|
21
|
+
if node.element?
|
22
|
+
result_hash = {}
|
23
|
+
if node.attributes != {}
|
24
|
+
attributes = {}
|
25
|
+
node.attributes.keys.each do |key|
|
26
|
+
attributes[node.attributes[key].name] = node.attributes[key].value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
if node.children.size > 0
|
30
|
+
node.children.each do |child|
|
31
|
+
result = xml_node_to_hash(child)
|
32
|
+
|
33
|
+
if child.name == "text"
|
34
|
+
unless child.next_sibling || child.previous_sibling
|
35
|
+
return result unless attributes
|
36
|
+
result_hash[child.name] = result
|
37
|
+
end
|
38
|
+
elsif result_hash[child.name]
|
39
|
+
|
40
|
+
if result_hash[child.name].is_a?(Object::Array)
|
41
|
+
result_hash[child.name] << result
|
42
|
+
else
|
43
|
+
result_hash[child.name] = [result_hash[child.name]] << result
|
44
|
+
end
|
45
|
+
else
|
46
|
+
result_hash[child.name] = result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
if attributes
|
50
|
+
#add code to remove non-data attributes e.g. xml schema, namespace here
|
51
|
+
#if there is a collision then node content supersets attributes
|
52
|
+
result_hash = attributes.merge(result_hash)
|
53
|
+
end
|
54
|
+
return result_hash
|
55
|
+
else
|
56
|
+
return attributes
|
57
|
+
end
|
58
|
+
else
|
59
|
+
return node.content.to_s
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/maremma/version.rb
CHANGED
data/spec/maremma_spec.rb
CHANGED
@@ -459,6 +459,11 @@ describe Maremma do
|
|
459
459
|
expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>"abc"})
|
460
460
|
end
|
461
461
|
|
462
|
+
it 'from_xml with attribute' do
|
463
|
+
string = '<word type="small">abc</word>'
|
464
|
+
expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>{"type"=>"small", "text"=>"abc"}})
|
465
|
+
end
|
466
|
+
|
462
467
|
it 'from_string' do
|
463
468
|
string = "abc"
|
464
469
|
expect(subject.parse_success_response(string)).to eq("data"=>"abc")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maremma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: '3.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Fenner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -303,6 +303,7 @@ files:
|
|
303
303
|
- README.md
|
304
304
|
- Rakefile
|
305
305
|
- lib/maremma.rb
|
306
|
+
- lib/maremma/hash.rb
|
306
307
|
- lib/maremma/version.rb
|
307
308
|
- maremma.gemspec
|
308
309
|
- spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml
|