http_mini 0.2.3 → 0.3.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/lib/http_mini.rb +16 -39
  4. metadata +2 -3
  5. data/lib/request.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2043cd9aeffdf055e5fde5eadcc7f0b41f77e15
4
- data.tar.gz: fe4aa4a6c61b5e69adb0e507389264e89d2a83d4
3
+ metadata.gz: 166acd0db0024022ec7e07c1de9c80541df9b499
4
+ data.tar.gz: 876d20b39d257334c356b19196efa1b15417ecb7
5
5
  SHA512:
6
- metadata.gz: f4c28d37b8acafd27471987a48633b3fe36c27e052ff80cd8f879603963078bab050a29e55b0509324a1e5ef236fb896bdfbf571dc9e7809c4cc397209af2e88
7
- data.tar.gz: 32119819d2015104e88e0aeb377522a0e2eede3d5dbf20172fc9d439c658b09b93b4b893f9b61b09616998947a9fcca11075a109b5d660d8abf9c24bb6c80aec
6
+ metadata.gz: 4dc9413dcbdb34d68a6b22a8949cb7596b3f5bae1a311facc2808bcc5a28028bfcef317fe834ca1a3981b0dcc1870c79ede099d177515c420b7bb4a8dc0ef845
7
+ data.tar.gz: 7d90442a228947c494491a61775cc8d96e33b6d7a1ee09e130d77ee192ba2a9c8e688e45a5b4b4bf1a144b1cc41acfed15079bca5b894f3136d2e78bef3192cb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## vNEXT
2
2
 
3
+ ## v3.0.0
4
+ * Performance improvements
5
+ * Refactoring. As part of the refactoring, there is now only one option for timeout used for both open and read
6
+ and no more default values.
7
+
3
8
  ## v0.2.3
4
9
  * Allow to set request headers via options hash
5
10
  * Remove unnecessary code since 0.2.2 improved uri handling
data/lib/http_mini.rb CHANGED
@@ -5,12 +5,10 @@ class HttpMini
5
5
 
6
6
  attr_accessor :opts
7
7
 
8
- OPEN_TIMEOUT = 2
9
- READ_TIMEOUT = 2
10
8
  IGNORE_ERROR = true
11
9
 
12
10
  def self.VERSION
13
- '0.2.3'
11
+ '0.3.0'
14
12
  end
15
13
 
16
14
  def initialize(uri, opts = {})
@@ -19,27 +17,27 @@ class HttpMini
19
17
  end
20
18
 
21
19
  def head
22
- request Net::HTTP::Head.new(full_path)
20
+ request Net::HTTP::Head.new(full_path, headers)
23
21
  end
24
22
 
25
23
  def get
26
- request Net::HTTP::Get.new(full_path)
24
+ request Net::HTTP::Get.new(full_path, headers)
27
25
  end
28
26
 
29
27
  def post(data)
30
- request Net::HTTP::Post.new(full_path), data
28
+ request Net::HTTP::Post.new(full_path, headers), data
31
29
  end
32
30
 
33
31
  def put(data)
34
- request Net::HTTP::Put.new(full_path), data
32
+ request Net::HTTP::Put.new(full_path, headers), data
35
33
  end
36
34
 
37
35
  def delete
38
- request Net::HTTP::Delete.new(full_path)
36
+ request Net::HTTP::Delete.new(full_path, headers)
39
37
  end
40
38
 
41
39
  def options
42
- request Net::HTTP::Options.new(full_path)
40
+ request Net::HTTP::Options.new(full_path, headers)
43
41
  end
44
42
 
45
43
  def poke
@@ -65,7 +63,7 @@ class HttpMini
65
63
  end
66
64
 
67
65
  def path(path=nil)
68
- path.nil? ? default_path(@uri.path) : set_path(path)
66
+ path.nil? ? @uri.request_uri : set_path(path)
69
67
  end
70
68
 
71
69
  private
@@ -75,23 +73,18 @@ class HttpMini
75
73
  end
76
74
 
77
75
  def handle_missing_scheme(uri)
78
- uri.match(/https?:\/\//) ? uri : "http://#{uri}"
76
+ uri[0..3] == 'http' ? uri : "http://#{uri}"
79
77
  end
80
78
 
81
79
  def request(req, data=nil)
82
- Net::HTTP.start(host, port, :use_ssl => ssl?) { |http| set_timeout(http) and http.request(set_headers(req), data) }
80
+ http.start { |http| http.request(req, data) }
83
81
  end
84
82
 
85
- def ssl?
86
- @uri.scheme == 'https'
87
- end
88
-
89
- def set_timeout(http)
90
- http.open_timeout, http.read_timeout = timeouts
91
- end
92
-
93
- def set_headers(req)
94
- headers.each { |key, value| req[key] = value } and return req
83
+ def http
84
+ http = Net::HTTP.new(@uri.host, @uri.port)
85
+ http.use_ssl = @uri.instance_of?(URI::HTTPS)
86
+ http.open_timeout = http.read_timeout = opts[:timeout] if opts.key? :timeout
87
+ http
95
88
  end
96
89
 
97
90
  def headers
@@ -99,11 +92,7 @@ class HttpMini
99
92
  end
100
93
 
101
94
  def full_path
102
- @uri.query ? path + '?' + @uri.query : path
103
- end
104
-
105
- def default_path(path)
106
- path.to_s.empty? ? '/' : path
95
+ @uri.request_uri
107
96
  end
108
97
 
109
98
  def set_path(path)
@@ -116,18 +105,6 @@ class HttpMini
116
105
  path.gsub /\?.*/, ''
117
106
  end
118
107
 
119
- def timeouts
120
- [open_timeout, read_timeout]
121
- end
122
-
123
- def open_timeout
124
- opts[:open_timeout].nil? ? OPEN_TIMEOUT : opts[:open_timeout]
125
- end
126
-
127
- def read_timeout
128
- opts[:read_timeout].nil? ? READ_TIMEOUT : opts[:read_timeout]
129
- end
130
-
131
108
  def ignore_error?
132
109
  opts[:ignore_error].nil? ? IGNORE_ERROR : opts[:ignore_error]
133
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_mini
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Touffe-Blin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-02 00:00:00.000000000 Z
11
+ date: 2013-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -76,7 +76,6 @@ extra_rdoc_files:
76
76
  - CHANGELOG.md
77
77
  files:
78
78
  - lib/http_mini.rb
79
- - lib/request.rb
80
79
  - LICENSE
81
80
  - README.md
82
81
  - CHANGELOG.md
data/lib/request.rb DELETED
@@ -1,17 +0,0 @@
1
- require 'net/http'
2
- require "uri"
3
-
4
- class Request
5
-
6
- @@request = HttpMini.new nil
7
-
8
- class << self
9
-
10
- def get(uri, opts={})
11
- @@request.opts = opts
12
- @@request.uri(uri).get
13
- end
14
-
15
- end
16
-
17
- end