ff_api 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ff_api/district.rb +22 -0
- data/lib/ff_api.rb +49 -28
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d981b2de6980eb11f6282830bcf623fe8f8e871350c01a2acd0c7dba2830644
|
4
|
+
data.tar.gz: 2045caf3e038024d70cf8687d7dbc20611430118424f9bc314ca102819f686a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '069584465682c60aadad6d4a6b533220bc150b0273656d070f54c81c6ebe1c10f12558d2849bb7b5cf33ca9bfedcc2a10718e2cb1860373e4fc280edd8cba859'
|
7
|
+
data.tar.gz: 80600f4c68d441d399c91238445a2c3fe733c7b2131093d0efd754a98c9b8fa3c702f1183aa886dd6d8201306e3b3f6845e7333c01212976bc01729e4b615384
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FfApi
|
2
|
+
class District
|
3
|
+
attr_accessor(
|
4
|
+
*%w[
|
5
|
+
nces_id
|
6
|
+
nces_name
|
7
|
+
name
|
8
|
+
address
|
9
|
+
schools
|
10
|
+
]
|
11
|
+
)
|
12
|
+
def initialize(district)
|
13
|
+
set(district)
|
14
|
+
end
|
15
|
+
|
16
|
+
def set(params)
|
17
|
+
params.each { |key, value| send("#{key}=", value) }
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/ff_api.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require("faraday")
|
2
2
|
require("byebug")
|
3
3
|
require('ff_api/school')
|
4
|
+
require('ff_api/district')
|
4
5
|
|
5
6
|
|
6
7
|
module FfApi
|
@@ -17,37 +18,57 @@ module FfApi
|
|
17
18
|
|
18
19
|
def schools(params = {})
|
19
20
|
connection = Faraday.new(url: base_url)
|
20
|
-
|
21
|
-
|
21
|
+
if params.is_a?(Hash)
|
22
|
+
response = connection.get("schools.json", params) do |request|
|
23
|
+
request.headers["Authorization"] = "Bearer #{api_key}"
|
24
|
+
end
|
25
|
+
if response.status == 200
|
26
|
+
schools = JSON.parse(response.body)
|
27
|
+
schools.map { |school_hash| FfApi::School.new(school_hash) }
|
28
|
+
else
|
29
|
+
respond_to_error(response)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
response = connection.get("school/#{params}.json") do |request|
|
33
|
+
request.headers["Authorization"] = "Bearer #{api_key}"
|
34
|
+
end
|
35
|
+
if response.status == 200
|
36
|
+
FfApi::School.new(JSON.parse(response.body))
|
37
|
+
else
|
38
|
+
respond_to_error(response)
|
39
|
+
end
|
22
40
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
41
|
+
end
|
42
|
+
|
43
|
+
def districts(params = {})
|
44
|
+
connection = Faraday.new(url: base_url)
|
45
|
+
if params.is_a?(Hash)
|
46
|
+
response = connection.get("districts.json", params) do |request|
|
47
|
+
request.headers["Authorization"] = "Bearer #{api_key}"
|
48
|
+
end
|
49
|
+
if response.status == 200
|
50
|
+
districts = JSON.parse(response.body)
|
51
|
+
districts.map { |district_hash| FfApi::District.new(district_hash) }
|
52
|
+
else
|
53
|
+
respond_to_error(response)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
response = connection.get("district/#{params}.json") do |request|
|
57
|
+
request.headers["Authorization"] = "Bearer #{api_key}"
|
58
|
+
end
|
59
|
+
if response.status == 200
|
60
|
+
FfApi::District.new(JSON.parse(response.body))
|
61
|
+
else
|
62
|
+
respond_to_error(response)
|
63
|
+
end
|
29
64
|
end
|
30
65
|
end
|
31
|
-
end
|
32
66
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# level
|
40
|
-
# ]
|
41
|
-
# )
|
42
|
-
# def initialize(school_hash)
|
43
|
-
# set(school_hash)
|
44
|
-
# end
|
45
|
-
|
46
|
-
# def set(params)
|
47
|
-
# params.each { |key, value| send("#{key}=", value) }
|
48
|
-
# self
|
49
|
-
# end
|
50
|
-
|
51
|
-
# end
|
67
|
+
def respond_to_error(response)
|
68
|
+
body = JSON.parse(response.body)
|
69
|
+
body.merge(status: response.status)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
52
73
|
|
53
74
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ff_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austin Cotant
|
@@ -18,6 +18,7 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/ff_api.rb
|
21
|
+
- lib/ff_api/district.rb
|
21
22
|
- lib/ff_api/school.rb
|
22
23
|
homepage: https://rubygems.org/gems/ff_api
|
23
24
|
licenses:
|