caseblocks_bucket_extractor 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +13 -5
  2. data/lib/caseblocks_bucket_extractor.rb +27 -3
  3. metadata +25 -10
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 19cdabd20e7d7276f24c7ae042c9480f59ec6196
4
- data.tar.gz: 0257f0d5f4105e86449537ec2c73a20ad32b1d04
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDk0ZTE5Y2MzYjkzNzdkOWI4MjgwZjRkYmNkNDVhYjMwNGY4NmY4MQ==
5
+ data.tar.gz: !binary |-
6
+ OTk5YWRhZTNmMDA3ZWE5ZDc5NzUzMzdhOGE4MTE3ZWFkYjE1YzQ3MA==
5
7
  SHA512:
6
- metadata.gz: acc06ae75580605a3b97200e6700bb6e89791ebb514a5d81a5f2a1b40bd2c25d3183dbf7f7d32b9a693cbe652967860cd785e3e776451e710bc77cce12875879
7
- data.tar.gz: c6c602ead6f7d518b447e2627791c9ee08755fd13eb6e79be38f1c612cc3aa8f933ea962494e3b9b30d50fbb44d148c2a3b5add4c18be7e9c31eb2ccc4978db0
8
+ metadata.gz: !binary |-
9
+ OTRlYjE0NzI5YjVlYWUxNDI4ZjYzYjM3NjEyMDhjNmU1NGJiZDMzNzNkNGY2
10
+ NjY5MzkxMzYxOTliZWRkNmIyNDFjODMxYmUwMGM3OWE1YjI4OGM0MGE5YmI2
11
+ NjgzMjc1NzQ5MzBlOWY5NDcwMzA5MDQzYmNjMjM5ZGMzZTUyM2E=
12
+ data.tar.gz: !binary |-
13
+ ZTkxZmUxMDAwOGE5ZGI0ZWNhZjI0ODAzMDVkYjg1OTBlYjg3ZmE5ZDMzYmU1
14
+ MDA1MTVmOGQ1YzJhY2UyMTgxNzFmY2FhNWFkZTIzOTBiY2M0Zjk5MWI1ZTI4
15
+ YzU2NDZkMmQwYWZiNDQwMjUyNWE1MTZjZmI4NzU3MWJlYmNjZmE=
@@ -1,6 +1,7 @@
1
1
  require 'httparty'
2
2
  require 'json'
3
3
  require 'open-uri'
4
+ require 'zip'
4
5
 
5
6
  class CaseblocksBucketExtractor
6
7
  include HTTParty
@@ -12,7 +13,7 @@ class CaseblocksBucketExtractor
12
13
  headers "Accept" => "application/json"
13
14
  headers "Content-Type" => "application/json"
14
15
 
15
- def initialize(url, auth_token, download_options={:retry_limit => 60,:time_between_retries => 60})
16
+ def initialize(url, auth_token, extract_path, download_options={:retry_limit => 60,:time_between_retries => 60})
16
17
  self.class.base_uri url
17
18
 
18
19
  puts url
@@ -21,9 +22,11 @@ class CaseblocksBucketExtractor
21
22
 
22
23
  @retry_limit = download_options[:retry_limit]
23
24
  @time_between_retries = download_options[:time_between_retries]
25
+ @extract_path = extract_path
24
26
  end
25
27
 
26
28
  def download(case_type_name, bucket_slug, file_options)
29
+
27
30
  response = self.class.get("/case_blocks/#{URI::encode(case_type_name)}/buckets/#{bucket_slug}/schedule_download_job")
28
31
  job_url = get_job_url(response.body)
29
32
 
@@ -50,11 +53,14 @@ class CaseblocksBucketExtractor
50
53
  hol_up
51
54
  count_of_retries -= 1
52
55
 
53
- response = HTTParty.get("#{job_url}?auth_token=#{self.auth_token}")
56
+ url = "#{job_url}?auth_token=#{self.auth_token}"
57
+ puts url
58
+ response = HTTParty.get(url)
54
59
 
55
60
  begin
56
61
  result = JSON.parse(response.body)
57
62
  rescue
63
+ puts response.body
58
64
  puts "STATUS UPDATE: cannot parse JSON received response code with body of #{response.body}"
59
65
  next
60
66
  end
@@ -73,11 +79,27 @@ class CaseblocksBucketExtractor
73
79
  files = json["job"]["job_log"].find{|f| f["files"] }
74
80
  file_options.each do |file_option|
75
81
  json_file = files["files"].find{|f| f["file"].include?(file_option[:name])}
76
- download_file(file_option[:path], json_file["link"])
82
+ if json_file
83
+ download_file(file_option[:path], json_file["link"])
84
+ puts "Reading zip file #{file_option[:path]}"
85
+ Zip::File.open(file_option[:path]) do |zip_file|
86
+ # Handle entries one by one
87
+ zip_file.each do |entry|
88
+ # Extract to file/directory/symlink
89
+ extract_filepath = "#{@extract_path}/#{entry.name}"
90
+ puts "Extracting #{extract_filepath}"
91
+ entry.extract(extract_filepath) { true }
92
+ end
93
+ end
94
+
95
+ else
96
+ puts "Unable to find link for #{file_option[:name]}"
97
+ end
77
98
  end
78
99
  end
79
100
 
80
101
  def download_file(file_location,s3_link)
102
+ puts "Downloading #{s3_link} to #{file_location}"
81
103
  File.open(file_location, "wb") do |saved_file|
82
104
  open(s3_link, 'rb') do |read_file|
83
105
  IO.copy_stream(read_file, saved_file)
@@ -88,6 +110,8 @@ class CaseblocksBucketExtractor
88
110
  def get_job_url(response_body)
89
111
  begin
90
112
  job_url = JSON.parse(response_body)["job_url"]
113
+ job_url = job_url.gsub("http:", "https:") if job_url =~ /http:/
114
+ job_url = "#{job_url}.json" unless job_url =~ /\.json\z/
91
115
  rescue
92
116
  puts "SCHEDULE_DOWNLOAD: cannot get job_url with body of #{response_body}"
93
117
  return nil
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caseblocks_bucket_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Quinn, Stewart McKee, Colin Gemmell
8
+ - Ijonas Kisselbach
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
@@ -28,25 +29,39 @@ dependencies:
28
29
  name: slop
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ~>
32
33
  - !ruby/object:Gem::Version
33
- version: '0'
34
+ version: 3.6.0
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 3.6.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubyzip
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
39
47
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description: A simple hello world gem
48
+ version: 1.1.7
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.1.7
56
+ description: A gem to download bucket data from CaseBlocks
42
57
  email: development@emergeadapt.com
43
58
  executables:
44
59
  - bucket_downloader
45
60
  extensions: []
46
61
  extra_rdoc_files: []
47
62
  files:
48
- - lib/caseblocks_bucket_extractor.rb
49
63
  - bin/bucket_downloader
64
+ - lib/caseblocks_bucket_extractor.rb
50
65
  homepage: http://rubygems.org/gems/caseblocks_bucket_extractor
51
66
  licenses: []
52
67
  metadata: {}
@@ -56,17 +71,17 @@ require_paths:
56
71
  - lib
57
72
  required_ruby_version: !ruby/object:Gem::Requirement
58
73
  requirements:
59
- - - '>='
74
+ - - ! '>='
60
75
  - !ruby/object:Gem::Version
61
76
  version: '0'
62
77
  required_rubygems_version: !ruby/object:Gem::Requirement
63
78
  requirements:
64
- - - '>='
79
+ - - ! '>='
65
80
  - !ruby/object:Gem::Version
66
81
  version: '0'
67
82
  requirements: []
68
83
  rubyforge_project:
69
- rubygems_version: 2.0.2
84
+ rubygems_version: 2.4.6
70
85
  signing_key:
71
86
  specification_version: 4
72
87
  summary: Gem to kick off, poll and save bucket downloads from CaseBlocks