gds-api-adapters 22.0.0 → 23.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/rummager.rb +0 -14
- data/lib/gds_api/version.rb +1 -1
- data/test/rummager_test.rb +0 -67
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ea6ab5e0f8cd1e6568d3588d21b9918c7818a65
|
4
|
+
data.tar.gz: 57953905ccbcd5453f4acc5548248a02b57e1fa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fed21cbb734110e486fe6e390a4e8960b4f018d886643a76cd1d75c91ca076a87fd052103c5c982afc287b869c83336d60da7e6a60bcd66ca7f43f3ba6c6db32
|
7
|
+
data.tar.gz: e2f4fdf14f51fe5ece8d45ffd822b4c4f1fcbc393a3d601bf224a89a6c94bacea7ccf941f20b0e9b0ed8db0ddc045e255da3a0930e3740233c0f3e4947fca885
|
data/lib/gds_api/rummager.rb
CHANGED
@@ -4,11 +4,6 @@ require 'rack/utils'
|
|
4
4
|
module GdsApi
|
5
5
|
class Rummager < Base
|
6
6
|
|
7
|
-
def search(query, extra_params={})
|
8
|
-
raise ArgumentError.new("Query cannot be blank") if query.nil? || query.strip.empty?
|
9
|
-
get_json!(search_url(:search, query, extra_params))
|
10
|
-
end
|
11
|
-
|
12
7
|
def unified_search(args)
|
13
8
|
request_url = "#{base_url}/unified_search.json?#{Rack::Utils.build_nested_query(args)}"
|
14
9
|
get_json!(request_url)
|
@@ -43,15 +38,6 @@ module GdsApi
|
|
43
38
|
|
44
39
|
private
|
45
40
|
|
46
|
-
def search_url(type, query, extra_params={})
|
47
|
-
request_path = "#{base_url}/#{type}?q=#{CGI.escape(query)}"
|
48
|
-
if extra_params
|
49
|
-
request_path << "&"
|
50
|
-
request_path << Rack::Utils.build_query(extra_params)
|
51
|
-
end
|
52
|
-
request_path
|
53
|
-
end
|
54
|
-
|
55
41
|
def base_url
|
56
42
|
endpoint
|
57
43
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/test/rummager_test.rb
CHANGED
@@ -3,77 +3,10 @@ require "gds_api/rummager"
|
|
3
3
|
|
4
4
|
describe GdsApi::Rummager do
|
5
5
|
before(:each) do
|
6
|
-
stub_request(:get, /example.com\/search/).to_return(body: "[]")
|
7
6
|
stub_request(:get, /example.com\/advanced_search/).to_return(body: "[]")
|
8
7
|
stub_request(:get, /example.com\/unified_search/).to_return(body: "[]")
|
9
8
|
end
|
10
9
|
|
11
|
-
it "should raise an exception if the service at the search URI returns a 500" do
|
12
|
-
stub_request(:get, /example.com\/search/).to_return(status: [500, "Internal Server Error"])
|
13
|
-
assert_raises(GdsApi::HTTPServerError) do
|
14
|
-
GdsApi::Rummager.new("http://example.com").search("query")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should raise an exception if the service at the search URI returns a 404" do
|
19
|
-
stub_request(:get, /example.com\/search/).to_return(status: [404, "Not Found"])
|
20
|
-
assert_raises(GdsApi::HTTPNotFound) do
|
21
|
-
GdsApi::Rummager.new("http://example.com").search("query")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should raise an exception if the service at the search URI times out" do
|
26
|
-
stub_request(:get, /example.com\/search/).to_timeout
|
27
|
-
assert_raises(GdsApi::TimedOutException) do
|
28
|
-
GdsApi::Rummager.new("http://example.com").search("query")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return the search deserialized from json" do
|
33
|
-
search_results = [{"title" => "document-title"}]
|
34
|
-
stub_request(:get, /example.com\/search/).to_return(body: search_results.to_json)
|
35
|
-
results = GdsApi::Rummager.new("http://example.com").search("query")
|
36
|
-
|
37
|
-
assert_equal search_results, results.to_hash
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should return an empty set of results without making request if query is empty" do
|
41
|
-
assert_raises(ArgumentError) do
|
42
|
-
GdsApi::Rummager.new("http://example.com").search("")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should return an empty set of results without making request if query is nil" do
|
47
|
-
assert_raises(ArgumentError) do
|
48
|
-
GdsApi::Rummager.new("http://example.com").search(nil)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should request the search results in JSON format" do
|
53
|
-
GdsApi::Rummager.new("http://example.com").search("query")
|
54
|
-
|
55
|
-
assert_requested :get, /.*/, headers: {"Accept" => "application/json"}
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should issue a request for the search term specified" do
|
59
|
-
GdsApi::Rummager.new("http://example.com").search "search-term"
|
60
|
-
|
61
|
-
assert_requested :get, /\?q=search-term/
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should escape characters that would otherwise be invalid in a URI" do
|
65
|
-
GdsApi::Rummager.new("http://example.com").search "search term with spaces"
|
66
|
-
|
67
|
-
#the actual request is "?q=search+term+with+spaces", but Webmock appears to be re-escaping.
|
68
|
-
assert_requested :get, /\?q=search%20term%20with%20spaces/
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should append arbitrary parameters when supplied" do
|
72
|
-
GdsApi::Rummager.new("http://example.com").search("search-term", foo: "bar", zoo: "baz")
|
73
|
-
|
74
|
-
assert_requested :get, /\?foo=bar&q=search-term&zoo=baz/
|
75
|
-
end
|
76
|
-
|
77
10
|
# tests for #organisations
|
78
11
|
|
79
12
|
it "should request the list of organisations" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 23.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|