Skip to content

Commit ed6909f

Browse files
committed
Deprecate Query#language
#65 (review)
1 parent c6bd806 commit ed6909f

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/twingly/search/query.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ module Search
66
# Twingly Search API query
77
#
88
# @attr [String] search_query the search query.
9-
# @attr [String] language language to restrict the query to.
109
# @attr [Client] client the client that this query is connected to.
1110
class Query
12-
attr_accessor :search_query, :language, :client
11+
attr_accessor :search_query, :client
1312

1413
# @deprecated Please use {#search_query} instead
1514
def pattern
@@ -23,6 +22,18 @@ def pattern=(search_query)
2322
@search_query = search_query
2423
end
2524

25+
# @deprecated Please use {#search_query} instead
26+
def language
27+
warn "[DEPRECATION] `language` is deprecated. Please use `search_query` instead."
28+
@language
29+
end
30+
31+
# @deprecated Please use {#search_query=} instead
32+
def language=(language_code)
33+
warn "[DEPRECATION] `language=` is deprecated. Please use `search_query=` instead."
34+
@language = language_code
35+
end
36+
2637
# @return [Time] the time that was set with {#start_time=}.
2738
def start_time
2839
@start_time
@@ -66,7 +77,7 @@ def url_parameters
6677
# @return [Hash] the request parameters.
6778
def request_parameters
6879
full_search_query = search_query.to_s.dup
69-
full_search_query << " lang:#{language}" if language
80+
full_search_query << " lang:#{@language}" unless @language.to_s.empty?
7081
full_search_query << " start-date:#{formatted_start_date}" if start_time
7182
full_search_query << " end-date:#{formatted_end_date}" if end_time
7283

spec/query_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
it { expect { subject.pattern = "test" }.to output(/deprecated/).to_stderr }
2424
end
2525

26+
describe "#language" do
27+
it { expect { subject.language }.to output(/deprecated/).to_stderr }
28+
it { expect { subject.language = "en" }.to output(/deprecated/).to_stderr }
29+
30+
it "should be included in the search query" do
31+
subject.language = "no"
32+
expect(subject.request_parameters.fetch(:q)).to include("lang:no")
33+
end
34+
end
35+
2636
describe ".new" do
2737
context "without client" do
2838
subject { described_class.new }

0 commit comments

Comments
 (0)