maremma 3.1.5 → 3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4915ffe0ca6454d2cf9b8d577a50f9ae6821a38c
4
- data.tar.gz: c234f8ee74ad2bc1d41a104c50f7cf1ca5652da4
3
+ metadata.gz: aeb93b6fbd1989f0b9e4fa2ff44208c4be9df6ab
4
+ data.tar.gz: e3222f0a8c5325ffdba5c1062ff8a8371f195d64
5
5
  SHA512:
6
- metadata.gz: 53a4b285f838e4a49ef0b64e93a91dee9690264314ccf7158847ce4eb5c4f22be33c54b639b5831847f123d314f99c95d152d16792a2fd2f28e768b7424e2b1d
7
- data.tar.gz: 7a4d14c96fa953d83c84fbeb68eb8b0d46cc8acca1951e7cf5326f24aacde23989661ed8bfbc15fe9500031358bf587366e8e6262befad40a06b919cdae75f3d
6
+ metadata.gz: 93d75cc7a087ea4251fc4a8a94ffbe93b697479c94094bfd5ad6d2024faa2899550c980707747abdd6ba94fab7f8ff6302e37f22c461a9824ebf8ea2449e1619
7
+ data.tar.gz: 59287bb7153af851dfb492ebc6cee926df4dc38c5a2e9ff4d7da204658ad08ae6f0d3dba81ddb853f71491d83abb5ef7d4855514d261d910438c470bf2842d5a
@@ -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:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maremma (3.1.5)
4
+ maremma (3.5)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  addressable (>= 2.3.6)
7
7
  builder (~> 3.2, >= 3.2.2)
@@ -96,4 +96,4 @@ DEPENDENCIES
96
96
  webmock (~> 1.22, >= 1.22.3)
97
97
 
98
98
  BUNDLED WITH
99
- 1.12.5
99
+ 1.14.4
@@ -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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Maremma
2
- VERSION = "3.1.5"
2
+ VERSION = "3.5"
3
3
  end
@@ -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.1.5
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-12 00:00:00.000000000 Z
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