Class: VoxcastApi::Version0

Inherits:
Http
  • Object
show all
Defined in:
lib/voxcast_api/purge.rb

Instance Attribute Summary

Attributes inherited from Http

#password, #url, #user

Instance Method Summary collapse

Methods inherited from Http

#execute, #get_http, #get_method, #timestamp

Constructor Details

#initialize(entry = nil) ⇒ Version0

Returns a new instance of Version0.



105
106
107
108
# File 'lib/voxcast_api/purge.rb', line 105

def initialize(entry = nil)
  super(entry)
  @http_domain = @entry.http_domain if @entry
end

Instance Method Details

#get_basic_auth(params = {}) ⇒ Object



122
123
124
# File 'lib/voxcast_api/purge.rb', line 122

def get_basic_auth(params = {})
  [ @user, @password ]
end

#get_path_and_params(params = {}, url = nil) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/voxcast_api/purge.rb', line 114

def get_path_and_params(params = {}, url = nil)
  url = @url if url.blank?
  uri = URI.parse(url)
  site = "http://#{@http_domain}/"
  args = {'source' => 'web', 'site' => site, 'submit' => 'Purge'}.merge(params)
  [uri.path, args]
end

#get_urls(files) ⇒ Object



110
111
112
# File 'lib/voxcast_api/purge.rb', line 110

def get_urls(files)
  files.join(13.chr+10.chr)
end

#process_response(resp, complex = false) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/voxcast_api/purge.rb', line 126

def process_response(resp, complex = false)
  if resp.code.to_i == 200
    return {:status => true, :detail => ''}
  else
    return {:status => false, :detail => resp.to_s}
  end
end

#purge(files) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/voxcast_api/purge.rb', line 134

def purge(files)
  # this will purge the files the old way, since its possible some cdn entries will not work with the new way
  # specifically the ones that are used by perez
  return if files.empty?
  url = @url || 'http://purge.voxcdn.com/purge.php?KEY=2caf5c2eaf'
  # this will do mass purging
  begin
    start = Time.now
    @logger.info("attempting to purge from site #{@http_domain}")
    params = {'urls' =>  get_urls(files)}
    execute(url, params)
    taken = Time.now - start
    @logger.info("purged #{files.size} files in #{taken.to_s} seconds")
  rescue Exception => err
    puts err.to_s
    @logger.error("*** Could not purge urls #{url} : #{err.to_s}")
    {:status => false, :detail => err.to_s}
  end
end