Module: KMData

Defined in:
lib/kmdata.rb,
lib/kmdata/version.rb

Constant Summary collapse

VERSION =
"0.0.8"

Class Method Summary collapse

Class Method Details

.endpointObject



10
11
12
# File 'lib/kmdata.rb', line 10

def endpoint
  "kmdata.osu.edu"
end

.get(path, params = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kmdata.rb', line 14

def get(path, params = {})
  path = path_with_params("/api/#{path}.json", params)

  response = http.request(Net::HTTP::Get.new(path))

  if response.body
    json = JSON.parse(response.body)

    if json.is_a? Array
      json.map do |j|
        RecursiveOpenStruct.new(j, recurse_over_arrays: true)
      end
    else
      RecursiveOpenStruct.new(json, recurse_over_arrays: true)
    end
  end
end

.httpObject



32
33
34
35
36
37
38
# File 'lib/kmdata.rb', line 32

def http
  @http ||= begin
    http = Net::HTTP.new(endpoint, 443)
    http.use_ssl = true
    http
  end
end