nyt_cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +63 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/nyt-books +4 -0
- data/bin/setup +8 -0
- data/lib/nyt_cli.rb +21 -0
- data/lib/nyt_cli/api.rb +28 -0
- data/lib/nyt_cli/book.rb +58 -0
- data/lib/nyt_cli/cli.rb +216 -0
- data/lib/nyt_cli/version.rb +5 -0
- data/nyt_cli.gemspec +39 -0
- data/pkg/nyt_cli-0.1.0.gem +0 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f4a6bc1fbeca17aa27b79b06823dbe3aa81f9a11ed80ff59e45564087366769
|
4
|
+
data.tar.gz: 4e8173dde9120de295dfa70b813bbaa7167e612bfd03b70446a7c3a02e96e4fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9374eb53872a5703351d42a86959a7c766f741726874a8a8e09923f165769cca2094728ed07acff2d0e8f81c4f4ef7d7250cf1a9b70d9ebbe45ce9138bb72d5
|
7
|
+
data.tar.gz: 8f65a5fcbf1472e0e13ed5eede66ccba8d66f58c0989de3d2efdc8f2d83b8be2aeca015079449028514fce052aeff6e6f9df86d97ea4e87a148b041c2a0faf38
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.env
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nyt_cli (0.1.0)
|
5
|
+
colorize
|
6
|
+
launchy
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
ast (2.4.1)
|
14
|
+
colorize (0.8.1)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
launchy (2.5.0)
|
17
|
+
addressable (~> 2.7)
|
18
|
+
parallel (1.20.1)
|
19
|
+
parser (3.0.0.0)
|
20
|
+
ast (~> 2.4.1)
|
21
|
+
public_suffix (4.0.6)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
rake (13.0.3)
|
24
|
+
regexp_parser (2.0.3)
|
25
|
+
rexml (3.2.4)
|
26
|
+
rspec (3.10.0)
|
27
|
+
rspec-core (~> 3.10.0)
|
28
|
+
rspec-expectations (~> 3.10.0)
|
29
|
+
rspec-mocks (~> 3.10.0)
|
30
|
+
rspec-core (3.10.1)
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-expectations (3.10.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.10.0)
|
35
|
+
rspec-mocks (3.10.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-support (3.10.1)
|
39
|
+
rubocop (0.93.1)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 2.7.1.5)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
regexp_parser (>= 1.8)
|
44
|
+
rexml
|
45
|
+
rubocop-ast (>= 0.6.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
48
|
+
rubocop-ast (1.4.0)
|
49
|
+
parser (>= 2.7.1.5)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
unicode-display_width (1.7.0)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
x86_64-darwin-20
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
nyt_cli!
|
58
|
+
rake (~> 13.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
rubocop (~> 0.80)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.2.3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 alliecaton
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Allie
|
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,40 @@
|
|
1
|
+
# NytCli
|
2
|
+
|
3
|
+
Welcome to the New York Times Fiction Bestsellers CLI gem! In this application, you are able to view the NYT bestselling fiction books for a given date, view more information about the books on the list for each date, and save books that interest you to a collection.
|
4
|
+
|
5
|
+
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/nyt_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
<!-- Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'nyt_cli'
|
14
|
+
``` -->
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install nyt_cli
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
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.
|
31
|
+
|
32
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nyt_cli.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "nyt_cli"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/nyt-books
ADDED
data/bin/setup
ADDED
data/lib/nyt_cli.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# environment
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'time'
|
5
|
+
require 'colorize'
|
6
|
+
require 'dotenv/load'
|
7
|
+
require 'pry'
|
8
|
+
require 'launchy'
|
9
|
+
require 'open-uri'
|
10
|
+
require 'net/http'
|
11
|
+
require 'json'
|
12
|
+
require_relative "nyt_cli/version"
|
13
|
+
require_relative './nyt_cli/cli.rb'
|
14
|
+
require_relative './nyt_cli/book.rb'
|
15
|
+
require_relative './nyt_cli/api.rb'
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# puts String.colors
|
20
|
+
# puts String.modes
|
21
|
+
# puts String.color_samples
|
data/lib/nyt_cli/api.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class NytCli::Api
|
2
|
+
|
3
|
+
attr_accessor :date
|
4
|
+
|
5
|
+
def initialize(date)
|
6
|
+
@date = date
|
7
|
+
create_book
|
8
|
+
end
|
9
|
+
|
10
|
+
## Calls on the API with the date initialized
|
11
|
+
def get
|
12
|
+
url = "https://api.nytimes.com/svc/books/v3/lists/#{@date}/combined-print-and-e-book-fiction.json?api-key=#{ENV["API_KEY"]}"
|
13
|
+
uri = URI.parse(url)
|
14
|
+
response = Net::HTTP.get_response(uri)
|
15
|
+
response_hash = JSON.parse(response.body)
|
16
|
+
response_hash["results"]["books"]
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
## Creates a book using a hash of relevant attributes
|
21
|
+
def create_book
|
22
|
+
get.each do |book|
|
23
|
+
new_book = NytCli::Book.new(book)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
data/lib/nyt_cli/book.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class NytCli::Book
|
2
|
+
|
3
|
+
attr_accessor :title, :author, :rank, :description, :buy_links
|
4
|
+
|
5
|
+
@@all = [] ## All book instances
|
6
|
+
@@all_selected = [] ## All book instances that the user has viewed
|
7
|
+
@@saved = [] ## Books user has saved to their session collection
|
8
|
+
|
9
|
+
## Initializes book with only specified keys of a hash-- possibly add where to buy later
|
10
|
+
def initialize(hash)
|
11
|
+
@title = title
|
12
|
+
@author = author
|
13
|
+
# @description = description
|
14
|
+
hash.each do |key,value|
|
15
|
+
if key == "title"
|
16
|
+
self.send(("#{key}="), value)
|
17
|
+
elsif key == "rank"
|
18
|
+
self.send(("#{key}="), value)
|
19
|
+
elsif key == "author"
|
20
|
+
self.send(("#{key}="), value)
|
21
|
+
elsif key == "description"
|
22
|
+
self.send(("#{key}="), value)
|
23
|
+
elsif key == "buy_links"
|
24
|
+
self.send(("#{key}="), value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
save
|
28
|
+
end
|
29
|
+
|
30
|
+
def save
|
31
|
+
@@all << self
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.all
|
35
|
+
@@all
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.all_viewed
|
39
|
+
@@all_selected
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.collection
|
43
|
+
@@saved
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.find_by_title(title)
|
47
|
+
@@all.find do |book|
|
48
|
+
if book.title == title
|
49
|
+
book
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.reset!
|
55
|
+
@@all.clear
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/nyt_cli/cli.rb
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
class NytCli::Cli
|
2
|
+
|
3
|
+
@@emojis= ["🚨", "📚", "👋"]
|
4
|
+
|
5
|
+
## Kickstarts the CLI
|
6
|
+
|
7
|
+
def start
|
8
|
+
call
|
9
|
+
ask_input
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
puts "\n\n#{@@emojis[1]} Welcome to the New York Times Bestseller List CLI. Within this CLI, you will be able to view the books on the NYT Bestselling Fiction list for a given date. #{@@emojis[1]} \n\n".cyan.bold.center(100)
|
14
|
+
end
|
15
|
+
|
16
|
+
## Asks for initial user input
|
17
|
+
def ask_input
|
18
|
+
puts "\n\nPlease choose an option by entering a number:\n\n"
|
19
|
+
puts "[1] ".yellow + "Get fiction bestsellers list for a given date"
|
20
|
+
puts "[2] ".yellow + "View your saved books"
|
21
|
+
puts "[3] ".yellow + "Exit the application\n\n"
|
22
|
+
input = gets.chomp.downcase.strip
|
23
|
+
|
24
|
+
case input
|
25
|
+
when "1"
|
26
|
+
get_date
|
27
|
+
when "2"
|
28
|
+
puts "\n"
|
29
|
+
view_saved
|
30
|
+
when "3"
|
31
|
+
puts "Goodbye! #{@@emojis[2]}"
|
32
|
+
sleep(1)
|
33
|
+
exit!
|
34
|
+
else
|
35
|
+
puts "\n#{@@emojis[0]} Please enter the number that corresponds with what you would like to do. #{@@emojis[0]}\n".red
|
36
|
+
sleep(1)
|
37
|
+
ask_input
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
## Get user date they would like to view
|
42
|
+
def get_date
|
43
|
+
puts "\nThe first published online NYT Bestsellers list was on 2011-02-13.\nTo get started, please enter a date (YYYY-MM-DD):\n".yellow
|
44
|
+
date = gets.chomp
|
45
|
+
if valid_date?(date) && valid_timeframe?(date)
|
46
|
+
create_api_and_book(date)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
## Checks if date is real and in the correct format
|
51
|
+
def valid_date?(date)
|
52
|
+
Date.valid_date? *"#{Date.strptime(date,"%Y-%m-%d")}".split('-').map(&:to_i)
|
53
|
+
rescue
|
54
|
+
puts "\n#{@@emojis[0]} Oops! That input is invalid. Please input a valid date using YYYY-MM-DD #{@@emojis[0]}\n".red
|
55
|
+
sleep(1)
|
56
|
+
get_date
|
57
|
+
end
|
58
|
+
|
59
|
+
## Checks to make sure the date is between the NYT start date, and the current date
|
60
|
+
def valid_timeframe?(date)
|
61
|
+
new_date = Time.new(date.split("-")[0].to_i, date.split("-")[1].to_i, date.split("-")[2].to_i)
|
62
|
+
nyt_start_date = Time.new(2011, 2, 13)
|
63
|
+
if new_date <= Time.now && new_date >= nyt_start_date
|
64
|
+
true
|
65
|
+
else
|
66
|
+
puts "\n#{@@emojis[0]} Oops! That input is invalid. Make sure your date falls between now and 2011-02-13 #{@@emojis[0]}\n".red
|
67
|
+
sleep(1)
|
68
|
+
get_date
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
## creates the new API call, initialized with validated input date. Once called, asks user for input
|
73
|
+
def create_api_and_book(date)
|
74
|
+
NytCli::Book.reset!
|
75
|
+
api= NytCli::Api.new(date)
|
76
|
+
ask
|
77
|
+
end
|
78
|
+
|
79
|
+
## Asks user what they want to do
|
80
|
+
def ask
|
81
|
+
puts "\n\nHere are the best selling books for that date. Choose a book to view more information.\n ".yellow
|
82
|
+
list_books
|
83
|
+
puts "\nPlease enter the number that corresponds to the book you would like to view\n".yellow
|
84
|
+
num = gets.chomp.to_i
|
85
|
+
puts "\n"
|
86
|
+
if num.between?(1,NytCli::Book.all.count)
|
87
|
+
show_book(num)
|
88
|
+
else
|
89
|
+
puts "#{@@emojis[0]} Please input a valid number #{@@emojis[0]}"
|
90
|
+
sleep(1)
|
91
|
+
ask
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
## List all books
|
96
|
+
def list_books
|
97
|
+
NytCli::Book.all.each.with_index(1) do |book,index|
|
98
|
+
puts "[#{index}] ".green + "#{book.title.downcase.split(/ |\_|\-/).map(&:capitalize).join(" ")} - #{book.author}".white
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
## View saved collection for session if your collection count is greater than 0
|
103
|
+
def view_saved
|
104
|
+
if NytCli::Book.collection.count != 0
|
105
|
+
NytCli::Book.collection.uniq.each.with_index(1) do |book,index|
|
106
|
+
puts "[#{index}] ".green + "#{book.title.downcase.split(/ |\_|\-/).map(&:capitalize).join(" ")} - #{book.author}".white
|
107
|
+
end
|
108
|
+
collection_options
|
109
|
+
else
|
110
|
+
puts "\n#{@@emojis[0]} You have no saved books #{@@emojis[0]}\n\n"
|
111
|
+
sleep(1)
|
112
|
+
ask_input
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def collection_options
|
117
|
+
puts "\n\nIf you would like more information on any of your saved books, input the number associated with the book you would like to view"
|
118
|
+
num = gets.chomp.to_i
|
119
|
+
if num.between?(1,NytCli::Book.collection.count)
|
120
|
+
show_from_collection(num)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
## Show individual chosen book from collection
|
125
|
+
def show_from_collection(num)
|
126
|
+
chosen_book = NytCli::Book.collection[num - 1]
|
127
|
+
NytCli::Book.all_viewed << chosen_book
|
128
|
+
puts "Title: ".blue + "#{chosen_book.title.downcase.split(/ |\_|\-/).map(&:capitalize).join(" ")} \n" + "Author: ".blue + "#{chosen_book.author}" + " \nRank: ".blue + "#{chosen_book.rank}" + " \nDescription: ".blue + "#{chosen_book.description}\n\n"
|
129
|
+
from_collection_menu
|
130
|
+
end
|
131
|
+
|
132
|
+
def from_collection_menu
|
133
|
+
puts "What would you like to do? Please input a number\n\n"
|
134
|
+
puts "[1] ".yellow + "Return to your collection"
|
135
|
+
puts "[2] ".yellow + "Buy book"
|
136
|
+
puts "[3] ".yellow + "Return to main menu"
|
137
|
+
puts "[4] ".yellow + "Exit the application\n\n"
|
138
|
+
input = gets.chomp.downcase.strip
|
139
|
+
|
140
|
+
case input
|
141
|
+
when "1"
|
142
|
+
view_saved
|
143
|
+
when "2"
|
144
|
+
buy_book(NytCli::Book.all_viewed.last.title)
|
145
|
+
when "3"
|
146
|
+
ask_input
|
147
|
+
when "4"
|
148
|
+
puts "Goodbye! #{@@emojis[2]}"
|
149
|
+
sleep(1)
|
150
|
+
exit!
|
151
|
+
else
|
152
|
+
puts "\n #{@@emojis[0]} Please enter the number that corresponds with what you would like to do. #{@@emojis[0]}\n".red
|
153
|
+
sleep(1)
|
154
|
+
from_collection_menu
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
## Shows attributes of individaul book after selected by user, saves the user choice into class array @@all_selected for easy access
|
159
|
+
def show_book(num)
|
160
|
+
chosen_book = NytCli::Book.all[num - 1]
|
161
|
+
NytCli::Book.all_viewed << chosen_book
|
162
|
+
puts "Title: ".blue + "#{chosen_book.title.downcase.split(/ |\_|\-/).map(&:capitalize).join(" ")} \n" + "Author: ".blue + "#{chosen_book.author}" + " \nRank: ".blue + "#{chosen_book.rank}" + " \nDescription: ".blue + "#{chosen_book.description}\n\n"
|
163
|
+
indiv_book_menu
|
164
|
+
end
|
165
|
+
|
166
|
+
## Menu choices for individual book
|
167
|
+
def indiv_book_menu
|
168
|
+
puts "What would you like to do? Please input a number\n\n"
|
169
|
+
puts "[1] ".yellow + "Select another book from the list"
|
170
|
+
puts "[2] ".yellow + "Buy book"
|
171
|
+
puts "[3] ".yellow + "Add book to session collection"
|
172
|
+
puts "[4] ".yellow + "Return to main menu"
|
173
|
+
puts "[5] ".yellow + "Exit the application\n\n"
|
174
|
+
input = gets.chomp.downcase.strip
|
175
|
+
|
176
|
+
case input
|
177
|
+
when "1"
|
178
|
+
self.ask
|
179
|
+
when "2"
|
180
|
+
buy_book(NytCli::Book.all_viewed.last.title)
|
181
|
+
when "3"
|
182
|
+
add_to_collection
|
183
|
+
when "4"
|
184
|
+
ask_input
|
185
|
+
when "5"
|
186
|
+
puts "Goodbye! #{@@emojis[2]}"
|
187
|
+
sleep(1)
|
188
|
+
exit!
|
189
|
+
else
|
190
|
+
puts "\ #{@@emojis[0]} Please enter the number that corresponds with what you would like to do. #{@@emojis[0]}\n".red
|
191
|
+
sleep(1)
|
192
|
+
indiv_book_menu
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
## Links out to a B&N link for selected book
|
197
|
+
def buy_book(title)
|
198
|
+
current_book = NytCli::Book.find_by_title (title)
|
199
|
+
current_book.buy_links.each do |shop|
|
200
|
+
if shop["url"].include? "barnes"
|
201
|
+
Launchy.open(shop["url"])
|
202
|
+
self.ask_input
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
## Adds book to collection for the session
|
208
|
+
def add_to_collection
|
209
|
+
NytCli::Book.collection << NytCli::Book.all_viewed.last
|
210
|
+
puts "\nYou've added " + "#{NytCli::Book.all_viewed.last.title.downcase.split(/ |\_|\-/).map(&:capitalize).join(" ")} ".blue + "to your saved collection for the session.\n\n"
|
211
|
+
sleep(1)
|
212
|
+
self.ask_input
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
end
|
data/nyt_cli.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/nyt_cli/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "nyt_cli"
|
7
|
+
spec.version = NytCli::VERSION
|
8
|
+
spec.authors = ["Allie Caton"]
|
9
|
+
spec.email = ["alliecaton3@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Get a list of all the NYT Bestseller Ficition books for a given date, and get more information about each book."
|
12
|
+
spec.homepage = "https://github.com/alliecaton/nyt_bestsellers_CLI"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/alliecaton/nyt_bestsellers_CLI"
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
spec.add_dependency "colorize"
|
33
|
+
spec.add_dependency "launchy"
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, checkout our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nyt_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Allie Caton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: launchy
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- alliecaton3@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".DS_Store"
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/nyt-books
|
58
|
+
- bin/setup
|
59
|
+
- lib/nyt_cli.rb
|
60
|
+
- lib/nyt_cli/api.rb
|
61
|
+
- lib/nyt_cli/book.rb
|
62
|
+
- lib/nyt_cli/cli.rb
|
63
|
+
- lib/nyt_cli/version.rb
|
64
|
+
- nyt_cli.gemspec
|
65
|
+
- pkg/nyt_cli-0.1.0.gem
|
66
|
+
homepage: https://github.com/alliecaton/nyt_bestsellers_CLI
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata:
|
70
|
+
allowed_push_host: https://rubygems.org
|
71
|
+
homepage_uri: https://github.com/alliecaton/nyt_bestsellers_CLI
|
72
|
+
source_code_uri: https://github.com/alliecaton/nyt_bestsellers_CLI
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.3.0
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.2.3
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Get a list of all the NYT Bestseller Ficition books for a given date, and
|
92
|
+
get more information about each book.
|
93
|
+
test_files: []
|