top_apps 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e11caa6ddc9ccb093b3aa0dc15cc8afb91ed2ad348f314702dad705ccff447f4
4
+ data.tar.gz: ce077cf025d0e7b2cd84244aa4c5c856542d7c5f35e80dfcadeef8f958948c29
5
+ SHA512:
6
+ metadata.gz: e8a93c6cd1542d79478b5cf3699cabaf6d6a582d85a805f936dc8baf03d29249a830db0e4c4f79e3287b7472dd08da1fc3bf93d2cf33fe2e9a8540f33667cd19
7
+ data.tar.gz: be51606e5ccbc22444f765691d709d688367bb851bf2df7d61a627614fb7bb947d49ca673bf470544adb25ace2d5004b2ffd38551906f937a8e5b06904448317
data/bin/top-apps ADDED
@@ -0,0 +1,5 @@
1
+ #!usr/bin/env ruby
2
+
3
+ require_relative "../lib/top_apps"
4
+
5
+ TopApps::CLI.run
data/lib/top_apps.rb ADDED
@@ -0,0 +1,9 @@
1
+ module TopApps
2
+ end
3
+
4
+ require "nokogiri"
5
+ require "pry"
6
+ require "open-uri"
7
+ require_relative "top_apps/cli"
8
+ require_relative "top_apps/app"
9
+ require_relative "top_apps/scraper"
@@ -0,0 +1,25 @@
1
+ class TopApps::App
2
+ attr_accessor :name, :category, :rank, :profile_url, :notes, :developer, :rating
3
+ @@all = []
4
+
5
+ def self.create_apps_from_index(index_array)
6
+ index_array.each { |index_hash| new(index_hash) }
7
+ end
8
+
9
+ def self.all
10
+ @@all
11
+ end
12
+
13
+ def self.find_by_rank(rank)
14
+ all[rank.to_i - 1]
15
+ end
16
+
17
+ def initialize(hash)
18
+ hash.each { |attr_key, attr_value| send("#{attr_key}=", attr_value) }
19
+ @@all << self
20
+ end
21
+
22
+ def add_attributes_from_profile(profile_hash)
23
+ profile_hash.each { |attr_key, attr_value| send("#{attr_key}=", attr_value) }
24
+ end
25
+ end
@@ -0,0 +1,90 @@
1
+ class TopApps::CLI
2
+ def self.run
3
+ create_apps
4
+ greeting
5
+ display_apps
6
+ end
7
+
8
+ def self.create_apps
9
+ index_array = TopApps::Scraper.scrape_index("https://www.apple.com/itunes/charts/")
10
+ TopApps::App.create_apps_from_index(index_array)
11
+ end
12
+
13
+ def self.add_attributes(app)
14
+ profile_hash = TopApps::Scraper.scrape_profile(app.profile_url)
15
+ app.add_attributes_from_profile(profile_hash)
16
+ end
17
+
18
+ def self.greeting
19
+ puts "Welcome to Top Apps!"
20
+ puts "Top Apps is a CLI that displays the hottest apps in the Apple Store right now."
21
+ puts "You can select an app to learn more about it."
22
+ end
23
+
24
+ def self.display_apps
25
+ puts "\n"
26
+ puts "Here are the top #{TopApps::App.all.size} free apps in the Apple Store right now:"
27
+ TopApps::App.all.each do |app|
28
+ puts "#{app.rank}. #{app.name} - #{app.category}"
29
+ end
30
+ select_app
31
+ end
32
+
33
+ def self.select_app
34
+ puts "\n"
35
+ puts "To learn more about an app, enter its rank."
36
+ puts "To quit, enter 'quit'."
37
+ input = gets.strip.downcase
38
+
39
+ if input.to_i.between?(1, TopApps::App.all.size)
40
+ app = TopApps::App.find_by_rank(input)
41
+ add_attributes(app) if !app.developer
42
+ display_profile(input)
43
+ elsif input == "quit"
44
+ quit
45
+ else
46
+ sorry
47
+ select_app
48
+ end
49
+ end
50
+
51
+ def self.quit
52
+ puts "\n"
53
+ puts "Thanks for using Top Apps. Goodbye!"
54
+ exit
55
+ end
56
+
57
+ def self.sorry
58
+ puts "\n"
59
+ puts "I'm sorry, I don't understand you."
60
+ end
61
+
62
+ def self.display_profile(rank)
63
+ app = TopApps::App.find_by_rank(rank)
64
+ puts "\n"
65
+ puts "#{app.name}"
66
+ puts "Ranked ##{app.rank}"
67
+ puts "Category: #{app.category}"
68
+ puts "Developer: #{app.developer}"
69
+ puts "Rating: #{app.rating}"
70
+ puts "Editor's Notes:"
71
+ puts "#{app.notes}"
72
+ back_to_apps
73
+ end
74
+
75
+ def self.back_to_apps
76
+ puts "\n"
77
+ puts "If you want to go back to the apps, enter 'back', if you want to quit, enter 'quit'."
78
+ input = gets.strip.downcase
79
+
80
+ case input
81
+ when "back"
82
+ display_apps
83
+ when "quit"
84
+ quit
85
+ else
86
+ sorry
87
+ back_to_apps
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,28 @@
1
+ class TopApps::Scraper
2
+ def self.scrape_index(index_url)
3
+ doc = Nokogiri::HTML(open(index_url))
4
+ free_apps_section = doc.css(".section.chart-grid.apps div.section-content").first
5
+ free_apps_list = free_apps_section.css("li")
6
+
7
+ free_apps_list.map do |app|
8
+ {
9
+ name: app.css("h3 a").text,
10
+ category: app.css("h4 a").text,
11
+ rank: app.css("strong").text.chomp("."),
12
+ profile_url: app.css("a").attribute("href").value
13
+ }
14
+ end
15
+ end
16
+
17
+ def self.scrape_profile(profile_url)
18
+ doc = Nokogiri::HTML(open(profile_url))
19
+ notes = doc.css("div.we-editor-notes.lockup.ember-view p").text.strip
20
+ notes == "" ? notes = "Unavailable." : nil
21
+
22
+ {
23
+ notes: notes,
24
+ developer: doc.css("h2.product-header__identity.app-header__identity a").text,
25
+ rating: doc.css("figcaption.we-rating-count.star-rating__count").text.split(",").first
26
+ }
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module TopApps
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: top_apps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Sunyoung'"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-17 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: nokogiri
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: 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
+ description: Top Apps is a CLI that lists the current top 5 free apps on Apple's iTunes
70
+ Chart and allows you to learn more about them.
71
+ email:
72
+ - "'sunyounghwang13@gmail.com'"
73
+ executables:
74
+ - top-apps
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - bin/top-apps
79
+ - lib/top_apps.rb
80
+ - lib/top_apps/app.rb
81
+ - lib/top_apps/cli.rb
82
+ - lib/top_apps/scraper.rb
83
+ - lib/top_apps/version.rb
84
+ homepage: https://github.com/sunyounghwang/top_apps
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.7.7
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Top Apps displays the top 5 free apps on Apple's iTunes Chart.
108
+ test_files: []