Class: ComicWalker::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/comic_walker/cli.rb

Constant Summary collapse

CONFIG_DIR =
Pathname.new(ENV['HOME']).join('.comic-walker')
CONFIG_PATH =
CONFIG_DIR.join('config.yml')
CONFIG_DIR.join('cookie.yml')

Instance Method Summary collapse

Instance Method Details

#contentsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/comic_walker/cli.rb', line 44

def contents
  jar = HTTP::CookieJar.new
  load_cookies(jar)
  client = V1::Client.new(jar, load_uuid)
  json = client.contents(per_page: options[:per_page], page: options[:page])
  save_cookies(jar)

  json['contents'].sort_by { |content| Time.parse(content['updated_at']) }.reverse_each do |content|
    next unless content.has_key?('sub_contents')
    puts "#{content['name']} http://comic-walker.com/contents/detail/#{content['content_id']}"
    puts "  Updated: #{format_time(content['updated_at'])}"
    puts "  Deliver: #{format_time(content['deliver_start_date'])} - #{format_time(content['deliver_stop_date'])}"
    tags = content['tags']
    puts "  Episodes:"
    tags['visible_episodes'].each_key do |episode|
      _, desc, cid = *episode.split('|')
      puts "    #{desc} http://comic-walker.com/viewer/?cid=#{cid}"
    end
    if next_issue = tags['publication_date_of_next_issue']
      next_issue = format_time(next_issue.keys.first)
    else
      next_issue = 'UNKNOWN'
    end
    puts "  Next: #{next_issue}"
  end
end

#save(*cids) ⇒ Object



20
21
22
23
24
25
# File 'lib/comic_walker/cli.rb', line 20

def save(*cids)
  client = Client.new
  cids.each do |cid|
    ContentDownloader.new(client, cid).save
  end
end

#save_all(*parent_cids) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/comic_walker/cli.rb', line 28

def save_all(*parent_cids)
  jar = HTTP::CookieJar.new
  load_cookies(jar)
  child_cids = find_sub_contents(V1::Client.new(jar, load_uuid), parent_cids)
  save_cookies(jar)
  save(*child_cids)
end