Class: ComerDeTapas::Client
- Inherits:
-
Object
- Object
- ComerDeTapas::Client
- Defined in:
- lib/comer_de_tapas/client.rb
Instance Method Summary collapse
-
#authenticate ⇒ Object
Authenticate and return Cookie.
-
#download_all_tapas! ⇒ Object
Download episode in parallel using Actors Powered by Celluloid::IO.
-
#fetch_episodes!(force = nil) ⇒ Object
Fetch latest feed on rubytapas.dpdcart.com Parse it to episode, save episodes data as json to ~/.rubytapas.json.
-
#init! ⇒ Object
Initialize comer de tapas $ mkdir -p ~/.rubytapas/ $ touch ~/.rubytapas/.credentials.
-
#load_episodes ⇒ Object
Load episodes json from EPISODES_JSON_FILE.
-
#prepare_save_folder! ⇒ Object
Create user specified folder: credentials.
-
#save_folder ⇒ Pathname
User spefified folder to save episodes.
Instance Method Details
#authenticate ⇒ Object
Authenticate and return Cookie
39 40 41 |
# File 'lib/comer_de_tapas/client.rb', line 39 def authenticate ||= HTTP.post(LOGIN_URL, form_params).headers['Set-Cookie'] end |
#download_all_tapas! ⇒ Object
Download episode in parallel using Actors Powered by Celluloid::IO
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/comer_de_tapas/client.rb', line 56 def download_all_tapas! episodes.each do |episode| FileUtils.cd(save_folder.) do episode_title = episode['title'] puts "Downloading Epsiode #{episode_title}..." episode_folder = save_folder.join(sanitized episode_title). FileUtils.mkdir_p episode_folder unless File.exist? episode_folder FileUtils.cd episode_folder do fetcher = Fetcher.new file_and_links = episode['links'] downloadables = find_downloadables file_and_links if downloadables.all? &:nil? puts 'Already downloaded, skip.' next end download_parallelly! downloadables puts "Episode #{episode_title} content all saved." end end end end |
#fetch_episodes!(force = nil) ⇒ Object
Fetch latest feed on rubytapas.dpdcart.com Parse it to episode, save episodes data as json to ~/.rubytapas.json
22 23 24 25 26 27 28 |
# File 'lib/comer_de_tapas/client.rb', line 22 def fetch_episodes! force=nil return puts 'Use cached episode data.' if fresh? && force.nil? puts 'Fetching episodes...' get_feed_with_basic_auth save_feed_data parse_xml_feed puts 'Episodes successfully fetched.' end |
#init! ⇒ Object
Initialize comer de tapas $ mkdir -p ~/.rubytapas/ $ touch ~/.rubytapas/.credentials
12 13 14 15 16 17 18 |
# File 'lib/comer_de_tapas/client.rb', line 12 def init! if File.exist?(RUBYTAPAS_DIR) && File.exist?(CREDENTIAL_FILE) abort 'Credentials found. type `comer_de_tapas download` to download.' end create_rubytapas_files! puts '~/.rubytapas/.credentials folder and file has been created.' end |
#load_episodes ⇒ Object
Load episodes json from EPISODES_JSON_FILE
44 45 46 |
# File 'lib/comer_de_tapas/client.rb', line 44 def load_episodes @episodes ||= JSON.parse(File.read EPISODES_JSON_FILE) end |
#prepare_save_folder! ⇒ Object
Create user specified folder: credentials
31 32 33 34 35 36 |
# File 'lib/comer_de_tapas/client.rb', line 31 def prepare_save_folder! return puts "#{save_folder} found." if File.exist? save_folder FileUtils.mkdir_p save_folder. puts "#{save_folder} created." end |
#save_folder ⇒ Pathname
User spefified folder to save episodes.
50 51 52 |
# File 'lib/comer_de_tapas/client.rb', line 50 def save_folder Pathname credentials[:save_path] end |