Class: CaseblocksBucketExtractor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, auth_token, extract_path, download_options = {:retry_limit => 60,:time_between_retries => 60}) ⇒ CaseblocksBucketExtractor

Returns a new instance of CaseblocksBucketExtractor.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/caseblocks_bucket_extractor.rb', line 16

def initialize(url, auth_token, extract_path, download_options={:retry_limit => 60,:time_between_retries => 60})
  self.class.base_uri url

  puts url
  @auth_token = auth_token
  self.class.default_params("auth_token" => @auth_token)

  @retry_limit = download_options[:retry_limit]
  @time_between_retries = download_options[:time_between_retries]
  @extract_path = extract_path
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



9
10
11
# File 'lib/caseblocks_bucket_extractor.rb', line 9

def auth_token
  @auth_token
end

#retry_limitObject (readonly)

Returns the value of attribute retry_limit.



10
11
12
# File 'lib/caseblocks_bucket_extractor.rb', line 10

def retry_limit
  @retry_limit
end

#time_between_retriesObject (readonly)

Returns the value of attribute time_between_retries.



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

def time_between_retries
  @time_between_retries
end

Instance Method Details

#download(case_type_name, bucket_slug, file_options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/caseblocks_bucket_extractor.rb', line 28

def download(case_type_name, bucket_slug, file_options)

  response = self.class.get("/case_blocks/#{URI::encode(case_type_name)}/buckets/#{bucket_slug}/schedule_download_job")
  job_url = get_job_url(response.body)


  #raise response.headers["status"] unless response.headers["status"].start_with?("200")

  result = start_polling(job_url)


  if !result.nil? && result["job"]["status"] == "completed"
    create_files(file_options,result)
  else
    raise "!!!!!  Job - #{job_url} did not complete. !!!!!!"
  end
end