caseblocks_bucket_extractor 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/bin/bucket_downloader +66 -0
  2. metadata +25 -7
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'slop'
5
+ require 'csv'
6
+ require 'fileutils'
7
+ require (File.expand_path '../..', __FILE__) + '/lib/caseblocks_bucket_extractor'
8
+
9
+ opts = Slop.parse do
10
+ banner 'Usage: bucket_downloader [options]'
11
+
12
+ on 'casetype=', 'Case Type Name'
13
+ on 'bucket=', 'Bucket Slug'
14
+ on 'username=', 'Username'
15
+ on 'password=', 'Password'
16
+ on 'f', 'forcequotes', 'Force quotation marks'
17
+ on 'l', 'local', "Download from localhost"
18
+ end
19
+
20
+ if opts[:casetype] && opts[:bucket]
21
+
22
+ # Bucket Downloader
23
+ puts " == Bucket Downloader == "
24
+
25
+ bucket_name = opts[:bucket]
26
+ case_type = opts[:casetype]
27
+
28
+ puts "Downloading bucket: #{bucket_name}"
29
+
30
+ #Create instance of CaseblocksBucketExtractor passing URL, email and password with optional download_options i.e. {:retry_limit => 5,:time_between_retries => 5}
31
+ puts "Creating Bucket Extractor... "
32
+ if opts[:local]
33
+ puts "http://localhost:3001"
34
+ bucket_extractor = CaseblocksBucketExtractor.new("http://localhost:3000", opts[:username], opts[:password], {:retry_limit => 12,:time_between_retries => 10})
35
+ else
36
+ bucket_extractor = CaseblocksBucketExtractor.new("https://login.caseblocks.com", opts[:username], opts[:password], {:retry_limit => 5,:time_between_retries => 5})
37
+ end
38
+
39
+ #Setup file options array. :name -> will find extracted CSV file containing value, :path -> local file path to save file to
40
+
41
+ file_path = File.expand_path("..", __FILE__) + "/"+ DateTime.now.strftime("%y-%m-%d-%M-%H") + "_" + bucket_name + ".csv"
42
+
43
+ file_options = [{:path => file_path, :name => "domain.csv"}]
44
+
45
+ puts "Downloading to #{file_path}"
46
+
47
+ #Begin download specifying Case Type Name, bucket slug and the file options defined above
48
+ bucket_extractor.download(case_type, bucket_name, file_options)
49
+
50
+ if opts[:forcequotes]
51
+ puts "Forcing fields to have quotes"
52
+
53
+ CSV.open("#{file_path[0..-5]}.tmp", "w+", :force_quotes => true) do |tmp_csv|
54
+ puts "file_path: #{file_path}"
55
+ CSV.open(file_path, "r").each do |row|
56
+ tmp_csv << row
57
+ end
58
+ end
59
+ FileUtils.mv("#{file_path[0..-5]}.tmp", file_path)
60
+ end
61
+
62
+ puts "End Bucket Downloader"
63
+ else
64
+ puts opts
65
+ end
66
+
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caseblocks_bucket_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Charlie Quinn
8
+ - Charlie Quinn, Stewart McKee
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-06 00:00:00.000000000 Z
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -27,13 +27,31 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.11.0
30
- description: Gem to kick off, poll and save bucket downloads from CaseBlocks
31
- email: charlie@emergeadapt.com
32
- executables: []
30
+ - !ruby/object:Gem::Dependency
31
+ name: slop
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A simple hello world gem
47
+ email: development@emergeadapt.com
48
+ executables:
49
+ - bucket_downloader
33
50
  extensions: []
34
51
  extra_rdoc_files: []
35
52
  files:
36
53
  - lib/caseblocks_bucket_extractor.rb
54
+ - bin/bucket_downloader
37
55
  homepage: http://rubygems.org/gems/caseblocks_bucket_extractor
38
56
  licenses: []
39
57
  post_install_message:
@@ -54,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
72
  version: '0'
55
73
  requirements: []
56
74
  rubyforge_project:
57
- rubygems_version: 1.8.25
75
+ rubygems_version: 1.8.24
58
76
  signing_key:
59
77
  specification_version: 3
60
78
  summary: Gem to kick off, poll and save bucket downloads from CaseBlocks