parliament-opensearch 0.2.2 → 0.2.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89764f0e23de18af2c597be14a52198dc7011e16
|
4
|
+
data.tar.gz: 95f44a316c601778ad1fd466757b2b9b5deec1ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d48aa35039abcee3cef6731d79af106f020b306098f11e01bca5bec6e49f16aecf7415d65613ce680dfa944b2f8a467a4236fe788aac86a51f67ace2d2c1df
|
7
|
+
data.tar.gz: acb15d5c8218eb7fd4d817f9dfe01683c734b3fff359b6c7cea1a59723d08e219bd3e617152d9ce69252c8f7b96ac67ca4b3ec94641d8f29c682b8f14f8dadc4
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Parliament
|
2
|
+
module OpenSearch
|
3
|
+
# An error raised when there is an issue processing an OpenSearch description file.
|
4
|
+
# This could be raised when the URL provided is invalid, or when we are unable to find a URL template for future requests.
|
5
|
+
#
|
6
|
+
# @attr_reader url the description url that caused the Parliament::OpenSearchDescriptionError.
|
7
|
+
#
|
8
|
+
# @since 0.2.3
|
9
|
+
class DescriptionError < StandardError
|
10
|
+
attr_reader :url
|
11
|
+
|
12
|
+
# @param [String] description_url the description url that caused the Parliament::OpenSearchDescriptionError.
|
13
|
+
def initialize(description_url)
|
14
|
+
@url = description_url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -15,16 +15,20 @@ module Parliament
|
|
15
15
|
|
16
16
|
# Creates a new instance of Parliament::OpenSearch::Request.
|
17
17
|
#
|
18
|
-
# An interesting note for #initialize is that setting
|
19
|
-
#
|
20
|
-
#
|
18
|
+
# An interesting note for #initialize is that setting description_url on the class means you don't need to pass in a description_url.
|
19
|
+
# You can pass one anyway to override the class parameter. Similarly, headers can be set by either settings the headers on the class,
|
20
|
+
# or passing headers in.
|
21
21
|
#
|
22
22
|
# @see Parliament::BaseRequest#initialize
|
23
|
-
# @param [String]
|
23
|
+
# @param [String] description_url the url for the OpenSearch API description file. (expected: http://example.com/description.xml - without the trailing slash).
|
24
24
|
# @param [Hash] headers the headers being sent in the request.
|
25
25
|
# @param [Parliament::OpenSearch::Builder] builder the builder required to create the response.
|
26
|
-
def initialize(
|
27
|
-
@
|
26
|
+
def initialize(description_url: nil, headers: nil, builder: nil)
|
27
|
+
@description_url = description_url
|
28
|
+
|
29
|
+
raise Parliament::OpenSearch::DescriptionError.new(@description_url), 'No description URL passed to Parliament::OpenSearchRequest#new and, no Parliament::OpenSearchRequest#base_url value set. Without a description URL, we are unable to make any search requests.' if @description_url.nil? && self.class.base_url.nil?
|
30
|
+
|
31
|
+
@base_url = Parliament::Request::OpenSearchRequest.get_description(@description_url) || self.class.base_url
|
28
32
|
@open_search_parameters = self.class.open_search_parameters
|
29
33
|
|
30
34
|
super(base_url: @base_url, headers: headers, builder: builder)
|
@@ -46,10 +50,11 @@ module Parliament
|
|
46
50
|
# @attr [String] base_url the base url for the OpenSearch API description. (expected: http://example.com - without the trailing slash).
|
47
51
|
# @attr [Hash] open_search_parameters the possible parameters to use in the query url.
|
48
52
|
class << self
|
49
|
-
attr_reader :
|
53
|
+
attr_reader :description_url, :base_url
|
50
54
|
|
51
|
-
def
|
52
|
-
@
|
55
|
+
def description_url=(description_url)
|
56
|
+
@description_url = description_url
|
57
|
+
@base_url = Parliament::Request::OpenSearchRequest.get_description(@description_url)
|
53
58
|
end
|
54
59
|
|
55
60
|
def open_search_parameters
|
@@ -59,12 +64,26 @@ module Parliament
|
|
59
64
|
def get_description(url)
|
60
65
|
return if url.nil?
|
61
66
|
|
67
|
+
begin
|
68
|
+
URI.parse(url)
|
69
|
+
rescue URI::InvalidURIError => e
|
70
|
+
raise Parliament::OpenSearch::DescriptionError.new(url), "Invalid description URI passed '#{url}': #{e.message}"
|
71
|
+
end
|
72
|
+
|
62
73
|
request = Parliament::Request::BaseRequest.new(base_url: url,
|
63
74
|
headers: {'Accept' => 'application/opensearchdescription+xml'})
|
64
75
|
xml_response = request.get
|
65
76
|
|
66
|
-
|
67
|
-
|
77
|
+
begin
|
78
|
+
xml_root = REXML::Document.new(xml_response.body).root
|
79
|
+
template = xml_root.elements['Url'].attributes['template']
|
80
|
+
|
81
|
+
raise Parliament::OpenSearch::DescriptionError.new(url), "The document found does not contain a require node. Attempted to get a 'Url' element with the attribute 'template'. Please check the description document at '#{url}' and try again." if template.nil?
|
82
|
+
rescue NoMethodError
|
83
|
+
raise Parliament::OpenSearch::DescriptionError.new(url), "The document found does not appear to be XML. Please check the description document at '#{url}' and try again."
|
84
|
+
end
|
85
|
+
|
86
|
+
template
|
68
87
|
end
|
69
88
|
end
|
70
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parliament-opensearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rebecca Appleyard
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-04-
|
12
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: feedjira
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- bin/setup
|
166
166
|
- lib/parliament/builder/open_search_response_builder.rb
|
167
167
|
- lib/parliament/open_search.rb
|
168
|
+
- lib/parliament/open_search/description_error.rb
|
168
169
|
- lib/parliament/open_search/version.rb
|
169
170
|
- lib/parliament/request/open_search_request.rb
|
170
171
|
- parliament-opensearch.gemspec
|