maremma 3.5 → 3.5.1

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: aeb93b6fbd1989f0b9e4fa2ff44208c4be9df6ab
4
- data.tar.gz: e3222f0a8c5325ffdba5c1062ff8a8371f195d64
3
+ metadata.gz: ba82a8adc41f610974a1e5f0fee1616d04e4d465
4
+ data.tar.gz: 4eaf91d77ceebe086c1bdeab2f068d9e143a5c68
5
5
  SHA512:
6
- metadata.gz: 93d75cc7a087ea4251fc4a8a94ffbe93b697479c94094bfd5ad6d2024faa2899550c980707747abdd6ba94fab7f8ff6302e37f22c461a9824ebf8ea2449e1619
7
- data.tar.gz: 59287bb7153af851dfb492ebc6cee926df4dc38c5a2e9ff4d7da204658ad08ae6f0d3dba81ddb853f71491d83abb5ef7d4855514d261d910438c470bf2842d5a
6
+ metadata.gz: ba82e06bd569ae40504b93c0d4327c0f53d76d06bb198d4100209e3501101de59dfa957b66ec61009b5350b1817eaa43f7c4ceb32824bade269e5bed8738736f
7
+ data.tar.gz: 234196702252c07ae88ba1bcd57d41b130751c8230a06056429d18171ccbe239903c8ea4db22c9dd88cb7a75ea79f1f0667bf564979426493b32e291359f2c3e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maremma (3.5)
4
+ maremma (3.5.1)
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.14.4
99
+ 1.12.5
data/lib/maremma.rb CHANGED
@@ -7,20 +7,20 @@ require 'faraday/encoding'
7
7
  require 'excon'
8
8
  require 'uri'
9
9
  require 'addressable/uri'
10
- require 'maremma/hash'
11
-
12
- DEFAULT_TIMEOUT = 60
13
- NETWORKABLE_EXCEPTIONS = [Faraday::ClientError,
14
- Faraday::TimeoutError,
15
- Faraday::SSLError,
16
- Faraday::ConnectionFailed,
17
- URI::InvalidURIError,
18
- Encoding::UndefinedConversionError,
19
- ArgumentError,
20
- NoMethodError,
21
- TypeError]
10
+ require 'maremma/xml_converter'
22
11
 
23
12
  module Maremma
13
+ DEFAULT_TIMEOUT = 60
14
+ NETWORKABLE_EXCEPTIONS = [Faraday::ClientError,
15
+ Faraday::TimeoutError,
16
+ Faraday::SSLError,
17
+ Faraday::ConnectionFailed,
18
+ URI::InvalidURIError,
19
+ Encoding::UndefinedConversionError,
20
+ ArgumentError,
21
+ NoMethodError,
22
+ TypeError]
23
+
24
24
  def self.post(url, options={})
25
25
  is_valid_url?(url)
26
26
 
@@ -1,3 +1,3 @@
1
1
  module Maremma
2
- VERSION = "3.5"
2
+ VERSION = "3.5.1"
3
3
  end
@@ -0,0 +1,12 @@
1
+ # modified from http://stackoverflow.com/a/29431089
2
+ # preserve attributes in xml
3
+
4
+ module ActiveSupport
5
+ class XMLConverter
6
+ private
7
+
8
+ def become_content?(value)
9
+ value['type'] == 'file' || (value['__content__'] && (value.keys.size == 1 && value['__content__'].present?))
10
+ end
11
+ end
12
+ end
data/spec/maremma_spec.rb CHANGED
@@ -461,7 +461,12 @@ describe Maremma do
461
461
 
462
462
  it 'from_xml with attribute' do
463
463
  string = '<word type="small">abc</word>'
464
- expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>{"type"=>"small", "text"=>"abc"}})
464
+ expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>{"type"=>"small", "__content__"=>"abc"}})
465
+ end
466
+
467
+ it 'from_xml with mixed attribute' do
468
+ string = '<word type="small">abc<footnote>1</footnote></word>'
469
+ expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>{"type"=>"small", "footnote"=>"1", "__content__"=>"abc"}})
465
470
  end
466
471
 
467
472
  it 'from_string' do
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.5'
4
+ version: 3.5.1
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-14 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -303,8 +303,8 @@ files:
303
303
  - README.md
304
304
  - Rakefile
305
305
  - lib/maremma.rb
306
- - lib/maremma/hash.rb
307
306
  - lib/maremma/version.rb
307
+ - lib/maremma/xml_converter.rb
308
308
  - maremma.gemspec
309
309
  - spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml
310
310
  - spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_APA-formatted_citation.yml
data/lib/maremma/hash.rb DELETED
@@ -1,63 +0,0 @@
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