twingly-search 5.1.2 → 5.3.1

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.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci-build-and-install-gem.yml +21 -0
  3. data/.github/workflows/ci.yml +27 -0
  4. data/CHANGELOG.md +58 -0
  5. data/README.md +18 -7
  6. data/examples/find_all_posts_mentioning_github.rb +8 -2
  7. data/lib/twingly/livefeed.rb +2 -0
  8. data/lib/twingly/livefeed/client.rb +5 -3
  9. data/lib/twingly/livefeed/error.rb +6 -1
  10. data/lib/twingly/livefeed/parser.rb +6 -3
  11. data/lib/twingly/livefeed/post.rb +34 -4
  12. data/lib/twingly/livefeed/result.rb +13 -9
  13. data/lib/twingly/livefeed/version.rb +3 -1
  14. data/lib/twingly/search.rb +2 -0
  15. data/lib/twingly/search/client.rb +4 -2
  16. data/lib/twingly/search/error.rb +12 -2
  17. data/lib/twingly/search/parser.rb +6 -3
  18. data/lib/twingly/search/post.rb +34 -4
  19. data/lib/twingly/search/query.rb +10 -3
  20. data/lib/twingly/search/result.rb +11 -5
  21. data/lib/twingly/search/version.rb +3 -1
  22. data/profiler/fixtures/vcr_cassettes/blog_livefeed_100.yml +43 -0
  23. data/profiler/fixtures/vcr_cassettes/blog_search_100.yml +43 -0
  24. data/profiler/profile_helper.rb +18 -0
  25. data/profiler/profile_livefeed.rb +21 -0
  26. data/profiler/profile_search.rb +23 -0
  27. data/spec/client_spec.rb +3 -3
  28. data/spec/error_spec.rb +4 -0
  29. data/spec/fixtures/unauthenticated_api_key_result.xml +3 -0
  30. data/spec/fixtures/unauthorized_api_key_result.xml +3 -3
  31. data/spec/fixtures/vcr_cassettes/search_for_spotify_on_sv_blogs.yml +1301 -565
  32. data/spec/livefeed/client_spec.rb +2 -2
  33. data/spec/livefeed/error_spec.rb +1 -0
  34. data/spec/livefeed/parser_spec.rb +3 -3
  35. data/spec/livefeed/post_spec.rb +47 -0
  36. data/spec/livefeed/result_spec.rb +22 -8
  37. data/spec/parser_spec.rb +11 -3
  38. data/spec/post_spec.rb +48 -0
  39. data/spec/query_spec.rb +6 -6
  40. data/spec/result_spec.rb +20 -6
  41. data/twingly-search-api-ruby.gemspec +8 -6
  42. metadata +60 -20
  43. data/.travis.yml +0 -21
@@ -40,7 +40,7 @@ module Twingly::LiveFeed
40
40
 
41
41
  it do
42
42
  expect { subject }
43
- .to raise_error(AuthError, "No API key has been provided.")
43
+ .to raise_error(AuthenticationError, "No API key has been provided.")
44
44
  end
45
45
  end
46
46
 
@@ -62,7 +62,7 @@ module Twingly::LiveFeed
62
62
  end
63
63
  end
64
64
 
65
- it "should not raise an AuthError" do
65
+ it "should not raise an AuthenticationError" do
66
66
  expect { subject }.not_to raise_exception
67
67
  end
68
68
 
@@ -13,6 +13,7 @@ module Twingly::LiveFeed
13
13
  let(:code) { 401 }
14
14
 
15
15
  it { is_expected.to be_a(AuthError) }
16
+ it { is_expected.to be_a(AuthenticationError) }
16
17
  end
17
18
 
18
19
  context "when given code 400" do
@@ -306,15 +306,15 @@ module Twingly::LiveFeed
306
306
  context "with an unauthorized api key result" do
307
307
  let(:fixture) { :unauthorized_api_key }
308
308
 
309
- it "should raise AuthError" do
310
- expect { subject }.to raise_error(AuthError)
309
+ it "should raise AuthenticationError" do
310
+ expect { subject }.to raise_error(AuthenticationError)
311
311
  end
312
312
  end
313
313
 
314
314
  context "with an empty api key result" do
315
315
  let(:fixture) { :empty_api_key }
316
316
 
317
- it "should raise AuthError" do
317
+ it "should raise QueryError" do
318
318
  expect { subject }.to raise_error(QueryError)
319
319
  end
320
320
  end
@@ -23,4 +23,51 @@ module Twingly::LiveFeed
23
23
  it { should respond_to :blog_rank }
24
24
  it { should respond_to :authority }
25
25
  end
26
+
27
+ describe "#to_h" do
28
+ let(:post) do
29
+ document = Fixture.livefeed_get(:valid)
30
+ result = Parser.new.parse(document)
31
+
32
+ result.posts.first
33
+ end
34
+
35
+ let(:post_hash) do
36
+ post.to_h
37
+ end
38
+
39
+ attributes = %i[
40
+ id
41
+ author
42
+ url
43
+ title
44
+ text
45
+ location_code
46
+ language_code
47
+ coordinates
48
+ links
49
+ tags
50
+ images
51
+ indexed_at
52
+ published_at
53
+ reindexed_at
54
+ inlinks_count
55
+ blog_id
56
+ blog_name
57
+ blog_url
58
+ blog_rank
59
+ authority
60
+ ]
61
+
62
+ it do
63
+ expect(post_hash.keys).to match_array(attributes)
64
+ end
65
+
66
+ attributes.each do |key|
67
+ describe "#to_h[:#{key}]" do
68
+ subject { post_hash[key] }
69
+ it { is_expected.to eq(post.public_send(key)) }
70
+ end
71
+ end
72
+ end
26
73
  end
@@ -2,17 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  module Twingly::LiveFeed
4
4
  describe Result do
5
- it { should respond_to :posts }
6
- it { should respond_to :ts }
7
- it { should respond_to :from }
8
- it { should respond_to :number_of_posts }
9
- it { should respond_to :max_number_of_posts }
10
- it { should respond_to :first_post }
11
- it { should respond_to :last_post }
12
- it { should respond_to :next_timestamp }
5
+ instance_methods = [
6
+ :posts,
7
+ :ts,
8
+ :from,
9
+ :number_of_posts,
10
+ :max_number_of_posts,
11
+ :first_post,
12
+ :last_post,
13
+ :next_timestamp,
14
+ ]
15
+
16
+ instance_methods.each do |method|
17
+ it { should respond_to method }
18
+ end
13
19
 
14
20
  context "before query has populated responses" do
15
21
  its(:posts) { should be_empty }
16
22
  end
23
+
24
+ describe "#inspect" do
25
+ subject { described_class.new.inspect }
26
+
27
+ instance_methods.each do |method|
28
+ it { should match(/ #{Regexp.quote(method)}[,=]/) }
29
+ end
30
+ end
17
31
  end
18
32
  end
data/spec/parser_spec.rb CHANGED
@@ -326,16 +326,24 @@ describe Parser do
326
326
  context "with a nonexistent api key result" do
327
327
  let(:fixture) { :nonexistent_api_key }
328
328
 
329
- it "should raise AuthError" do
329
+ it "should raise QueryError" do
330
330
  expect { subject }.to raise_error(QueryError)
331
331
  end
332
332
  end
333
333
 
334
+ context "with an unauthenticated api key result" do
335
+ let(:fixture) { :unauthenticated_api_key }
336
+
337
+ it "should raise AuthenticationError" do
338
+ expect { subject }.to raise_error(AuthenticationError)
339
+ end
340
+ end
341
+
334
342
  context "with an unauthorized api key result" do
335
343
  let(:fixture) { :unauthorized_api_key }
336
344
 
337
- it "should raise AuthError" do
338
- expect { subject }.to raise_error(AuthError)
345
+ it "should raise AuthenticationError" do
346
+ expect { subject }.to raise_error(AuthorizationError)
339
347
  end
340
348
  end
341
349
 
data/spec/post_spec.rb CHANGED
@@ -23,6 +23,7 @@ describe Post do
23
23
  it { should respond_to :blog_url }
24
24
  it { should respond_to :blog_rank }
25
25
  it { should respond_to :authority }
26
+ it { should respond_to :to_h }
26
27
 
27
28
  deprecated_methods = %i(summary indexed published outlinks)
28
29
  deprecated_methods.each do |method_name|
@@ -33,4 +34,51 @@ describe Post do
33
34
  end
34
35
  end
35
36
  end
37
+
38
+ describe "#to_h" do
39
+ let(:post) do
40
+ document = Fixture.get(:minimal_valid)
41
+ result = Parser.new.parse(document)
42
+
43
+ result.posts.first
44
+ end
45
+
46
+ let(:post_hash) do
47
+ post.to_h
48
+ end
49
+
50
+ attributes = %i[
51
+ id
52
+ author
53
+ url
54
+ title
55
+ text
56
+ location_code
57
+ language_code
58
+ coordinates
59
+ links
60
+ tags
61
+ images
62
+ indexed_at
63
+ published_at
64
+ reindexed_at
65
+ inlinks_count
66
+ blog_id
67
+ blog_name
68
+ blog_url
69
+ blog_rank
70
+ authority
71
+ ]
72
+
73
+ it do
74
+ expect(post_hash.keys).to match_array(attributes)
75
+ end
76
+
77
+ attributes.each do |key|
78
+ describe "#to_h[:#{key}]" do
79
+ subject { post_hash[key] }
80
+ it { is_expected.to eq(post.public_send(key)) }
81
+ end
82
+ end
83
+ end
36
84
  end
data/spec/query_spec.rb CHANGED
@@ -91,7 +91,7 @@ describe Query do
91
91
  let(:time) { Time.parse(timestamp) }
92
92
 
93
93
  it "should not change timezone" do
94
- expect(subject.request_parameters.fetch(:q)).to include("2016-02-09T09:01:22Z")
94
+ expect(subject.request_parameters.fetch(:q)).to include("2016-02-09T09:01:22")
95
95
  end
96
96
 
97
97
  it "should not modify the given time object" do
@@ -117,7 +117,7 @@ describe Query do
117
117
  let(:time) { Time.parse(timestamp) }
118
118
 
119
119
  it "should convert to UTC" do
120
- expect(subject.request_parameters.fetch(:q)).to include("2016-02-09T04:01:22Z")
120
+ expect(subject.request_parameters.fetch(:q)).to include("2016-02-09T04:01:22")
121
121
  end
122
122
 
123
123
  it "should not modify the given time object" do
@@ -158,7 +158,7 @@ describe Query do
158
158
  let(:time) { Time.parse(timestamp) }
159
159
 
160
160
  it "should not change timezone" do
161
- expect(subject.request_parameters.fetch(:q)).to include("end-date:2016-02-09T09:01:22Z")
161
+ expect(subject.request_parameters.fetch(:q)).to include("end-date:2016-02-09T09:01:22")
162
162
  end
163
163
 
164
164
  it "should not modify the given time object" do
@@ -184,7 +184,7 @@ describe Query do
184
184
  let(:time) { Time.parse(timestamp) }
185
185
 
186
186
  it "should convert to UTC" do
187
- expect(subject.request_parameters.fetch(:q)).to include("end-date:2016-02-09T04:01:22Z")
187
+ expect(subject.request_parameters.fetch(:q)).to include("end-date:2016-02-09T04:01:22")
188
188
  end
189
189
 
190
190
  it "should not modify the given time object" do
@@ -219,9 +219,9 @@ describe Query do
219
219
  expect(subject.request_parameters.fetch(:q)).to include("lang:en")
220
220
  end
221
221
 
222
- it "should encode url paramters" do
222
+ it "should encode url parameters" do
223
223
  subject.end_time = Time.parse("2013-12-28 09:01:22 UTC")
224
- expect(subject.url_parameters).to include('end-date%3A2013-12-28T09%3A01%3A22Z')
224
+ expect(subject.url_parameters).to include('end-date%3A2013-12-28T09%3A01%3A22')
225
225
  end
226
226
  end
227
227
 
data/spec/result_spec.rb CHANGED
@@ -5,15 +5,29 @@ require 'uri'
5
5
  include Twingly::Search
6
6
 
7
7
  describe Result do
8
- it { should respond_to :posts }
9
- it { should respond_to :number_of_matches_returned }
10
- it { should respond_to :number_of_matches_total }
11
- it { should respond_to :seconds_elapsed }
12
- it { should respond_to :all_results_returned? }
13
- it { should respond_to :incomplete? }
8
+ instance_methods = [
9
+ :posts,
10
+ :number_of_matches_returned,
11
+ :number_of_matches_total,
12
+ :seconds_elapsed,
13
+ :all_results_returned?,
14
+ :incomplete?,
15
+ ]
16
+
17
+ instance_methods.each do |method|
18
+ it { should respond_to method }
19
+ end
14
20
 
15
21
  context "before query has populated responses" do
16
22
  its(:posts) { should be_empty }
17
23
  its(:all_results_returned?) { should be_truthy }
18
24
  end
25
+
26
+ describe "#inspect" do
27
+ subject { described_class.new.inspect }
28
+
29
+ instance_methods.each do |method|
30
+ it { should match(/ #{Regexp.quote(method)}[,=]/) }
31
+ end
32
+ end
19
33
  end
@@ -13,18 +13,20 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = "Ruby API client for Twingly Search"
14
14
  spec.description = "Twingly Search is a product from Twingly AB"
15
15
  spec.license = 'MIT'
16
- spec.required_ruby_version = ">= 2.1.0"
16
+ spec.required_ruby_version = ">= 2.5.0"
17
17
 
18
18
  spec.files = `git ls-files`.split($/)
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "faraday", ['>= 0.9.2', '< 0.10']
22
+ spec.add_dependency "faraday", [">= 0.9.2", "< 2.0"]
23
23
  spec.add_dependency "nokogiri", "~> 1.0"
24
24
  spec.add_development_dependency "rspec", "~> 3"
25
25
  spec.add_development_dependency "rspec-its", "~> 1"
26
- spec.add_development_dependency "vcr", "~> 2.6"
27
- spec.add_development_dependency "webmock", "~> 1.0"
28
- spec.add_development_dependency "rake", "~> 11"
29
- spec.add_development_dependency "yard", "~> 0.8"
26
+ spec.add_development_dependency "vcr", "~> 4.0"
27
+ spec.add_development_dependency "webmock", "~> 3.4"
28
+ spec.add_development_dependency "rake", "~> 12"
29
+ spec.add_development_dependency "yard", [">= 0.9.11", "< 1.0.0"]
30
+ spec.add_development_dependency "memory_profiler", "~> 0.9"
31
+ spec.add_development_dependency "rubocop", "~> 0.66.0"
30
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twingly-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Twingly AB
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-29 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 0.9.2
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '0.10'
22
+ version: '2.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 0.9.2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.10'
32
+ version: '2.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: nokogiri
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -78,56 +78,90 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '2.6'
81
+ version: '4.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '2.6'
88
+ version: '4.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: webmock
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.0'
95
+ version: '3.4'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.0'
102
+ version: '3.4'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '11'
109
+ version: '12'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '11'
116
+ version: '12'
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: yard
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 0.9.11
124
+ - - "<"
125
+ - !ruby/object:Gem::Version
126
+ version: 1.0.0
127
+ type: :development
128
+ prerelease: false
129
+ version_requirements: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 0.9.11
134
+ - - "<"
135
+ - !ruby/object:Gem::Version
136
+ version: 1.0.0
137
+ - !ruby/object:Gem::Dependency
138
+ name: memory_profiler
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '0.9'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '0.9'
151
+ - !ruby/object:Gem::Dependency
152
+ name: rubocop
119
153
  requirement: !ruby/object:Gem::Requirement
120
154
  requirements:
121
155
  - - "~>"
122
156
  - !ruby/object:Gem::Version
123
- version: '0.8'
157
+ version: 0.66.0
124
158
  type: :development
125
159
  prerelease: false
126
160
  version_requirements: !ruby/object:Gem::Requirement
127
161
  requirements:
128
162
  - - "~>"
129
163
  - !ruby/object:Gem::Version
130
- version: '0.8'
164
+ version: 0.66.0
131
165
  description: Twingly Search is a product from Twingly AB
132
166
  email:
133
167
  - support@twingly.com
@@ -135,8 +169,9 @@ executables: []
135
169
  extensions: []
136
170
  extra_rdoc_files: []
137
171
  files:
172
+ - ".github/workflows/ci-build-and-install-gem.yml"
173
+ - ".github/workflows/ci.yml"
138
174
  - ".gitignore"
139
- - ".travis.yml"
140
175
  - CHANGELOG.md
141
176
  - Gemfile
142
177
  - LICENSE
@@ -161,6 +196,11 @@ files:
161
196
  - lib/twingly/search/query.rb
162
197
  - lib/twingly/search/result.rb
163
198
  - lib/twingly/search/version.rb
199
+ - profiler/fixtures/vcr_cassettes/blog_livefeed_100.yml
200
+ - profiler/fixtures/vcr_cassettes/blog_search_100.yml
201
+ - profiler/profile_helper.rb
202
+ - profiler/profile_livefeed.rb
203
+ - profiler/profile_search.rb
164
204
  - spec/client_spec.rb
165
205
  - spec/error_spec.rb
166
206
  - spec/fixtures/incomplete_result.xml
@@ -175,6 +215,7 @@ files:
175
215
  - spec/fixtures/non_xml_result.xml
176
216
  - spec/fixtures/nonexistent_api_key_result.xml
177
217
  - spec/fixtures/service_unavailable_result.xml
218
+ - spec/fixtures/unauthenticated_api_key_result.xml
178
219
  - spec/fixtures/unauthorized_api_key_result.xml
179
220
  - spec/fixtures/undefined_error_result.xml
180
221
  - spec/fixtures/valid_coordinates_result.xml
@@ -199,7 +240,7 @@ homepage: https://github.com/twingly/twingly-search-api-ruby
199
240
  licenses:
200
241
  - MIT
201
242
  metadata: {}
202
- post_install_message:
243
+ post_install_message:
203
244
  rdoc_options: []
204
245
  require_paths:
205
246
  - lib
@@ -207,16 +248,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
248
  requirements:
208
249
  - - ">="
209
250
  - !ruby/object:Gem::Version
210
- version: 2.1.0
251
+ version: 2.5.0
211
252
  required_rubygems_version: !ruby/object:Gem::Requirement
212
253
  requirements:
213
254
  - - ">="
214
255
  - !ruby/object:Gem::Version
215
256
  version: '0'
216
257
  requirements: []
217
- rubyforge_project:
218
- rubygems_version: 2.5.2
219
- signing_key:
258
+ rubygems_version: 3.1.4
259
+ signing_key:
220
260
  specification_version: 4
221
261
  summary: Ruby API client for Twingly Search
222
262
  test_files:
@@ -234,6 +274,7 @@ test_files:
234
274
  - spec/fixtures/non_xml_result.xml
235
275
  - spec/fixtures/nonexistent_api_key_result.xml
236
276
  - spec/fixtures/service_unavailable_result.xml
277
+ - spec/fixtures/unauthenticated_api_key_result.xml
237
278
  - spec/fixtures/unauthorized_api_key_result.xml
238
279
  - spec/fixtures/undefined_error_result.xml
239
280
  - spec/fixtures/valid_coordinates_result.xml
@@ -253,4 +294,3 @@ test_files:
253
294
  - spec/result_spec.rb
254
295
  - spec/spec_helper.rb
255
296
  - spec/vcr_setup.rb
256
- has_rdoc: