swiftype 1.2.1 → 1.2.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +7 -5
- data/lib/swiftype/client.rb +6 -4
- data/lib/swiftype/request.rb +16 -18
- data/lib/swiftype/version.rb +1 -1
- data/spec/client_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13981a414b87f3820b0561ce55e22014311c1766
|
4
|
+
data.tar.gz: 1f68d66bba5aea0b1d5beeed4a253deabd942502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec53f7d6df041432268ca9061bb3a49aab3a170a23b43f2d9c4bd0b2e1ea75cf1eac8b13e6d7ecc8de8195a7c4fd3860e206c2c7a28f9766f152ebb0c571fb04
|
7
|
+
data.tar.gz: 1ca58366f50297910aeb7f3086f31c4c561db38ec4c820dd30abcad36eb98e4c8260d16ccd785880c9f4d5a3b46e6f67844e62b2c975938110bdbcea91eb441f
|
data/.travis.yml
CHANGED
data/lib/swiftype/client.rb
CHANGED
@@ -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
|
|
data/lib/swiftype/request.rb
CHANGED
@@ -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
|
data/lib/swiftype/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -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(
|
97
|
-
expect(Timeout).to receive(:timeout).with(
|
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.
|
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-
|
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.
|
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
|