Class: Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/downloader.rb

Constant Summary collapse

DOWNLOAD_PATH =
'https://acpmasquerade-nepal-loadshedding-schedule-by-sparrow-sms.p.mashape.com/schedule.php'
API_KEY =
'8ibMI63bqPmshv9aq5XoZtwTDNxBp11nUMNjsnVVa3A88wMy1E'
HEADER =
'X-Mashape-Key'
INSTALL_PATH =
File.expand_path('~/.schedule.yml')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(download_path = nil) ⇒ Downloader

Returns a new instance of Downloader.



9
10
11
12
# File 'lib/downloader.rb', line 9

def initialize(download_path=nil)
  @path ||= download_path || DOWNLOAD_PATH
  @schedule_json = Hash.new
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/downloader.rb', line 7

def path
  @path
end

#schedule_jsonObject (readonly)

Returns the value of attribute schedule_json.



7
8
9
# File 'lib/downloader.rb', line 7

def schedule_json
  @schedule_json
end

Instance Method Details

#downloadObject

Download the schedule form masquerade API



15
16
17
18
19
20
21
# File 'lib/downloader.rb', line 15

def download
    puts "Downloading latest schedule".colorize(:green)
  (1..7).each do |group|
    group_schedule = download_for_group(group)
    @schedule_json.merge!({group => group_schedule})
  end
end