ftp_service 0.1.1

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Justin Blake
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ = FTP Service
2
+
3
+ An FTP Service is like a web service except stupid. You send your
4
+ request by uploading an xml file and get your response by downloading
5
+ another xml file. Have you ever had to deal with something like that? I
6
+ have.
7
+
8
+ == Installation
9
+
10
+ gem install ftp_service
11
+
12
+ == Usage
13
+
14
+ require 'ftp_service'
15
+
16
+ FtpService.open('host', 'user', 'pass') do |service|
17
+ path = '/the/remote/path'
18
+ service.write_request("#{path}/request.xml", '<foo>bar</foo>')
19
+ response = service.read_response("#{path}/response.xml")
20
+ end
21
+
22
+ * +read_response+ will block while it polls the server waiting for a
23
+ response.
24
+ * Temp files are created for the local request and response files and
25
+ deleted when no longer needed.
26
+
27
+ == Note on Patches/Pull Requests
28
+
29
+ * Fork the project.
30
+ * Make your feature addition or bug fix.
31
+ * Add tests for it. This is important so I don't break it in a
32
+ future version unintentionally.
33
+ * Commit, do not mess with rakefile, version, or history. (if you want
34
+ to have your own version, that is fine but bump version in a commit by
35
+ itself I can ignore when I pull)
36
+ * Send me a pull request. Bonus points for topic branches.
37
+
38
+ == Copyright
39
+
40
+ Copyright (c) 2010 Justin Blake. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ftp_service"
8
+ gem.summary = %Q{A class for dealing with the worst possible type of "web" service.}
9
+ gem.description = %Q{An FTP Service is like a web service except stupid. You send your request by uploading an xml file and get your response by downloading another xml file.}
10
+ gem.email = "justin@megablaix.com"
11
+ gem.homepage = "http://github.com/blaix/ftp_service"
12
+ gem.authors = ["Justin Blake"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "mocha", ">= 0.9.8"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "ftp_service #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ftp_service}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Justin Blake"]
12
+ s.date = %q{2010-03-05}
13
+ s.description = %q{An FTP Service is like a web service except stupid. You send your request by uploading an xml file and get your response by downloading another xml file.}
14
+ s.email = %q{justin@megablaix.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "ftp_service.gemspec",
27
+ "lib/ftp_service.rb",
28
+ "spec/ftp_service_spec.rb",
29
+ "spec/spec.opts",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/blaix/ftp_service}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.6}
36
+ s.summary = %q{A class for dealing with the worst possible type of "web" service.}
37
+ s.test_files = [
38
+ "spec/ftp_service_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
48
+ s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
49
+ else
50
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
55
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
56
+ end
57
+ end
58
+
@@ -0,0 +1,40 @@
1
+ require 'net/ftp'
2
+
3
+ # Class for dealing with a service that acts like a web service, except
4
+ # over FTP. Meaning an xml request is uploaded as a file, and the
5
+ # response xml is downloaded as another file.
6
+ class FtpService
7
+
8
+ # Open a connection to the FTP server and return an FtpService object.
9
+ # The object must be closed explicitely.
10
+ #
11
+ # ftp_service = FtpService.open(host, user, pass)
12
+ # ftp_service.write_request(path, request)
13
+ # response = ftp_service.read_response(path)
14
+ # ftp_service.close
15
+ def initialize(host, user, pass)
16
+ @ftp = Net::FTP.open(host, user, pass)
17
+ end
18
+
19
+ # Open a connection and pass an FtpService instance to the block. The
20
+ # instance will be closed when the block finishes, or when an
21
+ # exception is raised.
22
+ #
23
+ # FtpService.open(host, user, pass) do |ftp_service|
24
+ # ftp_service.write_request(path, request)
25
+ # response = ftp_service.read_response(path)
26
+ # end
27
+ def self.open(host, user, pass)
28
+ instance = new(host, user, pass)
29
+ begin
30
+ yield(instance)
31
+ ensure
32
+ instance.close
33
+ end
34
+ end
35
+
36
+ # Close the connection to the FTP server.
37
+ def close
38
+ @ftp.close
39
+ end
40
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "FtpService" do
4
+ before do
5
+ @ftp = stub_everything('ftp')
6
+ Net::FTP.stubs(:open).returns(@ftp)
7
+ end
8
+
9
+ describe '.new(host, user, pass)' do
10
+ it 'should connect to the requested ftp server' do
11
+ Net::FTP.expects(:open).with('host', 'user', 'pass').returns(@ftp)
12
+ FtpService.new('host', 'user', 'pass')
13
+ end
14
+
15
+ it 'should yield an instance of the ftp service' do
16
+ service = FtpService.new('host', 'user', 'pass')
17
+ service.should be_a(FtpService)
18
+ end
19
+ end
20
+
21
+ describe '.open(host, user, pass)' do
22
+ it 'should connect to the requested ftp server' do
23
+ Net::FTP.expects(:open).with('host', 'user', 'pass').returns(@ftp)
24
+ FtpService.open('host', 'user', 'pass') {}
25
+ end
26
+
27
+ it 'should yield an instance of the ftp service' do
28
+ service = nil
29
+ FtpService.open('host', 'user', 'pass') { |service| }
30
+ service.should be_a(FtpService)
31
+ end
32
+
33
+ it 'should automatically close the connection' do
34
+ @ftp.expects(:close)
35
+ FtpService.open('host', 'user', 'pass') {}
36
+ end
37
+
38
+ it 'should close the connection even if an exception is raised' do
39
+ @ftp.expects(:close)
40
+ lambda {
41
+ FtpService.open('host', 'user', 'pass') { raise "boom" }
42
+ }.should raise_error
43
+ end
44
+ end
45
+
46
+ describe '#close' do
47
+ it 'should close the connection to the ftp server' do
48
+ @ftp.expects(:close)
49
+ FtpService.new('host', 'user', 'pass').close
50
+ end
51
+ end
52
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'ftp_service'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+ config.mock_with :mocha
9
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ftp_service
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Justin Blake
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-05 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mocha
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 9
44
+ - 8
45
+ version: 0.9.8
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: An FTP Service is like a web service except stupid. You send your request by uploading an xml file and get your response by downloading another xml file.
49
+ email: justin@megablaix.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.rdoc
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - ftp_service.gemspec
65
+ - lib/ftp_service.rb
66
+ - spec/ftp_service_spec.rb
67
+ - spec/spec.opts
68
+ - spec/spec_helper.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/blaix/ftp_service
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: A class for dealing with the worst possible type of "web" service.
99
+ test_files:
100
+ - spec/ftp_service_spec.rb
101
+ - spec/spec_helper.rb