-
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 pull request #35 from turingschool/feature/microservice-connection
Feature/microservice connection
- Loading branch information
Showing
13 changed files
with
211 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Api::V1::SummariesController < ApplicationController | ||
def show | ||
summary = SummaryService.new.summarize | ||
summary_json = JSON.parse(summary.body, symbolize_names: true) | ||
render json: SummarySerializer.new(summary_json).serialize_json | ||
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,17 @@ | ||
class SummarySerializer | ||
def initialize(summary) | ||
@link = summary[:data][:link] | ||
@summary = summary[:data][:summary] | ||
end | ||
|
||
def serialize_json | ||
{ | ||
data: { | ||
attributes: { | ||
link: @link, | ||
summary: @summary | ||
} | ||
} | ||
} | ||
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,9 @@ | ||
class SummaryService | ||
def conn | ||
Faraday.new('https://nameless-garden-14218-de5663d17d61.herokuapp.com/') | ||
end | ||
|
||
def summarize | ||
conn.get('/api/v1/ping/') | ||
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
52 changes: 52 additions & 0 deletions
52
spec/fixtures/vcr_cassettes/SummaryService/gets_a_summary_for_a_link.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
spec/fixtures/vcr_cassettes/summary_request/can_get_a_summary_of_a_link.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'summary request' do | ||
it 'can get a summary of a link', :vcr do | ||
get '/api/v1/summary?link=www.example.com' | ||
|
||
expect(response).to be_successful | ||
|
||
summary = JSON.parse(response.body, symbolize_names: true) | ||
|
||
expect(summary[:data][:attributes][:link]).to eq('www.example.com') | ||
expect(summary[:data][:attributes][:summary]).to eq("1. example 1\n2. example 2\n3. example 3") | ||
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,15 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe SummaryService do | ||
it 'gets a summary for a link', :vcr do | ||
response = SummaryService.new.summarize | ||
|
||
summary = JSON.parse(response.body, symbolize_names: true) | ||
|
||
expect(summary[:data]).to have_key(:link) | ||
expect(summary[:data]).to have_key(:summary) | ||
|
||
expect(summary[:data][:link]).to eq 'www.example.com' | ||
expect(summary[:data][:summary]).to eq "1. example 1\n2. example 2\n3. example 3" | ||
end | ||
end |