kmdata 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +11 -0
- data/kmdata.gemspec +28 -0
- data/lib/kmdata/version.rb +3 -0
- data/lib/kmdata.rb +36 -0
- data/spec/fixtures/terms.json +1 -0
- data/spec/kmdata_spec.rb +65 -0
- data/spec/spec_helper.rb +4 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 236a165a8c4edf1cc467f6dadc62486a63d21d9f
|
4
|
+
data.tar.gz: 1a63a97001f8ac2aea3bd9b1e5626899e4dff599
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fcf8241c81a4ccb4e5289061ffde05ac3ab899820834cf6529d338e007e1f8d0e18a9beac753c86e4b578b5cd32eac44d03e4760a729006ee6fd33b3df956fd5
|
7
|
+
data.tar.gz: f5b35c143e81d1746fe47c3a2a021d5a445552e0f24f5088734c4d58fa52a255824f2c59c7f2a0cea68f9599a0f9b4092a00fa371a11a51daf62c543645bf392
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kyle Decot
|
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,36 @@
|
|
1
|
+
# KMData
|
2
|
+
|
3
|
+
A simple API wrapper for interacting with the [KMData](https://kmdata.osu.edu/) Project.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'kmdata'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install kmdata
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
terms = KMData.get('terms')
|
22
|
+
terms.each do |term|
|
23
|
+
puts term.description
|
24
|
+
end
|
25
|
+
|
26
|
+
resource_id = KMData.get('people', { q: 'Decot' }).first.resource_id
|
27
|
+
person = KMData.get("people/#{resource_id}")
|
28
|
+
puts person.display_name
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.fail_on_error = false
|
7
|
+
spec.rspec_opts = "--color --format documentation"
|
8
|
+
spec.pattern = FileList["spec/**/*_spec.rb"]
|
9
|
+
end
|
10
|
+
|
11
|
+
task default: :spec
|
data/kmdata.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "kmdata/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "kmdata"
|
9
|
+
spec.version = KMData::VERSION
|
10
|
+
spec.authors = ["Kyle Decot", "Mike Butsko", "Ryan Stocker"]
|
11
|
+
spec.email = ["decot.7@osu.edu", "butsko.7@osu.edu", "stocker.19@osu.edu"]
|
12
|
+
spec.description = %q{A simple API wrapper for interacting with the KMData Project}
|
13
|
+
spec.summary = %q{A simple API wrapper for interacting with the KMData Project}
|
14
|
+
spec.homepage = "https://github.com/ASCTech/kmdata-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
|
27
|
+
spec.add_runtime_dependency "json"
|
28
|
+
end
|
data/lib/kmdata.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
%w[kmdata/version net/http json ostruct].each { |f| require f }
|
2
|
+
|
3
|
+
module KMData
|
4
|
+
ENDPOINT = "kmdata.osu.edu"
|
5
|
+
|
6
|
+
def self.get(path, params = {})
|
7
|
+
path = "/api/#{path}.json?#{URI.encode_www_form(params)}"
|
8
|
+
response = request(path)
|
9
|
+
process(JSON.parse(response.body)) if response.code == "200"
|
10
|
+
rescue Exception => exception
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def self.request(path)
|
16
|
+
http.request(Net::HTTP::Get.new(path))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.http
|
20
|
+
@http ||= begin
|
21
|
+
http = Net::HTTP.new(ENDPOINT, 443)
|
22
|
+
http.use_ssl = true
|
23
|
+
http
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.process(json)
|
28
|
+
if json.is_a? Array
|
29
|
+
json.map { |element| process(element) }
|
30
|
+
elsif json.is_a? Hash
|
31
|
+
OpenStruct.new(Hash[json.map { |key, value| [key, process(value)] }])
|
32
|
+
else
|
33
|
+
json
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"description":"Summer 2012","id":1,"term_code":"1124"},{"description":"Autumn 2012","id":2,"term_code":"1128"},{"description":"Spring 2013","id":3,"term_code":"1132"},{"description":"Summer 2013","id":4,"term_code":"1134"},{"description":"Autumn 2013","id":5,"term_code":"1138"}]
|
data/spec/kmdata_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "kmdata"
|
3
|
+
|
4
|
+
describe KMData do
|
5
|
+
describe '.get' do
|
6
|
+
let(:json) { File.read(File.join('spec', 'fixtures', 'terms.json')) }
|
7
|
+
|
8
|
+
context 'success' do
|
9
|
+
it 'returns an array of terms' do
|
10
|
+
response = double()
|
11
|
+
response.stub!(:code) { "200" }
|
12
|
+
response.stub!(:body) { json }
|
13
|
+
|
14
|
+
KMData.stub!(:path_with_params).with("/api/terms.json", {})
|
15
|
+
KMData.stub!(:request).with(anything).and_return(response)
|
16
|
+
KMData.get('terms').should == KMData.send(:process, JSON.parse(json))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'failure' do
|
21
|
+
it 'returns nil' do
|
22
|
+
response = double()
|
23
|
+
response.stub!(:code) { "500" }
|
24
|
+
response.stub!(:body) { nil }
|
25
|
+
|
26
|
+
KMData.stub!(:path_with_params).with("/api/terms.json", {})
|
27
|
+
KMData.stub!(:request).with(anything).and_return(response)
|
28
|
+
KMData.get('terms').should be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.process' do
|
35
|
+
let(:data) { [1, 2, { foo: 'bar', baz: true }] }
|
36
|
+
subject { KMData.send :process, data }
|
37
|
+
it 'transforms json' do
|
38
|
+
subject[0].should eql 1
|
39
|
+
subject[2].foo.should eql 'bar'
|
40
|
+
subject[2].baz.should be_true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '.http' do
|
45
|
+
subject { KMData.send :http }
|
46
|
+
it { should respond_to(:request) }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.request' do
|
50
|
+
let(:response) do
|
51
|
+
response = double()
|
52
|
+
response.stub!(:body).and_return('')
|
53
|
+
response.stub!(:code).and_return('200')
|
54
|
+
response
|
55
|
+
end
|
56
|
+
subject { KMData.send(:request, '/api/terms.json') }
|
57
|
+
it 'should respond to body and code' do
|
58
|
+
http = double()
|
59
|
+
http.stub!(:request).and_return(response)
|
60
|
+
KMData.stub!(:http).and_return(http)
|
61
|
+
|
62
|
+
subject.should respond_to(:body, :code)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kmdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Decot
|
8
|
+
- Mike Butsko
|
9
|
+
- Ryan Stocker
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.3'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: pry
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: json
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
description: A simple API wrapper for interacting with the KMData Project
|
86
|
+
email:
|
87
|
+
- decot.7@osu.edu
|
88
|
+
- butsko.7@osu.edu
|
89
|
+
- stocker.19@osu.edu
|
90
|
+
executables: []
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files: []
|
93
|
+
files:
|
94
|
+
- .gitignore
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- kmdata.gemspec
|
100
|
+
- lib/kmdata.rb
|
101
|
+
- lib/kmdata/version.rb
|
102
|
+
- spec/fixtures/terms.json
|
103
|
+
- spec/kmdata_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: https://github.com/ASCTech/kmdata-ruby
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.0.3
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A simple API wrapper for interacting with the KMData Project
|
129
|
+
test_files:
|
130
|
+
- spec/fixtures/terms.json
|
131
|
+
- spec/kmdata_spec.rb
|
132
|
+
- spec/spec_helper.rb
|