swift_file 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in swift_file.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Michael Del Tito
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # SwiftFile
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'swift_file'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install swift_file
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/swift_file ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require "optparse"
3
+ require "swift_file"
4
+ require "pp"
5
+
6
+ options = {}
7
+
8
+ optparse = OptionParser.new do|opts|
9
+ opts.banner = "Usage: swift_file [options] file"
10
+
11
+ options[:group] = nil
12
+ opts.on( '-g', '--group GROUP', 'Add this file to a group' ) do |group|
13
+ options[:group] = group
14
+ end
15
+
16
+ options[:password] = nil
17
+ opts.on( '-p', '--password PASS', 'Secure the file with a password' ) do |pass|
18
+ options[:password] = pass
19
+ end
20
+ end
21
+
22
+ optparse.parse!
23
+
24
+ begin
25
+
26
+ f = File.new(ARGV[0])
27
+
28
+ sf = SwiftFile::SwiftUpload.new({
29
+ :file => f,
30
+ :group => options[:group],
31
+ :password => options[:password]
32
+ })
33
+
34
+ sf.upload
35
+ puts sf.url
36
+ rescue Exception => e
37
+ puts "ERROR: #{e}"
38
+ end
@@ -0,0 +1,57 @@
1
+ require 'curb'
2
+
3
+ module SwiftFile
4
+ class SwiftUpload
5
+ @@swiftfile_host = "https://www.swiftfile.net"
6
+ @@swiftfile_endpoint = ""
7
+ @@swiftfile_cookie = "/tmp/swift_file.cookie"
8
+
9
+ attr_accessor :file, :group, :url
10
+
11
+ def initialize(params)
12
+ if File.readable?(params[:file]) && File.file?(params[:file])
13
+ @file = params[:file]
14
+ else
15
+ raise ArgumentError.new('Invalid file supplied for upload')
16
+ end
17
+
18
+ @group = params[:group] || ''
19
+ @password = params[:password] || ''
20
+ end
21
+
22
+
23
+ def upload
24
+ # start a session by requestion the url via GET
25
+ client.perform
26
+
27
+ # now post
28
+ client.multipart_form_post = true
29
+ client.http_post(
30
+ Curl::PostField.file('file1', "#{@file.path}"),
31
+ Curl::PostField.content('file_group[name]', @group),
32
+ Curl::PostField.content('file_group[password]', @password),
33
+ Curl::PostField.content('file_group_expiration', '1m')
34
+ )
35
+
36
+ @url = client.last_effective_url
37
+ @url
38
+ end
39
+
40
+ ##
41
+ private
42
+
43
+ def client
44
+ if !@client
45
+ url = "#{@@swiftfile_host}/#{@@swiftfile_endpoint}"
46
+ @client = Curl::Easy.new(url) do |curl|
47
+ # curl.verbose= true
48
+ curl.follow_location = true
49
+ curl.enable_cookies = true
50
+ curl.cookiejar = @@swiftfile_cookie
51
+ end
52
+ end
53
+
54
+ @client
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module SwiftFile
2
+ VERSION = "0.0.1"
3
+ end
data/lib/swift_file.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "swift_file/version"
2
+ require "swift_file/swift_upload"
3
+
4
+ module SwiftFile
5
+
6
+ class << self
7
+ attr_accessor :swift_file, :swift_file_group, :swift_file_password
8
+
9
+ def self.upload
10
+ sf = SwiftFile::SwiftUpload.new({
11
+ :file => @swift_file,
12
+ :group => @swift_file_group || nil,
13
+ :password => @swift_file_password || nil
14
+ })
15
+
16
+ sf.upload
17
+ sf.url
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,21 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'swift_file'
9
+ RSpec.configure do |config|
10
+
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
21
+
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe SwiftUpload do
4
+ it "should be able to upload test file" do
5
+ f = File.new(File.dirname(__FILE__) + '/test_file.txt', 'rb')
6
+ sf = SwiftFile::SwiftUpload.new({:file => f})
7
+
8
+ sf.upload
9
+ sf.url.should =~ /^https/
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ TESTING
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'swift_file/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "swift_file"
8
+ gem.version = SwiftFile::VERSION
9
+ gem.authors = ["Michael Del Tito"]
10
+ gem.email = ["mdeltito@contextllc.com"]
11
+ gem.description = %q{Upload a file to the SwiftFile service}
12
+ gem.summary = %q{Upload a file to the SwiftFile service}
13
+ gem.homepage = "http://contextllc.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_dependency("rest-client", ">= 1.6.7")
22
+ gem.add_dependency("curb", ">= 0.8.1")
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swift_file
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Del Tito
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.6.7
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: 1.6.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: curb
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ description: Upload a file to the SwiftFile service
63
+ email:
64
+ - mdeltito@contextllc.com
65
+ executables:
66
+ - swift_file
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/swift_file
77
+ - lib/swift_file.rb
78
+ - lib/swift_file/swift_upload.rb
79
+ - lib/swift_file/version.rb
80
+ - spec/spec_helper.rb
81
+ - spec/swift_file_spec.rb
82
+ - spec/test_file.txt
83
+ - swift_file.gemspec
84
+ homepage: http://contextllc.com
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.24
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Upload a file to the SwiftFile service
108
+ test_files:
109
+ - spec/spec_helper.rb
110
+ - spec/swift_file_spec.rb
111
+ - spec/test_file.txt