faraday_middleware-parse_ox 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78d31b5cc79124690ab6732a85457aa0f51ee1de
4
+ data.tar.gz: 677665d37034a3044ecdc1de0e1276ae04b0d498
5
+ SHA512:
6
+ metadata.gz: 3b56274ec53d9958fc3f4d80a3e957e3514926156d2abc5f3fb1323e9ee85f1f1dea1aa98be8f03afc7705f915aec1cdcefc32624b0ef6235681af9652159e14
7
+ data.tar.gz: 735e7eb0786a5d723c4f403ce6ecc0def263944477f769cc221ca52777f38919f4298296014e4fb6d23c283bf910f27027f3535b494f8d5ee5fc11b9edbcdd24
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faraday_middleware-parse_ox.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # FaradayMiddleware::ParseOx
2
+
3
+ Faraday middleware for parsing response using ox. Based on faraday\_middleware-parse\_oj from
4
+ [@7even](https://github.com/7even )
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'faraday_middleware-parse_ox'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install faraday_middleware-parse_ox
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'faraday_middleware/parse_ox'
26
+
27
+ connection = Faraday.new do |builder|
28
+ builder.response :ox
29
+ builder.adapter Faraday.default_adapter
30
+ end
31
+
32
+ connection.get('http://example.com/some.xml')
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/faraday\_middleware-parse\_ox/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faraday_middleware/parse_ox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'faraday_middleware-parse_ox'
8
+ spec.version = FaradayMiddleware::ParseOx::VERSION
9
+ spec.authors = ['Vladimir Valgis']
10
+ spec.email = ['vladimir.valgis@gmail.com']
11
+ spec.summary = %q{Faraday middleware for parsing response using ox}
12
+ spec.description = %q{Faraday middleware for parsing response using ox. Based on faraday_middleware-parse_oj from 7even}
13
+ spec.homepage = 'https://github.com/vvalgis/faraday_middleware-parse_ox'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'faraday', '~> 0.9'
22
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.9'
23
+ spec.add_runtime_dependency 'ox', '~> 2.1'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.7'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'byebug'
29
+ end
@@ -0,0 +1,5 @@
1
+ require 'faraday_middleware/parse_ox/version'
2
+ require 'faraday_middleware/response_middleware'
3
+ require 'faraday_middleware/parse_ox/parser'
4
+
5
+ Faraday::Response.register_middleware ox: FaradayMiddleware::ParseOx::Parser
@@ -0,0 +1,15 @@
1
+ module FaradayMiddleware
2
+ module ParseOx
3
+ class Parser < ResponseMiddleware
4
+ dependency 'ox'
5
+
6
+ define_parser do |body|
7
+ matches = body.match(/encoding="(.*?)"/)
8
+ encoding = matches ? matches[1] : 'utf-8'
9
+ unless body.strip.empty?
10
+ Ox.load(body, skip: :skip_white, mode: :generic, symbolize_keys: true, encoding: encoding)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module FaradayMiddleware
2
+ module ParseOx
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FaradayMiddleware::ParseOx::Parser do
4
+
5
+ let(:response_body) do
6
+ <<-XML.gsub(/^\s{6}/s, '').strip
7
+ <?xml version="1.0" standalone="yes" encoding="utf-8"?>
8
+ <woot>
9
+ <node num="one">first</node>
10
+ <node num="two">second</node>
11
+ <node num="three">third</node>
12
+ </woot>
13
+ XML
14
+ end
15
+
16
+ let(:parsed_body) { double("Parsed body") }
17
+
18
+ let(:connection) do
19
+ Faraday.new do |builder|
20
+ builder.response :ox
21
+ builder.adapter :test do |stub|
22
+ stub.get('/url') { [200, {}, response_body] }
23
+ end
24
+ end
25
+ end
26
+
27
+ subject { connection.get('/url').body }
28
+
29
+
30
+ describe 'parse response body with ox' do
31
+ let(:options) { {skip: :skip_white, mode: :generic, symbolize_keys: true, encoding: 'utf-8'} }
32
+ it 'should called with options' do
33
+ expect(Ox).to receive(:load).with(response_body, options).and_return(parsed_body)
34
+ connection.get('/url')
35
+ end
36
+ it { expect(subject).to be_a(Ox::Document) }
37
+ it { expect(subject.root).to be_a(Ox::Element) }
38
+ it { expect(subject.root.nodes.count).to eq(3) }
39
+ it { expect(subject.woot.node.text).to eq('first') }
40
+ it { expect(subject.woot.node.num).to eq('one') }
41
+ it { expect(subject.woot.node(2).num).to eq('three') }
42
+ end
43
+
44
+ end
@@ -0,0 +1,31 @@
1
+ require 'bundler/setup'
2
+ require 'byebug'
3
+ require 'faraday_middleware/parse_ox'
4
+
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.filter_run :focus
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ config.disable_monkey_patching!
19
+
20
+ config.warnings = true
21
+
22
+ if config.files_to_run.one?
23
+ config.default_formatter = 'doc'
24
+ end
25
+
26
+ config.profile_examples = 10
27
+
28
+ config.order = :random
29
+
30
+ Kernel.srand config.seed
31
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday_middleware-parse_ox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Valgis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ox
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
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'
111
+ description: Faraday middleware for parsing response using ox. Based on faraday_middleware-parse_oj
112
+ from 7even
113
+ email:
114
+ - vladimir.valgis@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - faraday_middleware-parse_ox.gemspec
126
+ - lib/faraday_middleware/parse_ox.rb
127
+ - lib/faraday_middleware/parse_ox/parser.rb
128
+ - lib/faraday_middleware/parse_ox/version.rb
129
+ - spec/faraday_middleware/parse_ox_spec.rb
130
+ - spec/spec_helper.rb
131
+ homepage: https://github.com/vvalgis/faraday_middleware-parse_ox
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Faraday middleware for parsing response using ox
155
+ test_files:
156
+ - spec/faraday_middleware/parse_ox_spec.rb
157
+ - spec/spec_helper.rb
158
+ has_rdoc: