kmdata 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/kmdata +13 -0
- data/kmdata.gemspec +8 -7
- data/lib/kmdata/version.rb +1 -1
- data/lib/kmdata.rb +49 -25
- data/spec/kmdata_spec.rb +9 -36
- metadata +23 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20631034148f7e58e7e6c2b1fbcc877609dee837
|
4
|
+
data.tar.gz: 332e1967f58e34e826ac531ea30feece4a1b5f0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ccc95d034c84795f36832726b5f2c3155a6a5f5ebf68519111be9bf09c1b484e6530c1d46ea0f7a0598b12603bcf2ea45286a7a1dc6f5aec1dac48bb9728bf
|
7
|
+
data.tar.gz: a96294f18d0108e658819a0a0d2aec6d37456412bed1594b004ea90b197735e0781527978e5ae14ed97899b2edff4ef03811f659cc95d133a6264375e045a813
|
data/bin/kmdata
ADDED
data/kmdata.gemspec
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
4
|
+
require 'kmdata/version'
|
6
5
|
|
7
6
|
Gem::Specification.new do |spec|
|
8
7
|
spec.name = "kmdata"
|
9
8
|
spec.version = KMData::VERSION
|
10
|
-
spec.authors = ["Kyle Decot"
|
11
|
-
spec.email = ["decot.7@osu.edu"
|
9
|
+
spec.authors = ["Kyle Decot"]
|
10
|
+
spec.email = ["decot.7@osu.edu"]
|
12
11
|
spec.description = %q{A simple API wrapper for interacting with the KMData Project}
|
13
12
|
spec.summary = %q{A simple API wrapper for interacting with the KMData Project}
|
14
|
-
spec.homepage = "
|
13
|
+
spec.homepage = ""
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
17
16
|
spec.files = `git ls-files`.split($/)
|
@@ -21,8 +20,10 @@ Gem::Specification.new do |spec|
|
|
21
20
|
|
22
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
22
|
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "pry"
|
25
23
|
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
26
25
|
|
27
26
|
spec.add_runtime_dependency "json"
|
27
|
+
spec.add_runtime_dependency "recursive-open-struct"
|
28
|
+
|
28
29
|
end
|
data/lib/kmdata/version.rb
CHANGED
data/lib/kmdata.rb
CHANGED
@@ -1,36 +1,60 @@
|
|
1
|
-
|
1
|
+
require "kmdata/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'recursive-open-struct'
|
6
|
+
require 'pp'
|
2
7
|
|
3
8
|
module KMData
|
4
|
-
|
9
|
+
class << self
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
#
|
12
|
+
#
|
13
|
+
#
|
14
|
+
def endpoint
|
15
|
+
"kmdata.osu.edu"
|
16
|
+
end
|
12
17
|
|
13
|
-
|
18
|
+
#
|
19
|
+
#
|
20
|
+
#
|
21
|
+
def get(path, params = {})
|
22
|
+
path = path_with_params("/api/#{path}.json", params)
|
14
23
|
|
15
|
-
|
16
|
-
|
17
|
-
|
24
|
+
response = http.request(Net::HTTP::Get.new(path))
|
25
|
+
|
26
|
+
if response.body
|
27
|
+
json = JSON.parse(response.body)
|
18
28
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
if json.is_a? Array
|
30
|
+
json.map do |j|
|
31
|
+
RecursiveOpenStruct.new(j, recurse_over_arrays: true)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
RecursiveOpenStruct.new(json, recurse_over_arrays: true)
|
35
|
+
end
|
36
|
+
end
|
24
37
|
end
|
25
|
-
end
|
26
38
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
39
|
+
#
|
40
|
+
#
|
41
|
+
#
|
42
|
+
def http
|
43
|
+
@http ||= begin
|
44
|
+
http = Net::HTTP.new(endpoint, 443)
|
45
|
+
http.use_ssl = true
|
46
|
+
http
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
#
|
53
|
+
#
|
54
|
+
#
|
55
|
+
def path_with_params(path, params)
|
56
|
+
encoded_params = URI.encode_www_form(params)
|
57
|
+
[path, encoded_params].join('?')
|
34
58
|
end
|
35
59
|
end
|
36
60
|
end
|
data/spec/kmdata_spec.rb
CHANGED
@@ -8,58 +8,31 @@ describe KMData do
|
|
8
8
|
context 'success' do
|
9
9
|
it 'returns an array of terms' do
|
10
10
|
response = double()
|
11
|
-
response.stub
|
12
|
-
response.stub
|
11
|
+
response.stub(:code) { "200" }
|
12
|
+
response.stub(:body) { json }
|
13
13
|
|
14
|
-
KMData.stub
|
15
|
-
KMData.stub
|
16
|
-
KMData.get('terms').
|
14
|
+
KMData.stub(:path_with_params).with("/api/terms.json", {}).and_return("/api/terms.json")
|
15
|
+
KMData.stub(:request).with(anything()).and_return(response)
|
16
|
+
KMData.get('terms').should_not be_nil
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'failure' do
|
21
21
|
it 'returns nil' do
|
22
22
|
response = double()
|
23
|
-
response.stub
|
24
|
-
response.stub
|
23
|
+
response.stub(:code) { "500" }
|
24
|
+
response.stub(:body) { nil }
|
25
25
|
|
26
|
-
KMData.stub
|
27
|
-
KMData.stub
|
26
|
+
KMData.stub(:path_with_params).with("/api/terms.json", {}).and_return("/api/terms.json")
|
27
|
+
KMData.http.stub(:request).with(anything()).and_return(response)
|
28
28
|
KMData.get('terms').should be_nil
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
33
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
34
|
describe '.http' do
|
45
35
|
subject { KMData.send :http }
|
46
36
|
it { should respond_to(:request) }
|
47
37
|
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
38
|
end
|
metadata
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kmdata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Decot
|
8
|
-
- Mike Butsko
|
9
|
-
- Ryan Stocker
|
10
8
|
autorequire:
|
11
9
|
bindir: bin
|
12
10
|
cert_chain: []
|
13
|
-
date: 2013-
|
11
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
14
|
name: bundler
|
@@ -41,7 +39,7 @@ dependencies:
|
|
41
39
|
- !ruby/object:Gem::Version
|
42
40
|
version: '0'
|
43
41
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
42
|
+
name: rspec
|
45
43
|
requirement: !ruby/object:Gem::Requirement
|
46
44
|
requirements:
|
47
45
|
- - '>='
|
@@ -55,7 +53,7 @@ dependencies:
|
|
55
53
|
- !ruby/object:Gem::Version
|
56
54
|
version: '0'
|
57
55
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
56
|
+
name: pry
|
59
57
|
requirement: !ruby/object:Gem::Requirement
|
60
58
|
requirements:
|
61
59
|
- - '>='
|
@@ -82,12 +80,25 @@ dependencies:
|
|
82
80
|
- - '>='
|
83
81
|
- !ruby/object:Gem::Version
|
84
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: recursive-open-struct
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
85
97
|
description: A simple API wrapper for interacting with the KMData Project
|
86
98
|
email:
|
87
99
|
- decot.7@osu.edu
|
88
|
-
|
89
|
-
-
|
90
|
-
executables: []
|
100
|
+
executables:
|
101
|
+
- kmdata
|
91
102
|
extensions: []
|
92
103
|
extra_rdoc_files: []
|
93
104
|
files:
|
@@ -96,13 +107,14 @@ files:
|
|
96
107
|
- LICENSE.txt
|
97
108
|
- README.md
|
98
109
|
- Rakefile
|
110
|
+
- bin/kmdata
|
99
111
|
- kmdata.gemspec
|
100
112
|
- lib/kmdata.rb
|
101
113
|
- lib/kmdata/version.rb
|
102
114
|
- spec/fixtures/terms.json
|
103
115
|
- spec/kmdata_spec.rb
|
104
116
|
- spec/spec_helper.rb
|
105
|
-
homepage:
|
117
|
+
homepage: ''
|
106
118
|
licenses:
|
107
119
|
- MIT
|
108
120
|
metadata: {}
|
@@ -122,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
134
|
version: '0'
|
123
135
|
requirements: []
|
124
136
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.0.
|
137
|
+
rubygems_version: 2.0.6
|
126
138
|
signing_key:
|
127
139
|
specification_version: 4
|
128
140
|
summary: A simple API wrapper for interacting with the KMData Project
|