s3itch_client 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.2.0
4
+
5
+ * Adds filename parameterization support
6
+
7
+ ## 1.1.0
8
+
9
+ * Adds HTTPS support (without certificate validation)
10
+
11
+ ## 1.0.1
12
+
13
+ * URI encoding for filenames
14
+ * Doumentation updates
15
+
16
+ ## 1.0.0
17
+
18
+ * Initial release
data/README.md CHANGED
@@ -18,6 +18,7 @@ For your own convenience, create the `~/.s3itch.yml` file with the following con
18
18
  url: http://YOUR-S3ITCH-INSTANCE.herokuapp.com
19
19
  username: S3ITCH_USERNAME
20
20
  password: YOUR_PASSWORD
21
+ parameterize: true
21
22
 
22
23
  ## Usage
23
24
 
@@ -1,5 +1,6 @@
1
1
  require "s3itch_client/version"
2
2
 
3
+ require "i18n"
3
4
  require "net/http"
4
5
  require "securerandom"
5
6
  require "uri"
@@ -19,7 +20,7 @@ module S3itchClient
19
20
  password = options[:password]
20
21
 
21
22
  if File.exists?(filepath) && !File.directory?(filepath)
22
- uniq_name = build_unique_name(filepath)
23
+ uniq_name = build_unique_name(filepath, options[:parameterize])
23
24
 
24
25
  uri.path = "/#{uniq_name}"
25
26
 
@@ -48,7 +49,7 @@ module S3itchClient
48
49
  end
49
50
  end
50
51
 
51
- def self.build_unique_name(filepath)
52
+ def self.build_unique_name(filepath, to_param=false)
52
53
  filename = File.basename(filepath)
53
54
  extname = File.extname(filename)
54
55
  basename = File.basename(filename, extname)
@@ -56,7 +57,10 @@ module S3itchClient
56
57
  # Ruby 1.8.7 compatibility
57
58
  uuid = SecureRandom.respond_to?(:uuid) ? SecureRandom.uuid : SecureRandom.hex
58
59
 
59
- URI.encode("#{basename}_#{uuid}#{extname}")
60
+ uniq_name = "#{basename}_#{uuid}#{extname}"
61
+ uniq_name = parameterize(uniq_name) if to_param
62
+
63
+ URI.encode(uniq_name)
60
64
  end
61
65
 
62
66
  def self.indifferent_hash(hash)
@@ -64,4 +68,21 @@ module S3itchClient
64
68
  indifferent.merge(hash)
65
69
  end
66
70
 
71
+ def self.parameterize(string)
72
+ parameterized_string = I18n.transliterate(string, :replacement => "-", :locale => :en)
73
+
74
+ # Turn unwanted chars into the separator
75
+ parameterized_string.gsub!(/[^a-z0-9\-_]+/i, "-")
76
+
77
+ re_sep = Regexp.escape("-")
78
+
79
+ # No more than one of the separator in a row.
80
+ parameterized_string.gsub!(/#{re_sep}{2,}/, "-")
81
+
82
+ # Remove leading/trailing separator.
83
+ parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
84
+
85
+ parameterized_string
86
+ end
87
+
67
88
  end
@@ -29,6 +29,10 @@ module S3itchClient
29
29
  options["password"] = password
30
30
  end
31
31
 
32
+ opts.on("-e", "--[no-]parameterize", "Parameterize the filename") do |parameterize|
33
+ options["parameterize"] = parameterize
34
+ end
35
+
32
36
  opts.on_tail("-h", "--help", "Show this message") do
33
37
  puts opts
34
38
  exit
@@ -1,3 +1,3 @@
1
1
  module S3itchClient
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -12,6 +12,8 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = %q{Upload files to S3 via your own s3itch instance}
13
13
  gem.homepage = "https://github.com/k33l0r/s3itch_client"
14
14
 
15
+ gem.add_dependency "i18n", ">= 0.6.1"
16
+
15
17
  gem.add_development_dependency "bundler"
16
18
  gem.add_development_dependency "rake"
17
19
  gem.add_development_dependency "rspec", "~> 2.11.0"
@@ -37,6 +37,29 @@ describe S3itchClient do
37
37
  name = S3itchClient.build_unique_name("/tmp/cute kitten.jpeg")
38
38
  name.should match(/\Acute%20kitten_[\da-z-]{32,36}\.jpeg\z/)
39
39
  end
40
+
41
+ it "parameterizes the name if required to" do
42
+ S3itchClient.should_receive(:parameterize).with(/\Akitten/).and_return do |argument|
43
+ argument
44
+ end
45
+ S3itchClient.build_unique_name("kitten", true)
46
+ end
47
+ end
48
+
49
+ describe ".parameterize" do
50
+ it "transliterates non-ASCII characters" do
51
+ utf8 = "Ä-Ö-Ü-Å-Æ-and-Ø"
52
+ ascii = S3itchClient.parameterize(utf8)
53
+ ascii.should == "A-O-U-A-AE-and-O"
54
+ end
55
+
56
+ it "converts spaces to hyphens" do
57
+ S3itchClient.parameterize("This and that").should == "This-and-that"
58
+ end
59
+
60
+ it "removes 'unwanted' characters" do
61
+ S3itchClient.parameterize("Unwanted?!€Characters").should == "Unwanted-Characters"
62
+ end
40
63
  end
41
64
 
42
65
  describe ".upload" do
metadata CHANGED
@@ -1,96 +1,112 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3itch_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matias Korhonen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-02 00:00:00.000000000 Z
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bundler
16
- version_requirements: !ruby/object:Gem::Requirement
15
+ name: i18n
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
17
18
  requirements:
18
19
  - - ! '>='
19
20
  - !ruby/object:Gem::Version
20
- version: '0'
21
+ version: 0.6.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
21
25
  none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.6.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
22
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
23
34
  requirements:
24
35
  - - ! '>='
25
36
  - !ruby/object:Gem::Version
26
37
  version: '0'
27
- none: false
28
- prerelease: false
29
38
  type: :development
30
- - !ruby/object:Gem::Dependency
31
- name: rake
39
+ prerelease: false
32
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
33
42
  requirements:
34
43
  - - ! '>='
35
44
  - !ruby/object:Gem::Version
36
45
  version: '0'
37
- none: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
38
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
39
50
  requirements:
40
51
  - - ! '>='
41
52
  - !ruby/object:Gem::Version
42
53
  version: '0'
43
- none: false
44
- prerelease: false
45
54
  type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rspec
48
- version_requirements: !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
49
66
  requirements:
50
67
  - - ~>
51
68
  - !ruby/object:Gem::Version
52
69
  version: 2.11.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
53
73
  none: false
54
- requirement: !ruby/object:Gem::Requirement
55
74
  requirements:
56
75
  - - ~>
57
76
  - !ruby/object:Gem::Version
58
77
  version: 2.11.0
59
- none: false
60
- prerelease: false
61
- type: :development
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: webmock
64
- version_requirements: !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
65
82
  requirements:
66
83
  - - ~>
67
84
  - !ruby/object:Gem::Version
68
85
  version: 1.8.11
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
69
89
  none: false
70
- requirement: !ruby/object:Gem::Requirement
71
90
  requirements:
72
91
  - - ~>
73
92
  - !ruby/object:Gem::Version
74
93
  version: 1.8.11
75
- none: false
76
- prerelease: false
77
- type: :development
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: simplecov
80
- version_requirements: !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
81
98
  requirements:
82
99
  - - ~>
83
100
  - !ruby/object:Gem::Version
84
101
  version: 0.6.4
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
85
105
  none: false
86
- requirement: !ruby/object:Gem::Requirement
87
106
  requirements:
88
107
  - - ~>
89
108
  - !ruby/object:Gem::Version
90
109
  version: 0.6.4
91
- none: false
92
- prerelease: false
93
- type: :development
94
110
  description: Send files to s3itch from the command line
95
111
  email:
96
112
  - me@matiaskorhonen.fi
@@ -102,6 +118,7 @@ files:
102
118
  - .gitignore
103
119
  - .rspec
104
120
  - .travis.yml
121
+ - CHANGELOG.md
105
122
  - CONTRIBUTING.md
106
123
  - Gemfile
107
124
  - LICENSE.txt
@@ -117,36 +134,35 @@ files:
117
134
  - spec/support/kitten.jpeg
118
135
  homepage: https://github.com/k33l0r/s3itch_client
119
136
  licenses: []
120
- post_install_message:
137
+ post_install_message:
121
138
  rdoc_options: []
122
139
  require_paths:
123
140
  - lib
124
141
  required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
125
143
  requirements:
126
144
  - - ! '>='
127
145
  - !ruby/object:Gem::Version
146
+ version: '0'
128
147
  segments:
129
148
  - 0
130
- version: '0'
131
- hash: 2
132
- none: false
149
+ hash: 3180291602005236204
133
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
134
152
  requirements:
135
153
  - - ! '>='
136
154
  - !ruby/object:Gem::Version
155
+ version: '0'
137
156
  segments:
138
157
  - 0
139
- version: '0'
140
- hash: 2
141
- none: false
158
+ hash: 3180291602005236204
142
159
  requirements: []
143
- rubyforge_project:
160
+ rubyforge_project:
144
161
  rubygems_version: 1.8.24
145
- signing_key:
162
+ signing_key:
146
163
  specification_version: 3
147
164
  summary: Upload files to S3 via your own s3itch instance
148
165
  test_files:
149
166
  - spec/s3itch_client_spec.rb
150
167
  - spec/spec_helper.rb
151
168
  - spec/support/kitten.jpeg
152
- ...