rufus-jig 0.1.19 → 0.1.20
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/CHANGELOG.txt +5 -0
- data/Rakefile +25 -18
- data/lib/rufus/jig/adapters/em.rb +1 -1
- data/lib/rufus/jig/http.rb +47 -13
- data/lib/rufus/jig/version.rb +1 -1
- data/rufus-jig.gemspec +4 -3
- data/test/ct_1_couchdb.rb +13 -0
- data/test/ut_0_http_get.rb +9 -0
- data/test/ut_7_parse_uri.rb +52 -0
- metadata +4 -3
data/CHANGELOG.txt
CHANGED
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ require 'rake'
|
|
10
10
|
# CLEAN
|
11
11
|
|
12
12
|
require 'rake/clean'
|
13
|
-
CLEAN.include('pkg', 'tmp', 'html')
|
13
|
+
CLEAN.include('pkg', 'tmp', 'html', 'rdoc')
|
14
14
|
task :default => [ :clean ]
|
15
15
|
|
16
16
|
|
@@ -55,33 +55,40 @@ Jeweler::GemcutterTasks.new
|
|
55
55
|
#
|
56
56
|
# DOC
|
57
57
|
|
58
|
-
begin
|
58
|
+
#begin
|
59
|
+
# require 'yard'
|
60
|
+
# YARD::Rake::YardocTask.new do |doc|
|
61
|
+
# doc.options = [
|
62
|
+
# '-o', 'html/rufus-jig', '--title',
|
63
|
+
# "rufus-jig #{Rufus::Jig::VERSION}"
|
64
|
+
# ]
|
65
|
+
# end
|
66
|
+
#rescue LoadError
|
67
|
+
# task :yard do
|
68
|
+
# abort "YARD is not available : sudo gem install yard"
|
69
|
+
# end
|
70
|
+
#end
|
59
71
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
rescue LoadError
|
70
|
-
|
71
|
-
task :yard do
|
72
|
-
abort "YARD is not available : sudo gem install yard"
|
73
|
-
end
|
72
|
+
#
|
73
|
+
# make sure to have rdoc 2.5.x to run that
|
74
|
+
#
|
75
|
+
require 'rake/rdoctask'
|
76
|
+
Rake::RDocTask.new do |rd|
|
77
|
+
rd.main = 'README.rdoc'
|
78
|
+
rd.rdoc_dir = 'rdoc/rufus-jig'
|
79
|
+
rd.rdoc_files.include('README.rdoc', 'CHANGELOG.txt', 'lib/**/*.rb')
|
80
|
+
rd.title = "rufus-jig #{Rufus::Jig::VERSION}"
|
74
81
|
end
|
75
82
|
|
76
83
|
|
77
84
|
#
|
78
85
|
# TO THE WEB
|
79
86
|
|
80
|
-
task :upload_website => [ :clean, :
|
87
|
+
task :upload_website => [ :clean, :rdoc ] do
|
81
88
|
|
82
89
|
account = 'jmettraux@rubyforge.org'
|
83
90
|
webdir = '/var/www/gforge-projects/rufus'
|
84
91
|
|
85
|
-
sh "rsync -azv -e ssh
|
92
|
+
sh "rsync -azv -e ssh rdoc/rufus-jig #{account}:#{webdir}/"
|
86
93
|
end
|
87
94
|
|
data/lib/rufus/jig/http.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
#++
|
24
24
|
|
25
25
|
require 'uri'
|
26
|
+
require 'ostruct'
|
26
27
|
|
27
28
|
require 'rufus/lru' # gem install rufus-lru
|
28
29
|
|
@@ -68,6 +69,44 @@ module Rufus::Jig
|
|
68
69
|
attr_reader :original
|
69
70
|
end
|
70
71
|
|
72
|
+
URI_REGEX = /https?:\/\/([^\/]+)([^\?]*)(\?.+)?$/
|
73
|
+
|
74
|
+
# The current URI lib is not UTF-8 friendly, so this is a workaround.
|
75
|
+
# Temporary hopefully.
|
76
|
+
#
|
77
|
+
def self.parse_uri (s)
|
78
|
+
|
79
|
+
m = URI_REGEX.match(s)
|
80
|
+
|
81
|
+
host, port, path, query = if m
|
82
|
+
|
83
|
+
h, p = m[1].split(':')
|
84
|
+
p ||= 80
|
85
|
+
|
86
|
+
query = m[3] ? m[3][1..-1] : nil
|
87
|
+
|
88
|
+
[ h, p, m[2], query ]
|
89
|
+
|
90
|
+
else
|
91
|
+
|
92
|
+
p, q = s.split('?')
|
93
|
+
|
94
|
+
[ nil, nil, p, q ]
|
95
|
+
end
|
96
|
+
|
97
|
+
OpenStruct.new(:host => host, :port => port, :path => path, :query => query)
|
98
|
+
end
|
99
|
+
|
100
|
+
# The current URI lib is not UTF-8 friendly, so this is a workaround.
|
101
|
+
# Temporary hopefully.
|
102
|
+
#
|
103
|
+
def self.parse_host (s)
|
104
|
+
|
105
|
+
u = parse_uri(s)
|
106
|
+
|
107
|
+
u ? u.host : nil
|
108
|
+
end
|
109
|
+
|
71
110
|
# The base for the Rufus::Jig::Http class.
|
72
111
|
#
|
73
112
|
class HttpCore
|
@@ -223,22 +262,17 @@ module Rufus::Jig
|
|
223
262
|
|
224
263
|
def add_prefix (path, opts)
|
225
264
|
|
226
|
-
|
227
|
-
|
228
|
-
if !uri.host.nil?
|
229
|
-
return uri.to_s
|
230
|
-
|
231
|
-
else
|
232
|
-
uri.host.nil?
|
265
|
+
host = Rufus::Jig.parse_host(path)
|
233
266
|
|
234
|
-
|
267
|
+
return path if host
|
235
268
|
|
236
|
-
|
237
|
-
elts.unshift(prefix)
|
238
|
-
end
|
269
|
+
elts = [ path ]
|
239
270
|
|
240
|
-
|
271
|
+
if path.match(/^[^\/]/) && prefix = @options[:prefix]
|
272
|
+
elts.unshift(prefix)
|
241
273
|
end
|
274
|
+
|
275
|
+
Path.join(*elts)
|
242
276
|
end
|
243
277
|
|
244
278
|
def add_params (path, opts)
|
@@ -340,7 +374,7 @@ class Rufus::Jig::Http
|
|
340
374
|
args.shift
|
341
375
|
|
342
376
|
when /^http:\/\//
|
343
|
-
u =
|
377
|
+
u = Rufus::Jig.parse_uri(args.shift)
|
344
378
|
args.unshift(u.path)
|
345
379
|
[ u.host, u.port ]
|
346
380
|
|
data/lib/rufus/jig/version.rb
CHANGED
data/rufus-jig.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rufus-jig}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.20"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Mettraux", "Kenneth Kalmer"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-22}
|
13
13
|
s.description = %q{
|
14
14
|
Json Interwebs Get.
|
15
15
|
|
@@ -60,7 +60,8 @@ Gem::Specification.new do |s|
|
|
60
60
|
"test/ut_3_http_put.rb",
|
61
61
|
"test/ut_4_http_prefix.rb",
|
62
62
|
"test/ut_5_http_misc.rb",
|
63
|
-
"test/ut_6_args.rb"
|
63
|
+
"test/ut_6_args.rb",
|
64
|
+
"test/ut_7_parse_uri.rb"
|
64
65
|
]
|
65
66
|
s.homepage = %q{http://github.com/jmettraux/rufus-jig/}
|
66
67
|
s.rdoc_options = ["--charset=UTF-8"]
|
data/test/ct_1_couchdb.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
3
|
#
|
3
4
|
# testing rufus-jig
|
@@ -187,5 +188,17 @@ class CtCouchDbTest < Test::Unit::TestCase
|
|
187
188
|
|
188
189
|
assert_equal true, r
|
189
190
|
end
|
191
|
+
|
192
|
+
def test_put_utf8_id
|
193
|
+
|
194
|
+
r = @c.put('_id' => 'コーヒー', 'type' => 'espresso')
|
195
|
+
|
196
|
+
assert_nil r
|
197
|
+
|
198
|
+
doc =
|
199
|
+
Rufus::Jig::Http.new('127.0.0.1', 5984).get('/rufus_jig_test/コーヒー')
|
200
|
+
|
201
|
+
assert_not_nil doc['_rev']
|
202
|
+
end
|
190
203
|
end
|
191
204
|
|
data/test/ut_0_http_get.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
3
|
#
|
3
4
|
# testing rufus-jig
|
@@ -178,5 +179,13 @@ class UtHttpGetTest < Test::Unit::TestCase
|
|
178
179
|
assert_equal 'Peugeot', b['car']
|
179
180
|
assert_equal 200, @h.last_response.status
|
180
181
|
end
|
182
|
+
|
183
|
+
def test_get_utf8_uri
|
184
|
+
|
185
|
+
b = @h.get('/川崎')
|
186
|
+
|
187
|
+
assert_nil b
|
188
|
+
assert_equal 404, @h.last_response.status
|
189
|
+
end
|
181
190
|
end
|
182
191
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#
|
4
|
+
# testing rufus-jig
|
5
|
+
#
|
6
|
+
# Tue Jun 22 12:31:35 JST 2010
|
7
|
+
#
|
8
|
+
|
9
|
+
require File.join(File.dirname(__FILE__), 'base')
|
10
|
+
|
11
|
+
|
12
|
+
class UtParseUriTest < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def test_parse_host
|
15
|
+
|
16
|
+
assert_equal 'www.unifr.ch', Rufus::Jig.parse_host('http://www.unifr.ch')
|
17
|
+
assert_equal 'mufg.jp', Rufus::Jig.parse_host('http://mufg.jp/大和')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_parse_uri
|
21
|
+
|
22
|
+
assert_equal(
|
23
|
+
'www.unifr.ch',
|
24
|
+
Rufus::Jig.parse_uri('http://www.unifr.ch').host)
|
25
|
+
assert_equal(
|
26
|
+
'www.unifr.ch',
|
27
|
+
Rufus::Jig.parse_uri('http://www.unifr.ch/').host)
|
28
|
+
assert_equal(
|
29
|
+
'mufg.jp',
|
30
|
+
Rufus::Jig.parse_uri('http://mufg.jp/大和').host)
|
31
|
+
assert_equal(
|
32
|
+
'8080',
|
33
|
+
Rufus::Jig.parse_uri('http://mufg.jp:8080/大和').port)
|
34
|
+
assert_equal(
|
35
|
+
'/大和',
|
36
|
+
Rufus::Jig.parse_uri('http://mufg.jp:8080/大和').path)
|
37
|
+
assert_equal(
|
38
|
+
'nada=surf&rock=roll',
|
39
|
+
Rufus::Jig.parse_uri('http://mufg.jp:8080/大和?nada=surf&rock=roll').query)
|
40
|
+
assert_equal(
|
41
|
+
'脳=電',
|
42
|
+
Rufus::Jig.parse_uri('http://mufg.jp:8080/大和?脳=電').query)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_parse_uri_with_path
|
46
|
+
|
47
|
+
assert_equal(
|
48
|
+
nil,
|
49
|
+
Rufus::Jig.parse_uri('/').host)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 20
|
9
|
+
version: 0.1.20
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Mettraux
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-06-22 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- test/ut_4_http_prefix.rb
|
153
153
|
- test/ut_5_http_misc.rb
|
154
154
|
- test/ut_6_args.rb
|
155
|
+
- test/ut_7_parse_uri.rb
|
155
156
|
has_rdoc: true
|
156
157
|
homepage: http://github.com/jmettraux/rufus-jig/
|
157
158
|
licenses: []
|