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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 236a165a8c4edf1cc467f6dadc62486a63d21d9f
4
- data.tar.gz: 1a63a97001f8ac2aea3bd9b1e5626899e4dff599
3
+ metadata.gz: 20631034148f7e58e7e6c2b1fbcc877609dee837
4
+ data.tar.gz: 332e1967f58e34e826ac531ea30feece4a1b5f0b
5
5
  SHA512:
6
- metadata.gz: fcf8241c81a4ccb4e5289061ffde05ac3ab899820834cf6529d338e007e1f8d0e18a9beac753c86e4b578b5cd32eac44d03e4760a729006ee6fd33b3df956fd5
7
- data.tar.gz: f5b35c143e81d1746fe47c3a2a021d5a445552e0f24f5088734c4d58fa52a255824f2c59c7f2a0cea68f9599a0f9b4092a00fa371a11a51daf62c543645bf392
6
+ metadata.gz: f5ccc95d034c84795f36832726b5f2c3155a6a5f5ebf68519111be9bf09c1b484e6530c1d46ea0f7a0598b12603bcf2ea45286a7a1dc6f5aec1dac48bb9728bf
7
+ data.tar.gz: a96294f18d0108e658819a0a0d2aec6d37456412bed1594b004ea90b197735e0781527978e5ae14ed97899b2edff4ef03811f659cc95d133a6264375e045a813
data/bin/kmdata ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'kmdata'
4
+ require 'pry'
5
+ person = KMData.get("people", q: ARGV[0])
6
+
7
+ if person.any?
8
+ person.each do |p|
9
+ p.to_h.each do |k, v|
10
+ puts "#{k}: #{v}"
11
+ end
12
+ end
13
+ end
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 "kmdata/version"
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", "Mike Butsko", "Ryan Stocker"]
11
- spec.email = ["decot.7@osu.edu", "butsko.7@osu.edu", "stocker.19@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 = "https://github.com/ASCTech/kmdata-ruby"
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
@@ -1,3 +1,3 @@
1
1
  module KMData
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/kmdata.rb CHANGED
@@ -1,36 +1,60 @@
1
- %w[kmdata/version net/http json ostruct].each { |f| require f }
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
- ENDPOINT = "kmdata.osu.edu"
9
+ class << self
5
10
 
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
11
+ #
12
+ #
13
+ #
14
+ def endpoint
15
+ "kmdata.osu.edu"
16
+ end
12
17
 
13
- private
18
+ #
19
+ #
20
+ #
21
+ def get(path, params = {})
22
+ path = path_with_params("/api/#{path}.json", params)
14
23
 
15
- def self.request(path)
16
- http.request(Net::HTTP::Get.new(path))
17
- end
24
+ response = http.request(Net::HTTP::Get.new(path))
25
+
26
+ if response.body
27
+ json = JSON.parse(response.body)
18
28
 
19
- def self.http
20
- @http ||= begin
21
- http = Net::HTTP.new(ENDPOINT, 443)
22
- http.use_ssl = true
23
- http
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
- 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
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!(:code) { "200" }
12
- response.stub!(:body) { json }
11
+ response.stub(:code) { "200" }
12
+ response.stub(:body) { json }
13
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))
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!(:code) { "500" }
24
- response.stub!(:body) { nil }
23
+ response.stub(:code) { "500" }
24
+ response.stub(:body) { nil }
25
25
 
26
- KMData.stub!(:path_with_params).with("/api/terms.json", {})
27
- KMData.stub!(:request).with(anything).and_return(response)
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.1
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-06-25 00:00:00.000000000 Z
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: pry
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: rspec
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
- - butsko.7@osu.edu
89
- - stocker.19@osu.edu
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: https://github.com/ASCTech/kmdata-ruby
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.3
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