Class: E621ExportDownloader::Client

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/e621_export_downloader/client.rb,
lib/e621_export_downloader/client/options.rb,
lib/e621_export_downloader/client/options/builder.rb,
lib/e621_export_downloader/client/options/builder/parsers.rb

Defined Under Namespace

Classes: Options

Constant Summary collapse

Logger =
::Logger.new($stdout)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Client

Returns a new instance of Client.



16
17
18
# File 'lib/e621_export_downloader/client.rb', line 16

def initialize(options = nil)
  @options = T.let(options || Options.new, Options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/e621_export_downloader/client.rb', line 13

def options
  @options
end

Instance Method Details

#config(&block) ⇒ Object



21
22
23
# File 'lib/e621_export_downloader/client.rb', line 21

def config(&block)
  block.call(Options::Builder.new(@options))
end

#connectionObject



26
27
28
# File 'lib/e621_export_downloader/client.rb', line 26

def connection
  Faraday.new(url: Constants::BASE_URL, headers: { "User-Agent" => Constants::USER_AGENT })
end

#debug(msg, header: []) ⇒ Object



31
32
33
# File 'lib/e621_export_downloader/client.rb', line 31

def debug(msg, header: [])
  Logger.debug("[e621_export_downloader#{":#{header.join(':')}" unless header.empty?}] #{msg}")
end

#get(type) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/e621_export_downloader/client.rb', line 36

def get(type)
  if type.is_a?(String)
    case type
    when "pools"
      type = Types::Pools
    when "posts"
      type = Types::Posts
    when "tag_aliases"
      type = Types::TagAliases
    when "tag_implications"
      type = Types::TagImplications
    when "tags"
      type = Types::Tags
    when "wiki_pages"
      type = Types::WikiPages
    else
      raise(ArgumentError, "invalid type: #{type}")
    end
  end

  T.assert_type!(type, Types)
  ExportHelper.new(client: self, type: type, parser: options.parsers.public_send(type.serialize))
end

#get_pools(date = Date.today) ⇒ Object



66
67
68
# File 'lib/e621_export_downloader/client.rb', line 66

def get_pools(date = Date.today)
  pools.get(date)
end

#get_posts(date = Date.today) ⇒ Object



76
77
78
# File 'lib/e621_export_downloader/client.rb', line 76

def get_posts(date = Date.today)
  posts.get(date)
end

#get_tag_aliases(date = Date.today) ⇒ Object



86
87
88
# File 'lib/e621_export_downloader/client.rb', line 86

def get_tag_aliases(date = Date.today)
  tag_aliases.get(date)
end

#get_tag_implications(date = Date.today) ⇒ Object



96
97
98
# File 'lib/e621_export_downloader/client.rb', line 96

def get_tag_implications(date = Date.today)
  tag_implications.get(date)
end

#get_tags(date = Date.today) ⇒ Object



106
107
108
# File 'lib/e621_export_downloader/client.rb', line 106

def get_tags(date = Date.today)
  tags.get(date)
end

#get_wiki_pages(date = Date.today) ⇒ Object



116
117
118
# File 'lib/e621_export_downloader/client.rb', line 116

def get_wiki_pages(date = Date.today)
  wiki_pages.get(date)
end

#poolsObject



61
62
63
# File 'lib/e621_export_downloader/client.rb', line 61

def pools
  get(Types::Pools)
end

#postsObject



71
72
73
# File 'lib/e621_export_downloader/client.rb', line 71

def posts
  get(Types::Posts)
end

#tag_aliasesObject



81
82
83
# File 'lib/e621_export_downloader/client.rb', line 81

def tag_aliases
  get(Types::TagAliases)
end

#tag_implicationsObject



91
92
93
# File 'lib/e621_export_downloader/client.rb', line 91

def tag_implications
  get(Types::TagImplications)
end

#tagsObject



101
102
103
# File 'lib/e621_export_downloader/client.rb', line 101

def tags
  get(Types::Tags)
end

#wiki_pagesObject



111
112
113
# File 'lib/e621_export_downloader/client.rb', line 111

def wiki_pages
  get(Types::WikiPages)
end