DataDotGov 0.1.0

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: e1e5b43f0aa359795e8a8aede1b4868ad2722163
4
+ data.tar.gz: a2e34091b85c3c191d91f0e818bbd841201af2b6
5
+ SHA512:
6
+ metadata.gz: 29d25f5f3e1489b135a7fa26352f56e80862428af47e2071e1e52fd6baed3a45a9a5aaa89c959d29242fb6f45ed227af4dec839dbbcccb0c7b571acf7a8fa3ce
7
+ data.tar.gz: bc1179b242195a6ef2a647575a0411de59f8ea5ee32b3b82909b534fd97ebdd8a6cbc81d3079b4176018d9fadb66b6eb8cf1943eff2e48ab8bd517c49207a95e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'DataDotGov/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'DataDotGov'
8
+ spec.version = DataDotGov::VERSION
9
+ spec.authors = ['Colin Young']
10
+ spec.email = ['cyoung@moneythink.org']
11
+
12
+ spec.summary = 'Search and query the Data.gov CKAN APIs in Ruby'
13
+ spec.description = 'Search and query the Data.gov CKAN APIs in Ruby'
14
+ spec.homepage = 'https://github.com/moneythink/data.gov'
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+ spec.required_ruby_version = '~> 2.0'
29
+
30
+ spec.add_dependency 'oj', '~> 2.15'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.9'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec'
35
+ spec.add_development_dependency 'vcr', '~> 3.0'
36
+ spec.add_development_dependency 'webmock'
37
+ spec.add_development_dependency 'codeclimate-test-reporter'
38
+ spec.add_development_dependency 'byebug'
39
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in DataDotGov.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # DataDotGov
2
+
3
+ [![Circle CI](https://circleci.com/gh/moneythink/data.gov.svg?style=svg)](https://circleci.com/gh/moneythink/data.gov) [![Code Climate](https://codeclimate.com/repos/5716a309ec824e00920037de/badges/f9f006b036c05bbbc3cd/gpa.svg)](https://codeclimate.com/repos/5716a309ec824e00920037de/feed) [![Test Coverage](https://codeclimate.com/repos/5716a309ec824e00920037de/badges/f9f006b036c05bbbc3cd/coverage.svg)](https://codeclimate.com/repos/5716a309ec824e00920037de/coverage)
4
+
5
+ This gem can be used to easily search and query the Data.gov CKAN APIs. For example, those located at:
6
+
7
+ - http://www.ed.gov/developer
8
+ - (Not an exhaustive list)
9
+
10
+ Any resource that can be found on [data.gov](http://www.data.gov/) should be searchable via its `resource_id`. These generally adhere to a format like `c95fae96-ce4a-459c-a935-ba2a37767ac9`, and can be found on Inventory pages [(example)](https://inventory.data.gov/dataset/032e19b4-5a90-41dc-83ff-6e4cd234f565/resource/38625c3d-5388-4c16-a30f-d105432553a4) and are found in the final portion of the URL path.
11
+
12
+ ## Installation
13
+
14
+ ```ruby
15
+ gem 'DataDotGov', github: 'moneythink/data.gov'
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```ruby
21
+ # use predefined resources
22
+ resource = DataDotGov::Resources::Ed::PostSecondary::DIRECTORY_LISTING
23
+ client = DataDotGov::Client.new(resource)
24
+ client.search('depaul') #=> [#<DataDotGov::Objects::PostSecondary:0x007ff8c5904cf8 @_id=1104, @institution_name="DePaul University", @state="IL", ... ]
25
+
26
+ # use whatever resource_id you like (obtain from Data.gov):
27
+ client = DataDotGov::Client.new(resource_id: '6d2a0324-5964-44c3-97be-061c0eb5fcc9')
28
+ results = client.search('Child Care Provider/Assistant')
29
+ results.last.program_title # => 'Child Card Provider/Assistant'
30
+ results.first.award_level # => 'Associate's degree'
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec DataDotGov` to use the code located in this directory, ignoring other installed copies of this gem.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/[my-github-username]/DataDotGov/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'DataDotGov'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.0.0
@@ -0,0 +1,2 @@
1
+ ---
2
+ endpoint: https://inventory.data.gov/api/3
data/lib/DataDotGov.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'DataDotGov/version'
2
+ relpath = __FILE__.chomp('.rb') + '/objects/*'
3
+ Dir[relpath].each { |f| require f }
4
+
5
+ require 'DataDotGov/client'
6
+ require 'DataDotGov/resources'
7
+
8
+ module DataDotGov
9
+ end
@@ -0,0 +1,66 @@
1
+ require 'yaml'
2
+ require 'uri'
3
+ require 'open-uri'
4
+ require 'oj'
5
+
6
+ module DataDotGov
7
+ class Client
8
+ DEFAULTS = YAML.load_file(File.dirname(__FILE__) + '/../../config/defaults.yml')
9
+
10
+ def initialize(options = {})
11
+ options = stringify_hash(options)
12
+
13
+ if options.key?('link')
14
+ options['resource_id'] = options['link'].split('/').last
15
+ end
16
+
17
+ options['type'] ||= DataDotGov::Objects::Base
18
+
19
+ @options = DEFAULTS.merge(stringify_hash(options))
20
+ end
21
+
22
+ def search(value, _offset = 0, _limit = @options['limit'])
23
+ preflight!
24
+
25
+ params = {
26
+ q: value,
27
+ resource_id: resource_id
28
+ }
29
+ query = URI.encode_www_form(params)
30
+ uri = URI.parse(endpoint + '/action/datastore_search' + '?' + query)
31
+ parse_response uri.read
32
+ end
33
+
34
+ def endpoint
35
+ @options['endpoint']
36
+ end
37
+
38
+ def resource_id
39
+ @options['resource_id']
40
+ end
41
+
42
+ private
43
+
44
+ def parse_response(response)
45
+ payload = Oj.load(response)
46
+ result = payload['result']
47
+ return unless result
48
+
49
+ type = @options['type']
50
+ result['records'].map { |record| type.new(record) }
51
+ end
52
+
53
+ def preflight!
54
+ missing_key!('endpoint') unless endpoint
55
+ missing_key!('resource_id') unless resource_id
56
+ end
57
+
58
+ def missing_key!(key)
59
+ fail ArgumentError.new("Required key '#{key}' not defined in #{self.class.name}.new().")
60
+ end
61
+
62
+ def stringify_hash(hash)
63
+ Hash[hash.map { |k, v| [k.to_s, v] }]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,28 @@
1
+ module DataDotGov
2
+ module Objects
3
+ DEFAULT_ALIASES = {
4
+ 'COUNTYNM' => 'county_name',
5
+ 'STABBR' => 'state',
6
+ 'WEBADDR' => 'web_address',
7
+ 'LONGITUD' => 'longitude',
8
+ 'LATITUDE' => 'latitude',
9
+ 'ZIP' => 'zip_code'
10
+ }
11
+
12
+ class Base
13
+ def initialize(attributes = {}, aliases = {})
14
+ aliases = DEFAULT_ALIASES.merge(aliases)
15
+ attributes.each do |key, value|
16
+ # https://github.com/ohler55/oj#options
17
+ key = aliases[key] if aliases[key]
18
+ instance_variable_set(:"@#{key}", value)
19
+ end
20
+ end
21
+
22
+ def method_missing(*args)
23
+ name = args.shift
24
+ instance_variable_get("@#{name}") || instance_variable_get("@#{name.upcase}")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module DataDotGov
2
+ module Objects
3
+ class PostSecondary < Base
4
+ def initialize(attributes = {}, _aliases = {})
5
+ super(
6
+ attributes,
7
+ # Aliases
8
+ 'INSTNM' => 'institution_name',
9
+ 'CHFTITLE' => 'chairman_title',
10
+ 'CHFNM' => 'chairman_name',
11
+ 'ADMINURL' => 'admin_url',
12
+ 'FAIDURL' => 'financial_aid_url',
13
+ 'GENTELE' => 'telephone',
14
+ 'LANDGRNT' => 'land_grant'
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ module Inspectable
2
+ def inspect
3
+ constants.inspect
4
+ end
5
+ end
6
+
7
+ module DataDotGov
8
+ module Resources
9
+ # Department of Education: ed.gov/developer
10
+ module Ed
11
+ extend Inspectable
12
+
13
+ # PostSecondary (Colleges and Universities)
14
+ module PostSecondary
15
+ extend Inspectable
16
+
17
+ DIRECTORY_LISTING = {
18
+ link: 'https://inventory.data.gov/dataset/032e19b4-5a90-41dc-83ff-6e4cd234f565/resource/38625c3d-5388-4c16-a30f-d105432553a4',
19
+ type: DataDotGov::Objects::PostSecondary
20
+ }
21
+ CIP_2000 = {
22
+ link: 'https://inventory.data.gov/dataset/b06ca923-ec64-4000-a9e1-86216bb3907d/resource/6fa1786f-ef01-4471-b033-aea7a7169e6c'
23
+ }
24
+ AWARDS_DEGREES_CONFERRED_BY_PROGRAM = {
25
+ link: 'https://inventory.data.gov/dataset/1e63afca-9587-4b72-aa05-a7f597e9305b/resource/6d2a0324-5964-44c3-97be-061c0eb5fcc9'
26
+ }
27
+ AWARDS_DEGREES_CONFERRED_ADV = {
28
+ link: 'https://inventory.data.gov/dataset/c44c10ef-4dff-4f15-a3bb-2847f5d70a59/resource/ec830504-afb7-499e-bb97-406388bc6078'
29
+ }
30
+ EDUCATIONAL_OFFERINGS__ATHLETIC_ASSOCIATIONS = {
31
+ link: 'https://inventory.data.gov/dataset/fb384d70-fff0-4bed-802c-935875500206/resource/8a656436-59e7-4f4d-bd16-a7fd58cfbb60'
32
+ }
33
+ FINAID_AND_NET_PRICE = {
34
+ link: 'https://inventory.data.gov/dataset/d3c1aa87-e6ba-4963-9d8d-43f2417d3925/resource/2384aff0-e30f-4e92-8ea4-1f1127a91912'
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module DataDotGov
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: DataDotGov
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Colin Young
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
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: codeclimate-test-reporter
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
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Search and query the Data.gov CKAN APIs in Ruby
126
+ email:
127
+ - cyoung@moneythink.org
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - DataDotGov.gemspec
137
+ - Gemfile
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - circle.yml
143
+ - config/defaults.yml
144
+ - lib/DataDotGov.rb
145
+ - lib/DataDotGov/client.rb
146
+ - lib/DataDotGov/objects/base.rb
147
+ - lib/DataDotGov/objects/post_secondary.rb
148
+ - lib/DataDotGov/resources.rb
149
+ - lib/DataDotGov/version.rb
150
+ homepage: https://github.com/moneythink/data.gov
151
+ licenses: []
152
+ metadata:
153
+ allowed_push_host: https://rubygems.org
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - "~>"
161
+ - !ruby/object:Gem::Version
162
+ version: '2.0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.4.5
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Search and query the Data.gov CKAN APIs in Ruby
174
+ test_files: []