ff_api 0.0.2 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4c6fde97fd38da882b0e0ef52e6a0b2988e647a523354746643fd58e51ab4d5
4
- data.tar.gz: e1932ea676ce4709d93661430c75e6097698146b22233065eea2925e515109ea
3
+ metadata.gz: 601131a4aa2b4ebf9302aea8b37082d4350cddd44060eeffa4d4d2504918ade1
4
+ data.tar.gz: 95757f23e8f47488340ef5d7eb079a68bdc2f599c2baed70e070e3c75196e7c0
5
5
  SHA512:
6
- metadata.gz: eb6adeb322821945519698eb36002973781ee91b6b99672b5fd77a256a3de9739beb091bd1ea76b0d55c1e1ce94967879e66fe5e06a4c51f566ea05f7fc0c738
7
- data.tar.gz: '09cbcd9ee9cf917f46b1e7f935551f5337f5020541627aad8318c0e8dce59156844144456bd2f2125899d0b2b3fdd46616e17d7b686c886a7cbcc71289623869'
6
+ metadata.gz: 77873c1de12e4d8c9de40d4a6db6fffe4a540865b40f637548472044b72f87673723850f612a34650aa36c198615c220a67aa7e2e08dcf62cb12916477638b89
7
+ data.tar.gz: 702f98934970ed046303cafd9d7aa9bda64f64f8b35368e8cad58bec92ab107ee569d20f6534bf661ca230d54ffb4c150461d02b4d3d57574e45c03db2a7be4c
@@ -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/school.rb CHANGED
@@ -6,6 +6,7 @@ module FfApi
6
6
  nces_name
7
7
  name
8
8
  level
9
+ address
9
10
  ]
10
11
  )
11
12
  def initialize(school_hash)
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
- response = connection.get("schools.json", {}) do |request|
21
- request.headers["Authorization"] = "Bearer #{api_key}"
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
- if response.status == 200
24
- schools = JSON.parse(response.body)
25
- schools.map { |school_hash| FfApi::School.new(school_hash) }
26
- elsif response.status == 401
27
- body = JSON.parse(response.body)
28
- body.merge(status: response.status)
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
- # class School
34
- # attr_accessor(
35
- # *%w[
36
- # nces_id
37
- # nces_name
38
- # name
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.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Cotant
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-04-23 00:00:00.000000000 Z
12
+ date: 2024-04-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: An easy to use ruby gem to fetch data from the finalforms database
15
15
  email: austin@finalforms.com
@@ -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: