class CurseClient::Client
Constants
- CACHE_DIR
- HOME_DIR
Attributes
api[R]
feed[R]
Public Class Methods
new(feed = CurseClient::Feed.new, api = CurseClient::API.new)
click to toggle source
# 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
Public Instance Methods
addon(id)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/curse_client/client.rb, line 30 def find_by_name(name) modpack = modpacks. select { |m| m[:name] == name }. first modpack && addon(modpack[:id]) end
install(modpack, path, version)
click to toggle source
# File lib/curse_client/client.rb, line 57 def install(modpack, path, version) Installer.new(self).install(modpack, path, version) end
modpacks()
click to toggle source
# File lib/curse_client/client.rb, line 24 def modpacks projects. select { |d| d[:category_section] == :modpacks }. sort_by { |d| d[:name] } end
projects()
click to toggle source
# File lib/curse_client/client.rb, line 20 def projects @projects ||= load_projects end
Private Instance Methods
authenticate()
click to toggle source
# File lib/curse_client/client.rb, line 72 def authenticate print "Curse username: " username = $stdin.gets.chomp print "Curse Password: " password = $stdin.noecho(&:gets).chomp puts "" api.authenticate(username, password) self.token = api.token true rescue API::UnauthorizedError puts "Inavlid username or password" false end
load_projects()
click to toggle source
# File lib/curse_client/client.rb, line 86 def load_projects puts "Loading project information from curse" store = load_store if store[:complete_timestamp] < feed.complete_timestamp complete = feed.complete store[:complete_timestamp] = complete[:timestamp] store[:projects] = strip_data(complete[:data]) save_store(store) end store[:projects] end
load_store()
click to toggle source
# File lib/curse_client/client.rb, line 112 def load_store store = PStore.new("#{CACHE_DIR}/projects.pstore") store.transaction(true) do { complete_timestamp: store[:complete_timestamp] || 0, projects: store[:projects] } end end
save_store(data)
click to toggle source
# File lib/curse_client/client.rb, line 122 def save_store(data) store = PStore.new("#{CACHE_DIR}/projects.pstore") store.transaction do store[:complete_timestamp] = data[:complete_timestamp] store[:projects] = data[:projects] end end
strip_data(data)
click to toggle source
# File lib/curse_client/client.rb, line 101 def strip_data(data) data.map do |project| { id: project[:id], name: project[:name], summary: project[:summary], category_section: project[:category_section][:name].downcase.gsub(/ /, "_").to_sym, } end end
token()
click to toggle source
# File lib/curse_client/client.rb, line 130 def token @token ||= begin store = PStore.new("#{HOME_DIR}/token.pstore") store.transaction(true) do store[:token] end end end
token=(t)
click to toggle source
# File lib/curse_client/client.rb, line 140 def token=(t) store = PStore.new("#{HOME_DIR}/token.pstore") store.transaction do store[:token] = t end end
with_authentication() { || ... }
click to toggle source
# File lib/curse_client/client.rb, line 66 def with_authentication yield rescue API::UnauthorizedError retry if authenticate end