dirty_harry 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 972bd13de571b411780ca90801dccb3c123ce291
4
+ data.tar.gz: 65031ed1a4559f832506b6918d8fef3a82113841
5
+ SHA512:
6
+ metadata.gz: dfed7e1fbc7f012b54c1e52d5d1ce9a1a006deb33947bfb1b33fdde53192c677e0f6a298da74ab72546be55b587beaa9bbf880ada6bdac7128d34ffbb4bd0bfc
7
+ data.tar.gz: a3e077c3c7e0acfa9d6977b9bfc9cdfad5772ac749cceda613ce40e491c18a68fbde58bab75dcfb69d9f131c0ecb55e1dc38d3c65cb058de50e7e14e05d30d55
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/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-2
7
+ deploy:
8
+ provider: rubygems
9
+ api_key:
10
+ secure: bYWegLeur9B7imXEsGhcIzwURQwDP7lFyd/hDQmgz5Kqt2WIstrB6tSpQUx23WELpeOLrlu4dSNwO0m4htW2Tl7w8J1BQeT6iXsyu7ECzAo17tlnu7ihjbuAh166H5yCUHrYijXeD0wz0dJZjLD7Qtsbx56IMQjguOZU5dLWIHY=
11
+ gem: dirty_harry
12
+ on:
13
+ tags: true
14
+ repo: theodi/dirty_harry
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dirty_harry.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+ ---------------------
3
+
4
+ Copyright (c) 2015 The Open Data Institute
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ [![Build Status](http://img.shields.io/travis/theodi/dirty_harry.svg)](https://travis-ci.org/theodi/dirty_harry)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/theodi/dirty_harry.svg)](https://gemnasium.com/theodi/dirty_harry)
3
+ [![Coverage Status](http://img.shields.io/coveralls/theodi/dirty_harry.svg)](https://coveralls.io/r/theodi/dirty_harry)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/theodi/dirty_harry.svg)](https://codeclimate.com/github/theodi/dirty_harry)
5
+ [![Gem Version](http://img.shields.io/gem/v/dirty_harry.svg)](https://rubygems.org/gems/dirty_harry)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://theodi.mit-license.org)
7
+ [![Badges](http://img.shields.io/:badges-7/7-ff6799.svg)](https://github.com/badges/badgerbadgerbadger)
8
+
9
+ # DirtyHarry
10
+
11
+ > I know what you’re thinking: 'Did he fire six shots or only five?' Well, to tell you the truth, in all this excitement, I’ve kinda lost track myself. But being this is a .44 Magnum, the most powerful handgun in the world, and would blow your head clean off, you’ve got to ask yourself one question: 'Do I feel lucky?' Well, do ya, punk?
12
+
13
+ A quick and dirty wrapper around the http://csvlint.io [Webservice](https://github.com/theodi/csvlint/wiki/Webservice).
14
+
15
+ So called because CSVlint -> Clint -> Clint Eastwood -> Dirty Harry. Also, it's quick and dirty. And also NAMING THINGS IS HARD OK?
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'dirty_harry'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install dirty_harry
32
+
33
+ ## Usage
34
+
35
+ validation = DirtyHarry::Validation.new(URL_TO_YOUR_CSV)
36
+ validation.url #=> http://csvlint.io/validations/53566ef96373767abf010000
37
+ validation.source #=> URL_TO_YOUR_CSV
38
+ validation.state #=> One of 'valid', 'invalid' or 'warnings'
39
+ validation.badge #=> http://csvlint.io/validations/53566ef96373767abf010000.svg
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/dirty_harry/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ $:.unshift File.join( File.dirname(__FILE__), "lib")
2
+
3
+ require 'rspec/core/rake_task'
4
+ require "bundler/gem_tasks"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -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 'dirty_harry/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dirty_harry"
8
+ spec.version = DirtyHarry::VERSION
9
+ spec.authors = ["pezholio"]
10
+ spec.email = ["pezholio@gmail.com"]
11
+ spec.summary = "A quick and dirty wrapper around the http://csvlint.io webservice"
12
+ spec.homepage = "https://github.com/theodi/dirty_harry"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "coveralls"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "pry"
26
+
27
+ spec.add_dependency "httparty"
28
+ spec.add_dependency "retryable"
29
+ end
@@ -0,0 +1,10 @@
1
+ require "httparty"
2
+ require "json"
3
+ require "retryable"
4
+
5
+ require "dirty_harry/version"
6
+ require "dirty_harry/validation"
7
+
8
+ module DirtyHarry
9
+
10
+ end
@@ -0,0 +1,46 @@
1
+ module DirtyHarry
2
+ class Validation
3
+ include HTTParty
4
+
5
+ attr_accessor :csv
6
+ base_uri 'http://csvlint.io'
7
+
8
+ def initialize(csv)
9
+ @csv = csv
10
+ end
11
+
12
+ ["url", "source", "state"].each do |k|
13
+ define_method(k.to_sym) do
14
+ result[k]
15
+ end
16
+ end
17
+
18
+ def badge
19
+ "#{url}.svg"
20
+ end
21
+
22
+ private
23
+
24
+ def result
25
+ @response ||= JSON.parse(package)
26
+ @response["package"]["validations"].first
27
+ end
28
+
29
+ def response
30
+ JSON.parse(self.class.post("/package.json", query: { urls: [@csv] }).body)
31
+ end
32
+
33
+ def package_url
34
+ response["package"]["url"]
35
+ end
36
+
37
+ def package
38
+ response = nil
39
+ until !response.nil?
40
+ response = self.class.get(package_url).body
41
+ end
42
+ response
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module DirtyHarry
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DirtyHarry::Validation" do
4
+
5
+ before(:each) do
6
+ @csv = "http://www.example.com/example.csv"
7
+ @stub = stub_request(:post, "http://csvlint.io/package.json").
8
+ with(query: {urls: [@csv]}).to_return(body: File.open(File.join("spec", "fixtures", "response.json")))
9
+
10
+ stub_request(:get, "http://csvlint.io/package/5500513863737643690d0000").
11
+ to_return(body: File.read(File.join(File.dirname(__FILE__), "fixtures", "package.json")),
12
+ headers: {"Content-Type" => "application/json"})
13
+ end
14
+
15
+ it "sets the correct variables on initialization" do
16
+ csv = DirtyHarry::Validation.new(@csv)
17
+
18
+ expect(csv.csv).to eq(@csv)
19
+ end
20
+
21
+ it "posts to csvlint" do
22
+ csv = DirtyHarry::Validation.new(@csv)
23
+ csv.send(:response)
24
+
25
+ expect(@stub).to have_been_requested.once
26
+ end
27
+
28
+ it "returns a url for a validation" do
29
+ csv = DirtyHarry::Validation.new(@csv)
30
+
31
+ expect(csv.send(:package_url)).to eq("http://csvlint.io/package/5500513863737643690d0000")
32
+ end
33
+
34
+ it "waits for the package to be created" do
35
+ stub_request(:get, "http://csvlint.io/package/5500513863737643690d0000").
36
+ to_return({status: 404}).times(2).then.
37
+ to_return(body: File.read(File.join(File.dirname(__FILE__), "fixtures", "package.json")),
38
+ headers: {"Content-Type" => "application/json"})
39
+
40
+ csv = DirtyHarry::Validation.new(@csv)
41
+
42
+ expect(csv.url).to eq("http://csvlint.io/validation/53566ef96373767abf010000")
43
+ expect(csv.source).to eq("http://www.example.com/example.csv")
44
+ expect(csv.state).to eq("invalid")
45
+ end
46
+
47
+ it "returns a badge" do
48
+ stub_request(:get, "http://csvlint.io/package/5500513863737643690d0000").
49
+ to_return(body: File.read(File.join(File.dirname(__FILE__), "fixtures", "package.json")),
50
+ headers: {"Content-Type" => "application/json"})
51
+
52
+ csv = DirtyHarry::Validation.new(@csv)
53
+
54
+ expect(csv.badge).to eq("http://csvlint.io/validation/53566ef96373767abf010000.svg")
55
+ end
56
+
57
+ end
@@ -0,0 +1,13 @@
1
+ {
2
+ "version":"0.1",
3
+ "licence":"http://opendatacommons.org/licenses/odbl/",
4
+ "package":{
5
+ "validations":[
6
+ {
7
+ "url":"http://csvlint.io/validation/53566ef96373767abf010000",
8
+ "source":"http://www.example.com/example.csv",
9
+ "state":"invalid"
10
+ }
11
+ ]
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ {"package":{"url":"http://csvlint.io/package/5500513863737643690d0000"}}
@@ -0,0 +1,7 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'dirty_harry'
5
+ require 'webmock'
6
+ require 'webmock/rspec'
7
+ require 'pry'
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dirty_harry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - pezholio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: retryable
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - pezholio@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - LICENSE.md
136
+ - README.md
137
+ - Rakefile
138
+ - dirty_harry.gemspec
139
+ - lib/dirty_harry.rb
140
+ - lib/dirty_harry/validation.rb
141
+ - lib/dirty_harry/version.rb
142
+ - spec/dirty_harry_spec.rb
143
+ - spec/fixtures/package.json
144
+ - spec/fixtures/response.json
145
+ - spec/spec_helper.rb
146
+ homepage: https://github.com/theodi/dirty_harry
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.2.2
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: A quick and dirty wrapper around the http://csvlint.io webservice
170
+ test_files:
171
+ - spec/dirty_harry_spec.rb
172
+ - spec/fixtures/package.json
173
+ - spec/fixtures/response.json
174
+ - spec/spec_helper.rb