Class: NgpodScraper::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/ngpod_scraper/client.rb', line 5

def initialize(config)
  @config = symbolize_keys(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/ngpod_scraper/client.rb', line 3

def config
  @config
end

Instance Method Details

#get_photoObject



9
10
11
# File 'lib/ngpod_scraper/client.rb', line 9

def get_photo
  PhotoPage.new(config[:url], config).photo
end

#log(message) ⇒ Object



13
14
15
16
17
# File 'lib/ngpod_scraper/client.rb', line 13

def log(message)
  if config[:show_logs]
    puts message
  end
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ngpod_scraper/client.rb', line 19

def run
  photo = get_photo
  if photo.exists?
    log "Wasn't able to download the photo of the day. Maybe the photo has already been downloaded."
  else
    photo.save
    photo.save_wallpaper
    log "Downloaded #{photo.path}"
  end
  photo
end