-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
602 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module Nautilus | ||
# A builder for articles that come from Nautilus | ||
class Builder < GenericBuilder | ||
private | ||
|
||
def publication | ||
Publication.nautilus.first | ||
end | ||
|
||
def publication_url | ||
'http://http://mitp.nautil.us/' | ||
end | ||
|
||
def article_title | ||
@xml.css('.LongformA_textbody h2').text | ||
end | ||
|
||
def article_full_text | ||
@xml.css('article').text | ||
end | ||
|
||
def article_published_on | ||
# Inexact since Nautilus uses monthly publication | ||
DateTime.parse(@xml.css('.general_datetype').text) | ||
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Nautilus | ||
# HTTParty client for Nautilus that takes an article path | ||
# and get's the text of the article | ||
class Client < GenericClient | ||
base_uri 'mitp.nautil.us' | ||
|
||
private | ||
|
||
def call_builder | ||
Nautilus::Builder.new(@response_body, @path, @article_id).article | ||
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
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 Nautilus::Builder, type: :builder do | ||
let!(:publication) { Publication.create(name: 'Nautilus') } | ||
|
||
describe 'building an article' do | ||
let(:response_body) { File.open('spec/fixtures/nautilus_article.html').read } | ||
let(:path) { '/feature/257/how-to-obfuscate' } | ||
let(:subject) { Nautilus::Builder.new(response_body, path) } | ||
|
||
it 'creates a article in the database' do | ||
expect(subject.article).to eq(Article.first) | ||
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,30 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Nautilus::Builder, type: :client do | ||
let!(:publication) { Publication.create(name: 'New York Times') } | ||
|
||
describe 'building an article' do | ||
let(:response_body) { File.open('spec/fixtures/nautilus_article.html').read } | ||
let(:url) { 'http://mitp.nautil.us/feature/257/how-to-obfuscate' } | ||
let(:article_id) { nil } | ||
let(:subject) { Nautilus::Client.new(url, article_id) } | ||
|
||
context 'good response' do | ||
let!(:stub) { stub_request(:any, /nautil/).to_return(body: response_body) } | ||
|
||
it 'creates a article in the database' do | ||
expect(subject.article.title).to eq(Article.first.title) | ||
expect(subject.article.date).to eq(Article.first.date) | ||
end | ||
end | ||
|
||
context '404 response' do | ||
let!(:stub) { stub_request(:any, /nautil/).to_return(status: 404) } | ||
|
||
it 'captures the code and does not create an article' do | ||
expect(subject.article).to eq(nil) | ||
expect(subject.code).to eq(404) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.