class ThemeBandit::Downloader

Attributes

document[R]
error[R]
options[R]
url[R]

Public Class Methods

error() click to toggle source
# File lib/theme_bandit/downloader.rb, line 15
def self.error
  Log.red 'Invalid configuration, please configure through ./bin wrapper or ThemeBandit::Configure'
end
fetch(url, options = {}) click to toggle source
# File lib/theme_bandit/downloader.rb, line 11
def self.fetch(url, options = {})
  new(url, options).document
end
get_theme(url = ThemeBandit.configuration.url) click to toggle source
# File lib/theme_bandit/downloader.rb, line 7
def self.get_theme(url = ThemeBandit.configuration.url)
  url ? fetch(url) : error
end
new(url, options = {}) click to toggle source
# File lib/theme_bandit/downloader.rb, line 21
def initialize(url, options = {})
  @url, @options = default_to_http(url), options
  @document = get_document(url)
end

Public Instance Methods

get_document(url) click to toggle source
# File lib/theme_bandit/downloader.rb, line 26
def get_document(url)
  response = self.class.get(url, options)
  log_request(url, response)
  response
rescue => e
  Log.red "request failed for #{url} #{e}"
  false
end

Private Instance Methods

default_to_http(url) click to toggle source
# File lib/theme_bandit/downloader.rb, line 46
def default_to_http(url)
  url[/(^http:\/\/|^https:\/\/)/] ? url : "http://#{url}"
end
log_request(url, response) click to toggle source
# File lib/theme_bandit/downloader.rb, line 37
def log_request(url, response)
  if response.code != 200
    @error = response.code
    Log.red   "Request failure trying to download #{url}, status #{response.code}"
  else
    Log.green "Downloading #{url}"
  end
end