faithteams-api 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/CODEOWNERS +1 -0
  4. data/.github/CONTRIBUTING.md +35 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +8 -0
  6. data/.github/workflows/jeweler.yml +11 -0
  7. data/.github/workflows/puller.yml +17 -0
  8. data/.gitignore +16 -0
  9. data/.rspec +2 -0
  10. data/.rubocop.yml +227 -0
  11. data/.tool-versions +1 -0
  12. data/CHANGELOG.md +70 -0
  13. data/CODE_OF_CONDUCT.md +128 -0
  14. data/Gemfile +6 -0
  15. data/Gemfile.lock +171 -0
  16. data/Guardfile +50 -0
  17. data/LICENSE +21 -0
  18. data/README.md +85 -0
  19. data/Rakefile +8 -0
  20. data/bin/console +15 -0
  21. data/bin/setup +8 -0
  22. data/faithteams-api.gemspec +47 -0
  23. data/guides/api_client_interface.md +18 -0
  24. data/guides/release-process.md +11 -0
  25. data/lib/faithteams/api/v2/connection.rb +142 -0
  26. data/lib/faithteams/api/v2/entity/base.rb +36 -0
  27. data/lib/faithteams/api/v2/entity/batch.rb +68 -0
  28. data/lib/faithteams/api/v2/entity/contribution.rb +19 -0
  29. data/lib/faithteams/api/v2/entity/contribution_record.rb +137 -0
  30. data/lib/faithteams/api/v2/entity/contribution_type.rb +37 -0
  31. data/lib/faithteams/api/v2/entity/fund.rb +52 -0
  32. data/lib/faithteams/api/v2/entity/person.rb +77 -0
  33. data/lib/faithteams/api/v2/entity.rb +17 -0
  34. data/lib/faithteams/api/v2/error/no_search_parameter_provided.rb +12 -0
  35. data/lib/faithteams/api/v2/error/request.rb +46 -0
  36. data/lib/faithteams/api/v2/error.rb +13 -0
  37. data/lib/faithteams/api/v2/gateway.rb +51 -0
  38. data/lib/faithteams/api/v2/gateway_base.rb +25 -0
  39. data/lib/faithteams/api/v2/resource/base.rb +46 -0
  40. data/lib/faithteams/api/v2/resource/batch.rb +58 -0
  41. data/lib/faithteams/api/v2/resource/contribution.rb +39 -0
  42. data/lib/faithteams/api/v2/resource/contribution_type.rb +38 -0
  43. data/lib/faithteams/api/v2/resource/fund.rb +22 -0
  44. data/lib/faithteams/api/v2/resource/person.rb +48 -0
  45. data/lib/faithteams/api/v2/resource/user.rb +40 -0
  46. data/lib/faithteams/api/v2/resource.rb +18 -0
  47. data/lib/faithteams/api/v2.rb +15 -0
  48. data/lib/faithteams/api.rb +8 -0
  49. data/lib/faithteams/version.rb +6 -0
  50. data/lib/faithteams.rb +7 -0
  51. data/thunder-tests/.gitignore +2 -0
  52. data/thunder-tests/collections/tc_col_faithteams.json +2390 -0
  53. data/thunder-tests/environments/tc_env_faithteams.json +59 -0
  54. data/thunder-tests/faithteams.env.template +5 -0
  55. metadata +283 -0
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FaithTeams
4
+ module API
5
+ module V2
6
+ module Resource
7
+ # Fund resource
8
+ class Fund < Base
9
+ # @param args [Hash] These are ignored as no filters are available for this endpoint
10
+ # @return [Array<Entity::Fund>]
11
+ # @raise [Error::Request]
12
+ def search(**args)
13
+ data = connection.get(path: "/funds")["data"]
14
+ return [] unless data
15
+
16
+ data.map { |r| Entity::Fund.new(attributes: r) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FaithTeams
4
+ module API
5
+ module V2
6
+ module Resource
7
+ # Person resource
8
+ class Person < Base
9
+ # By default, it only looks for active people. To search for inactive people, pass in status: "I".
10
+ # @param args [Hash] Search parameters consisting of symbole key => value pairs
11
+ # @return [Array<Entity::Person>]
12
+ # @raise [Error::Request]
13
+ def search(**args)
14
+ params = { status: "A" }.merge(args)
15
+
16
+ data = connection.get(path: "/people", params: params.stringify_keys)["data"]
17
+ return [] unless data.present?
18
+
19
+ data.map { |r| Entity::Person.new(attributes: r) }
20
+ end
21
+
22
+ # @param id [Integer]
23
+ # @return [Entity::Person, nil]
24
+ # @raise [Error::Request]
25
+ def find(id:)
26
+ raise FaithTeams::API::V2::Error::NoSearchParameterProvided if id.nil?
27
+
28
+ data = connection.get(path: "/people/#{id}")["data"]
29
+ return nil unless data
30
+
31
+ Entity::Person.new(attributes: data)
32
+ rescue Error::Request => e
33
+ return nil if e.not_found?
34
+ raise
35
+ end
36
+
37
+ # @param entity [Entity::Person]
38
+ # @return [Entity::Person]
39
+ # @raise [Error::Request]
40
+ def create(entity:)
41
+ data = connection.post(path: "/people", body: entity.to_h)["data"]
42
+ Entity::Person.new(attributes: data)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FaithTeams
4
+ module API
5
+ module V2
6
+ module Resource
7
+ # User resource
8
+ class User < Base
9
+ # @return [String] auth_token
10
+ # @raise [Error::Request]
11
+ def authenticate
12
+ response = http.post("#{FaithTeams::API::V2::Connection::ENDPOINT_BASE_URLS["authenticate"]}/authenticate")
13
+
14
+ # raise errors
15
+ raise Error::Request.new(response: response, message: "Request unsuccessful (#{response.status})") unless response.status.success?
16
+
17
+ # parse response
18
+ begin
19
+ response_body = response.parse(:json)
20
+ rescue JSON::ParserError
21
+ raise Error::Request.new(response: response, message: "Failed to parse JSON")
22
+ end
23
+
24
+ response_body.dig("data", "token")
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :http
30
+
31
+ # @return [HTTP::Client]
32
+ def http
33
+ user_credentials = Base64.strict_encode64("#{connection.user_id}:#{connection.password}")
34
+ @http ||= HTTP.auth("Basic #{user_credentials}")
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource/base"
4
+ require_relative "resource/batch"
5
+ require_relative "resource/fund"
6
+ require_relative "resource/person"
7
+ require_relative "resource/contribution"
8
+ require_relative "resource/user"
9
+ require_relative "resource/contribution_type"
10
+
11
+ module FaithTeams
12
+ module API
13
+ module V2
14
+ # A resource that provides CRUD functionality
15
+ module Resource; end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "v2/connection"
4
+ require_relative "v2/entity"
5
+ require_relative "v2/error"
6
+ require_relative "v2/gateway"
7
+ require_relative "v2/gateway_base"
8
+ require_relative "v2/resource"
9
+
10
+ module FaithTeams
11
+ module API
12
+ # FaithTeams API v2
13
+ module V2; end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api/v2"
4
+
5
+ module FaithTeams
6
+ # FaithTeams API
7
+ module API; end
8
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FaithTeams
4
+ # Current version number.
5
+ VERSION = "2.0.1"
6
+ end
data/lib/faithteams.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "faithteams/api"
4
+ require_relative "faithteams/version"
5
+
6
+ # All FaithTeams functionality
7
+ module FaithTeams; end
@@ -0,0 +1,2 @@
1
+ *.env
2
+