faithteams-api 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.github/CODEOWNERS +1 -0
- data/.github/CONTRIBUTING.md +35 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +8 -0
- data/.github/workflows/jeweler.yml +11 -0
- data/.github/workflows/puller.yml +17 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.rubocop.yml +227 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +70 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +171 -0
- data/Guardfile +50 -0
- data/LICENSE +21 -0
- data/README.md +85 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/faithteams-api.gemspec +47 -0
- data/guides/api_client_interface.md +18 -0
- data/guides/release-process.md +11 -0
- data/lib/faithteams/api/v2/connection.rb +142 -0
- data/lib/faithteams/api/v2/entity/base.rb +36 -0
- data/lib/faithteams/api/v2/entity/batch.rb +68 -0
- data/lib/faithteams/api/v2/entity/contribution.rb +19 -0
- data/lib/faithteams/api/v2/entity/contribution_record.rb +137 -0
- data/lib/faithteams/api/v2/entity/contribution_type.rb +37 -0
- data/lib/faithteams/api/v2/entity/fund.rb +52 -0
- data/lib/faithteams/api/v2/entity/person.rb +77 -0
- data/lib/faithteams/api/v2/entity.rb +17 -0
- data/lib/faithteams/api/v2/error/no_search_parameter_provided.rb +12 -0
- data/lib/faithteams/api/v2/error/request.rb +46 -0
- data/lib/faithteams/api/v2/error.rb +13 -0
- data/lib/faithteams/api/v2/gateway.rb +51 -0
- data/lib/faithteams/api/v2/gateway_base.rb +25 -0
- data/lib/faithteams/api/v2/resource/base.rb +46 -0
- data/lib/faithteams/api/v2/resource/batch.rb +58 -0
- data/lib/faithteams/api/v2/resource/contribution.rb +39 -0
- data/lib/faithteams/api/v2/resource/contribution_type.rb +38 -0
- data/lib/faithteams/api/v2/resource/fund.rb +22 -0
- data/lib/faithteams/api/v2/resource/person.rb +48 -0
- data/lib/faithteams/api/v2/resource/user.rb +40 -0
- data/lib/faithteams/api/v2/resource.rb +18 -0
- data/lib/faithteams/api/v2.rb +15 -0
- data/lib/faithteams/api.rb +8 -0
- data/lib/faithteams/version.rb +6 -0
- data/lib/faithteams.rb +7 -0
- data/thunder-tests/.gitignore +2 -0
- data/thunder-tests/collections/tc_col_faithteams.json +2390 -0
- data/thunder-tests/environments/tc_env_faithteams.json +59 -0
- data/thunder-tests/faithteams.env.template +5 -0
- 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
|
data/lib/faithteams.rb
ADDED