simple_uri 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_uri/version.rb +1 -1
- data/lib/simple_uri.rb +28 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e05ec3ed68d47c4d1e5014a03fa778a2a15d82e
|
4
|
+
data.tar.gz: 2b4ff8f760a510a0cf03d85036992abb579b6749
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8bbab9e126f3de9de9581e02cc915766f4fab43a240e14122237cff291b776f7cef74416e7c53776a7ee4901e545fcc53bcb875376e5c928275b7fa3800bf49
|
7
|
+
data.tar.gz: 41447113367896c8f5a8e4b24d7cfc587c2c0725d59d8b8adaf3124e456f52a8c0d89e88f9ae336c7b75e3ee59783b1132d9424542850bcb1039760ae8cbdfcc
|
data/lib/simple_uri/version.rb
CHANGED
data/lib/simple_uri.rb
CHANGED
@@ -8,10 +8,9 @@ module SimpleUri
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
-
|
11
|
+
MODES = { debug: false, autofix: false }
|
12
12
|
|
13
|
-
def connect(url='', method=nil, options={ params: nil, user: nil, password: nil, debug:
|
14
|
-
enable_debug_mode(options[:debug])
|
13
|
+
def connect(url='', method=nil, options={ params: nil, user: nil, password: nil, debug: debug_mode })
|
15
14
|
uri = URI.parse(URI.encode(prepare_url(url)))
|
16
15
|
http = Net::HTTP.new(uri.host, uri.port)
|
17
16
|
http.read_timeout = 1000
|
@@ -29,7 +28,9 @@ module SimpleUri
|
|
29
28
|
[req, http]
|
30
29
|
end
|
31
30
|
|
32
|
-
def send_request(url=nil, method=:get, options={ params: nil, req_body: nil, req_headers: nil, user: nil, password: nil, debug:
|
31
|
+
def send_request(url=nil, method=:get, options={ params: nil, req_body: nil, req_headers: nil, user: nil, password: nil, debug: debug_mode, autofix: autofix_mode, cookies: false })
|
32
|
+
enable_debug_mode(options[:debug])
|
33
|
+
enable_autofix_mode(options[:autofix])
|
33
34
|
get_params = options[:req_body] ? '?'+prepare_req_body(options[:req_body]).to_s : ''
|
34
35
|
options[:params] = method==:post ? nil : get_params
|
35
36
|
req, http = connect(url, method, { params: options[:params], user: options[:user], password: options[:password], debug: options[:debug] })
|
@@ -54,34 +55,50 @@ module SimpleUri
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def prepare_url(url)
|
57
|
-
|
58
|
-
|
59
|
-
url
|
60
|
-
|
58
|
+
if autofix_mode
|
59
|
+
m = url.match(/http(s)?:\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.\w{2,5}(:\d+)?\/([1-9.\w])+(.{0})/) #TODO
|
60
|
+
if m && m[0]==url && url[-1] != '/'
|
61
|
+
url += '/'
|
62
|
+
debug_msg 'Append \'/\' to url.'
|
63
|
+
end
|
61
64
|
end
|
62
65
|
url
|
63
66
|
end
|
64
67
|
|
65
68
|
def enable_debug_mode(enabled)
|
66
69
|
if enabled
|
67
|
-
|
70
|
+
debug_mode(true)
|
68
71
|
@log = Logger.new(debug_output)
|
69
72
|
@log.level = Logger::DEBUG
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
76
|
+
def enable_autofix_mode(enabled)
|
77
|
+
autofix_mode(true) if enabled
|
78
|
+
end
|
79
|
+
|
73
80
|
def debug_msg(msg)
|
74
|
-
@log.debug(msg) if @log &&
|
81
|
+
@log.debug(msg) if @log && debug_mode
|
75
82
|
end
|
76
83
|
|
77
84
|
def debug_http(http)
|
78
|
-
http.set_debug_output(debug_output) if
|
85
|
+
http.set_debug_output(debug_output) if debug_mode
|
79
86
|
end
|
80
87
|
|
81
88
|
def debug_output
|
82
89
|
STDOUT
|
83
90
|
end
|
84
91
|
|
92
|
+
def debug_mode(mode=nil)
|
93
|
+
MODES[:debug]=mode unless mode.nil?
|
94
|
+
MODES[:debug]
|
95
|
+
end
|
96
|
+
|
97
|
+
def autofix_mode(mode=nil)
|
98
|
+
MODES[:autofix]=mode unless mode.nil?
|
99
|
+
MODES[:autofix]
|
100
|
+
end
|
101
|
+
|
85
102
|
end
|
86
103
|
|
87
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikulin Aleksander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: To simplify working with url
|
14
14
|
email: nikulinaleksandr@gmail.com
|