developer_news_cli_app 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1e7342c46b1e77606cfc63af7ea4e237a0efa5fd927098a10ccd65c37b65c272
4
+ data.tar.gz: a295f496964f7133e378defe0e04129f0321d10ee3597b262a4a2a52ef238276
5
+ SHA512:
6
+ metadata.gz: 524fbd17c9b25ee18c7d52db75a4efc83fead0758881b98e61d6311db3b66498d1f0109b7138b3da0fe4a3a848cc12355b5a07d2e60cc6eecb1f4e98430c4083
7
+ data.tar.gz: 5495b5f8f697ce61aff0a4df85b7700f7744563ef4c7e7b22bc9855b504dec257457d6673b003d43eb93976f58e480f3fdbdddf6950f55ed13cca2a68d5b5862
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .screenflow
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at anthony@anthonygharvey.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in developer_news_cli_app.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ developer_news_cli_app (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.0)
12
+ mini_portile2 (2.3.0)
13
+ nokogiri (1.8.1)
14
+ mini_portile2 (~> 2.3.0)
15
+ pry (0.11.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.5.0)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.1)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.16)
38
+ developer_news_cli_app!
39
+ nokogiri
40
+ pry
41
+ rake (~> 10.0)
42
+ rspec (~> 3.0)
43
+
44
+ BUNDLED WITH
45
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Anthony
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/NOTES.md ADDED
@@ -0,0 +1,87 @@
1
+ ### A command line interface for current articles on freeCodeCamp, HackerNoon, Codeburst and baseCS
2
+
3
+ user types "developer-news"
4
+
5
+ shows a list of top 3 articles from each website
6
+
7
+ freeCodeCamp (FCC)
8
+ 1. The unlikely history of the #100DaysOfCode Challenge, and why you should try it for 2018
9
+ 2. An Introduction to React Router v4 and its Philosophy Toward Routing
10
+ 3. Why we should convice our users to update their browsers - it's a win-win
11
+
12
+ HackerNoon (HN)
13
+ 4. Will Robots Become Designers? 3 Tech Design Leaders Are Skeptical
14
+ 5. I'm harvesting credit card numbers and passwords from your site. Here's how.
15
+ 6. Founder Interview: How Codacy Uses Codacy to Build Codacy.
16
+
17
+ Codeburst (CB)
18
+ 7. Focus on scales - d3.js integration
19
+ 8. What Did I Learn in 2017?
20
+ 9. How Operating Sytems Work: 10 Concepts you Should Know as a developer
21
+
22
+ baseCS (BCS)
23
+ 10. A Most Perfect Union: Just-In-Time Compilers
24
+ 11. A Deeper Inspection Into Compilation And Interpolation
25
+ 12. Leveling Up One's Parsing Game with ASTs
26
+
27
+ Enter 1 - 12 to read an article
28
+ puts "Or type the website abbreviation to see its 10 most recent articles
29
+ puts "Or type list to see the main list of articles
30
+ puts "Or type exit to end the program
31
+
32
+ 1
33
+ Article 1 summary
34
+
35
+ 2
36
+ Article 2 summary
37
+
38
+ fcc
39
+ displays the 10 most recent fcc articles
40
+
41
+ hn
42
+ displays the 10 most recent hn articles
43
+
44
+ 1
45
+ displays article 1 summary from hn
46
+
47
+ 5
48
+ displays article 5 summary from hn
49
+
50
+ list
51
+ displays the main list of top 3 articles from each website
52
+
53
+ exit
54
+ thanks the user for using the app and exits
55
+ ___
56
+
57
+
58
+
59
+ check the terms of service for the websites
60
+ if they prohibit scraping, just email them and let them know I'm a Flatiron student and I'd like to scrape the website for a project and publish it to rubygems and that it is not for profit.
61
+
62
+
63
+ ### CLI Workflow
64
+ def call
65
+ get_articles
66
+ start
67
+ end
68
+
69
+ def get_articles
70
+ DeveloperNewsCliApp::FreeCodeCampScrapper.make_artciles
71
+ DeveloperNewsCliApp::HackerNewsScrapper.make_artciles
72
+ DeveloperNewsCliApp::CodeBurstScrapper.make_artciles
73
+ DeveloperNewsCliApp::BaseCSScrapper.make_artciles
74
+ end
75
+
76
+
77
+
78
+ ### Scraper workflow
79
+ def get_articles
80
+ end
81
+
82
+
83
+
84
+ ### Scrapper workflow
85
+ def make_articles
86
+ use Nokoguri to scrape article information from the homepage and create new articles from the Article class; which stores all of the articles in the @@all class variable
87
+ end
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Developer News Cli App
2
+
3
+ The Developer News Cli App is a Ruby gem that scrapes information about the articles on the homepages for FreeCodeCamp, HackerNoon and Codeburst. The gem allows you to select a website and view the article headlines. The app also allows you to select an article to see more information and read the article in your browser; all from the command line.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'developer_news_cli_app'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install developer_news_cli_app
20
+
21
+ ## Usage
22
+
23
+ To start the gem, open your terminal and type:
24
+
25
+ ```
26
+ ./bin/developer-news
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/anthonygharvey/developer_news_cli_app. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the DeveloperNewsCliApp project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/developer_news_cli_app/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "developer_news_cli_app"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/developer_news_cli_app'
4
+
5
+ DeveloperNewsCliApp::CLI.new.call
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ require_relative '../lib/developer_news_cli_app/cli'
6
+ require_relative '../lib/developer_news_cli_app/article'
7
+ require_relative '../lib/developer_news_cli_app/FreeCodeCampScrapper'
8
+ require_relative '../lib/developer_news_cli_app/HackerNoonScrapper'
9
+ require_relative '../lib/developer_news_cli_app/CodeBurstScrapper'
10
+ require_relative '../lib/developer_news_cli_app/AListApartScrapper'
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "developer_news_cli_app/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "developer_news_cli_app"
8
+ spec.version = DeveloperNewsCliApp::VERSION
9
+ spec.authors = ["Anthony"]
10
+ spec.email = ["anthony@anthonygharvey.com"]
11
+
12
+ spec.summary = "An app to display current developer news"
13
+ spec.description = "displays the most recent news from developer websites"
14
+ spec.homepage = "http://anthonygharvey.com"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "nokogiri"
38
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "./developer_news_cli_app/version"
2
+ require_relative '../config/environment.rb'
3
+
4
+ module DeveloperNewsCliApp
5
+ # Your code goes here...
6
+ end
7
+
8
+
@@ -0,0 +1,32 @@
1
+ class DeveloperNewsCliApp::AListApartScrapper
2
+ @@all = []
3
+
4
+ def get_page
5
+ Nokogiri::HTML(open("https://alistapart.com/articles"))
6
+ end
7
+
8
+ def get_articles
9
+ self.get_page.css(".entry-list")
10
+ end
11
+
12
+ def make_article
13
+ self.get_articles.each do |article|
14
+ a = DeveloperNewsCliApp::Article.new
15
+ a.title = article.css(".entry-title a").text
16
+ a.author = article.css(".author").text
17
+ a.date = article.css("time").text
18
+ a.trailing = article.css("p")[1].text
19
+ a.url = "https://alistapart.com" + article.css(".entry-title a").attribute("href").value
20
+ @@all << a
21
+ end
22
+ end
23
+
24
+ def self.articles
25
+ @@all
26
+ end
27
+
28
+ def self.article_count
29
+ @@all.count
30
+ end
31
+
32
+ end
@@ -0,0 +1,33 @@
1
+ class DeveloperNewsCliApp::CodeBurstScrapper
2
+ @@all = []
3
+
4
+ def get_page
5
+ Nokogiri::HTML(open("https://codeburst.io/"))
6
+ end
7
+
8
+ def get_articles
9
+ self.get_page.css(".js-trackedPost")
10
+ end
11
+
12
+ def make_article
13
+ self.get_articles.each do |article|
14
+ a = DeveloperNewsCliApp::Article.new
15
+ a.title = article.css("h3").text
16
+ a.author = article.css(".postMetaInline-authorLockup a").text
17
+ a.date = article.css("time").text
18
+ a.url = article.css("a").attribute("href").value
19
+ a.website = "CodeBurst"
20
+ a.trailing = article.search(".u-fontSize18").text == "" ? nil : article.search(".u-fontSize18").text
21
+ @@all << a
22
+ end
23
+ end
24
+
25
+ def self.articles
26
+ @@all
27
+ end
28
+
29
+ def self.article_count
30
+ @@all.count
31
+ end
32
+
33
+ end
@@ -0,0 +1,35 @@
1
+ class DeveloperNewsCliApp::FreeCodeCampScrapper
2
+ @@all = []
3
+
4
+ def get_page
5
+ Nokogiri::HTML(open("https://medium.freecodecamp.org/"))
6
+ end
7
+
8
+ def get_articles
9
+ self.get_page.css(".postArticle")
10
+ end
11
+
12
+ def make_article
13
+ self.get_articles.each do |article|
14
+ a = DeveloperNewsCliApp::Article.new
15
+ a.title = article.css("h3").text
16
+ a.author = article.css(".ds-link").text
17
+ a.date = article.css("time").text
18
+ a.read_time = article.css(".readingTime").attribute("title").value
19
+ a.url = article.css(".postArticle-readMore a").attribute("href").value
20
+ a.website = "FreeCodeCamp"
21
+ a.subtitle = article.css("h4").text == "" ? nil : article.css("h4").text
22
+ a.trailing = article.css("p").text == "" ? nil : article.css("p").text
23
+ @@all << a
24
+ end
25
+ end
26
+
27
+ def self.articles
28
+ @@all
29
+ end
30
+
31
+ def self.article_count
32
+ @@all.count
33
+ end
34
+
35
+ end
@@ -0,0 +1,33 @@
1
+ class DeveloperNewsCliApp::HackerNoonScrapper
2
+ @@all = []
3
+
4
+ def get_page
5
+ Nokogiri::HTML(open("https://hackernoon.com/"))
6
+ end
7
+
8
+ def get_articles
9
+ self.get_page.css(".js-trackedPost")
10
+ end
11
+
12
+ def make_article
13
+ self.get_articles.each do |article|
14
+ a = DeveloperNewsCliApp::Article.new
15
+ a.title = article.css("h3").text
16
+ a.author = article.css(".ds-link").text
17
+ a.date = article.css("time").text
18
+ a.url = article.css("a").attribute("href").value
19
+ a.website = "HackerNoon"
20
+ a.trailing = article.css(".u-fontSize18").text == "" ? nil : article.css(".u-fontSize18").text
21
+ @@all << a
22
+ end
23
+ end
24
+
25
+ def self.articles
26
+ @@all
27
+ end
28
+
29
+ def self.article_count
30
+ @@all.count
31
+ end
32
+
33
+ end
@@ -0,0 +1,60 @@
1
+ class DeveloperNewsCliApp::Article
2
+ attr_accessor :title, :author, :date, :read_time, :url, :website, :subtitle, :trailing
3
+
4
+ @@all = []
5
+
6
+ def initialize(title = nil, author = nil, date = nil, read_time = nil, url = nil, website = nil, subtile = nil, trailing = nil)
7
+ @title = title
8
+ @author = author
9
+ @date = date
10
+ @read_time = read_time
11
+ @url = url
12
+ @website = website
13
+ @subtitle = subtile
14
+ @trailing = trailing
15
+ @@all << self
16
+ end
17
+
18
+ def self.all
19
+ @@all
20
+ end
21
+
22
+ def self.current_articles
23
+ @@current_articles
24
+ end
25
+
26
+ def self.clear_current_articles
27
+ @@current_articles.clear
28
+ end
29
+
30
+ def self.add_to_current_artciles(articles)
31
+ self.current_articles << articles
32
+ end
33
+
34
+ def self.print_titles
35
+ self.all.each do |article|
36
+ puts "#{article.title}"
37
+ end
38
+ end
39
+
40
+ def self.website(website)
41
+ self.all.collect do |article|
42
+ if article.website == website
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.display_top_three(website)
48
+ self.website(website)[0..2].each.with_index(1) do |article, index|
49
+ puts " #{index}. #{article.title}"
50
+ end
51
+ end
52
+
53
+ def self.display_articles(site)
54
+ puts "#{site}:\n"
55
+ self.website(site)[0..9].each.with_index(1) do |article, index|
56
+ puts " #{index}. #{article.title}"
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,229 @@
1
+ class DeveloperNewsCliApp::CLI
2
+ @@websites = ["FreeCodeCamp", "HackerNoon", "CodeBurst", "A List Apart"]
3
+ @@current_article_count = 0
4
+ @@current_website = ""
5
+ @@current_articles = []
6
+
7
+ def call
8
+ welcome
9
+ get_articles
10
+ list_websites
11
+ get_article_selection
12
+ end
13
+
14
+ def welcome
15
+ puts "Welcome to the Developer News CLI App."
16
+ puts "Scrapping the websties now..."
17
+ end
18
+
19
+ def get_articles
20
+ DeveloperNewsCliApp::FreeCodeCampScrapper.new.make_article
21
+ DeveloperNewsCliApp::HackerNoonScrapper.new.make_article
22
+ DeveloperNewsCliApp::CodeBurstScrapper.new.make_article
23
+ DeveloperNewsCliApp::AListApartScrapper.new.make_article
24
+ end
25
+
26
+ def list_websites
27
+ puts ""
28
+ self.websites.each.with_index(1){|website, index| puts"#{index}. #{website}"}
29
+ puts ""
30
+ puts "Please type the number of the website to see more of its articles"
31
+ puts "Or type exit to end the program"
32
+ get_website_input
33
+ end
34
+
35
+ def get_website_input
36
+ input = nil
37
+ input = gets.strip
38
+ if input == "1"
39
+ show_FreeCodeCampArticles
40
+ elsif input == "2"
41
+ show_HackerNoonArticles
42
+ elsif input == "3"
43
+ show_CodeBurstArticles
44
+ elsif input == "4"
45
+ show_AListApartArticles
46
+ elsif input == "exit"
47
+ goodbye
48
+ elsif input == "list"
49
+ list_websites
50
+ else
51
+ puts "I'm not sure what you meant."
52
+ list_websites
53
+ end
54
+ end
55
+
56
+ def article_selection_instructions
57
+ puts "\nType the number of an article to see more information about it."
58
+ puts "Or type list or l to see a list of websites."
59
+ puts "Or type exit to end the program."
60
+ get_article_selection
61
+ end
62
+
63
+ def get_article_selection
64
+ input = nil
65
+ max_number = @@current_articles.count
66
+ input = gets.strip
67
+ if input.to_i <= max_number && input.to_i != 0
68
+ print_summary(@@current_articles[input.to_i - 1])
69
+ elsif input == "list" || input == "l"
70
+ list_websites
71
+ initial_instructions
72
+ elsif input.to_i > max_number
73
+ puts "I'm not sure what you meant."
74
+ article_selection_instructions
75
+ elsif input =="exit"
76
+ goodbye
77
+ else
78
+ get_article_selection
79
+ end
80
+ end
81
+
82
+ def print_summary(article)
83
+ puts "---------- #{@@current_website} ----------"
84
+ puts "Title: #{article.title}"
85
+ if article.subtitle != nil
86
+ puts "Subtitle: #{article.subtitle}"
87
+ end
88
+ if article.trailing != nil
89
+ puts "Trailing: #{article.trailing}"
90
+ end
91
+ puts "Author: #{article.author}"
92
+ if article.date != nil
93
+ puts "Date: #{article.date}"
94
+ end
95
+ if article.read_time != nil
96
+ puts "Read Time: #{article.read_time}"
97
+ end
98
+ get_article_summary_input(article)
99
+ end
100
+
101
+ def get_article_summary_input(article)
102
+ puts "\nType read or r to open the article in your browser."
103
+ puts "Type back or b to go back to the list of #{@@current_website} articles."
104
+ puts "Type list or l to see a list of websites."
105
+ puts "Type exit to exit the program."
106
+
107
+ input = gets.strip
108
+ case input
109
+ when "r", "read"
110
+ open_url(article)
111
+ print_summary(article)
112
+ when "b", "back"
113
+ if @@current_website == "FreeCodeCamp"
114
+ show_FreeCodeCampArticles
115
+ article_selection_instructions
116
+ elsif @@current_website == "HackerNoon"
117
+ show_HackerNoonArticles
118
+ article_selection_instructions
119
+ elsif @@current_website == "CodeBurst"
120
+ show_CodeBurstArticles
121
+ article_selection_instructions
122
+ else
123
+ show_AListApartArticles
124
+ article_selection_instructions
125
+ end
126
+ when "list", "l"
127
+ list_websites
128
+ # initial_instructions
129
+ get_website_input
130
+ when "exit"
131
+ goodbye
132
+ else
133
+ puts "I'm not sure what you meant."
134
+ get_article_summary_input(article)
135
+ end
136
+ end
137
+
138
+ def show_FreeCodeCampArticles
139
+ @@current_website = "FreeCodeCamp"
140
+ update_current_article_count("FreeCodeCamp")
141
+ @@current_articles = DeveloperNewsCliApp::FreeCodeCampScrapper.articles
142
+ puts "\nFreeCodeCamp:\n"
143
+ DeveloperNewsCliApp::FreeCodeCampScrapper.articles.each.with_index(1) do |article, index|
144
+ puts "#{index}. #{article.title}"
145
+ end
146
+ article_selection_instructions
147
+ end
148
+
149
+ def show_HackerNoonArticles
150
+ @@current_website = "HackerNoon"
151
+ update_current_article_count("HackerNoon")
152
+ @@current_articles = DeveloperNewsCliApp::HackerNoonScrapper.articles
153
+ puts "\nHackerNoon:\n"
154
+ DeveloperNewsCliApp::HackerNoonScrapper.articles.each.with_index(1) do |article, index|
155
+ puts "#{index}. #{article.title}"
156
+ end
157
+ article_selection_instructions
158
+ end
159
+
160
+ def show_CodeBurstArticles
161
+ @@current_website = "CodeBurst"
162
+ update_current_article_count("CodeBurst")
163
+ @@current_articles = DeveloperNewsCliApp::CodeBurstScrapper.articles
164
+ puts "\nCodeBurst:\n"
165
+ DeveloperNewsCliApp::CodeBurstScrapper.articles.each.with_index(1) do |article, index|
166
+ puts "#{index}. #{article.title}"
167
+ end
168
+ article_selection_instructions
169
+ end
170
+
171
+ def show_AListApartArticles
172
+ @@current_website = "AListApart"
173
+ update_current_article_count("AListApart")
174
+ @@current_articles = DeveloperNewsCliApp::AListApartScrapper.articles
175
+ puts "\nA List Apart:\n"
176
+ DeveloperNewsCliApp::AListApartScrapper.articles.each.with_index(1) do |article, index|
177
+ puts "#{index}. #{article.title}"
178
+ end
179
+ article_selection_instructions
180
+ end
181
+
182
+ def list_articles
183
+ puts "Today's top developer articles:"
184
+ puts ""
185
+ display_summaries
186
+ puts ""
187
+ end
188
+
189
+ def display_summaries
190
+ DeveloperNewsCliApp::Article.clear_current_articles
191
+ puts "Free Code Camp (FCC)"
192
+ DeveloperNewsCliApp::Article.add_to_current_artciles(DeveloperNewsCliApp::Article.display_top_three("FreeCodeCamp"))
193
+ puts "HackerNoon (HN)"
194
+ DeveloperNewsCliApp::Article.add_to_current_artciles(DeveloperNewsCliApp::Article.display_top_three("HackerNoon"))
195
+ puts "CodeBurst (CB)"
196
+ DeveloperNewsCliApp::Article.add_to_current_artciles(DeveloperNewsCliApp::Article.display_top_three("CodeBurst"))
197
+ end
198
+
199
+ def open_url(article)
200
+ `open #{article.url}`
201
+ end
202
+
203
+ def websites
204
+ @@websites
205
+ end
206
+
207
+ def current_article_count
208
+ @@current_article_count
209
+ end
210
+
211
+ def update_current_article_count(website)
212
+ case website
213
+ when "FreeCodeCamp"
214
+ @@current_article_count = DeveloperNewsCliApp::FreeCodeCampScrapper.article_count
215
+ when "HackerNoon"
216
+ @@current_article_count = DeveloperNewsCliApp::HackerNoonScrapper.article_count
217
+ when "CodeBurst"
218
+ @@current_article_count = DeveloperNewsCliApp::CodeBurstScrapper.article_count
219
+ when "AListApart"
220
+ @@current_article_count = DeveloperNewsCliApp::AListApartScrapper.article_count
221
+ end
222
+ end
223
+
224
+ def goodbye
225
+ puts "Thanks for using Developer News!"
226
+ exit
227
+ end
228
+
229
+ end
@@ -0,0 +1,3 @@
1
+ module DeveloperNewsCliApp
2
+ VERSION = "0.1.0"
3
+ end
data/spec.md ADDED
@@ -0,0 +1,8 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application - I created a CLI that presents the user with an initial list of websites to view their recent articles. Once the user selects a website a list of its recent articles is shown and the user is presented with options to either select a particular article to view more information about it, go back to the list of websites, or exit the program. If the user selects an article, they are shown more details about the article and given an option to read the article, which will open their browser to the article, go back to the list of website articles, go back to the list of websites, or exit the program.
5
+
6
+ - [x] Pull data from an external source - I used Nokoguri to scrape the homepages of FreeCodeCamp, HackerNoon and Codeburst for article information.
7
+
8
+ - [x] Implement both list and detail views - The CLI allows the user to see a list of websites and is able to drill-down to a list of current articles for their chosen website and to further drill-down to see specific details about a chosen article.
@@ -0,0 +1,50 @@
1
+ ### Updated CLI Workflow for Website Selection
2
+
3
+ ```
4
+ 1. FreeCodeCamp
5
+ 2. HackerNoon
6
+ 3. CodeBurst
7
+
8
+ Welcome to the Developer News CLI App.
9
+ Please type the number of the website to see more of its articles
10
+ Or type exit to end the program
11
+
12
+ $ 1
13
+
14
+ FreeCodeCamp:
15
+ 1. Article Name
16
+ 2. Article Name
17
+ 3. Article Name
18
+ 4. Article Name
19
+ 5. Article Name
20
+ 6. Article Name
21
+ 7. Article Name
22
+ 8. Article Name
23
+ 9. Article Name
24
+ 10. Article Name
25
+ 11. Article Name
26
+
27
+ Type the number of an article to see more information about it.
28
+ Or type list to see a list of websites.
29
+ Or type exit to end the program.
30
+
31
+ $ 3
32
+
33
+ Article Title by Author
34
+ Subtitle
35
+ Trailing
36
+ Date
37
+ Read Time
38
+ URL
39
+
40
+ Type read or r to open the article in your browser.
41
+ Type back to go back to the list of #{website} articles.
42
+ Type list to see a list of websites.
43
+ Type exit to exit the program.
44
+ ```
45
+
46
+
47
+ **Open a website**
48
+ ```
49
+ `open #{DeveloperNewsCliApp::FreeCodeCampScrapper.articles[-1].url}`
50
+ ```
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: developer_news_cli_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: displays the most recent news from developer websites
84
+ email:
85
+ - anthony@anthonygharvey.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - NOTES.md
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/developer-news
102
+ - bin/setup
103
+ - config/environment.rb
104
+ - developer_news_cli_app.gemspec
105
+ - lib/developer_news_cli_app.rb
106
+ - lib/developer_news_cli_app/AListApartScrapper.rb
107
+ - lib/developer_news_cli_app/CodeBurstScrapper.rb
108
+ - lib/developer_news_cli_app/FreeCodeCampScrapper.rb
109
+ - lib/developer_news_cli_app/HackerNoonScrapper.rb
110
+ - lib/developer_news_cli_app/article.rb
111
+ - lib/developer_news_cli_app/cli.rb
112
+ - lib/developer_news_cli_app/version.rb
113
+ - spec.md
114
+ - website_selection_notes.md
115
+ homepage: http://anthonygharvey.com
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.7.6
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: An app to display current developer news
139
+ test_files: []