UrgentcareCLI 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d62d9e62ebcc0e1b2318252471997712e2f515b1144ae192cb464fe4b496307
4
- data.tar.gz: a62a1ad60b8fbb783cb8bc21eb5d93a5d53665db357af52368b5f5795e4edb1d
3
+ metadata.gz: a14a0119b6b23342e667a36ec24f7fa392101ccd0bf4c0301c559fd47f596a13
4
+ data.tar.gz: 6e0de22214194db170cdf8a1380edd1843da5dbc3e0f6aff7539cd508a79bba2
5
5
  SHA512:
6
- metadata.gz: 3637e6bd4dd19d26d5d71945d589883f3f5a65d999fd9f81fc184a84e884e1f2ea8f23286a85a0698e2cab51d6b7a8ed70f7b73c45899fbd684d6e3674589c1b
7
- data.tar.gz: 76793ffbfcac85d94cc8e23a89814eb625a0f7419727436796aae16b9cebc6dc1559db607f08635d491b9d61f4c23b25b3d9e7f98da22586349f8cbc1c8bb5ab
6
+ metadata.gz: db7f73326afa9d948ffd554379bb90334c20fc622f42ad629746a9eafe8bb4477a8fea4c0946084ed27b4e6b932de84e72805f26b4557fcdda8f5e5e93d5e238
7
+ data.tar.gz: ae6275370f573733cc5892d925062490be2ad4d1632681a35e87794f4b5fe5c7bc7ef497718dd0562b4489b1fc8abdad5f461f2a3d4f35c951b65b34551931c7
@@ -1,4 +1,14 @@
1
+ require_relative "./Office"
2
+ require_relative "./Scraper"
3
+
1
4
  class Urgentcare::CLI
5
+ #dependency injection to make code more testable
6
+ #remove strict dependency on other classes
7
+
8
+ def initialize(scraper: Urgentcare::Scraper.new, offices: Urgentcare::Office.all)
9
+ @scraper = scraper
10
+ @offices = offices
11
+ end
2
12
 
3
13
  def call
4
14
  welcome
@@ -6,50 +16,67 @@ class Urgentcare::CLI
6
16
 
7
17
  def welcome
8
18
  #puts displays with a new line
19
+ puts " "
20
+ puts " "
9
21
  puts "Welcome to the Urgent Care CLI"
10
22
  puts " "
11
23
  puts " "
24
+ puts " "
25
+ loading_message
26
+ office_list
27
+ end
28
+
29
+ def office_list
30
+ @scraper.get_office_list
12
31
  puts "Please choose a number from the following list for details on
13
32
  an Urgent Care location."
14
- puts " "
15
-
16
- Urgentcare::Scraper.new.get_clinics
17
- @clinics = Urgentcare::Office.all
18
- @clinics.each_with_index do |office, i|
33
+ puts " "
34
+ @offices.each_with_index do |office, i|
19
35
  puts "#{i + 1}. #{office.name}"
20
36
  end
21
37
  list
22
38
  end
23
39
 
24
40
  def list
25
- puts " "
26
- location = gets.chomp
41
+ puts " "
42
+ location = $stdin.gets.chomp
27
43
  if location == "Exit" ||location == "exit"
28
44
  puts "Thank you and Goodbye!"
29
- else
30
- @index = location.to_i - 1
45
+ elsif location != "Exit" || location != "exit"
46
+ location = location.to_i
47
+ $index = location - 1
48
+ loading_message
49
+ @scraper.get_clinic_site
31
50
  office_details
51
+ else
52
+ puts "Invalid response"
32
53
  end
33
54
  end
34
55
 
35
56
  def office_details
36
- the_office = Urgentcare::Office.all
37
- if @index != "Exit" ||@index != "exit"
57
+ if $index != "Exit" || $index != "exit"
58
+ puts " "
59
+ puts " "
38
60
  puts " "
39
61
  puts "---"
40
- puts "Office Name: #{the_office[@index].name}"
41
- puts "Office Number: #{the_office[@index].phone_number}"
42
- puts "Office URL: #{the_office[@index].url}"
43
- puts "Office Next Available Appointment: #{the_office[@index].next_available}"
62
+ puts "Office Name: #{@offices[$index].name}"
63
+ puts "Office Number: #{@offices[$index].phone_number}"
64
+ puts "Office URL: #{@offices[$index].url}"
65
+ puts "Office Next Available Appointment: #{@offices[$index].next_available}"
44
66
  puts "---"
45
67
  puts " "
68
+ puts " "
69
+ puts " "
46
70
 
47
71
  else
48
72
  puts "No results found. Please try again."
49
73
  end
74
+ puts " "
75
+ puts " "
76
+ puts " "
50
77
  puts "Would you like to select another office from the list?"
51
78
  puts " "
52
- @clinics.each_with_index do |office, i|
79
+ @offices.each_with_index do |office, i|
53
80
  puts "#{i + 1}. #{office.name}"
54
81
  end
55
82
  puts " "
@@ -57,4 +84,13 @@ class Urgentcare::CLI
57
84
  puts " "
58
85
  list
59
86
  end
87
+
88
+ def loading_message
89
+ puts " "
90
+ puts "Retrieving data...."
91
+ puts "Loading......"
92
+ puts "............."
93
+ puts " "
94
+ end
95
+
60
96
  end
@@ -9,15 +9,11 @@ class Urgentcare::Office
9
9
  @url = url
10
10
  @next_available = next_available
11
11
  @phone_number = phone_number
12
- @@all << self
12
+ self.class.all << self #the class of this instance. abstracted away use of variable.
13
13
  end
14
14
 
15
15
  def self.all
16
16
  @@all
17
17
  end
18
18
 
19
- def self.clear
20
- @@all.clear
21
- end
22
-
23
19
  end
@@ -1,5 +1,10 @@
1
1
  class Urgentcare::Scraper
2
2
 
3
+ def initialize(office = Urgentcare::Office, scraper: Urgentcare::Scraper)
4
+ @office = office
5
+ @scraper = scraper
6
+ end
7
+
3
8
  def self.send_cmd(driver, cmd, params={}) #method by Hernando Torres- Rocca
4
9
  bridge = driver.send(:bridge)
5
10
  resource = "session/#{bridge.session_id}/chromium/send_command_and_get_result"
@@ -8,58 +13,66 @@ class Urgentcare::Scraper
8
13
  return response[:value]
9
14
  end
10
15
 
11
- #@ instance variable
12
16
  @@client = Selenium::WebDriver::Remote::Http::Default.new #class variable
13
17
  @@client.read_timeout = 3000 # seconds – default is 60
14
18
 
15
19
  @@browser = Watir::Browser.new :chrome, headless: true, http_client: @@client
16
20
  send_cmd(@@browser.driver, "Network.setBlockedURLs", {'urls': ["*careuc.netmng.com*"]}) #url pending when page loads
17
- send_cmd(@@browser.driver, "Network.enable")
21
+ send_cmd(@@browser.driver, "Network.enable")
18
22
 
23
+ @@clinic_page = @@browser.goto('https://www.carewellurgentcare.com/centers/')
19
24
 
20
- @@clinic_page = @@browser.goto('https://www.carewellurgentcare.com/centers/')
25
+ @@url = []
21
26
 
22
27
  def get_page # page that lists all clinics
23
28
  doc = @@browser.div(id: 'et-main-area').wait_until(&:present?)
24
29
  inner = Nokogiri::HTML(doc.inner_html) #return value of the method
25
30
  end
26
31
 
27
- def get_clinics #called first in CLI
28
- new_page = get_page.css('.centers-list')
29
- new_page.each_with_index do |office_details, index|
30
- make_office(office_details, index)
32
+ def get_office_list #called first in CLI
33
+ @new_page = get_page.css('.centers-list')
34
+ office_url
35
+ end
36
+
37
+ def office_url
38
+ @new_page.each do |office_details| #does not create additional objects. returns original object
31
39
  if office_details.css('a').length > 3
32
- url = office_details.css('a')[3][name="href"]
40
+ @@url << office_details.css('a')[3][name="href"]
33
41
  else
34
- url = office_details.css('a')[2][name="href"]
42
+ @@url << office_details.css('a')[2][name="href"]
35
43
  end
36
- get_waittime(url)
44
+ @off = @office.new
45
+ make_office(office_details)
37
46
  end
38
47
  end
39
-
40
- def get_waittime(url) #retrieve waittime and add to new office model
41
- @@browser.goto(url)
42
- js_doc = @@browser.iframe.wait_until(&:present?)
43
- if js_doc.button(data_id: "timeSelector").exists?
44
- @wait_time = js_doc.button(data_id: "timeSelector").text.gsub("\n", " ")
45
- Urgentcare::Office.all.last.next_available = @wait_time
46
- elsif js_doc.element(tag_name: 'h3').exists?
47
- @wait_time = js_doc.element(tag_name: 'h3').text
48
- Urgentcare::Office.all.last.next_available = @wait_time
49
- else
50
- @wait_time = "No time available"
51
- Urgentcare::Office.all.last.next_available = @wait_time
52
- end
48
+
49
+ def get_clinic_site
50
+ @@browser.goto(@@url[$index])
51
+ @js_doc = @@browser.iframe.wait_until(&:present?)
52
+ get_appttime_date
53
53
  end
54
54
 
55
- def make_office(office_details, index)
56
- office = Urgentcare::Office.new
57
- office.name = office_details.css('h2').text
55
+ def make_office(office_details)
56
+ @off.name = office_details.css('h2').text
58
57
  if office_details.css('a').length > 3
59
- office.url = office_details.css('a')[3][name="href"]
58
+ @off.url = office_details.css('a')[3][name="href"]
60
59
  else
61
- office.url = office_details.css('a')[2][name="href"]
60
+ @off.url = office_details.css('a')[2][name="href"]
61
+ end
62
+ @off.phone_number = office_details.css('a[href]').text.gsub("Get DirectionsBook Urgent Care Appointment", " ")
63
+ end
64
+
65
+ def get_appttime_date #retrieve waittime and add to new office model
66
+ sleep(1);
67
+ iframe_info = Nokogiri::HTML(@js_doc.html)
68
+ if iframe_info.css('div.time-slots')
69
+ @wait_day = iframe_info.css('div.d-flex.d-md-none.header').text
70
+ @wait_time = iframe_info.css('div.time-slot.selected').text
71
+ @office.all[$index].next_available = "#{@wait_day} #{@wait_time}"
72
+ else
73
+ @wait_time = "No time available"
74
+ @office.all[$index].next_available = "#{@wait_time}"
62
75
  end
63
- office.phone_number = office_details.css('a[href]').text.gsub("Get DirectionsBook Urgent Care Appointment", " ")
64
76
  end
77
+
65
78
  end
@@ -1,3 +1,3 @@
1
1
  module Urgentcare
2
- VERSION = "0.2.1" #increment a version with each release
2
+ VERSION = "0.2.2" #increment a version with each release
3
3
  end #semantic versioning
data/lib/UrgentCare.rb CHANGED
@@ -7,7 +7,7 @@ require 'capybara'
7
7
 
8
8
 
9
9
  require_relative "./Urgentcare/CLI"
10
- require_relative "./Urgentcare/version" #why was this not a relative path?
10
+ require_relative "./Urgentcare/version"
11
11
  require_relative "./Urgentcare/Office"
12
12
  require_relative "./Urgentcare/Scraper"
13
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: UrgentcareCLI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - PamelaTorres-Rocca
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-26 00:00:00.000000000 Z
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler