Skip to content

Commit 40a0612

Browse files
authored
Merge pull request #7 from tithely/IN-2429/use-basic-auth
IN-2429 3.0.0 Remove Resource::User and authenticate methods for basic authentication
2 parents b1f1490 + 9b6bb6d commit 40a0612

File tree

16 files changed

+2510
-2524
lines changed

16 files changed

+2510
-2524
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ All notable changes to this project will be documented in this file.
77
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

10-
## [2.0.2] - 2024-04-03
10+
## [3.0.0] - 2024-05-20 -
11+
12+
### Fixed
13+
14+
1. Use basic auth for all API requests and remove User. (IN-2429)
15+
16+
### Removed
17+
18+
1. Remove `Resource::User` and `Resource::User#authenticate`. (IN-2429)
19+
20+
## [2.0.2] - 2024-04-04 - https://github.com/tithely/faithteams-api/pull/5
1121

1222
### Fixed
1323

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
faithteams-api (2.0.2)
4+
faithteams-api (3.0.0)
55
activesupport (>= 6.1.7)
66
http (~> 5.1)
77

lib/faithteams/api/v2/connection.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module V2
1010
class Connection
1111
# Specific base urls for different resources
1212
ENDPOINT_BASE_URLS = {
13-
"authenticate" => "https://app.faithteams.com/api/v2",
1413
"batches" => "https://api-v2.faithteams.com",
1514
"contributions" => "https://api-v2.faithteams.com",
1615
"contributiontypes" => "https://api-v2.faithteams.com",
@@ -77,8 +76,6 @@ def request(method: :get, path:, params: {}, body: {})
7776
response = http.get(url, params: params)
7877
end
7978
break if response.status != 401 || retries >= 2
80-
81-
authenticate
8279
end
8380

8481
raise Error::Request.new(response: response, message: "Request unsuccessful (#{response.status})") unless response.status.success?
@@ -116,26 +113,14 @@ def user_resource
116113

117114
# @return [HTTP::Client]
118115
def http
119-
@http ||= HTTP.headers("Token" => "#{auth_token}")
116+
@http ||= HTTP.basic_auth(user: user_id, pass: password)
120117
end
121118

122119
# @param path [String]
123120
# @return [String]
124121
def base_url(path:)
125122
ENDPOINT_BASE_URLS[path.split("/")[1]]
126123
end
127-
128-
# Set the auth_token for these requests
129-
# @return [String]
130-
def auth_token
131-
@auth_token ||= user_resource.authenticate
132-
end
133-
134-
# Resets existing auth_token and re-authenticates
135-
def authenticate
136-
@auth_token = nil
137-
auth_token
138-
end
139124
end
140125
end
141126
end

lib/faithteams/api/v2/gateway.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ def contribution
3232
@contribution ||= Resource::Contribution.new(connection: connection)
3333
end
3434

35-
# @return [Resource::User]
36-
def user
37-
@user ||= Resource::User.new(connection: connection)
38-
end
39-
4035
# @return [Resource::ContributionType]
4136
def contribution_type
4237
@contribution_type ||= Resource::ContributionType.new(connection: connection)

lib/faithteams/api/v2/resource.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require_relative "resource/fund"
66
require_relative "resource/person"
77
require_relative "resource/contribution"
8-
require_relative "resource/user"
98
require_relative "resource/contribution_type"
109

1110
module FaithTeams

lib/faithteams/api/v2/resource/user.rb

Lines changed: 0 additions & 40 deletions
This file was deleted.

lib/faithteams/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module FaithTeams
44
# Current version number.
5-
VERSION = "2.0.2"
5+
VERSION = "3.0.0"
66
end

spec/faithteams/api/v2/connection_spec.rb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
it "is false if connection is not valid" do
3131
stub_contribution_types(status: 401, body: any_json(status: 401))
32-
stub_authenticate(status: 401, body: any_json(status: 401))
3332
expect(connection.valid?).to be(false)
3433
end
3534
end
@@ -118,45 +117,29 @@
118117

119118
describe "request" do
120119
context "when successful" do
121-
before do
122-
stub_authenticate
123-
end
124-
125120
it "returns HTTP::Response" do
126121
stub_funds
127122
expect(connection.request(path: "/funds")).to be_a(HTTP::Response)
128123
end
129124
end
130125

131-
context "when authentication fails on non-authenticate request" do
126+
context "when failure" do
132127
before do
133128
stub_funds(status: 401, body: any_json(status: 401))
134-
stub_authenticate
135129
end
136130

137131
it "will raise unathenticated error after multiple attempts" do
138-
expect(connection.user_resource).to receive(:authenticate).exactly(2).times.and_call_original
139-
140132
expect { connection.request(path: "/funds") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful (401 Unauthorized): Unauthorized")
141133
end
142-
end
143-
144-
context "when authentication fails on authenticate request" do
145-
before do
146-
stub_authenticate(status: 401, body: any_json(status: 401))
147-
end
148134

149135
it "will raise unathenticated error immediately" do
150-
expect(connection.user_resource).to receive(:authenticate).once.and_call_original
151-
152136
expect { connection.request(path: "/funds") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful (401 Unauthorized): Unauthorized")
153137
end
154138
end
155139

156140
context "when not successful" do
157141
before do
158142
stub_funds(status: 511, body: "")
159-
stub_authenticate
160143
end
161144

162145
it "raises Error::Request" do
@@ -185,7 +168,6 @@
185168

186169
context "not successful" do
187170
it "raises error if response is not 200" do
188-
stub_authenticate
189171
stub_funds(status: 500, body: any_json(status: 500))
190172
expect { connection.request_and_parse(path: "/funds") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful (500 Internal Server Error): Internal Server Error")
191173
end
@@ -207,7 +189,6 @@
207189

208190
context "200 status but success = false" do
209191
it "raises Error::Request" do
210-
stub_authenticate
211192
stub_contributions_find(parent_id: 30, description: "error")
212193
expect { connection.request_and_parse(path: "/contributions/30") }.to raise_error(FaithTeams::API::V2::Error::Request, "Request unsuccessful: Error: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: '429955534343434'")
213194
end

spec/faithteams/api/v2/gateway_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
end
3535
end
3636

37-
describe "user" do
38-
it "is a Resource::User" do
39-
expect(gateway.user).to be_instance_of(FaithTeams::API::V2::Resource::User)
40-
end
41-
end
42-
4337
describe "contribution_type" do
4438
it "is a Resource::ContributionType" do
4539
expect(gateway.contribution_type).to be_instance_of(FaithTeams::API::V2::Resource::ContributionType)

spec/faithteams/api/v2/resource/user_spec.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)