swiftype 1.2.1 → 1.2.2

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: f11f2ce09ccdf271510c73431424c332a41182b9
4
- data.tar.gz: e83507c697bbca3b65df19a806b9a99d93881d2b
3
+ metadata.gz: 13981a414b87f3820b0561ce55e22014311c1766
4
+ data.tar.gz: 1f68d66bba5aea0b1d5beeed4a253deabd942502
5
5
  SHA512:
6
- metadata.gz: 0cafb2792d12bdc1bbfef1e814c9c050a88318b17252e149f2caf989bc8a2baeeb5bd28a901cb46f17a7ef47d924195a8fe68dd230c5c428ca80585e2e14d814
7
- data.tar.gz: 51c46e6e9f9bdc2f2055338bb5bb6e552908e177bbbf9c2a4fdf23c286da0e5f6f8ce16f3d13fb025c259ae3538695c954651e0192e25b8bd600d6eac87be7bf
6
+ metadata.gz: ec53f7d6df041432268ca9061bb3a49aab3a170a23b43f2d9c4bd0b2e1ea75cf1eac8b13e6d7ecc8de8195a7c4fd3860e206c2c7a28f9766f152ebb0c571fb04
7
+ data.tar.gz: 1ca58366f50297910aeb7f3086f31c4c561db38ec4c820dd30abcad36eb98e4c8260d16ccd785880c9f4d5a3b46e6f67844e62b2c975938110bdbcea91eb441f
@@ -1,11 +1,13 @@
1
1
  language: ruby
2
2
  script: rspec
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
8
- - jruby-19mode
4
+ - 1.9
5
+ - 2.0
6
+ - 2.1
7
+ - 2.2
8
+ - jruby
9
+ jdk:
10
+ - oraclejdk8
9
11
 
10
12
  before_install:
11
13
  - gem update --system
@@ -5,6 +5,8 @@ require 'swiftype/request'
5
5
  module Swiftype
6
6
  # API client for the {Swiftype API}[https://swiftype.com/documentation/overview].
7
7
  class Client
8
+ DEFAULT_TIMEOUT = 15
9
+
8
10
  include Swiftype::Request
9
11
 
10
12
  def self.configure(&block)
@@ -17,8 +19,8 @@ module Swiftype
17
19
  # @param options [Hash] a hash of configuration options that will override what is set on the Swiftype class.
18
20
  # @option options [String] :api_key an API Key to use for this client
19
21
  # @option options [String] :platform_access_token a user's access token, will be used instead of API key for authenticating requests
20
- # @option options [Numeric] :overall_timeout overall timeout for requests in seconds
21
- # @option options [Numeric] :open_timeout the number of seconds Net::HTTP
22
+ # @option options [Numeric] :overall_timeout overall timeout for requests in seconds (default: 15s)
23
+ # @option options [Numeric] :open_timeout the number of seconds Net::HTTP (default: 15s)
22
24
  # will wait while opening a connection before raising a Timeout::Error
23
25
 
24
26
  def initialize(options={})
@@ -34,11 +36,11 @@ module Swiftype
34
36
  end
35
37
 
36
38
  def open_timeout
37
- @options[:open_timeout]
39
+ @options[:open_timeout] || DEFAULT_TIMEOUT
38
40
  end
39
41
 
40
42
  def overall_timeout
41
- @options[:overall_timeout].to_f
43
+ (@options[:overall_timeout] || DEFAULT_TIMEOUT).to_f
42
44
  end
43
45
 
44
46
 
@@ -53,30 +53,28 @@ module Swiftype
53
53
  #
54
54
  # @raise [Timeout::Error] when the timeout expires
55
55
  def request(method, path, params={})
56
- uri = URI.parse("#{Swiftype.endpoint}#{path}")
57
-
58
- request = build_request(method, uri, params)
59
- http = Net::HTTP.new(uri.host, uri.port)
60
- http.open_timeout = open_timeout
61
-
62
- if uri.scheme == 'https'
63
- http.use_ssl = true
64
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
65
- http.ca_file = File.join(File.dirname(__FILE__), '..', 'data', 'ca-bundle.crt')
66
- end
67
-
68
- response = nil
69
56
  Timeout.timeout(overall_timeout) do
57
+ uri = URI.parse("#{Swiftype.endpoint}#{path}")
58
+
59
+ request = build_request(method, uri, params)
60
+ http = Net::HTTP.new(uri.host, uri.port)
61
+ http.open_timeout = open_timeout
62
+ http.read_timeout = overall_timeout
63
+
64
+ if uri.scheme == 'https'
65
+ http.use_ssl = true
66
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
67
+ http.ca_file = File.join(File.dirname(__FILE__), '..', 'data', 'ca-bundle.crt')
68
+ http.ssl_timeout = open_timeout
69
+ end
70
+
70
71
  response = http.request(request)
72
+ handle_errors(response)
73
+ JSON.parse(response.body) if response.body && response.body.strip != ''
71
74
  end
72
-
73
- handle_errors(response)
74
-
75
- JSON.parse(response.body) if response.body && response.body.strip != ''
76
75
  end
77
76
 
78
77
  private
79
-
80
78
  def handle_errors(response)
81
79
  case response
82
80
  when Net::HTTPSuccess
@@ -1,3 +1,3 @@
1
1
  module Swiftype
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -93,8 +93,8 @@ describe Swiftype::Client do
93
93
  context 'without timeout specified' do
94
94
  let(:options) { Hash.new }
95
95
  it 'omits the option' do
96
- expect(options_client.overall_timeout).to eq(0.0)
97
- expect(Timeout).to receive(:timeout).with(0.0).and_call_original
96
+ expect(options_client.overall_timeout).to eq(Swiftype::Client::DEFAULT_TIMEOUT.to_f)
97
+ expect(Timeout).to receive(:timeout).with(Swiftype::Client::DEFAULT_TIMEOUT.to_f).and_call_original
98
98
  VCR.use_cassette(:engine_search) do
99
99
  options_client.search(engine_slug, 'cat')
100
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiftype
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quin Hoxie
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-26 00:00:00.000000000 Z
12
+ date: 2016-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  version: '0'
192
192
  requirements: []
193
193
  rubyforge_project:
194
- rubygems_version: 2.4.8
194
+ rubygems_version: 2.4.5
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Official gem for accessing the Swiftype Search API