diff --git a/app/components/generic_client.rb b/app/components/generic_client.rb index de5b35b..b5a5b6d 100644 --- a/app/components/generic_client.rb +++ b/app/components/generic_client.rb @@ -5,19 +5,19 @@ class GenericClient attr_reader :code, :response_body include HTTParty + base_uri 'https://test.test' # intialize method for the client that sets the article's path # # @param path [String] a uri path # @param article_id [Integer] id of Article if one was already instanciated def initialize(path, article_id = nil) - base_uri # this call ensures that base_uri is implemented @path = path @article_id = article_id end # This method gets the article and calls the builder, returning - # an article if one is built + # an article if one is built. It will fail if base_uri is not set # # @return [Article] def article @@ -30,10 +30,6 @@ def article private - def base_uri - raise NotImplementedError, 'You must implement the base_uri method' - end - def call_builder raise NotImplementedError, 'You must implement the call_builder method' end diff --git a/app/components/long_reads/client.rb b/app/components/long_reads/client.rb index bab21b4..34f4dee 100644 --- a/app/components/long_reads/client.rb +++ b/app/components/long_reads/client.rb @@ -4,11 +4,9 @@ module LongReads # HTTParty client for LongReads that takes an article path # and get's the text of the article class Client < GenericClient - private + base_uri 'longreads.com' - def base_uri - 'longreads.com' - end + private def call_builder LongReads::Builder.new(@response_body, @path, @article_id).article diff --git a/app/components/nautilus/builder.rb b/app/components/nautilus/builder.rb new file mode 100644 index 0000000..5a953fd --- /dev/null +++ b/app/components/nautilus/builder.rb @@ -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 diff --git a/app/components/nautilus/client.rb b/app/components/nautilus/client.rb new file mode 100644 index 0000000..e00f32b --- /dev/null +++ b/app/components/nautilus/client.rb @@ -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 diff --git a/app/components/ny_times/client.rb b/app/components/ny_times/client.rb index 5f088cf..f74785e 100644 --- a/app/components/ny_times/client.rb +++ b/app/components/ny_times/client.rb @@ -4,11 +4,9 @@ module NyTimes # HTTParty client for the NewYork Times that takes an article path # and get's the text of the article class Client < GenericClient - private + base_uri 'nytimes.com' - def base_uri - 'nytimes.com' - end + private def call_builder NyTimes::Builder.new(@response_body, @path, @article_id).article diff --git a/app/models/publication.rb b/app/models/publication.rb index 46e5765..3a0a1d8 100644 --- a/app/models/publication.rb +++ b/app/models/publication.rb @@ -7,4 +7,5 @@ class Publication < ApplicationRecord validates_uniqueness_of :name, :site scope :new_york_times, -> { find_by(name: 'New York Times') } scope :long_reads, -> { find_by(name: 'Long Reads') } + scope :nautilus, -> { find_by(name: 'Nautilus') } end diff --git a/app/views/layouts/_nav_list.html.erb b/app/views/layouts/_nav_list.html.erb index 1bd2e1e..5712e35 100644 --- a/app/views/layouts/_nav_list.html.erb +++ b/app/views/layouts/_nav_list.html.erb @@ -3,6 +3,11 @@ + <%- if current_user.admin? %> + + <% end %> <% end %>