Class: ThemeBandit::Downloader

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/theme_bandit/downloader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Downloader

Returns a new instance of Downloader.



21
22
23
24
# File 'lib/theme_bandit/downloader.rb', line 21

def initialize(url, options = {})
  @url, @options = default_to_http(url), options
  @document = get_document(url)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



19
20
21
# File 'lib/theme_bandit/downloader.rb', line 19

def document
  @document
end

#errorObject (readonly)

Returns the value of attribute error.



19
20
21
# File 'lib/theme_bandit/downloader.rb', line 19

def error
  @error
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/theme_bandit/downloader.rb', line 19

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



19
20
21
# File 'lib/theme_bandit/downloader.rb', line 19

def url
  @url
end

Class Method Details

.errorObject



15
16
17
# 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 = {}) ⇒ Object



11
12
13
# File 'lib/theme_bandit/downloader.rb', line 11

def self.fetch(url, options = {})
  new(url, options).document
end

.get_theme(url = ThemeBandit.configuration.url) ⇒ Object



7
8
9
# File 'lib/theme_bandit/downloader.rb', line 7

def self.get_theme(url = ThemeBandit.configuration.url)
  url ? fetch(url) : error
end

Instance Method Details

#get_document(url) ⇒ Object



26
27
28
29
30
31
32
33
# 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