Skip to content

Commit 16ec282

Browse files
authored
Merge pull request #1239 from ctti-clinicaltrials/dev
Fix CTGov API Connection Issue
2 parents 8b367be + ee6d9db commit 16ec282

File tree

8 files changed

+38
-20
lines changed

8 files changed

+38
-20
lines changed

Gemfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ source "https://rubygems.org"
22

33
ruby "2.7.7"
44

5+
# Pin ffi to version compatible with Ruby 2.7.7 and RubyGems 3.1.6
6+
gem 'ffi', '< 1.17.0'
7+
58
gem "sprockets"
69
gem "rubyzip", ">= 1.2.2"
710

@@ -17,7 +20,7 @@ gem 'activesupport', '6.0.0'
1720
gem 'actionpack', '6.0.0'
1821
gem 'rails-html-sanitizer'
1922
gem "rack-timeout"
20-
gem "faraday"
23+
gem "faraday", "~> 2.7"
2124
gem 'faraday-retry'
2225
gem "autoprefixer-rails"
2326
gem "flutie"
@@ -46,6 +49,8 @@ gem 'airbrake'
4649
gem 'parallel'
4750
gem 'ruby-progressbar'
4851
gem "aws-sdk-s3", require: false
52+
# Faraday adapter using libcurl (HTTP/2 support, bypasses WAF/bot detection)
53+
gem 'faraday-typhoeus'
4954

5055
# deployment to server
5156
gem 'capistrano', '~> 3.8'

Gemfile.lock

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ GEM
8686
aws-sigv4 (~> 1.4)
8787
aws-sigv4 (1.4.0)
8888
aws-eventstream (~> 1, >= 1.0.2)
89+
base64 (0.3.0)
8990
builder (3.2.4)
9091
bullet (7.0.1)
9192
activesupport (>= 3.0.0)
@@ -131,18 +132,25 @@ GEM
131132
enumerize (2.5.0)
132133
activesupport (>= 3.2)
133134
erubi (1.10.0)
135+
ethon (0.15.0)
136+
ffi (>= 1.15.0)
134137
execjs (2.8.1)
135138
factory_bot (6.2.0)
136139
activesupport (>= 5.0.0)
137140
factory_bot_rails (6.2.0)
138141
factory_bot (~> 6.2.0)
139142
railties (>= 5.0.0)
140-
faraday (2.1.0)
141-
faraday-net_http (~> 2.0)
143+
faraday (2.8.1)
144+
base64
145+
faraday-net_http (>= 2.0, < 3.1)
142146
ruby2_keywords (>= 0.0.4)
143-
faraday-net_http (2.0.1)
147+
faraday-net_http (3.0.2)
144148
faraday-retry (2.2.1)
145149
faraday (~> 2.0)
150+
faraday-typhoeus (1.1.0)
151+
faraday (~> 2.0)
152+
typhoeus (~> 1.4)
153+
ffi (1.16.3)
146154
flutie (2.2.0)
147155
font-awesome-rails (4.7.0.8)
148156
railties (>= 3.2, < 8.0)
@@ -355,6 +363,8 @@ GEM
355363
thread_safe (0.3.6)
356364
tilt (2.0.10)
357365
timecop (0.9.4)
366+
typhoeus (1.5.0)
367+
ethon (>= 0.9.0, < 0.16.0)
358368
tzinfo (1.2.10)
359369
thread_safe (~> 0.1)
360370
unf (0.1.4)
@@ -395,8 +405,10 @@ DEPENDENCIES
395405
enumerize
396406
execjs
397407
factory_bot_rails
398-
faraday
408+
faraday (~> 2.7)
399409
faraday-retry
410+
faraday-typhoeus
411+
ffi (< 1.17.0)
400412
flutie
401413
font-awesome-rails
402414
formulaic

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# AACT
22

3-
AACT or Aggregated Analysis of ClinicalTrials.gov is an application for retrieving all of the public data from <a href="clinicaltrials.gov" target="_blank">clinicaltrials.gov</a> (via their API) and make the information available in a relational database. We do this to make this valuable body of information accessible to the public as a complete aggregated set of data.
3+
AACT or Aggregated Analysis of ClinicalTrials.gov is an application for retrieving all of the public data from ClinicalTrials.gov (via their API) and makes the information available in a relational database. We do this to provide this valuable body of information accessible to the public as a complete aggregated set of data.
44

5-
If you need a copy of the database, but don't want to bother installing & running this app, copies of the database are available for download from the <a href='https://aact.ctti-clinicaltrials.org/snapshots' target='_blank'>AACT website (Download page).</a> We use pg_dump to create a snapshot of the database after each nightly update, so a version is always available with the most current info from clinicaltrials.gov.
5+
If you need a copy of the database, but don't want to install and run this app, copies of the database are available for download from the <a href='https://aact.ctti-clinicaltrials.org/downloads' target='_blank'>AACT website (Download page).</a> We use pg_dump to create a snapshot of the database after each nightly update, so a version is always available with the most current info from clinicaltrials.gov.
66

77
### Database Explanation:
88

@@ -249,4 +249,4 @@ for example:
249249
rake compare:v2_model[NCT06225401,design]
250250
```
251251

252-
This tool will tell you where there is a mismatch between version 1 and version 2 of the api
252+
This tool will tell you where there is a mismatch between version 1 and version 2 of the api

app/services/http_client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def setup_connection(base_url, timeout: 10, open_timeout: 5, retries: 3)
2323
f.response :raise_error # 40x, 50x errors -> Faraday::ClientError, Faraday::ServerError
2424
# convert JSON string to Ruby hash inside body if header is application/json
2525
f.response :json # fails with Faraday::ParsingError
26-
f.adapter Faraday.default_adapter # keep for clarity
26+
# Use Typhoeus adapter with HTTP/2 support to mimic curl behavior
27+
f.adapter :typhoeus, http_version: :httpv2_0
2728
f.options.timeout = timeout # max timeout for request
2829
f.options.open_timeout = open_timeout # for connection to open
2930
end

spec/mailers/notifier_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'spec_helper'
33

44
describe Notifier, type: :mailer do
5-
let(:stub_request_headers) { {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v2.1.0' } }
5+
let(:stub_request_headers) { {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v2.8.1' } }
66
let(:study_statistics_body) {File.read('spec/support/json_data/study_statistics.json') }
77
let(:mailer_stub) { stub_request(:get, 'https://classic.clinicaltrials.gov/api//info/study_statistics?fmt=json').with(headers: stub_request_headers).to_return(:status => 200, :body => study_statistics_body, :headers => {}) }
88
let(:msg) { described_class.send_msg('test@gmail.com', event) }

spec/models/clinical_trials_api_v2_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
headers: {
99
'Accept'=>'*/*',
1010
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
11-
'User-Agent'=>'Faraday v2.1.0'
11+
'User-Agent'=>'Faraday v2.8.1'
1212
}).
1313
to_return(status: 200, body: '[{"nctId": "NCT123456", "title": "Sample Study"}]', headers: {})
1414

@@ -27,7 +27,7 @@
2727
headers: {
2828
'Accept'=>'*/*',
2929
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
30-
'User-Agent'=>'Faraday v2.1.0'
30+
'User-Agent'=>'Faraday v2.8.1'
3131
}).
3232
to_return(status: 200, body: '{"nctId": "NCT123456", "title": "Sample Study"}', headers: {})
3333

@@ -44,7 +44,7 @@
4444
headers: {
4545
'Accept'=>'*/*',
4646
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
47-
'User-Agent'=>'Faraday v2.1.0'
47+
'User-Agent'=>'Faraday v2.8.1'
4848
}).
4949
to_return(status: 200, body: '[{"field": "sampleField"}]', headers: {})
5050

@@ -61,7 +61,7 @@
6161
headers: {
6262
'Accept'=>'*/*',
6363
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
64-
'User-Agent'=>'Faraday v2.1.0'
64+
'User-Agent'=>'Faraday v2.8.1'
6565
}).
6666
to_return(status: 200, body: '{"size": 100}', headers: {})
6767

@@ -78,7 +78,7 @@
7878
headers: {
7979
'Accept'=>'*/*',
8080
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
81-
'User-Agent'=>'Faraday v2.1.0'
81+
'User-Agent'=>'Faraday v2.8.1'
8282
}).
8383
to_return(status: 200, body: '{"fieldValues": ["value1", "value2"]}', headers: {})
8484

@@ -96,7 +96,7 @@
9696
headers: {
9797
'Accept'=>'*/*',
9898
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
99-
'User-Agent'=>'Faraday v2.1.0'
99+
'User-Agent'=>'Faraday v2.8.1'
100100
}).
101101
to_return(status: 200, body: "{\"field\": \"#{field}\", \"values\": [\"value1\", \"value2\"]}", headers: {})
102102

@@ -114,7 +114,7 @@
114114
headers: {
115115
'Accept'=>'*/*',
116116
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
117-
'User-Agent'=>'Faraday v2.1.0'
117+
'User-Agent'=>'Faraday v2.8.1'
118118
}).
119119
to_return(status: 200, body: '{"listSizes": [10, 20]}', headers: {})
120120

@@ -132,7 +132,7 @@
132132
headers: {
133133
'Accept'=>'*/*',
134134
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
135-
'User-Agent'=>'Faraday v2.1.0'
135+
'User-Agent'=>'Faraday v2.8.1'
136136
}).
137137
to_return(status: 200, body: "{\"field\": \"#{field}\", \"size\": 5}", headers: {})
138138

spec/models/utils/util_updater_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22

33
describe Util::Updater do
4-
let(:stub_request_headers) { {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v2.1.0' } }
4+
let(:stub_request_headers) { {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v2.8.1' } }
55
let(:ctg_api_body) {File.read('spec/support/json_data/ctg_api_all.json') }
66
let(:api_url) { 'https://classic.clinicaltrials.gov/api//query/study_fields?fields=NCTId,StudyFirstPostDate,LastUpdatePostDate&fmt=json&max_rnk=1000&min_rnk=1'}
77
before do

spec/services/http_client_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
expect {
101101
api_client.get(endpoint, params)
102-
}.to raise_error(Faraday::ConnectionFailed) # final error after retries
102+
}.to raise_error(Faraday::TimeoutError) # final error after retries
103103

104104
expect(WebMock).to have_requested(:get, url)
105105
.with(query: params)

0 commit comments

Comments
 (0)