simple_uri 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 888a8ac42686f92a12609b7384f879f672b9f24f
4
- data.tar.gz: 6b65ab65de184ae39cf4c3cd7e161050aedc4c0f
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmEzNjE5YTJhODgwOGJkMDExZDc1YzEwOTk0NTRlMGM5ZTE2ODNmOQ==
5
+ data.tar.gz: !binary |-
6
+ OTYxMTM3YjYyYmFkN2EzNGVhMzk2MjExMzI3ZWUxODJjMzI4NTRhNQ==
5
7
  SHA512:
6
- metadata.gz: 6360a9cca63d4327b0996fdf43801e4bd5f0f05646e7b58c0b64a3a7376987d50a5fa9bd186778bc4af835cac99b724e9b59cd6f36eb55108ddc23639d7cd4eb
7
- data.tar.gz: bbbbdb9398120c52357b4df2847735fcee3c801417425455b5a998f6f1eafc814c3ac9bea3f5013da2d63eb4950b9c3e0d0a0f165b9e1d96337d646e499e2620
8
+ metadata.gz: !binary |-
9
+ M2E5YmVjYjNhNDk3ZTc5ZmE2MjhjZjExZjMwNzM1OTQwNDRlMWY0ZDZlMWM3
10
+ MWUzOGQ2ZTBjNDg1ZTQ3MDQ0NjYzMzY3ZDdiZmYwYmEwZDg4ZDRhYmVkMzAw
11
+ MDA5MWU3MWY1NzE3NGM3Yjg3MWM5MzhhMDNmMTBlNjRkZWVkY2I=
12
+ data.tar.gz: !binary |-
13
+ MjY2ODFkODY0NzA5MzE3OGM3YzFmZDZiN2JmNjljYmU4YTg4NGRkZTlmMDkz
14
+ NGEwYTE0ZjI2MzE4YTVhNTI4MWI4MGJmNzFkNjI1ZWIwNzUyMjMyMjkzZTQ2
15
+ ODNjNGRiMzcwNWMzY2M4NDRhNTJiNzk2MWQ5MWU0MTI1Y2JkYmE=
@@ -1,3 +1,3 @@
1
1
  module SimpleUri
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/simple_uri.rb CHANGED
@@ -10,9 +10,8 @@ module SimpleUri
10
10
 
11
11
  @@debug_mode = false
12
12
 
13
- #parameters:url-String, method-Symbol||String, params-String, user-String, password:String, debug-Boolean
14
- def connect(url: nil, method: nil, params: nil, user: nil, password: nil, debug: @@debug_mode)
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
- #parameters:url-String, method-Symbol||String, params-String, req_body-String, req_headers-Hash, user-String, password:String, debug-Boolean, cookies-Boolean
31
- def send_request(url: nil, method: nil, params: nil, req_body: nil, req_headers: nil, user: nil, password: nil, debug: @@debug_mode, cookies: false)
32
- req, http = connect(url: url, method: method, params: params, user: user, password: password, debug: debug)
33
- req.body = prepare_req_body(req_body)
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
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: