sploder 1.0.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ rescue LoadError
12
12
  end
13
13
 
14
14
  # This line is what prints the running message
15
- puts "Main Sploder executable running."
15
+ puts "Sploder is sploding..."
16
16
 
17
17
  opts = Trollop::options do
18
18
  opt :upload, "Upload a file to S3"
@@ -27,7 +27,7 @@ opts = Trollop::options do
27
27
  opt :delete, "Delete an existing bucket. WARNING: This deletes the entire contents of your bucket"
28
28
  opt :website, "Enables webhosting for the specified bucket"
29
29
  opt :options, "Use optional settings. Not all operations support this flag"
30
-
30
+ opt :file, "Get information about a file and delete or download it"
31
31
  end
32
32
 
33
33
  # Initialize the settings class to later check for .sploder file
@@ -72,7 +72,8 @@ when opts[:explore]
72
72
  when opts[:create]
73
73
  settings.settings_exist # Check that Sploder has been set up
74
74
  unless opts[:name]
75
- puts "Please enter a name for your new bucket"
75
+ puts "Please enter a name for your new bucket using the -n flag"
76
+ puts "Example: sploder --create -n my_new_bucket"
76
77
  exit 1
77
78
  end
78
79
  name = opts[:name]
@@ -98,17 +99,17 @@ when opts[:website]
98
99
  key = settings.load_settings['key']
99
100
  secret = settings.load_settings['secret']
100
101
  bucket_name = opts[:name]
101
- index = ARGV[0]
102
- error = ARGV[1]
102
+ index_doc = ARGV[0]
103
+ error_doc = ARGV[1]
103
104
  if opts[:options]
104
- unless index && error
105
+ unless index_doc && error_doc
105
106
  puts "Please enter BOTH an index AND error page to enable hosting."
106
107
  puts "Example: sploder --website -n mybucket index.html error.html"
107
108
  exit 1
108
109
  end
109
110
  end
110
111
  website = Sploder::Bucket.new
111
- website.host_website(bucket_name, index, error, key, secret)
112
+ website.host_website(bucket_name, index_doc, error_doc, key, secret)
112
113
  when opts[:nohost]
113
114
  settings.settings_exist # Make sure settings are set
114
115
  key = settings.load_settings['key']
@@ -116,14 +117,30 @@ when opts[:nohost]
116
117
  bucket_name = opts[:name]
117
118
  disable = Sploder::Bucket.new
118
119
  disable.end_hosting(bucket_name, index, error, key, secret)
120
+ when opts[:file]
121
+ settings.settings_exist # Make sure Sploder is set up
122
+ key = settings.load_settings['key']
123
+ secret = settings.load_settings['secret']
124
+ bucket_name = ARGV[0]
125
+ file = ARGV[1]
126
+ operation = ARGV[2]
127
+ unless operation.nil?
128
+ if operation == 'download'
129
+ download = Sploder::Object.new
130
+ download.download_file(bucket_name, file, key, secret)
131
+ elsif operation == 'delete'
132
+ delete = Sploder::Object.new
133
+ delete.delete_file(bucket_name, file, key, secret)
134
+ end
135
+ exit 0
136
+ end
137
+ url = Sploder::Object.new
138
+ url.get_url(bucket_name, file, key, secret)
119
139
  else
120
140
  puts "USAGE:"
121
- puts "Run setup and enter your AWS credentials before using:"
122
- puts " sploder --setup OR sploder -s"
123
- puts " "
124
- puts "Upload a file:"
125
- puts " sploder --upload <BUCKET_NAME> <FILE> (Optional: -p <PATH> -a <ACL_POLICY>)"
126
- puts " "
127
- puts "List available buckets:"
128
- puts " sploder --list"
141
+ puts "Available flags: --list, --upload, --create, --delete , --setup, --explore"
142
+ puts ""
143
+ puts "Full documentation:"
144
+ puts "http://sploder.cleverlabs.info"
145
+ puts "or run `sploder -h`"
129
146
  end
@@ -2,3 +2,4 @@ require "sploder/upload"
2
2
  require "sploder/setup"
3
3
  require "sploder/list"
4
4
  require "sploder/bucket"
5
+ require "sploder/object"
@@ -20,7 +20,7 @@ module Sploder
20
20
  end
21
21
 
22
22
  # The following methods do nothing. They will in the future.
23
- def host_website (bucket_name, index, error, key, secret)
23
+ def host_website (bucket_name, index_doc, error_doc, key, secret)
24
24
  s3 = AWS::S3.new(
25
25
  :access_key_id => key,
26
26
  :secret_access_key => secret)
@@ -28,18 +28,25 @@ module Sploder
28
28
  # Get the bucket
29
29
  bucket = s3.buckets[bucket_name]
30
30
 
31
+ unless bucket.exists?
32
+ puts "Looks like that bucket does not exist in your account."
33
+ puts "Would you like to create it?"
34
+ puts "Just run 'sploder --create -n #{bucket_name}'"
35
+ exit 1
36
+ end
37
+
31
38
  # Set default index and error documents
32
- unless index
33
- index = "index.html"
39
+ unless index_doc
40
+ index_doc = 'index.html'
34
41
  end
35
42
 
36
- unless error
37
- error = "error.html"
43
+ unless error_doc
44
+ error_doc = 'error.html'
38
45
  end
39
46
 
40
47
  bucket.configure_website do |cfg|
41
- cfg.index_document_suffix = index
42
- cfg.error_document_key = error
48
+ cfg.index_document_suffix = index_doc
49
+ cfg.error_document_key = error_doc
43
50
  end
44
51
 
45
52
  puts "All set! #{bucket_name} is now configured as a web host"
@@ -19,6 +19,13 @@ module Sploder
19
19
  # Access the specified bucket
20
20
  bucket = s3.buckets[bucket_name]
21
21
 
22
+ unless bucket.exists?
23
+ puts "Looks like that bucket does not exist in your account."
24
+ puts "Would you like to create it?"
25
+ puts "Just run 'sploder --create -n #{bucket_name}'"
26
+ exit 1
27
+ end
28
+
22
29
  if prefix.nil?
23
30
  bucket.objects.each do |obj|
24
31
  puts obj.key
@@ -0,0 +1,34 @@
1
+ require 'aws-sdk'
2
+
3
+ module Sploder
4
+ class Object
5
+ def get_url (bucket_name, file, key, secret)
6
+ s3 = AWS::S3.new(
7
+ :access_key_id => key,
8
+ :secret_access_key => secret)
9
+
10
+ bucket = s3.buckets[bucket_name].objects[file]
11
+ puts "Your file's public url:"
12
+ puts bucket.public_url
13
+ end
14
+
15
+ def download_file (bucket_name, file, key, secret)
16
+ s3 = AWS::S3.new(
17
+ :access_key_id => key,
18
+ :secret_access_key => secret)
19
+
20
+ puts "Download function is not available in Sploder stable versions currently."
21
+ puts "You can download the latest edge version from http://sploder.cleverlabs.info"
22
+ end
23
+
24
+ def delete_file (bucket_name, file, key, secret)
25
+ s3 = AWS::S3.new(
26
+ :access_key_id => key,
27
+ :secret_access_key => secret)
28
+
29
+ bucket = s3.buckets[bucket_name].objects[file]
30
+ bucket.delete
31
+ puts "Deleted #{file} from #{bucket_name}"
32
+ end
33
+ end
34
+ end
@@ -3,7 +3,6 @@ require 'yaml'
3
3
  module Sploder
4
4
  class Setup
5
5
  def run (key, secret)
6
- puts "Setup class loaded?"
7
6
  file = File.expand_path('.sploder', '~')
8
7
  File.open(file, 'w') do |f|
9
8
  f.puts "key: #{key}\nsecret: #{secret}"
@@ -5,7 +5,8 @@ module Sploder
5
5
  class Upload
6
6
  def run (bucket, file, path, acl, key, secret)
7
7
  unless bucket && file
8
- puts "Usage: sploder <BUCKET_NAME> <FILE_NAME> | Optional: <S3_PATH> <ACL_POLICY>"
8
+ puts "You must at least enter a bucket name and relative or absolute path to the file to upload."
9
+ puts "USAGE: sploder --upload BUCKET_NAME FILE_NAME | Optional: -p S3_PATH -a ACL_POLICY"
9
10
  exit 1
10
11
  end
11
12
 
@@ -22,6 +23,13 @@ module Sploder
22
23
  :secret_access_key => secret)
23
24
 
24
25
  bucket = s3.buckets[bucket]
26
+ unless bucket.exists?
27
+ puts "Looks like that bucket does not exist in your account."
28
+ puts "Would you like to create it?"
29
+ puts "Just run 'sploder --create -n #{bucket}'"
30
+ exit 1
31
+ end
32
+
25
33
  basename = File.basename(file)
26
34
  upload = bucket.objects["#{path}#{basename}"]
27
35
  upload.write(:file => file, :acl => acl)
@@ -1,3 +1,3 @@
1
1
  module Sploder
2
- VERSION = "1.0.1"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sploder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-03 00:00:00.000000000 Z
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- description: Sploder is the S3 uploader
62
+ description: Sploder lets you work with S3 buckets from the command line
63
63
  email:
64
64
  - bill@billpatrianakos.me
65
65
  executables:
@@ -70,6 +70,7 @@ files:
70
70
  - bin/sploder
71
71
  - lib/sploder/bucket.rb
72
72
  - lib/sploder/list.rb
73
+ - lib/sploder/object.rb
73
74
  - lib/sploder/setup.rb
74
75
  - lib/sploder/upload.rb
75
76
  - lib/sploder/version.rb
@@ -94,8 +95,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  version: '0'
95
96
  requirements: []
96
97
  rubyforge_project:
97
- rubygems_version: 1.8.24
98
+ rubygems_version: 1.8.25
98
99
  signing_key:
99
100
  specification_version: 3
100
- summary: Easily upload files to S3, create buckets, set ACL, and more
101
+ summary: Easily upload files to S3, create buckets, delete them, see bucket contents,
102
+ set ACL, and more
101
103
  test_files: []