faraday_middleware-parse_oj 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faraday_middleware-parse_oj.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Vsevolod Romashov
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,39 @@
1
+ # FaradayMiddleware::ParseOj
2
+
3
+ A simple Faraday middleware that parses JSON responses. It is identical to `FaradayMiddleware::ParseJson` from `faraday_middleware` gem except that it uses `Oj.load` instead of `JSON.parse`.
4
+
5
+ ## Installation
6
+
7
+ ``` ruby
8
+ # Gemfile
9
+ gem 'faraday_middleware-parse_oj'
10
+ ```
11
+
12
+ or
13
+
14
+ ``` bash
15
+ $ gem install faraday_middleware-parse_oj
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ The same as `FaradayMiddleware::ParseJson`:
21
+
22
+ ``` ruby
23
+ require 'faraday_middleware/parse_oj'
24
+
25
+ connection = Faraday.new do |builder|
26
+ builder.response :oj
27
+ builder.adapter Faraday.default_adapter
28
+ end
29
+
30
+ connection.get('http://example.com/some.json')
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.rspec_opts = '--color --format doc'
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/faraday_middleware/parse_oj', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Vsevolod Romashov']
6
+ gem.email = ['7@7vn.ru']
7
+ gem.summary = %q{Oj middleware for Faraday}
8
+ gem.description = %q{Faraday middleware for parsing JSON using the Oj parser.}
9
+ gem.homepage = 'https://github.com/7even/faraday_middleware-parse_oj'
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'faraday_middleware-parse_oj'
15
+ gem.require_paths = ['lib']
16
+ gem.version = FaradayMiddleware::ParseOj::VERSION
17
+
18
+ gem.add_runtime_dependency 'faraday_middleware', '~> 0.8'
19
+ gem.add_runtime_dependency 'oj', '~> 1.2'
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'faraday_middleware/response_middleware'
2
+
3
+ module FaradayMiddleware
4
+ class ParseOj < ResponseMiddleware
5
+ dependency 'oj'
6
+
7
+ define_parser do |body|
8
+ Oj.load(body) unless body.strip.empty?
9
+ end
10
+
11
+ VERSION = '0.1'
12
+ end
13
+ end
14
+
15
+ Faraday.register_middleware :response, :oj => FaradayMiddleware::ParseOj
@@ -0,0 +1,22 @@
1
+ require 'faraday_middleware/parse_oj'
2
+
3
+ describe FaradayMiddleware::ParseOj do
4
+ before(:each) do
5
+ @body = '{"a": 1, "b": 2}'
6
+ @parsed_body = stub("Parsed body")
7
+
8
+ @connection = Faraday.new do |builder|
9
+ builder.response :oj
10
+ builder.adapter :test do |stub|
11
+ stub.get('/url') do
12
+ [200, {}, @body]
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ it "parses the response body with Oj.load" do
19
+ Oj.should_receive(:load).with(@body).and_return(@parsed_body)
20
+ @connection.get('/url').body.should == @parsed_body
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday_middleware-parse_oj
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vsevolod Romashov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday_middleware
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
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.8'
30
+ - !ruby/object:Gem::Dependency
31
+ name: oj
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.2'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Faraday middleware for parsing JSON using the Oj parser.
79
+ email:
80
+ - 7@7vn.ru
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - faraday_middleware-parse_oj.gemspec
91
+ - lib/faraday_middleware/parse_oj.rb
92
+ - spec/parse_oj_spec.rb
93
+ homepage: https://github.com/7even/faraday_middleware-parse_oj
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.23
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Oj middleware for Faraday
117
+ test_files:
118
+ - spec/parse_oj_spec.rb
119
+ has_rdoc: