swiftype 1.2.0 → 1.2.1

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: 54e1e3d18b1ef0d4ac96736071a83904c332fa62
4
- data.tar.gz: 7c387aedb4ccca99caef021296dc6f9f2adad14f
3
+ metadata.gz: f11f2ce09ccdf271510c73431424c332a41182b9
4
+ data.tar.gz: e83507c697bbca3b65df19a806b9a99d93881d2b
5
5
  SHA512:
6
- metadata.gz: 380b9b2cd117f33f243386e1b5dac701ceb460d6ffd4f5f898bdedd5717d77585f1049f07b396613ce18dbc5add22487f6444d07f062f069cceedce02e717576
7
- data.tar.gz: ccf234d1156a1338b9c11f12c2e68b06fb7b0b58b94118c8c60c9fb80d67f5e994c7f138fdbc914ced223351c73e3945aa8d07559917ec7d382dc938fd258318
6
+ metadata.gz: 0cafb2792d12bdc1bbfef1e814c9c050a88318b17252e149f2caf989bc8a2baeeb5bd28a901cb46f17a7ef47d924195a8fe68dd230c5c428ca80585e2e14d814
7
+ data.tar.gz: 51c46e6e9f9bdc2f2055338bb5bb6e552908e177bbbf9c2a4fdf23c286da0e5f6f8ce16f3d13fb025c259ae3538695c954651e0192e25b8bd600d6eac87be7bf
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- script: rspec
2
+ script: rspec
3
3
  rvm:
4
4
  - 1.8.7
5
5
  - 1.9.3
@@ -10,3 +10,4 @@ rvm:
10
10
  before_install:
11
11
  - gem update --system
12
12
  - gem --version
13
+ - gem update bundler
@@ -17,7 +17,8 @@ module Swiftype
17
17
  # @param options [Hash] a hash of configuration options that will override what is set on the Swiftype class.
18
18
  # @option options [String] :api_key an API Key to use for this client
19
19
  # @option options [String] :platform_access_token a user's access token, will be used instead of API key for authenticating requests
20
- # @option options [Fixnum] :open_timeout the number of seconds Net::HTTP
20
+ # @option options [Numeric] :overall_timeout overall timeout for requests in seconds
21
+ # @option options [Numeric] :open_timeout the number of seconds Net::HTTP
21
22
  # will wait while opening a connection before raising a Timeout::Error
22
23
 
23
24
  def initialize(options={})
@@ -36,6 +37,11 @@ module Swiftype
36
37
  @options[:open_timeout]
37
38
  end
38
39
 
40
+ def overall_timeout
41
+ @options[:overall_timeout].to_f
42
+ end
43
+
44
+
39
45
  # Methods wrapping the Swiftype private search and API endpoints. Using these methods, you can perform full-text
40
46
  # and prefix searches over the Documents in your Engine, in a specific DocumentType, or any subset of DocumentTypes.
41
47
  # You can also filter results and get faceted counts for results.
@@ -1,5 +1,5 @@
1
1
  require 'net/https'
2
- if RUBY_VERSION < "1.9"
2
+ if RUBY_VERSION < '1.9'
3
3
  require 'swiftype/ext/backport-uri'
4
4
  else
5
5
  require 'uri'
@@ -49,12 +49,15 @@ module Swiftype
49
49
  end
50
50
  end
51
51
 
52
+ # Construct and send a request to the API.
53
+ #
54
+ # @raise [Timeout::Error] when the timeout expires
52
55
  def request(method, path, params={})
53
56
  uri = URI.parse("#{Swiftype.endpoint}#{path}")
54
57
 
55
58
  request = build_request(method, uri, params)
56
59
  http = Net::HTTP.new(uri.host, uri.port)
57
- http.open_timeout = @options[:open_timeout]
60
+ http.open_timeout = open_timeout
58
61
 
59
62
  if uri.scheme == 'https'
60
63
  http.use_ssl = true
@@ -62,7 +65,10 @@ module Swiftype
62
65
  http.ca_file = File.join(File.dirname(__FILE__), '..', 'data', 'ca-bundle.crt')
63
66
  end
64
67
 
65
- response = http.request(request)
68
+ response = nil
69
+ Timeout.timeout(overall_timeout) do
70
+ response = http.request(request)
71
+ end
66
72
 
67
73
  handle_errors(response)
68
74
 
@@ -1,3 +1,3 @@
1
1
  module Swiftype
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -71,9 +71,35 @@ describe Swiftype::Client do
71
71
  let(:options_client) { Swiftype::Client.new(options) }
72
72
 
73
73
  context '#request' do
74
- let(:options) { { :open_timeout => 3 } }
75
- it 'respects the Net::HTTP open_timeout option' do
76
- expect(options_client.open_timeout).to eq(3)
74
+ context 'open_timeout' do
75
+ let(:options) { { :open_timeout => 3 } }
76
+ it 'respects the Net::HTTP open_timeout option' do
77
+ expect(options_client.open_timeout).to eq(3)
78
+ end
79
+ end
80
+
81
+ context 'overall_timeout' do
82
+ context 'with timeout specified' do
83
+ let(:options) { { :overall_timeout => 0.001 } }
84
+ it 'respects the overall timeout option' do
85
+ expect(options_client.overall_timeout).to eq(0.001)
86
+ allow_any_instance_of(Net::HTTP).to receive(:request) { sleep 3 }
87
+ expect {
88
+ options_client.search(engine_slug, 'cat')
89
+ }.to raise_error(Timeout::Error)
90
+ end
91
+ end
92
+
93
+ context 'without timeout specified' do
94
+ let(:options) { Hash.new }
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
98
+ VCR.use_cassette(:engine_search) do
99
+ options_client.search(engine_slug, 'cat')
100
+ end
101
+ end
102
+ end
77
103
  end
78
104
  end
79
105
  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.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quin Hoxie
@@ -9,62 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-16 00:00:00.000000000 Z
12
+ date: 2016-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.0.0
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 3.0.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: awesome_print
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: vcr
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: 2.9.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: 2.9.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: webmock
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  description: API client for accessing the Swiftype Search API with no dependencies
@@ -75,8 +75,8 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
79
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
80
  - Gemfile
81
81
  - LICENSE.txt
82
82
  - README.md
@@ -181,17 +181,17 @@ require_paths:
181
181
  - lib
182
182
  required_ruby_version: !ruby/object:Gem::Requirement
183
183
  requirements:
184
- - - '>='
184
+ - - ">="
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
- - - '>='
189
+ - - ">="
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
193
  rubyforge_project:
194
- rubygems_version: 2.2.1
194
+ rubygems_version: 2.4.8
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Official gem for accessing the Swiftype Search API
@@ -276,4 +276,3 @@ test_files:
276
276
  - spec/spec_helper.rb
277
277
  - spec/ssl_spec.rb
278
278
  - spec/sso_spec.rb
279
- has_rdoc: