rorvswild 1.0.0.pre.alpha5 → 1.0.0.pre.alpha6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6631971318d1ff790b7c9179f0766b029ce79cd
4
- data.tar.gz: 0e2bfea436677d2367c5471cc6dbad4808f7231e
3
+ metadata.gz: 492dae0df8044448c77cf1d9822d0a38c620eb5d
4
+ data.tar.gz: 046530a1906c3987c082b077da9358dd8bb8c692
5
5
  SHA512:
6
- metadata.gz: 56736345c5a5c1f914051def41014701ce2a8bea7018a6fcc75644ed58c41063c03948199d95a8a623203c5930bb646393b63c22bc70f31b8abede040afd365e
7
- data.tar.gz: c36a1093d301a008a70aa15292a29abea44aeae55dd9bd15c48f87c60424a86716a344628ea1724deedc09e3aa5deb26ba2b4783694bad38ea8eafb5b9c6686f
6
+ metadata.gz: 8ab27a731ee5e63c9e08c11e89d6fe02376f943f7a5263652865ddebd5071e5faea20e66a52e11a3a619b5fa9505899cdc0aae599d61eb757f16facc03c9ccff
7
+ data.tar.gz: cdd6af7ec6ec368499e8f5ff8cb7da967474f2e56b3827baf4d54a24857f364ad333e20109bf63acea81a6410633f9524123ec7dd69b823a5e9fea0216f788ba
@@ -1,37 +1,40 @@
1
1
  require "set"
2
2
  require "uri"
3
- require "net/http"
4
3
  require "json/ext"
4
+ require "net/http"
5
+ require "net/http/persistent"
5
6
 
6
7
  module RorVsWild
7
8
  class Client
8
9
  HTTPS = "https".freeze
9
10
  CERTIFICATE_AUTHORITIES_PATH = File.expand_path("../../../cacert.pem", __FILE__)
11
+ DEFAULT_TIMEOUT = 1
10
12
 
11
- attr_reader :api_url, :api_key, :threads
13
+ attr_reader :api_url, :api_key, :timeout, :threads
12
14
 
13
15
  def initialize(config)
14
16
  Kernel.at_exit(&method(:at_exit))
15
17
  @api_url = config[:api_url]
16
18
  @api_key = config[:api_key]
19
+ @timeout ||= config[:timeout] || DEFAULT_TIMEOUT
17
20
  @threads = Set.new
18
21
  end
19
22
 
20
23
  def post(path, data)
21
24
  uri = URI(api_url + path)
22
- http = Net::HTTP.new(uri.host, uri.port)
23
-
24
- if uri.scheme == HTTPS
25
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
26
- http.ca_file = CERTIFICATE_AUTHORITIES_PATH
27
- http.use_ssl = true
28
- end
29
-
30
25
  post = Net::HTTP::Post.new(uri.path, "X-Gem-Version".freeze => RorVsWild::VERSION)
31
26
  post.content_type = "application/json".freeze
32
27
  post.basic_auth(nil, api_key)
33
28
  post.body = data.to_json
34
- http.request(post)
29
+ http.request(uri, post)
30
+ end
31
+
32
+ def http
33
+ return @http if @http
34
+ http = Net::HTTP::Persistent.new
35
+ http.retry_change_requests = true
36
+ http.open_timeout = timeout
37
+ @http = http
35
38
  end
36
39
 
37
40
  def post_async(path, data)
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "1.0.0-alpha5".freeze
2
+ VERSION = "1.0.0-alpha6".freeze
3
3
  end
data/rorvswild.gemspec CHANGED
@@ -19,4 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
+
23
+ spec.add_dependency "net-http-persistent", ">= 2.9.4"
22
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rorvswild
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha5
4
+ version: 1.0.0.pre.alpha6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-http-persistent
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.9.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.9.4
27
41
  description: Performances & quality insights for rails developers.
28
42
  email:
29
43
  - alexis@bernard.io