gds-api-adapters 6.1.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,14 +4,9 @@ require 'rack/utils'
4
4
  module GdsApi
5
5
  class Rummager < Base
6
6
 
7
- def search(query, format_filter = nil)
7
+ def search(query, extra_params={})
8
8
  return [] if query.nil? || query == ""
9
- get_json!(search_url(:search, query, format_filter))
10
- end
11
-
12
- def autocomplete(query, format_filter = nil)
13
- return [] if query.nil? || query == ""
14
- get_raw!(search_url(:autocomplete, query, format_filter)).body
9
+ get_json!(search_url(:search, query, extra_params))
15
10
  end
16
11
 
17
12
  def advanced_search(args)
@@ -22,9 +17,12 @@ module GdsApi
22
17
 
23
18
  private
24
19
 
25
- def search_url(type, query, format_filter = nil)
20
+ def search_url(type, query, extra_params={})
26
21
  request_path = "#{base_url}/#{type}?q=#{CGI.escape(query)}"
27
- request_path << "&format_filter=#{CGI.escape(format_filter)}" if format_filter
22
+ if extra_params
23
+ request_path << "&"
24
+ request_path << Rack::Utils.build_query(extra_params)
25
+ end
28
26
  request_path
29
27
  end
30
28
 
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '6.1.0'
2
+ VERSION = '7.0.0'
3
3
  end
@@ -4,7 +4,6 @@ require "gds_api/rummager"
4
4
  describe GdsApi::Rummager do
5
5
  before(:each) do
6
6
  stub_request(:get, /example.com\/search/).to_return(body: "[]")
7
- stub_request(:get, /example.com\/autocomplete/).to_return(body: "[]")
8
7
  stub_request(:get, /example.com\/advanced_search/).to_return(body: "[]")
9
8
  end
10
9
 
@@ -63,18 +62,6 @@ describe GdsApi::Rummager do
63
62
  assert_requested :get, /\?q=search-term/
64
63
  end
65
64
 
66
- it "should add a format filter parameter to searches if provided" do
67
- GdsApi::Rummager.new("http://example.com").search "search-term", "specialist_guidance"
68
-
69
- assert_requested :get, /format_filter=specialist_guidance/
70
- end
71
-
72
- it "should add a format filter parameter to autocomplete if provided" do
73
- GdsApi::Rummager.new("http://example.com").autocomplete "search-term", "specialist_guidance"
74
-
75
- assert_requested :get, /format_filter=specialist_guidance/
76
- end
77
-
78
65
  it "should escape characters that would otherwise be invalid in a URI" do
79
66
  GdsApi::Rummager.new("http://example.com").search "search term with spaces"
80
67
 
@@ -82,12 +69,10 @@ describe GdsApi::Rummager do
82
69
  assert_requested :get, /\?q=search%20term%20with%20spaces/
83
70
  end
84
71
 
85
- it "should pass autocomplete responses back as-is" do
86
- search_results_json = {"title" => "document-title"}.to_json
87
- stub_request(:get, /example.com\/autocomplete/).to_return(body: search_results_json)
88
- results = GdsApi::Rummager.new("http://example.com").autocomplete("test")
72
+ it "should append arbitrary parameters when supplied" do
73
+ GdsApi::Rummager.new("http://example.com").search("search-term", foo: "bar", zoo: "baz")
89
74
 
90
- assert_equal search_results_json, results
75
+ assert_requested :get, /\?foo=bar&q=search-term&zoo=baz/
91
76
  end
92
77
 
93
78
  # tests for #advanced_search
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 6.1.0
5
+ version: 7.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Stewart
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-05-24 00:00:00 Z
13
+ date: 2013-06-03 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -254,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
254
254
  requirements:
255
255
  - - ">="
256
256
  - !ruby/object:Gem::Version
257
- hash: -673475242320565941
257
+ hash: 3315844948382405852
258
258
  segments:
259
259
  - 0
260
260
  version: "0"
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  requirements:
264
264
  - - ">="
265
265
  - !ruby/object:Gem::Version
266
- hash: -673475242320565941
266
+ hash: 3315844948382405852
267
267
  segments:
268
268
  - 0
269
269
  version: "0"