simple_uri 0.0.4 → 0.0.5
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 +13 -5
- data/lib/simple_uri/version.rb +1 -1
- data/lib/simple_uri.rb +9 -11
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmEzNjE5YTJhODgwOGJkMDExZDc1YzEwOTk0NTRlMGM5ZTE2ODNmOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTYxMTM3YjYyYmFkN2EzNGVhMzk2MjExMzI3ZWUxODJjMzI4NTRhNQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2E5YmVjYjNhNDk3ZTc5ZmE2MjhjZjExZjMwNzM1OTQwNDRlMWY0ZDZlMWM3
|
10
|
+
MWUzOGQ2ZTBjNDg1ZTQ3MDQ0NjYzMzY3ZDdiZmYwYmEwZDg4ZDRhYmVkMzAw
|
11
|
+
MDA5MWU3MWY1NzE3NGM3Yjg3MWM5MzhhMDNmMTBlNjRkZWVkY2I=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjY2ODFkODY0NzA5MzE3OGM3YzFmZDZiN2JmNjljYmU4YTg4NGRkZTlmMDkz
|
14
|
+
NGEwYTE0ZjI2MzE4YTVhNTI4MWI4MGJmNzFkNjI1ZWIwNzUyMjMyMjkzZTQ2
|
15
|
+
ODNjNGRiMzcwNWMzY2M4NDRhNTJiNzk2MWQ5MWU0MTI1Y2JkYmE=
|
data/lib/simple_uri/version.rb
CHANGED
data/lib/simple_uri.rb
CHANGED
@@ -10,9 +10,8 @@ module SimpleUri
|
|
10
10
|
|
11
11
|
@@debug_mode = false
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
enable_debug_mode(debug)
|
13
|
+
def connect(url='', method=nil, options={ params: nil, user: nil, password: nil, debug: @@debug_mode })
|
14
|
+
enable_debug_mode(options[:debug])
|
16
15
|
uri = URI.parse(URI.encode(prepare_url(url)))
|
17
16
|
http = Net::HTTP.new(uri.host, uri.port)
|
18
17
|
http.read_timeout = 1000
|
@@ -22,16 +21,15 @@ module SimpleUri
|
|
22
21
|
http.use_ssl = true
|
23
22
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
24
23
|
end
|
25
|
-
req = "Net::HTTP::#{method.to_s.capitalize}".constantize.new(uri.path+params.to_s)
|
26
|
-
req.basic_auth user, password if user && password
|
24
|
+
req = "Net::HTTP::#{method.to_s.capitalize}".constantize.new(uri.path+options[:params].to_s)
|
25
|
+
req.basic_auth options[:user], options[:password] if options[:user] && options[:password]
|
27
26
|
[req, http]
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
req
|
33
|
-
|
34
|
-
req_headers.each { |k, v| req[k] = v } if req_headers
|
29
|
+
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 })
|
30
|
+
req, http = connect(url, method, { params: options[:params], user: options[:user], password: options[:password], debug: options[:debug] })
|
31
|
+
req.body = prepare_req_body(options[:req_body])
|
32
|
+
options[:req_headers].each { |k, v| req[k] = v } if options[:req_headers]
|
35
33
|
res = http.request(req)
|
36
34
|
res.body
|
37
35
|
res_body = begin
|
@@ -40,7 +38,7 @@ module SimpleUri
|
|
40
38
|
debug_msg 'Can\'t convert response to JSON'
|
41
39
|
res.body
|
42
40
|
end
|
43
|
-
cookies ? { body: res_body, cookies: res.response['set-cookie'] } : res_body
|
41
|
+
options[:cookies] ? { body: res_body, cookies: res.response['set-cookie'] } : res_body
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikulin Aleksander
|
@@ -28,12 +28,12 @@ require_paths:
|
|
28
28
|
- lib
|
29
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ! '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
@@ -43,3 +43,4 @@ signing_key:
|
|
43
43
|
specification_version: 4
|
44
44
|
summary: To simplify working with url
|
45
45
|
test_files: []
|
46
|
+
has_rdoc:
|