news_reader_cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.newsapi.rb +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/news_reader_cli +12 -0
- data/bin/setup +8 -0
- data/lib/news_reader_cli/api_key_validate.rb +38 -0
- data/lib/news_reader_cli/api_service.rb +23 -0
- data/lib/news_reader_cli/article.rb +62 -0
- data/lib/news_reader_cli/cli.rb +94 -0
- data/lib/news_reader_cli/version.rb +3 -0
- data/lib/news_reader_cli.rb +16 -0
- data/news_reader_cli.gemspec +41 -0
- metadata +120 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c59fbbe0570258304416ab304d0451dead16a3996e62118006e4167269d886ed
|
|
4
|
+
data.tar.gz: 4431f7c5a0620d87ca36c1f8b0ffc0b40f1ee5fdb11b3df8f98742047819e467
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b6aed8c7db77dfe2fb2e1d6143c335f516f74b0989544245acf14a97548590cdc4c7ece8f143f62c24c3682c92dd5ad4f2888ff970150ab8a936cd4f71669140
|
|
7
|
+
data.tar.gz: f4213fc5c499804a2fc7026dfdf3c58b6ae1d9034db147579335662ef7ac8fb0b6b6c216e135d444905f91fe82b8f7b1d54d38550535d6c9caa3567cc8d1ec55
|
data/.gitignore
ADDED
data/.newsapi.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
71fa5ddcc82d4f8ab52693f5f0ad3784
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -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 hanke.liu@gmail.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,10 @@
|
|
|
1
|
+
|
|
2
|
+
source "https://rubygems.org"
|
|
3
|
+
|
|
4
|
+
#gem 'dotenv-rails' # groups: [:development, :test] # not able to load dotenv
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
8
|
+
|
|
9
|
+
# Specify your gem's dependencies in news_reader_cli.gemspec
|
|
10
|
+
gemspec
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
news_reader_cli (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
actionpack (5.2.2)
|
|
10
|
+
actionview (= 5.2.2)
|
|
11
|
+
activesupport (= 5.2.2)
|
|
12
|
+
rack (~> 2.0)
|
|
13
|
+
rack-test (>= 0.6.3)
|
|
14
|
+
rails-dom-testing (~> 2.0)
|
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
16
|
+
actionview (5.2.2)
|
|
17
|
+
activesupport (= 5.2.2)
|
|
18
|
+
builder (~> 3.1)
|
|
19
|
+
erubi (~> 1.4)
|
|
20
|
+
rails-dom-testing (~> 2.0)
|
|
21
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
22
|
+
activesupport (5.2.2)
|
|
23
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
24
|
+
i18n (>= 0.7, < 2)
|
|
25
|
+
minitest (~> 5.1)
|
|
26
|
+
tzinfo (~> 1.1)
|
|
27
|
+
builder (3.2.3)
|
|
28
|
+
coderay (1.1.2)
|
|
29
|
+
concurrent-ruby (1.1.4)
|
|
30
|
+
crass (1.0.4)
|
|
31
|
+
dotenv (2.5.0)
|
|
32
|
+
dotenv-rails (2.5.0)
|
|
33
|
+
dotenv (= 2.5.0)
|
|
34
|
+
railties (>= 3.2, < 6.0)
|
|
35
|
+
erubi (1.8.0)
|
|
36
|
+
gem-release (2.0.1)
|
|
37
|
+
i18n (1.3.0)
|
|
38
|
+
concurrent-ruby (~> 1.0)
|
|
39
|
+
loofah (2.2.3)
|
|
40
|
+
crass (~> 1.0.2)
|
|
41
|
+
nokogiri (>= 1.5.9)
|
|
42
|
+
method_source (0.9.2)
|
|
43
|
+
mini_portile2 (2.4.0)
|
|
44
|
+
minitest (5.11.3)
|
|
45
|
+
nokogiri (1.9.1)
|
|
46
|
+
mini_portile2 (~> 2.4.0)
|
|
47
|
+
pry (0.12.2)
|
|
48
|
+
coderay (~> 1.1.0)
|
|
49
|
+
method_source (~> 0.9.0)
|
|
50
|
+
rack (2.0.6)
|
|
51
|
+
rack-test (1.1.0)
|
|
52
|
+
rack (>= 1.0, < 3)
|
|
53
|
+
rails-dom-testing (2.0.3)
|
|
54
|
+
activesupport (>= 4.2.0)
|
|
55
|
+
nokogiri (>= 1.6)
|
|
56
|
+
rails-html-sanitizer (1.0.4)
|
|
57
|
+
loofah (~> 2.2, >= 2.2.2)
|
|
58
|
+
railties (5.2.2)
|
|
59
|
+
actionpack (= 5.2.2)
|
|
60
|
+
activesupport (= 5.2.2)
|
|
61
|
+
method_source
|
|
62
|
+
rake (>= 0.8.7)
|
|
63
|
+
thor (>= 0.19.0, < 2.0)
|
|
64
|
+
rake (10.5.0)
|
|
65
|
+
thor (0.20.3)
|
|
66
|
+
thread_safe (0.3.6)
|
|
67
|
+
tzinfo (1.2.5)
|
|
68
|
+
thread_safe (~> 0.1)
|
|
69
|
+
|
|
70
|
+
PLATFORMS
|
|
71
|
+
ruby
|
|
72
|
+
|
|
73
|
+
DEPENDENCIES
|
|
74
|
+
bundler (~> 1.16)
|
|
75
|
+
dotenv-rails
|
|
76
|
+
gem-release
|
|
77
|
+
news_reader_cli!
|
|
78
|
+
pry
|
|
79
|
+
rake (~> 10.0)
|
|
80
|
+
|
|
81
|
+
BUNDLED WITH
|
|
82
|
+
1.16.5
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Henry
|
|
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/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# NewsReaderCli
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/news_reader_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
This Ruby Gem provides a CLI to view 36 live breaking headlines and contents from a variety of top US major publishers.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'news_reader_cli'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install news_reader_cli
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Before launch the command line, Go to https://newsapi.org/docs/get-started to register your account and request API key.
|
|
26
|
+
|
|
27
|
+
Type the below command and follow screen prompts
|
|
28
|
+
$ news_reader_cli
|
|
29
|
+
|
|
30
|
+
After message "please type in API Key from API News:" paste your API key received from API News. It is a hex string with 32 characters. The key will be saved on current computer, you won't be asked again for future logon.
|
|
31
|
+
|
|
32
|
+
Follow screen instructions to access News articles. Type Exit to end the program.
|
|
33
|
+
|
|
34
|
+
## Development
|
|
35
|
+
|
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
37
|
+
|
|
38
|
+
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).
|
|
39
|
+
|
|
40
|
+
## Contributing
|
|
41
|
+
|
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/news_reader_cli. 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.
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
47
|
+
|
|
48
|
+
## Code of Conduct
|
|
49
|
+
|
|
50
|
+
Everyone interacting in the NewsReaderCli project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/news_reader_cli/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "news_reader_cli"
|
|
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__)
|
data/bin/news_reader_cli
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative "../lib/news_reader_cli"
|
|
3
|
+
|
|
4
|
+
# myapikey = open(File.expand_path(".newsapi.rb", "~/Development/m1/news_reader_cli")).read.strip
|
|
5
|
+
# binding.pry
|
|
6
|
+
|
|
7
|
+
NewsReaderCli::ApiKeyValidate.new.key_validate
|
|
8
|
+
|
|
9
|
+
# binding.pry
|
|
10
|
+
|
|
11
|
+
Dotenv.load('.env')
|
|
12
|
+
NewsReaderCli::CLI.new.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class NewsReaderCli::ApiKeyValidate
|
|
2
|
+
def key_validate
|
|
3
|
+
# verify if the file .env exist.
|
|
4
|
+
# File.expand_path if return true, the file exist. if not, File.new create a file.
|
|
5
|
+
# if not create one. Let user input the key.
|
|
6
|
+
# if .env exists, load the file.
|
|
7
|
+
if !File.exist?(".env")
|
|
8
|
+
key_file = File.new(".env", "w+")
|
|
9
|
+
puts "please type in API Key from API News:"
|
|
10
|
+
|
|
11
|
+
# a condition verify key value is AES 128 Hex string 32 chars
|
|
12
|
+
|
|
13
|
+
key = gets.chomp.strip
|
|
14
|
+
|
|
15
|
+
while !key.match(/([0-9]|\w){32}/) do
|
|
16
|
+
|
|
17
|
+
# break if key == "exit"
|
|
18
|
+
# need to get out of the loop and remove the file .env
|
|
19
|
+
|
|
20
|
+
puts <<-HEREDOC
|
|
21
|
+
|
|
22
|
+
Your API keys value shows invalid.
|
|
23
|
+
Please check verify your API Key and type in again.
|
|
24
|
+
To exit, type in "exit"
|
|
25
|
+
|
|
26
|
+
HEREDOC
|
|
27
|
+
|
|
28
|
+
key = gets.chomp.strip
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
key_file.puts("key = #{key}")
|
|
32
|
+
key_file.close
|
|
33
|
+
|
|
34
|
+
#binding.pry
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class NewsReaderCli::ApiService
|
|
2
|
+
|
|
3
|
+
def self.newsapi
|
|
4
|
+
#url = "https://newsapi.org/v2/top-headlines?country=us&apiKey=(put key here)&pageSize=100"
|
|
5
|
+
assigned_api_key = ENV['key'].strip
|
|
6
|
+
#binding.pry
|
|
7
|
+
url = 'https://newsapi.org/v2/top-headlines?'\
|
|
8
|
+
'country=us&'\
|
|
9
|
+
"apiKey=#{assigned_api_key}&"\
|
|
10
|
+
'pageSize=100'
|
|
11
|
+
req = open(url)
|
|
12
|
+
response_body = req.read
|
|
13
|
+
json = JSON.parse(response_body)
|
|
14
|
+
|
|
15
|
+
json["articles"].each do |article|
|
|
16
|
+
NewsReaderCli::Article.new(article)
|
|
17
|
+
end
|
|
18
|
+
#binding.pry
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
class NewsReaderCli::Article
|
|
2
|
+
|
|
3
|
+
attr_accessor :source, :author, :title, :description, :url, :urltoimage, :publishedAt, :content
|
|
4
|
+
|
|
5
|
+
@@all = []
|
|
6
|
+
|
|
7
|
+
def initialize(article_hash)
|
|
8
|
+
|
|
9
|
+
article_hash.each do |method, article_data|
|
|
10
|
+
self.send("#{method}=", article_data) if self.respond_to?("#{method}=")
|
|
11
|
+
end
|
|
12
|
+
@@all << self
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.all
|
|
17
|
+
@@all
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#list all the articlels titles (in alphabat )
|
|
21
|
+
def self.list_all_titles
|
|
22
|
+
self.all.each.with_index(1) do |article, index|
|
|
23
|
+
puts "#{index}. #{article.title}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
#find the article instance by article index number
|
|
28
|
+
def self.find_article_by_article_index(number)
|
|
29
|
+
self.all.find.with_index(1) do |article, index|
|
|
30
|
+
index == number
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# pick an article to show the content
|
|
35
|
+
# def self.find_content_by_article_index(number)
|
|
36
|
+
# self.all.find.with_index(1) do |article, index|
|
|
37
|
+
# index == number
|
|
38
|
+
# #binding.pry
|
|
39
|
+
# end.content
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
# find an article's URL
|
|
43
|
+
def self.find_url_by_article_index(number)
|
|
44
|
+
self.all.find.with_index(1) do |article, index|
|
|
45
|
+
index == number
|
|
46
|
+
end.url
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# def self.find_source_name_by_article_index(number)
|
|
50
|
+
# self.all.find.with_index(1) do |article, index|
|
|
51
|
+
# index == number
|
|
52
|
+
# end.source["name"]
|
|
53
|
+
# end
|
|
54
|
+
|
|
55
|
+
# def self.find_pub_date_by_article_index(number)
|
|
56
|
+
# self.all.find.with_index(1) do |article, index|
|
|
57
|
+
# index == number
|
|
58
|
+
# end.publishedAt
|
|
59
|
+
# end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
end #end of class
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
class NewsReaderCli::CLI
|
|
3
|
+
|
|
4
|
+
def start
|
|
5
|
+
|
|
6
|
+
NewsReaderCli::ApiService.newsapi
|
|
7
|
+
puts "Welcome to the News Reader CLI!!!"
|
|
8
|
+
menu
|
|
9
|
+
goodbye
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def menu
|
|
14
|
+
|
|
15
|
+
help_menu
|
|
16
|
+
|
|
17
|
+
input = ""
|
|
18
|
+
|
|
19
|
+
while input != "exit" do
|
|
20
|
+
input = gets.chomp.strip
|
|
21
|
+
|
|
22
|
+
if input == "list"
|
|
23
|
+
NewsReaderCli::Article.list_all_titles
|
|
24
|
+
|
|
25
|
+
elsif input.slice(0) == "a" && (1..(NewsReaderCli::Article.all.length)).include?(input.gsub(/[a]/, '').to_i)
|
|
26
|
+
found_article_instance = NewsReaderCli::Article.find_article_by_article_index(input.gsub(/[a]/, '').to_i)
|
|
27
|
+
puts "Article #{input.gsub(/[a]/, "")}:"
|
|
28
|
+
puts "---------"
|
|
29
|
+
#binding.pry
|
|
30
|
+
puts "#{found_article_instance.content}"
|
|
31
|
+
puts "---------"
|
|
32
|
+
puts "Published Date: #{found_article_instance.publishedAt}"
|
|
33
|
+
puts "Publisher: #{found_article_instance.source["name"]}"
|
|
34
|
+
puts "Article URL: #{found_article_instance.url}"
|
|
35
|
+
|
|
36
|
+
elsif input.slice(0) == "u" && (1..(NewsReaderCli::Article.all.length)).include?(input.gsub(/[u]/, '').to_i)
|
|
37
|
+
found_url = NewsReaderCli::Article.find_url_by_article_index(input.gsub(/[u]/, '').to_i)
|
|
38
|
+
|
|
39
|
+
puts "Please check your browser, your article is opening now."
|
|
40
|
+
system("open", "#{found_url}")
|
|
41
|
+
|
|
42
|
+
elsif input == "exit"
|
|
43
|
+
#not output here. need to end the inner loop.
|
|
44
|
+
else
|
|
45
|
+
puts "Sorry! input is not valid. Please follow instructions."
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
self.help_menu
|
|
49
|
+
|
|
50
|
+
# puts <<-HEREDOC
|
|
51
|
+
#
|
|
52
|
+
# 1. Please type 'list' for a list of today's news headlines.
|
|
53
|
+
# 2. To read an article, please type 'a' follow by index number.
|
|
54
|
+
# 3. To open an article url, please type 'u' follow by index number.
|
|
55
|
+
# 4. To Exit, type 'exit'.
|
|
56
|
+
# HEREDOC
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def goodbye
|
|
61
|
+
puts "Goodbye! We will have more news for you tomorrow."
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def help_menu
|
|
65
|
+
puts <<-HEREDOC
|
|
66
|
+
1. Please type 'list' for a list of today's news headlines.
|
|
67
|
+
2. To read an article, please type 'a' follow by index number.
|
|
68
|
+
3. To open an article's url from publisher's website, please type 'u' follow by index number.
|
|
69
|
+
4. To Exit, type 'exit'.
|
|
70
|
+
HEREDOC
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end #end of class
|
|
74
|
+
|
|
75
|
+
# input2 = ""
|
|
76
|
+
# input2 = gets.chomp.strip
|
|
77
|
+
#
|
|
78
|
+
# if input2.slice!(0) == "a" && (1..(NewsReaderCli::Article.all.length)).include?(input2.to_i)
|
|
79
|
+
# found_content = NewsReaderCli::Article.find_content_by_article_index(input2.to_i)
|
|
80
|
+
# puts "#{found_content}"
|
|
81
|
+
# puts "Please type in 'l' to get today's news headlines"
|
|
82
|
+
# puts "To Exit, pease type 'exit'."
|
|
83
|
+
#
|
|
84
|
+
# elsif input2.slice!(0) == "u" && (1..(NewsReaderCli::Article.all.length)).include?(input2.to_i)
|
|
85
|
+
# found_url = NewsReaderCli::Article.find_url_by_article_index(input2.to_i)
|
|
86
|
+
# puts "#{found_url}"
|
|
87
|
+
# puts "Please type in 'l' to get today's news headlines"
|
|
88
|
+
# puts "To Exit, pease type 'exit'."
|
|
89
|
+
# elsif
|
|
90
|
+
# puts "It is not a valid input article number, please follow instructions."
|
|
91
|
+
# end
|
|
92
|
+
# else
|
|
93
|
+
# puts "Please type 'l' today's news headlines."
|
|
94
|
+
# puts "To Exit, type 'exit'."
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "pry"
|
|
2
|
+
require "open-uri"
|
|
3
|
+
require "dotenv"
|
|
4
|
+
require_relative "./news_reader_cli/version" #require "news_reader_cli/version" #
|
|
5
|
+
require_relative "./news_reader_cli/cli"
|
|
6
|
+
require_relative "./news_reader_cli/api_service"
|
|
7
|
+
require_relative "./news_reader_cli/article"
|
|
8
|
+
require_relative "./news_reader_cli/api_key_validate"
|
|
9
|
+
|
|
10
|
+
# Bundler.require(*Rails.groups)
|
|
11
|
+
# Dotenv::Railtie.load
|
|
12
|
+
# HOSTNAME = ENV['HOSTNAME']
|
|
13
|
+
|
|
14
|
+
module NewsReaderCli
|
|
15
|
+
# Your code goes here...
|
|
16
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "news_reader_cli/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "news_reader_cli"
|
|
8
|
+
spec.version = NewsReaderCli::VERSION
|
|
9
|
+
spec.authors = [" Henry"]
|
|
10
|
+
spec.email = ["hanke.liu@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{CLI for displaying news headlines of the day (as of 2018)}
|
|
13
|
+
spec.description = %q{Parse API from News API for viewing 36 top US breaking news from a variety of publishers }
|
|
14
|
+
spec.homepage = "https://github.com/hankeliu2015/news_reader_cli"
|
|
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
|
+
# Specify which files should be added to the gem when it is released.
|
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
30
|
+
end
|
|
31
|
+
spec.bindir = "bin" # exe
|
|
32
|
+
spec.executables = ["news_reader_cli"]#spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
|
+
|
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
37
|
+
spec.add_development_dependency "pry"
|
|
38
|
+
spec.add_development_dependency "gem-release"
|
|
39
|
+
#spec.add_development_dependency "open-uri"
|
|
40
|
+
#spec.add_development_dependency "nokogiri" # won't need it for now.
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: news_reader_cli
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- " Henry"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-12-25 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: pry
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: gem-release
|
|
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
|
+
description: 'Parse API from News API for viewing 36 top US breaking news from a variety
|
|
70
|
+
of publishers '
|
|
71
|
+
email:
|
|
72
|
+
- hanke.liu@gmail.com
|
|
73
|
+
executables:
|
|
74
|
+
- news_reader_cli
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- ".gitignore"
|
|
79
|
+
- ".newsapi.rb"
|
|
80
|
+
- CODE_OF_CONDUCT.md
|
|
81
|
+
- Gemfile
|
|
82
|
+
- Gemfile.lock
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- bin/console
|
|
87
|
+
- bin/news_reader_cli
|
|
88
|
+
- bin/setup
|
|
89
|
+
- lib/news_reader_cli.rb
|
|
90
|
+
- lib/news_reader_cli/api_key_validate.rb
|
|
91
|
+
- lib/news_reader_cli/api_service.rb
|
|
92
|
+
- lib/news_reader_cli/article.rb
|
|
93
|
+
- lib/news_reader_cli/cli.rb
|
|
94
|
+
- lib/news_reader_cli/version.rb
|
|
95
|
+
- news_reader_cli.gemspec
|
|
96
|
+
homepage: https://github.com/hankeliu2015/news_reader_cli
|
|
97
|
+
licenses:
|
|
98
|
+
- MIT
|
|
99
|
+
metadata: {}
|
|
100
|
+
post_install_message:
|
|
101
|
+
rdoc_options: []
|
|
102
|
+
require_paths:
|
|
103
|
+
- lib
|
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0'
|
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
requirements: []
|
|
115
|
+
rubyforge_project:
|
|
116
|
+
rubygems_version: 2.7.7
|
|
117
|
+
signing_key:
|
|
118
|
+
specification_version: 4
|
|
119
|
+
summary: CLI for displaying news headlines of the day (as of 2018)
|
|
120
|
+
test_files: []
|