Class: CurseClient::Client

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

Constant Summary collapse

HOME_DIR =
"#{Dir.home}/.curse_client"
CACHE_DIR =
"#{HOME_DIR}/cache"

Instance Method Summary collapse

Constructor Details

#initialize(feed = CurseClient::Feed.new, api = CurseClient::API.new) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
# File 'lib/curse_client/client.rb', line 11

def initialize(feed = CurseClient::Feed.new, api = CurseClient::API.new)
  @feed = feed
  @api = api

  FileUtils::mkpath(CACHE_DIR)

  api.token = token
end

Instance Method Details

#addon(id) ⇒ Object



37
38
39
40
41
# File 'lib/curse_client/client.rb', line 37

def addon(id)
  with_authentication do
    api.addon(id)
  end
end

#addon_file(addon_id, file_id) ⇒ Object



51
52
53
54
55
# File 'lib/curse_client/client.rb', line 51

def addon_file(addon_id, file_id)
  with_authentication do
    api.addon_file(addon_id, file_id)
  end
end

#addon_files(addon_id) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/curse_client/client.rb', line 43

def addon_files(addon_id)
  with_authentication do
    api.addon_files(addon_id)[:files].
      sort_by{|f| f[:file_date] }.
      reverse
  end
end

#find_by_name(name) ⇒ Object



30
31
32
33
34
35
# File 'lib/curse_client/client.rb', line 30

def find_by_name(name)
  modpack = modpacks.
    select { |m| m[:name] == name }.
    first
  addon(modpack[:id])
end

#install(modpack, path, version) ⇒ Object



57
58
59
# File 'lib/curse_client/client.rb', line 57

def install(modpack, path, version)
  Installer.new(self).install(modpack, path, version)
end

#modpacksObject



24
25
26
27
28
# File 'lib/curse_client/client.rb', line 24

def modpacks
  projects.
    select { |d| d[:category_section] == :modpacks }.
    sort_by { |d| d[:name] }
end

#projectsObject



20
21
22
# File 'lib/curse_client/client.rb', line 20

def projects
  @projects ||= load_projects
end