file_post_monster 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +16 -0
- data/README.rdoc +55 -0
- data/Rakefile +14 -0
- data/bin/post_file +7 -0
- data/features/post_file_cli.feature +71 -0
- data/features/step_definitions/cli_steps.rb +28 -0
- data/features/step_definitions/common_steps.rb +163 -0
- data/features/support/cli.rb +7 -0
- data/features/support/common.rb +29 -0
- data/features/support/env.rb +29 -0
- data/features/support/matchers.rb +11 -0
- data/file_post_monster.gemspec +35 -0
- data/lib/file_post_monster.rb +6 -0
- data/lib/post_file/cli.rb +48 -0
- data/tasks/rspec.rake +21 -0
- data/webservice/webservice.rb +34 -0
- data/webservice/webservice_control.rb +9 -0
- metadata +89 -0
data/Manifest
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Manifest
|
2
|
+
README.rdoc
|
3
|
+
Rakefile
|
4
|
+
bin/post_file
|
5
|
+
features/post_file_cli.feature
|
6
|
+
features/step_definitions/cli_steps.rb
|
7
|
+
features/step_definitions/common_steps.rb
|
8
|
+
features/support/cli.rb
|
9
|
+
features/support/common.rb
|
10
|
+
features/support/env.rb
|
11
|
+
features/support/matchers.rb
|
12
|
+
lib/file_post_monster.rb
|
13
|
+
lib/post_file/cli.rb
|
14
|
+
tasks/rspec.rake
|
15
|
+
webservice/webservice.rb
|
16
|
+
webservice/webservice_control.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= File! Post! MONSTER!
|
2
|
+
|
3
|
+
Uses an http post request to send a file to a url.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
gem install file_post_monster --source http://gemcutter.org
|
8
|
+
|
9
|
+
== Buy the ticket, take the ride
|
10
|
+
|
11
|
+
Well, this whole project has been hacked together pretty quickly, so at the mo it wont give you any feed back on success, and will just dump the default stack trace to the console on failure. Ill be working on this more in the coming weeks, so do stick around.
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
Use the post_file command from a shell...
|
16
|
+
|
17
|
+
$ post_file -f my_nice_file.txt -a http://monster/give_me_file
|
18
|
+
|
19
|
+
This will send the file 'my_nice_file.text' using an http POST to http://monster/give_me_file using the request parameter file.
|
20
|
+
|
21
|
+
Ohhh, here are some options...
|
22
|
+
|
23
|
+
-f, --file=PATH File to post (e.g. myfile.txt)
|
24
|
+
-a, --address=ADDRESS Address to post to (e.g. http://myfileservice.com/recieve)
|
25
|
+
-p, --param=PARAM_NAME Name of the parameter used for the file in the post request (e.g. file_param), DEFAULT => file
|
26
|
+
-l, --local_param=PARAM_NAME Name of a parameter used to post the exact local path with (e.g. local_file_path)
|
27
|
+
-n, --nesting=PARAM_NEST Parameter name you would like other parameters to be nested in
|
28
|
+
-h, --help Show this help message.
|
29
|
+
|
30
|
+
Thats it really!
|
31
|
+
|
32
|
+
Love Rob.
|
33
|
+
|
34
|
+
== License
|
35
|
+
|
36
|
+
Copyright (c) 2010 Robert Oles
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
39
|
+
a copy of this software and associated documentation files (the
|
40
|
+
"Software"), to deal in the Software without restriction, including
|
41
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
42
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
43
|
+
permit persons to whom the Software is furnished to do so, subject to
|
44
|
+
the following conditions:
|
45
|
+
|
46
|
+
The above copyright notice and this permission notice shall be
|
47
|
+
included in all copies or substantial portions of the Software.
|
48
|
+
|
49
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
52
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
53
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
54
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
55
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
6
|
+
|
7
|
+
Echoe.new('file_post_monster', '0.1.0') do |p|
|
8
|
+
p.description = "Monitors a directory for file changes then uses an http post request to send the file to a remote service"
|
9
|
+
p.url = "http://github.com/robertoles/file_post_monster"
|
10
|
+
p.author = "Robert Oles"
|
11
|
+
p.email = "robertoles@me.com"
|
12
|
+
p.ignore_pattern = ["tmp/*", "script/*", "spec/*"]
|
13
|
+
p.development_dependencies = ['rest-client']
|
14
|
+
end
|
data/bin/post_file
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
Feature: Can run "post_file" to send a file using an http post request to a url
|
2
|
+
As a anyone who needs to send a file over http
|
3
|
+
I want to send a file using a post request to a url
|
4
|
+
So that My webservice can pick it up and deal with it
|
5
|
+
|
6
|
+
Scenario: Run post_file without any arguments
|
7
|
+
When I run local executable "post_file" with arguments ""
|
8
|
+
Then I should see
|
9
|
+
"""
|
10
|
+
Usage: post_file -f file_name_to_post -a address_to_post_to [options]
|
11
|
+
|
12
|
+
-f, --file=PATH File to post (e.g. myfile.txt)
|
13
|
+
-a, --address=ADDRESS Address to post to (e.g. http://myfileservice.com/recieve)
|
14
|
+
-p, --param=PARAM_NAME Name of the parameter used for the file in the post request (e.g. file_param), DEFAULT => file
|
15
|
+
-l, --local_param=PARAM_NAME Name of a parameter used to post the exact local path with (e.g. local_file_path)
|
16
|
+
-n, --nesting=PARAM_NEST Parameter name you would like other parameters to be nested in
|
17
|
+
-h, --help Show this help message.
|
18
|
+
"""
|
19
|
+
|
20
|
+
Scenario: Run post_file with only file argument
|
21
|
+
When I run local executable "post_file" with arguments "-f some_file.txt"
|
22
|
+
Then I should see
|
23
|
+
"""
|
24
|
+
Usage: post_file -f file_name_to_post -a address_to_post_to [options]
|
25
|
+
|
26
|
+
-f, --file=PATH File to post (e.g. myfile.txt)
|
27
|
+
-a, --address=ADDRESS Address to post to (e.g. http://myfileservice.com/recieve)
|
28
|
+
-p, --param=PARAM_NAME Name of the parameter used for the file in the post request (e.g. file_param), DEFAULT => file
|
29
|
+
-l, --local_param=PARAM_NAME Name of a parameter used to post the exact local path with (e.g. local_file_path)
|
30
|
+
-n, --nesting=PARAM_NEST Parameter name you would like other parameters to be nested in
|
31
|
+
-h, --help Show this help message.
|
32
|
+
"""
|
33
|
+
|
34
|
+
Scenario: Run post_file with only address argument
|
35
|
+
When I run local executable "post_file" with arguments "-a some_address"
|
36
|
+
Then I should see
|
37
|
+
"""
|
38
|
+
Usage: post_file -f file_name_to_post -a address_to_post_to [options]
|
39
|
+
|
40
|
+
-f, --file=PATH File to post (e.g. myfile.txt)
|
41
|
+
-a, --address=ADDRESS Address to post to (e.g. http://myfileservice.com/recieve)
|
42
|
+
-p, --param=PARAM_NAME Name of the parameter used for the file in the post request (e.g. file_param), DEFAULT => file
|
43
|
+
-l, --local_param=PARAM_NAME Name of a parameter used to post the exact local path with (e.g. local_file_path)
|
44
|
+
-n, --nesting=PARAM_NEST Parameter name you would like other parameters to be nested in
|
45
|
+
-h, --help Show this help message.
|
46
|
+
"""
|
47
|
+
|
48
|
+
Scenario: Run post_file with file and address
|
49
|
+
Given this project is active project folder
|
50
|
+
Given a file exists "some_file.txt"
|
51
|
+
When I run local executable "post_file" with arguments "-f tmp/some_file.txt -a http://localhost:4567/just_file"
|
52
|
+
Then I should see webservice result "Received file some_file.txt"
|
53
|
+
|
54
|
+
Scenario: Run post_file with file, address and requiring local path include
|
55
|
+
Given this project is active project folder
|
56
|
+
Given a file exists "some_file.txt"
|
57
|
+
When I run local executable "post_file" with arguments "-f tmp/some_file.txt -a http://localhost:4567/file_and_path -l path"
|
58
|
+
Then I should see webservice result "Received file some_file.txt, with path"
|
59
|
+
And I should see webservice result "some_file.txt"
|
60
|
+
|
61
|
+
Scenario: Run post_file with file, address and a different file param name
|
62
|
+
Given this project is active project folder
|
63
|
+
Given a file exists "some_file.txt"
|
64
|
+
When I run local executable "post_file" with arguments "-f tmp/some_file.txt -a http://localhost:4567/file_with_diff_param -p diff_file"
|
65
|
+
Then I should see webservice result "Received diff file some_file.txt"
|
66
|
+
|
67
|
+
Scenario: Run post_file with file, address and a different nested params
|
68
|
+
Given this project is active project folder
|
69
|
+
Given a file exists "some_file.txt"
|
70
|
+
When I run local executable "post_file" with arguments "-f tmp/some_file.txt -a http://localhost:4567/file_with_nested_param -n nested"
|
71
|
+
Then I should see webservice result "Received nested file some_file.txt"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Given /^I start the webservice$/ do
|
2
|
+
in_project_folder do
|
3
|
+
system "ruby webservice/webservice_control.rb start"
|
4
|
+
end
|
5
|
+
sleep 1
|
6
|
+
end
|
7
|
+
|
8
|
+
Given /^I stop the webservice$/ do
|
9
|
+
in_project_folder do
|
10
|
+
system "ruby webservice/webservice_control.rb stop"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Given /^a file exists "([^\"]*)"$/ do |file_name|
|
15
|
+
in_tmp_folder do
|
16
|
+
File.open(file_name, "w" ) do |file|
|
17
|
+
file.puts "plop"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Then /^I should see webservice result "([^\"]*)"$/ do |text|
|
23
|
+
in_tmp_folder do
|
24
|
+
@web_out = File.expand_path("sinatra.out")
|
25
|
+
end
|
26
|
+
actual_output = File.read(@web_out)
|
27
|
+
actual_output.should contain(text)
|
28
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
Given /^this project is active project folder/ do
|
2
|
+
@active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^env variable \$([\w_]+) set to "(.*)"/ do |env_var, value|
|
6
|
+
ENV[env_var] = value
|
7
|
+
end
|
8
|
+
|
9
|
+
Given /"(.*)" folder is deleted/ do |folder|
|
10
|
+
in_project_folder { FileUtils.rm_rf folder }
|
11
|
+
end
|
12
|
+
|
13
|
+
When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
|
14
|
+
@stdout = StringIO.new
|
15
|
+
in_project_folder do
|
16
|
+
if Object.const_defined?("APP_ROOT")
|
17
|
+
APP_ROOT.replace(FileUtils.pwd)
|
18
|
+
else
|
19
|
+
APP_ROOT = FileUtils.pwd
|
20
|
+
end
|
21
|
+
run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
|
22
|
+
end
|
23
|
+
File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
|
24
|
+
@stdout.rewind
|
25
|
+
f << @stdout.read
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
|
30
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
31
|
+
in_project_folder do
|
32
|
+
system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
|
37
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
38
|
+
in_project_folder do
|
39
|
+
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
|
44
|
+
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
|
45
|
+
executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
|
46
|
+
in_project_folder do
|
47
|
+
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
When /^I invoke task "rake (.*)"/ do |task|
|
52
|
+
@stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
|
53
|
+
in_project_folder do
|
54
|
+
system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Then /^folder "(.*)" (is|is not) created/ do |folder, is|
|
59
|
+
in_project_folder do
|
60
|
+
File.exists?(folder).should(is == 'is' ? be_true : be_false)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Then /^file "(.*)" (is|is not) created/ do |file, is|
|
65
|
+
in_project_folder do
|
66
|
+
File.exists?(file).should(is == 'is' ? be_true : be_false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Then /^file with name matching "(.*)" is created/ do |pattern|
|
71
|
+
in_project_folder do
|
72
|
+
Dir[pattern].should_not be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
|
77
|
+
in_project_folder do
|
78
|
+
actual_output = File.read(file)
|
79
|
+
(does == 'does') ?
|
80
|
+
actual_output.should(match(/#{regex}/)) :
|
81
|
+
actual_output.should_not(match(/#{regex}/))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
|
86
|
+
File.exists?(gem_file).should be_true
|
87
|
+
File.exists?(project_file).should be_true
|
88
|
+
gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
|
89
|
+
project_file_contents = File.read(File.join(@active_project_folder, project_file))
|
90
|
+
project_file_contents.should == gem_file_contents
|
91
|
+
end
|
92
|
+
|
93
|
+
Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
|
94
|
+
actual_output = File.read(@stdout)
|
95
|
+
does_invoke == "does" ?
|
96
|
+
actual_output.should(match(/dependency\s+#{generator}/)) :
|
97
|
+
actual_output.should_not(match(/dependency\s+#{generator}/))
|
98
|
+
end
|
99
|
+
|
100
|
+
Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
|
101
|
+
actual_output = File.read(@stdout)
|
102
|
+
actual_output.should match(/#{opt1}/)
|
103
|
+
actual_output.should match(/#{opt2}/)
|
104
|
+
end
|
105
|
+
|
106
|
+
Then /^I should see$/ do |text|
|
107
|
+
actual_output = File.read(@stdout)
|
108
|
+
actual_output.should contain(text)
|
109
|
+
end
|
110
|
+
|
111
|
+
Then /^I should not see$/ do |text|
|
112
|
+
actual_output = File.read(@stdout)
|
113
|
+
actual_output.should_not contain(text)
|
114
|
+
end
|
115
|
+
|
116
|
+
Then /^I should see exactly$/ do |text|
|
117
|
+
actual_output = File.read(@stdout)
|
118
|
+
actual_output.should == text
|
119
|
+
end
|
120
|
+
|
121
|
+
Then /^I should see all (\d+) tests pass/ do |expected_test_count|
|
122
|
+
expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
|
123
|
+
actual_output = File.read(@stdout)
|
124
|
+
actual_output.should match(expected)
|
125
|
+
end
|
126
|
+
|
127
|
+
Then /^I should see all (\d+) examples pass/ do |expected_test_count|
|
128
|
+
expected = %r{^#{expected_test_count} examples?, 0 failures}
|
129
|
+
actual_output = File.read(@stdout)
|
130
|
+
actual_output.should match(expected)
|
131
|
+
end
|
132
|
+
|
133
|
+
Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
|
134
|
+
in_project_folder do
|
135
|
+
yaml = eval yaml
|
136
|
+
YAML.load(File.read(file)).should == yaml
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
Then /^Rakefile can display tasks successfully/ do
|
141
|
+
@stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
|
142
|
+
in_project_folder do
|
143
|
+
system "rake -T > #{@stdout} 2> #{@stdout}"
|
144
|
+
end
|
145
|
+
actual_output = File.read(@stdout)
|
146
|
+
actual_output.should match(/^rake\s+\w+\s+#\s.*/)
|
147
|
+
end
|
148
|
+
|
149
|
+
Then /^task "rake (.*)" is executed successfully/ do |task|
|
150
|
+
@stdout.should_not be_nil
|
151
|
+
actual_output = File.read(@stdout)
|
152
|
+
actual_output.should_not match(/^Don't know how to build task '#{task}'/)
|
153
|
+
actual_output.should_not match(/Error/i)
|
154
|
+
end
|
155
|
+
|
156
|
+
Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
|
157
|
+
in_project_folder do
|
158
|
+
gem_file = Dir["pkg/*.gem"].first
|
159
|
+
gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
|
160
|
+
spec_value = gem_spec.send(key.to_sym)
|
161
|
+
spec_value.to_s.should match(/#{regex}/)
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CommonHelpers
|
2
|
+
def in_tmp_folder(&block)
|
3
|
+
FileUtils.chdir(@tmp_root, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def in_project_folder(&block)
|
7
|
+
project_folder = @active_project_folder || @tmp_root
|
8
|
+
FileUtils.chdir(project_folder, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def in_home_folder(&block)
|
12
|
+
FileUtils.chdir(@home_path, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def force_local_lib_override(project_name = @project_name)
|
16
|
+
rakefile = File.read(File.join(project_name, 'Rakefile'))
|
17
|
+
File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
|
18
|
+
f << "$:.unshift('#{@lib_path}')\n"
|
19
|
+
f << rakefile
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_active_project_folder project_name
|
24
|
+
@active_project_folder = File.join(@tmp_root, project_name)
|
25
|
+
@project_name = project_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
World(CommonHelpers)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../lib/file_post_monster"
|
2
|
+
|
3
|
+
gem 'cucumber'
|
4
|
+
require 'cucumber'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
|
8
|
+
FileUtils.chdir(File.expand_path(File.dirname(__FILE__) + "/../..")) do
|
9
|
+
system "ruby webservice/webservice_control.rb start"
|
10
|
+
sleep 1
|
11
|
+
end
|
12
|
+
|
13
|
+
Before do
|
14
|
+
@tmp_root = File.dirname(__FILE__) + "/../../tmp"
|
15
|
+
@home_path = File.expand_path(File.join(@tmp_root, "home"))
|
16
|
+
FileUtils.rm_rf @tmp_root
|
17
|
+
FileUtils.mkdir_p @home_path
|
18
|
+
ENV['HOME'] = @home_path
|
19
|
+
end
|
20
|
+
|
21
|
+
require File.dirname(__FILE__) + '/../../webservice/webservice'
|
22
|
+
|
23
|
+
at_exit do
|
24
|
+
FileUtils.chdir(File.expand_path(File.dirname(__FILE__) + "/../..")) do
|
25
|
+
system "ruby webservice/webservice_control.rb stop"
|
26
|
+
File.delete('tmp/executable.out')
|
27
|
+
File.delete('tmp/sinatra.out')
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Matchers
|
2
|
+
def contain(expected)
|
3
|
+
simple_matcher("contain #{expected.inspect}") do |given, matcher|
|
4
|
+
matcher.failure_message = "expected #{given.inspect} to contain #{expected.inspect}"
|
5
|
+
matcher.negative_failure_message = "expected #{given.inspect} not to contain #{expected.inspect}"
|
6
|
+
given.index expected
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
World(Matchers)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{file_post_monster}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Robert Oles"]
|
9
|
+
s.date = %q{2010-02-09}
|
10
|
+
s.default_executable = %q{post_file}
|
11
|
+
s.description = %q{Monitors a directory for file changes then uses an http post request to send the file to a remote service}
|
12
|
+
s.email = %q{robertoles@me.com}
|
13
|
+
s.executables = ["post_file"]
|
14
|
+
s.extra_rdoc_files = ["README.rdoc", "bin/post_file", "lib/file_post_monster.rb", "lib/post_file/cli.rb", "tasks/rspec.rake"]
|
15
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "bin/post_file", "features/post_file_cli.feature", "features/step_definitions/cli_steps.rb", "features/step_definitions/common_steps.rb", "features/support/cli.rb", "features/support/common.rb", "features/support/env.rb", "features/support/matchers.rb", "lib/file_post_monster.rb", "lib/post_file/cli.rb", "tasks/rspec.rake", "webservice/webservice.rb", "webservice/webservice_control.rb", "file_post_monster.gemspec"]
|
16
|
+
s.homepage = %q{http://github.com/robertoles/file_post_monster}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "File_post_monster", "--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{file_post_monster}
|
20
|
+
s.rubygems_version = %q{1.3.5}
|
21
|
+
s.summary = %q{Monitors a directory for file changes then uses an http post request to send the file to a remote service}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_development_dependency(%q<rest-client>, [">= 0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'rest_client'
|
3
|
+
|
4
|
+
module FilePostMonster
|
5
|
+
class CLI
|
6
|
+
def self.execute(stdout, arguments=[])
|
7
|
+
options = {
|
8
|
+
:file_param => 'file'
|
9
|
+
}
|
10
|
+
mandatory_options = %w( file address )
|
11
|
+
|
12
|
+
parser = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: post_file -f file_name_to_post -a address_to_post_to [options]"
|
14
|
+
opts.separator ""
|
15
|
+
opts.on("-f", "--file=PATH", String, "File to post (e.g. myfile.txt)") { |arg| options[:file] = arg }
|
16
|
+
opts.on("-a", "--address=ADDRESS", String, "Address to post to (e.g. http://myfileservice.com/recieve)") do |arg|
|
17
|
+
options[:address] = arg
|
18
|
+
end
|
19
|
+
opts.on("-p", "--param=PARAM_NAME", String, "Name of the parameter used for the file in the post request (e.g. file_param), DEFAULT => file") do |arg|
|
20
|
+
options[:file_param] = arg
|
21
|
+
end
|
22
|
+
opts.on("-l", "--local_param=PARAM_NAME", String, "Name of a parameter used to post the exact local path with (e.g. local_file_path)") do |arg|
|
23
|
+
options[:path_param] = arg
|
24
|
+
end
|
25
|
+
opts.on("-n", "--nesting=PARAM_NEST", String, "Parameter name you would like other parameters to be nested in") do |arg|
|
26
|
+
options[:nesting] = arg
|
27
|
+
end
|
28
|
+
opts.on("-h", "--help",
|
29
|
+
"Show this help message.") { stdout.puts opts; exit }
|
30
|
+
opts.parse!(arguments)
|
31
|
+
|
32
|
+
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
33
|
+
stdout.puts opts; exit
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
post(options)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def self.post(options)
|
42
|
+
params = {options[:file_param] => File.new(options[:file])}
|
43
|
+
params[options[:path_param]] = File.expand_path(options[:file]) if options[:path_param]
|
44
|
+
params = {options[:nesting] => params} if options[:nesting]
|
45
|
+
RestClient.post options[:address], params
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ["-c"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
post '/just_file' do
|
5
|
+
FileUtils.chdir(File.dirname(__FILE__) + "/../tmp") do
|
6
|
+
File.open('sinatra.out', "w" ) do |file|
|
7
|
+
file.puts "Received file #{params[:file][:filename]}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
post '/file_and_path' do
|
13
|
+
FileUtils.chdir(File.dirname(__FILE__) + "/../tmp") do
|
14
|
+
File.open('sinatra.out', "w" ) do |file|
|
15
|
+
file.puts "Received file #{params[:file][:filename]}, with path #{params[:path]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
post '/file_with_diff_param' do
|
21
|
+
FileUtils.chdir(File.dirname(__FILE__) + "/../tmp") do
|
22
|
+
File.open('sinatra.out', "w" ) do |file|
|
23
|
+
file.puts "Received diff file #{params[:diff_file][:filename]}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
post '/file_with_nested_param' do
|
29
|
+
FileUtils.chdir(File.dirname(__FILE__) + "/../tmp") do
|
30
|
+
File.open('sinatra.out', "w" ) do |file|
|
31
|
+
file.puts "Received nested file #{params[:nested][:file][:filename]}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: file_post_monster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Oles
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-09 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Monitors a directory for file changes then uses an http post request to send the file to a remote service
|
26
|
+
email: robertoles@me.com
|
27
|
+
executables:
|
28
|
+
- post_file
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- bin/post_file
|
34
|
+
- lib/file_post_monster.rb
|
35
|
+
- lib/post_file/cli.rb
|
36
|
+
- tasks/rspec.rake
|
37
|
+
files:
|
38
|
+
- Manifest
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- bin/post_file
|
42
|
+
- features/post_file_cli.feature
|
43
|
+
- features/step_definitions/cli_steps.rb
|
44
|
+
- features/step_definitions/common_steps.rb
|
45
|
+
- features/support/cli.rb
|
46
|
+
- features/support/common.rb
|
47
|
+
- features/support/env.rb
|
48
|
+
- features/support/matchers.rb
|
49
|
+
- lib/file_post_monster.rb
|
50
|
+
- lib/post_file/cli.rb
|
51
|
+
- tasks/rspec.rake
|
52
|
+
- webservice/webservice.rb
|
53
|
+
- webservice/webservice_control.rb
|
54
|
+
- file_post_monster.gemspec
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/robertoles/file_post_monster
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --line-numbers
|
62
|
+
- --inline-source
|
63
|
+
- --title
|
64
|
+
- File_post_monster
|
65
|
+
- --main
|
66
|
+
- README.rdoc
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "1.2"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: file_post_monster
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Monitors a directory for file changes then uses an http post request to send the file to a remote service
|
88
|
+
test_files: []
|
89
|
+
|