faraday_csv 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.
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ .config
14
+ .directory
15
+ .elc
16
+ .emacs.desktop
17
+ .emacs.desktop.lock
18
+ .redcar
19
+ .yardoc
20
+ Desktop.ini
21
+ Gemfile.lock
22
+ Icon?
23
+ InstalledFiles
24
+ Session.vim
25
+ Thumbs.db
26
+ \#*\#
27
+ _yardoc
28
+ auto-save-list
29
+ coverage
30
+ doc
31
+ lib/bundler/man
32
+ pkg
33
+ pkg/*
34
+ rdoc
35
+ spec/reports
36
+ test/tmp
37
+ test/version_tmp
38
+ tmp
39
+ tmtags
40
+ tramp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - rbx
7
+ - ree
8
+ - ruby-head
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'yard'
5
+
6
+ group :development do
7
+ gem 'kramdown'
8
+ gem 'guard-rspec'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec'
13
+ gem 'simplecov', :require => false
14
+ end
15
+
16
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Steve Agalloco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Faraday CSV
2
+
3
+ CSV Parsing Middleware for use with [Faraday][]
4
+
5
+ [faraday]: https://github.com/lostisland/faraday
6
+
7
+ ## Usage
8
+
9
+ ```ruby
10
+ conn = Faraday::Connection.new(:url => "http://example.com") do |builder|
11
+ builder.adapter Faraday.default_adapter
12
+ builder.use Faraday::Response::CSV
13
+ end
14
+
15
+ resp = conn.get do |req|
16
+ req.url "/path/to/a.csv"
17
+ end
18
+
19
+ contents = resp.body
20
+ contents['header_column']
21
+ # => column_value
22
+ ```
23
+
24
+ You can also pass options, which are passed into `CSV::parse`:
25
+
26
+ ```ruby
27
+ conn = Faraday::Connection.new(:url => "http://example.com") do |builder|
28
+ builder.adapter Faraday.default_adapter
29
+ builder.use Faraday::Response::CSV, :headers => true
30
+ end
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ Pull requests welcome: fork, make a topic branch, commit (squash when possible) *with tests* and I'll happily consider.
36
+
37
+ ## Copyright
38
+
39
+ Copyright (c) 2013 Steve Agalloco. See [LICENSE](LICENSE.md) for detail
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.ruby_opts = '-w'
8
+ end
9
+
10
+ task :default => :spec
11
+ task :test => :spec
12
+
13
+ require 'yard'
14
+ namespace :doc do
15
+ YARD::Rake::YardocTask.new do |task|
16
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
17
+ task.options = ['--markup', 'markdown']
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faraday_csv/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'faraday_csv'
8
+ gem.version = FaradayCSV::VERSION
9
+ gem.homepage = 'https://github.com/spagalloco/faraday_csv'
10
+
11
+ gem.author = "Steve Agalloco"
12
+ gem.email = 'steve.agalloco@gmail.com'
13
+ gem.description = 'CSV Parsing Middleware for use with Faraday'
14
+ gem.summary = gem.description
15
+
16
+ gem.add_dependency 'faraday'
17
+
18
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+
22
+ gem.require_paths = ['lib']
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+ class Response::CSV < Response::Middleware
5
+ dependency 'csv'
6
+
7
+ def initialize(app = nil, options = {})
8
+ super(app)
9
+ @options = options
10
+ end
11
+
12
+ def parse(body)
13
+ CSV.parse(body, @options)
14
+ rescue Object => err
15
+ raise Faraday::Error::ParsingError.new(err)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ require 'faraday'
2
+
3
+ class Faraday::Response
4
+ autoload :CSV, 'faraday/response/csv.rb'
5
+ end
@@ -0,0 +1,3 @@
1
+ module FaradayCSV
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Faraday::Response::CSV do
4
+ let(:csv) { Faraday::Response::CSV.new }
5
+ let(:body) { "integer,string\n12,foobar" }
6
+
7
+ it "parses valid csv syntax" do
8
+ parsed = csv.on_complete(:body => body)
9
+ expect(parsed).to be_an Array
10
+ end
11
+
12
+ it 'raises Faraday::Error::ParsingError on invalid syntax' do
13
+ expect{
14
+ csv.on_complete(:body => ['foo'])
15
+ }.to raise_error Faraday::Error::ParsingError
16
+ end
17
+
18
+ context 'with options' do
19
+ let(:options) { { :headers => true } }
20
+ let(:csv) { Faraday::Response::CSV.new(lambda { |env| env }, options) }
21
+
22
+ it "parses valid csv syntax" do
23
+ parsed = csv.on_complete(:body => body)
24
+ expect(parsed).to be_a CSV::Table
25
+ end
26
+ end
27
+
28
+ context "integration tests" do
29
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
30
+ let(:conn) do
31
+ Faraday.new do |conn|
32
+ conn.adapter :test, stubs
33
+ conn.use Faraday::Response::CSV
34
+ end
35
+ end
36
+
37
+ it "creates a hash from the body" do
38
+ stubs.get("/csv") {[200, {'Content-Type' => 'text/csv'}, "integer,string\n12,foobar"]}
39
+ expect(conn.get("/csv").body).to be_an Array
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ unless ENV['CI']
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_group 'FaradayCSV', 'lib/faraday'
6
+ add_group 'Specs', 'spec'
7
+ end
8
+ end
9
+
10
+ require 'faraday_csv'
11
+ require 'rspec'
12
+
13
+ RSpec.configure do |config|
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = :expect
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday_csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Agalloco
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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'
30
+ description: CSV Parsing Middleware for use with Faraday
31
+ email: steve.agalloco@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gemtest
37
+ - .gitignore
38
+ - .rspec
39
+ - .travis.yml
40
+ - .yardopts
41
+ - Gemfile
42
+ - Guardfile
43
+ - LICENSE.md
44
+ - README.md
45
+ - Rakefile
46
+ - faraday_csv.gemspec
47
+ - lib/faraday/response/csv.rb
48
+ - lib/faraday_csv.rb
49
+ - lib/faraday_csv/version.rb
50
+ - spec/faraday/response/csv_spec.rb
51
+ - spec/spec_helper.rb
52
+ homepage: https://github.com/spagalloco/faraday_csv
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ segments:
65
+ - 0
66
+ hash: 3573867536999644780
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ segments:
74
+ - 0
75
+ hash: 3573867536999644780
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.23
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: CSV Parsing Middleware for use with Faraday
82
+ test_files:
83
+ - spec/faraday/response/csv_spec.rb
84
+ - spec/spec_helper.rb
85
+ has_rdoc: