Skip to content

Commit 3016f2e

Browse files
committed
Add OrionService and make call in OrgDomainController
1 parent 2606651 commit 3016f2e

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

app/controllers/api/org_domain_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ def index
1212
if email_param.present?
1313
# filtered_orgs = dummy_orgs.select { |org| org[:domain] == email_domain }
1414
org_results = OrgDomain.search_with_org_info(email_domain)
15+
16+
# Call OrionService to search by domain
17+
orion_response = ::ExternalApis::OrionService.search_by_domain(email_domain)
18+
puts orion_response
19+
1520
result = org_results.map { |record|
1621
{
1722
id: record.id,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# app/services/external_api/orion_service.rb
2+
3+
require 'net/http'
4+
require 'uri'
5+
require 'json'
6+
7+
module ExternalApis
8+
class OrionService
9+
ORION_URL = "http://74.220.18.40:8080/submit"
10+
11+
def self.search_by_ror_id(ror_id)
12+
return { error: 'Missing ROR ID' } if ror_id.blank?
13+
14+
payload = {
15+
cmd: "search_by_ror_id",
16+
value: [ror_id]
17+
}
18+
19+
post_to_orion(payload)
20+
end
21+
22+
def self.search_by_domain(domain)
23+
return { error: 'Missing domain' } if domain.blank?
24+
25+
payload = {
26+
cmd: "search_by_domain",
27+
value: domain
28+
}
29+
30+
post_to_orion(payload)
31+
end
32+
33+
def self.post_to_orion(payload)
34+
uri = URI.parse(ORION_URL)
35+
36+
response = Net::HTTP.post(
37+
uri,
38+
payload.to_json,
39+
{ "Content-Type" => "application/json" }
40+
)
41+
42+
JSON.parse(response.body)
43+
rescue JSON::ParserError
44+
{ error: 'Invalid response from Orion' }
45+
rescue => e
46+
{ error: e.message }
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)