-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #231 from TreinaDev/refactor/api-services
Refactor/api services
- Loading branch information
Showing
18 changed files
with
191 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
module InvitationRequestService | ||
COLABORA_PROJECTS_URL = 'http://localhost:3000/api/v1/projects'.freeze | ||
COLABORA_INVITATIONS_BASE_URL = 'http://localhost:3000/api/v1/invitations'.freeze | ||
include ProjectsService | ||
|
||
class ColaboraProject | ||
def self.send | ||
@response = Faraday.get(COLABORA_PROJECTS_URL) | ||
return build_projects if @response.success? | ||
|
||
raise StandardError | ||
end | ||
|
||
class << self | ||
private | ||
|
||
def build_projects | ||
projects = JSON.parse(@response.body, symbolize_names: true) | ||
projects.map do |project| | ||
Project.new(id: project[:id], | ||
title: project[:title], | ||
description: project[:description], | ||
category: project[:category]) | ||
end | ||
end | ||
end | ||
end | ||
COLABORA_BASE_URL = Rails.configuration.colabora_api_v1.base_url | ||
COLABORA_API_V1_PROJECTS_URL = Rails.configuration.colabora_api_v1.projects_url | ||
COLABORA_API_V1_PROPOSALS_URL = Rails.configuration.colabora_api_v1.proposals_url | ||
|
||
class InvitationRequest | ||
def self.send(requests) | ||
return [] if requests.empty? | ||
|
||
projects = ColaboraProject.send | ||
projects = ProjectsService::ColaBoraProject.send | ||
|
||
requests.map do |request| | ||
project = projects.find { |proj| proj.id == request.project_id } | ||
InvitationRequestInfo.new(invitation_request: request, project:) | ||
end | ||
end | ||
end | ||
|
||
class ColaBoraInvitationRequestPost | ||
def self.send(invitation_request) | ||
@invitation_request = invitation_request | ||
post_connection | ||
|
||
@response | ||
end | ||
|
||
class << self | ||
private | ||
|
||
def build_invitation_request_params(invitation_request) | ||
{ 'proposal': { 'invitation_request_id': invitation_request.id, 'email': invitation_request.profile.email, | ||
'message': invitation_request.message, 'profile_id': invitation_request.profile.id, | ||
'project_id': invitation_request.project_id } }.as_json | ||
end | ||
|
||
def post_connection | ||
url = "#{COLABORA_BASE_URL}#{COLABORA_API_V1_PROPOSALS_URL}" | ||
@response = Faraday.post(url, build_invitation_request_params(@invitation_request)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module ProjectsService | ||
COLABORA_BASE_URL = Rails.configuration.colabora_api_v1.base_url | ||
COLABORA_API_V1_PROJECTS_URL = Rails.configuration.colabora_api_v1.projects_url | ||
|
||
class ColaBoraProject | ||
def self.send | ||
@response = ColaBoraApiGetProjects.send | ||
return build_projects if @response.success? | ||
|
||
raise StandardError | ||
end | ||
|
||
class << self | ||
private | ||
|
||
def build_projects | ||
projects = JSON.parse(@response.body, symbolize_names: true) | ||
projects.map do |project| | ||
Project.new(id: project[:id], | ||
title: project[:title], | ||
description: project[:description], | ||
category: project[:category]) | ||
end | ||
end | ||
end | ||
end | ||
|
||
class ColaBoraApiGetProjects | ||
def self.send | ||
url = "#{COLABORA_BASE_URL}#{COLABORA_API_V1_PROJECTS_URL}" | ||
Faraday.get(url) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
development: | ||
base_url: 'http://localhost:3000' | ||
projects_url: '/api/v1/projects' | ||
proposals_url: '/api/v1/proposals' | ||
|
||
test: | ||
base_url: 'http://localhost:3000' | ||
projects_url: '/api/v1/projects' | ||
proposals_url: '/api/v1/proposals' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
development: | ||
base_url: 'http://localhost:4000' | ||
invitations_url: '/api/v1/invitations/' | ||
request_invitation_url: '/api/v1/projects/request_invitation' | ||
projects_url: '/api/v1/projects' | ||
|
||
test: | ||
base_url: 'http://localhost:4000' | ||
invitations_url: '/api/v1/invitations/' | ||
request_invitation_url: '/api/v1/projects/request_invitation' | ||
projects_url: '/api/v1/projects' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.