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, download_options = {:retry_limit => 60,:time_between_retries => 60}) ⇒ CaseblocksBucketExtractor

Returns a new instance of CaseblocksBucketExtractor.



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

def initialize(url, auth_token, 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]
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



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

def auth_token
  @auth_token
end

#retry_limitObject (readonly)

Returns the value of attribute retry_limit.



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

def retry_limit
  @retry_limit
end

#time_between_retriesObject (readonly)

Returns the value of attribute time_between_retries.



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

def time_between_retries
  @time_between_retries
end

Instance Method Details

#download(case_type_name, bucket_slug, file_options) ⇒ Object



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

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