tarpipe 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +31 -0
- data/License.txt +15 -0
- data/Manifest.txt +26 -0
- data/README.txt +55 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +74 -0
- data/config/requirements.rb +15 -0
- data/lib/tarpipe.rb +113 -0
- data/lib/tarpipe/version.rb +9 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/tarpipe_spec.rb +69 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +124 -0
- data/website/index.txt +56 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +101 -0
data/History.txt
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
== 0.1.1 2008-05-20
|
2
|
+
|
3
|
+
* Docs change
|
4
|
+
* Tiago Pinto email had a typo
|
5
|
+
|
6
|
+
== 0.1.0 2008-05-20
|
7
|
+
|
8
|
+
* API changes
|
9
|
+
* The #upload method now accepts an hash with the options
|
10
|
+
* It allows to more API stability in the future
|
11
|
+
* Update docs to match the new API
|
12
|
+
|
13
|
+
== 0.0.4 2008-05-20
|
14
|
+
|
15
|
+
* Yet another doc update
|
16
|
+
|
17
|
+
== 0.0.3 2008-05-20
|
18
|
+
|
19
|
+
* Docs update:
|
20
|
+
* Git repository URL was wrong
|
21
|
+
|
22
|
+
== 0.0.2 2008-05-19
|
23
|
+
|
24
|
+
* Small adjustments:
|
25
|
+
* endpoints are now acessors
|
26
|
+
* the TarPipe#upload now returns a boolean to indicate success or failure
|
27
|
+
|
28
|
+
== 0.0.1 2008-05-18
|
29
|
+
|
30
|
+
* Initial release:
|
31
|
+
* Behaviour very similar to the Python API (by Alcides Fonseca)
|
data/License.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Copyright (c) 2008 Ruben Fonseca
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
This program is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/tarpipe.rb
|
9
|
+
lib/tarpipe/version.rb
|
10
|
+
script/console
|
11
|
+
script/destroy
|
12
|
+
script/generate
|
13
|
+
script/txt2html
|
14
|
+
setup.rb
|
15
|
+
spec/spec.opts
|
16
|
+
spec/spec_helper.rb
|
17
|
+
spec/tarpipe_spec.rb
|
18
|
+
tasks/deployment.rake
|
19
|
+
tasks/environment.rake
|
20
|
+
tasks/rspec.rake
|
21
|
+
tasks/website.rake
|
22
|
+
website/index.html
|
23
|
+
website/index.txt
|
24
|
+
website/javascripts/rounded_corners_lite.inc.js
|
25
|
+
website/stylesheets/screen.css
|
26
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= tarpipe
|
2
|
+
|
3
|
+
* http://tarpipe.rubyforge.org
|
4
|
+
|
5
|
+
== AUTHORS:
|
6
|
+
|
7
|
+
* Ruben Fonseca <root (at) cpan (dot) org>
|
8
|
+
* Tiago Pinto <tpinto (at) webreakstuff (dot) com>
|
9
|
+
|
10
|
+
== DESCRIPTION:
|
11
|
+
|
12
|
+
TarPipe - Ruby bridge to tarpipe.com's REST API
|
13
|
+
|
14
|
+
== FEATURES:
|
15
|
+
|
16
|
+
tarpipe is a publishing mediation and distribution platform that simplifies regular upload activities:
|
17
|
+
|
18
|
+
* Publishing content to multiple Web locations;
|
19
|
+
* Combining different media into a single blog post or article;
|
20
|
+
* Transforming documents on-the-fly;
|
21
|
+
* Managing repeatable upload actions.
|
22
|
+
|
23
|
+
== SYNOPSIS:
|
24
|
+
|
25
|
+
require 'tarpipe'
|
26
|
+
t = TarPipe.new('workflow token')
|
27
|
+
t.upload(:title => 'title', :body => 'body', :image => 'path/to/image')
|
28
|
+
# Returns true or false
|
29
|
+
|
30
|
+
== REQUIREMENTS:
|
31
|
+
|
32
|
+
* rspec >= 1.1.3
|
33
|
+
* shared-mime-info >= 0.1
|
34
|
+
|
35
|
+
== INSTALL:
|
36
|
+
|
37
|
+
* sudo gem install tarpipe
|
38
|
+
|
39
|
+
== LICENSE:
|
40
|
+
|
41
|
+
Copyright (c) 2008 Ruben Fonseca
|
42
|
+
|
43
|
+
This program is free software: you can redistribute it and/or modify
|
44
|
+
it under the terms of the GNU General Public License as published by
|
45
|
+
the Free Software Foundation, either version 3 of the License, or
|
46
|
+
(at your option) any later version.
|
47
|
+
|
48
|
+
This program is distributed in the hope that it will be useful,
|
49
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
50
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
51
|
+
GNU General Public License for more details.
|
52
|
+
|
53
|
+
You should have received a copy of the GNU General Public License
|
54
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
55
|
+
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'tarpipe/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Ruben Fonseca'
|
4
|
+
EMAIL = "root@cpan.org"
|
5
|
+
DESCRIPTION = "Ruby bindings to the tarpipe.com API"
|
6
|
+
GEM_NAME = 'tarpipe'
|
7
|
+
RUBYFORGE_PROJECT = 'tarpipe'
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
['rspec', '>=1.1.3'],
|
12
|
+
['shared-mime-info', '>=0.1']
|
13
|
+
]
|
14
|
+
|
15
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
16
|
+
@config = nil
|
17
|
+
RUBYFORGE_USERNAME = "rubenfonseca"
|
18
|
+
def rubyforge_username
|
19
|
+
unless @config
|
20
|
+
begin
|
21
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
22
|
+
rescue
|
23
|
+
puts <<-EOS
|
24
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
25
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
26
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
27
|
+
EOS
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
REV = nil
|
36
|
+
# UNCOMMENT IF REQUIRED:
|
37
|
+
# REV = YAML.load(`svn info`)['Revision']
|
38
|
+
VERS = Tarpipe::VERSION::STRING + (REV ? ".#{REV}" : "")
|
39
|
+
RDOC_OPTS = ['--quiet', '--title', 'tarpipe documentation',
|
40
|
+
"--opname", "index.html",
|
41
|
+
"--line-numbers",
|
42
|
+
"--main", "README",
|
43
|
+
"--inline-source"]
|
44
|
+
|
45
|
+
class Hoe
|
46
|
+
def extra_deps
|
47
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
48
|
+
@extra_deps
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Generate all the Rake tasks
|
53
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
54
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
55
|
+
p.developer(AUTHOR, EMAIL)
|
56
|
+
p.description = DESCRIPTION
|
57
|
+
p.summary = DESCRIPTION
|
58
|
+
p.url = HOMEPATH
|
59
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
60
|
+
p.test_globs = ["test/**/test_*.rb"]
|
61
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
62
|
+
|
63
|
+
# == Optional
|
64
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
65
|
+
p.extra_deps = EXTRA_DEPENDENCIES
|
66
|
+
|
67
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
68
|
+
end
|
69
|
+
|
70
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
71
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
72
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
73
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
74
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/lib/tarpipe.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'shared-mime-info'
|
6
|
+
require 'net/http'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
# TarPipe is a bridge to the tarpipe.com's REST API
|
10
|
+
#
|
11
|
+
# Author:: Ruben Fonseca (mailto:root@cpan.org)
|
12
|
+
# Copyright:: Copyright (c) 2008 Ruben Fonseca
|
13
|
+
# License:: GPLv3 (see License.txt)
|
14
|
+
|
15
|
+
# This class encapsulates the TarPipe funcionality
|
16
|
+
class TarPipe
|
17
|
+
# If we want to change the endpoint
|
18
|
+
attr_accessor :endpoint, :endpoint_port
|
19
|
+
|
20
|
+
# This acessor allows the user to select the worflow key anytime
|
21
|
+
attr_accessor :key
|
22
|
+
|
23
|
+
# Error thrown when the user doesn't specify a workflow key
|
24
|
+
class NoWorkflowKey < ArgumentError; end
|
25
|
+
|
26
|
+
# The key is optional
|
27
|
+
def initialize(key = "")
|
28
|
+
@key = key
|
29
|
+
@endpoint = 'rest.receptor.tarpipe.net'
|
30
|
+
@endpoint_port = 8000
|
31
|
+
end
|
32
|
+
|
33
|
+
# Makes a call to a workflow. All the parameters are optional:
|
34
|
+
# :title a title
|
35
|
+
# :body a body
|
36
|
+
# :image a fill path for an existing file
|
37
|
+
def upload(params = {})
|
38
|
+
@key = params[:key] if params[:key]
|
39
|
+
raise NoWorkflowKey, "TarPipe API requires your Workflow Key" unless @key
|
40
|
+
|
41
|
+
# Filter arguments
|
42
|
+
args = [:title, :body].inject({}) do |res, arg|
|
43
|
+
res[arg] = params[arg] if params[arg]
|
44
|
+
res
|
45
|
+
end
|
46
|
+
|
47
|
+
# Filter files
|
48
|
+
files = [:image].inject({}) do |res, arg|
|
49
|
+
res[arg] = params[arg] if params[arg]
|
50
|
+
res
|
51
|
+
end
|
52
|
+
|
53
|
+
post "/?key=#{@key}", args, files
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
# Encapsulates the upload operation. Encodes the multipart post, sets headers and
|
58
|
+
# uploads the request. Returns the result from the server.
|
59
|
+
def post(path, args, files)
|
60
|
+
content_type, body = encode_multipart_formdata(args, files)
|
61
|
+
|
62
|
+
headers = {
|
63
|
+
'User-Agent' => 'TarPipe-Ruby',
|
64
|
+
'Content-Type' => content_type
|
65
|
+
}
|
66
|
+
|
67
|
+
http = Net::HTTP.new(@endpoint, @endpoint_port)
|
68
|
+
resp, data = http.post2(path, body, headers)
|
69
|
+
|
70
|
+
case resp
|
71
|
+
when Net::HTTPSuccess
|
72
|
+
true
|
73
|
+
else
|
74
|
+
false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Constructs a multipart/form-data body from the arguments and files passed
|
79
|
+
# as arguments.
|
80
|
+
def encode_multipart_formdata(fields, files, boundary = "427e4cb4ca329_133ae40413c81ef")
|
81
|
+
r = fields.inject('') do |result, element|
|
82
|
+
result << "--" << boundary << "\r\n"
|
83
|
+
result << "Content-Disposition: form-data; name=\"#{element.first}\"\r\n\r\n"
|
84
|
+
result << element.last
|
85
|
+
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
r << files.inject('') do |result, element|
|
90
|
+
result << "\r\n--" << boundary << "\r\n"
|
91
|
+
result << "Content-Disposition: form-data; name=\"#{element.first}\";"
|
92
|
+
result << "filename=\"#{element.last}\"\r\n"
|
93
|
+
result << "Content-Type: #{get_content_type(element.last)}\r\n\r\n"
|
94
|
+
result << File.new(element.last, 'r').read
|
95
|
+
|
96
|
+
result
|
97
|
+
end
|
98
|
+
|
99
|
+
r << "\r\n--" << boundary << "--\r\n"
|
100
|
+
|
101
|
+
content_type = 'multipart/form-data; boundary=%s' % boundary
|
102
|
+
return content_type, r
|
103
|
+
end
|
104
|
+
|
105
|
+
# Tries to guess the mime type of a file. Defaults to application/octet-stream.
|
106
|
+
def get_content_type(file)
|
107
|
+
begin
|
108
|
+
MIME.check(file).to_s
|
109
|
+
rescue Exception => e
|
110
|
+
'application/octet-stream'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/tarpipe.rb'}"
|
9
|
+
puts "Loading tarpipe gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
GEM_NAME = 'tarpipe' # what ppl will type to install your gem
|
4
|
+
RUBYFORGE_PROJECT = 'tarpipe'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
begin
|
8
|
+
require 'newgem'
|
9
|
+
require 'rubyforge'
|
10
|
+
rescue LoadError
|
11
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
12
|
+
puts "Install: gem install newgem\n\n"
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
require 'redcloth'
|
16
|
+
require 'syntax/convertors/html'
|
17
|
+
require 'erb'
|
18
|
+
require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
|
19
|
+
|
20
|
+
version = Tarpipe::VERSION::STRING
|
21
|
+
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
22
|
+
|
23
|
+
def rubyforge_project_id
|
24
|
+
RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
|
25
|
+
end
|
26
|
+
|
27
|
+
class Fixnum
|
28
|
+
def ordinal
|
29
|
+
# teens
|
30
|
+
return 'th' if (10..19).include?(self % 100)
|
31
|
+
# others
|
32
|
+
case self % 10
|
33
|
+
when 1: return 'st'
|
34
|
+
when 2: return 'nd'
|
35
|
+
when 3: return 'rd'
|
36
|
+
else return 'th'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Time
|
42
|
+
def pretty
|
43
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def convert_syntax(syntax, source)
|
48
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
49
|
+
end
|
50
|
+
|
51
|
+
if ARGV.length >= 1
|
52
|
+
src, template = ARGV
|
53
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
54
|
+
else
|
55
|
+
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
56
|
+
exit!
|
57
|
+
end
|
58
|
+
|
59
|
+
template = ERB.new(File.open(template).read)
|
60
|
+
|
61
|
+
title = nil
|
62
|
+
body = nil
|
63
|
+
File.open(src) do |fsrc|
|
64
|
+
title_text = fsrc.readline
|
65
|
+
body_text_template = fsrc.read
|
66
|
+
body_text = ERB.new(body_text_template).result(binding)
|
67
|
+
syntax_items = []
|
68
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
69
|
+
ident = syntax_items.length
|
70
|
+
element, syntax, source = $1, $2, $3
|
71
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
72
|
+
"syntax-temp-#{ident}"
|
73
|
+
}
|
74
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
75
|
+
body = RedCloth.new(body_text).to_html
|
76
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
77
|
+
end
|
78
|
+
stat = File.stat(src)
|
79
|
+
created = stat.ctime
|
80
|
+
modified = stat.mtime
|
81
|
+
|
82
|
+
$stdout << template.result(binding)
|