simple_uri 0.0.10 → 0.0.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3775df648d936f8ed5afd15e965fcd202ac0f7f4
4
- data.tar.gz: 4980e5d942bd91a74af68f9897fcf3881f77dc42
3
+ metadata.gz: 2e05ec3ed68d47c4d1e5014a03fa778a2a15d82e
4
+ data.tar.gz: 2b4ff8f760a510a0cf03d85036992abb579b6749
5
5
  SHA512:
6
- metadata.gz: 7c0b786265a6e375ad804b1f427805a360df0d20acbf0ab23f82a5f71e71f0084fdcc26368f0fd3e9a30ac253d482995de4b4274ea3ac37b3d323280a5101222
7
- data.tar.gz: ad8eddf56d282ff8c35674b74084a0689e42c420ea7b2546a64a10363c2ef34db21af2b267140bf5712bd4bd2d92b2adc46934a9e733d289597a9d350d68f311
6
+ metadata.gz: a8bbab9e126f3de9de9581e02cc915766f4fab43a240e14122237cff291b776f7cef74416e7c53776a7ee4901e545fcc53bcb875376e5c928275b7fa3800bf49
7
+ data.tar.gz: 41447113367896c8f5a8e4b24d7cfc587c2c0725d59d8b8adaf3124e456f52a8c0d89e88f9ae336c7b75e3ee59783b1132d9424542850bcb1039760ae8cbdfcc
@@ -1,3 +1,3 @@
1
1
  module SimpleUri
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/simple_uri.rb CHANGED
@@ -8,10 +8,9 @@ module SimpleUri
8
8
 
9
9
  class << self
10
10
 
11
- @@debug_mode = false
11
+ MODES = { debug: false, autofix: false }
12
12
 
13
- def connect(url='', method=nil, options={ params: nil, user: nil, password: nil, debug: @@debug_mode })
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: @@debug_mode, cookies: false })
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
- m = url.match(/http(s)?:\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.\w{2,5}(:\d+)?\/([1-9.\w])+(.{0})/)
58
- if m && m[0]==url && url[-1] != '/'
59
- url += '/'
60
- debug_msg 'Append \'/\' to url.'
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
- @@debug_mode = true
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 && @@debug_mode
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 @@debug_mode
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.10
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-27 00:00:00.000000000 Z
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