twingly-search 4.0.0 → 4.0.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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +1 -1
- data/lib/twingly/search/parser.rb +1 -1
- data/lib/twingly/search/version.rb +1 -1
- data/spec/client_spec.rb +32 -31
- data/spec/error_spec.rb +1 -1
- data/spec/fixtures/valid_non_blog_result.xml +26 -0
- data/spec/parser_spec.rb +16 -7
- data/spec/query_spec.rb +9 -10
- data/spec/result_spec.rb +1 -0
- data/twingly-search-api-ruby.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a62fb19132e1def965555e328f84667e5588a4c3
|
4
|
+
data.tar.gz: 9d04745eba432e6d60676c9ff5ce517d20f539fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d2c2e6d94f4748e78bb355d60376afa52abda4249bee1ccd1654c8a5e16995baf7d5b272ce09748c5eead3f777d4d41a3db48c4256b1e0fe93ae9232413a24a
|
7
|
+
data.tar.gz: 6094058ff17173434ee61da5251f47d9777625e6a49a2485b64741925ef192f9120170263f6d79d093b1a4d42752ba75c446529c3805c096282d715e036c7d26
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -49,7 +49,7 @@ To learn more about the capabilities of the API, please read the [Twingly Search
|
|
49
49
|
|
50
50
|
## Requirements
|
51
51
|
|
52
|
-
* API key, contact sales@twingly.com via [twingly.com](
|
52
|
+
* API key, contact sales@twingly.com via [twingly.com](https://www.twingly.com/try-for-free/) to get one
|
53
53
|
* Ruby
|
54
54
|
* Ruby 1.9, 2.0, 2.1, 2.2
|
55
55
|
* JRuby 9000
|
@@ -28,7 +28,7 @@ module Twingly
|
|
28
28
|
result.number_of_matches_total = data_node.attribute('numberOfMatchesTotal').value.to_i
|
29
29
|
result.seconds_elapsed = data_node.attribute('secondsElapsed').value.to_f
|
30
30
|
|
31
|
-
data_node.xpath('//post').each do |post|
|
31
|
+
data_node.xpath('//post[@contentType="blog"]').each do |post|
|
32
32
|
result.posts << parse_post(post)
|
33
33
|
end
|
34
34
|
|
data/spec/client_spec.rb
CHANGED
@@ -1,44 +1,36 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
include Twingly::Search
|
4
4
|
|
5
5
|
describe Client do
|
6
|
-
|
6
|
+
let(:valid_api_key) { "api_key" }
|
7
7
|
|
8
8
|
describe ".new" do
|
9
|
-
context
|
10
|
-
|
11
|
-
end
|
9
|
+
context "with API key as argument" do
|
10
|
+
subject { described_class.new(valid_api_key) }
|
12
11
|
|
13
|
-
|
14
|
-
expect(URI(Client::BASE_URL).to_s).to eq(Client::BASE_URL)
|
12
|
+
it { should be_a Twingly::Search::Client }
|
15
13
|
end
|
16
14
|
|
17
|
-
context
|
18
|
-
before {
|
19
|
-
subject { Client.new }
|
20
|
-
it { should be_a Client }
|
21
|
-
end
|
15
|
+
context "without API key as argument" do
|
16
|
+
before { expect_any_instance_of(described_class).to receive(:env_api_key).and_return(valid_api_key) }
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it { expect { subject }.to raise_error(AuthError, "No API key has been provided.") }
|
18
|
+
it "should be read from the environment" do
|
19
|
+
described_class.new
|
20
|
+
end
|
27
21
|
end
|
28
22
|
|
29
|
-
context "with
|
30
|
-
|
31
|
-
subject {
|
23
|
+
context "with no API key at all" do
|
24
|
+
before { expect_any_instance_of(described_class).to receive(:env_api_key).and_return(nil) }
|
25
|
+
subject { described_class.new }
|
32
26
|
|
33
|
-
it "
|
34
|
-
expect(subject.user_agent).to eq(user_agent)
|
35
|
-
end
|
27
|
+
it { expect { subject }.to raise_error(AuthError, "No API key has been provided.") }
|
36
28
|
end
|
37
29
|
|
38
30
|
context "with block" do
|
39
31
|
it "should yield self" do
|
40
32
|
yielded_client = nil
|
41
|
-
client =
|
33
|
+
client = described_class.new(valid_api_key) do |c|
|
42
34
|
yielded_client = c
|
43
35
|
end
|
44
36
|
|
@@ -46,10 +38,9 @@ describe Client do
|
|
46
38
|
end
|
47
39
|
|
48
40
|
context "when api key gets set in block" do
|
49
|
-
before { allow_any_instance_of(Client).to receive(:env_api_key).and_return(nil) }
|
50
41
|
let(:api_key) { "api_key_from_block" }
|
51
42
|
subject do
|
52
|
-
|
43
|
+
described_class.new do |client|
|
53
44
|
client.api_key = api_key
|
54
45
|
end
|
55
46
|
end
|
@@ -63,14 +54,23 @@ describe Client do
|
|
63
54
|
end
|
64
55
|
end
|
65
56
|
end
|
57
|
+
|
58
|
+
context "with optional :user_agent given" do
|
59
|
+
let(:user_agent) { "TwinglySearchTest/1.0" }
|
60
|
+
subject { described_class.new(valid_api_key, user_agent: user_agent) }
|
61
|
+
|
62
|
+
it "should use that user agent" do
|
63
|
+
expect(subject.user_agent).to eq(user_agent)
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe
|
69
|
-
subject {
|
68
|
+
describe "#query" do
|
69
|
+
subject { described_class.new(valid_api_key).query }
|
70
70
|
it { should be_a Query }
|
71
71
|
|
72
72
|
context "with block" do
|
73
|
-
subject {
|
73
|
+
subject { described_class.new(valid_api_key) }
|
74
74
|
|
75
75
|
it "should yield the query" do
|
76
76
|
yielded_query = nil
|
@@ -85,7 +85,8 @@ describe Client do
|
|
85
85
|
|
86
86
|
describe "#execute_query" do
|
87
87
|
context "with invalid API key" do
|
88
|
-
|
88
|
+
let(:invalid_api_key) { "wrong" }
|
89
|
+
subject { described_class.new(invalid_api_key) }
|
89
90
|
|
90
91
|
let(:query) do
|
91
92
|
query = subject.query
|
@@ -102,8 +103,8 @@ describe Client do
|
|
102
103
|
end
|
103
104
|
|
104
105
|
describe "#endpoint_url" do
|
105
|
-
subject {
|
106
|
-
let(:expected) { "#{
|
106
|
+
subject { described_class.new(valid_api_key).endpoint_url }
|
107
|
+
let(:expected) { "#{described_class::BASE_URL}#{described_class::SEARCH_PATH}" }
|
107
108
|
|
108
109
|
it { is_expected.to eq(expected) }
|
109
110
|
|
data/spec/error_spec.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><twinglydata numberOfMatchesReturned="2" secondsElapsed="0.022" numberOfMatchesTotal="2">
|
2
|
+
<post contentType="newspaper">
|
3
|
+
<url>http://www.someurl.com/post</url>
|
4
|
+
<title>Title</title>
|
5
|
+
<summary>Summary</summary>
|
6
|
+
<languageCode>sv</languageCode>
|
7
|
+
<published>2013-01-29 15:26:33Z</published>
|
8
|
+
<indexed>2013-01-29 15:27:07Z</indexed>
|
9
|
+
<blogUrl>http://www.someurl.com/</blogUrl>
|
10
|
+
<blogName>Newspaper Name</blogName>
|
11
|
+
<authority>0</authority>
|
12
|
+
<blogRank>1</blogRank>
|
13
|
+
</post>
|
14
|
+
<post contentType="blog">
|
15
|
+
<url>http://www.someotherurl.com/post</url>
|
16
|
+
<title>Title</title>
|
17
|
+
<summary>Summary</summary>
|
18
|
+
<languageCode>sv</languageCode>
|
19
|
+
<published>2013-01-29 15:26:33Z</published>
|
20
|
+
<indexed>2013-01-29 15:27:07Z</indexed>
|
21
|
+
<blogUrl>http://www.someotherurl.com/</blogUrl>
|
22
|
+
<blogName>Blog Name</blogName>
|
23
|
+
<authority>0</authority>
|
24
|
+
<blogRank>1</blogRank>
|
25
|
+
</post>
|
26
|
+
</twinglydata>
|
data/spec/parser_spec.rb
CHANGED
@@ -6,16 +6,25 @@ describe Parser do
|
|
6
6
|
it { should respond_to(:parse) }
|
7
7
|
|
8
8
|
describe "#parse" do
|
9
|
-
subject {
|
9
|
+
subject { described_class.new.parse(document) }
|
10
|
+
let(:document) { Fixture.get(fixture) }
|
10
11
|
|
11
12
|
context "with a valid result" do
|
12
|
-
let(:
|
13
|
+
let(:fixture) { :valid }
|
13
14
|
|
14
15
|
it { is_expected.to be_a Result }
|
15
16
|
end
|
16
17
|
|
18
|
+
context "with a valid result containing non-blogs" do
|
19
|
+
let(:fixture) { :valid_non_blog }
|
20
|
+
|
21
|
+
it "should exclude the non-blog entries" do
|
22
|
+
expect(subject.posts.size).to eq(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
17
26
|
context "with a nonexistent api key result" do
|
18
|
-
let(:
|
27
|
+
let(:fixture) { :nonexistent_api_key }
|
19
28
|
|
20
29
|
it "should raise AuthError" do
|
21
30
|
expect { subject }.to raise_error(AuthError)
|
@@ -23,7 +32,7 @@ describe Parser do
|
|
23
32
|
end
|
24
33
|
|
25
34
|
context "with an unauthorized api key result" do
|
26
|
-
let(:
|
35
|
+
let(:fixture) { :unauthorized_api_key }
|
27
36
|
|
28
37
|
it "should raise AuthError" do
|
29
38
|
expect { subject }.to raise_error(AuthError)
|
@@ -31,7 +40,7 @@ describe Parser do
|
|
31
40
|
end
|
32
41
|
|
33
42
|
context "with a service unavailable result" do
|
34
|
-
let(:
|
43
|
+
let(:fixture) { :service_unavailable }
|
35
44
|
|
36
45
|
it "should raise ServerError" do
|
37
46
|
expect { subject }.to raise_error(ServerError)
|
@@ -39,7 +48,7 @@ describe Parser do
|
|
39
48
|
end
|
40
49
|
|
41
50
|
context "with a undefined error result" do
|
42
|
-
let(:
|
51
|
+
let(:fixture) { :undefined_error }
|
43
52
|
|
44
53
|
it "should raise ServerError" do
|
45
54
|
expect { subject }.to raise_error(ServerError)
|
@@ -47,7 +56,7 @@ describe Parser do
|
|
47
56
|
end
|
48
57
|
|
49
58
|
context "with a undefined error result" do
|
50
|
-
let(:
|
59
|
+
let(:fixture) { :non_xml }
|
51
60
|
|
52
61
|
it "should raise ServerError" do
|
53
62
|
expect { subject }.to raise_error(ServerError, /503 Service Unavailable/)
|
data/spec/query_spec.rb
CHANGED
@@ -4,13 +4,13 @@ require 'vcr_setup'
|
|
4
4
|
include Twingly::Search
|
5
5
|
|
6
6
|
describe Query do
|
7
|
-
let(:client_double) {
|
7
|
+
let(:client_double) { instance_double("Client") }
|
8
8
|
|
9
9
|
before(:each) do
|
10
10
|
allow(client_double).to receive(:api_key).and_return("api_key")
|
11
11
|
end
|
12
12
|
|
13
|
-
subject {
|
13
|
+
subject { described_class.new(client_double) }
|
14
14
|
|
15
15
|
it { should respond_to(:pattern) }
|
16
16
|
it { should respond_to(:language) }
|
@@ -21,9 +21,9 @@ describe Query do
|
|
21
21
|
|
22
22
|
describe ".new" do
|
23
23
|
context "without client" do
|
24
|
-
subject {
|
24
|
+
subject { described_class.new }
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "raises an error" do
|
27
27
|
expect { subject }.to raise_error(ArgumentError)
|
28
28
|
end
|
29
29
|
end
|
@@ -31,7 +31,7 @@ describe Query do
|
|
31
31
|
context "with block" do
|
32
32
|
it "should yield self" do
|
33
33
|
yielded_query = nil
|
34
|
-
query =
|
34
|
+
query = described_class.new(client_double) do |q|
|
35
35
|
yielded_query = q
|
36
36
|
end
|
37
37
|
|
@@ -46,7 +46,7 @@ describe Query do
|
|
46
46
|
allow(client_double).to receive(:endpoint_url).and_return(endpoint_url)
|
47
47
|
end
|
48
48
|
|
49
|
-
let(:query) {
|
49
|
+
let(:query) { described_class.new(client_double) }
|
50
50
|
|
51
51
|
context "with valid pattern" do
|
52
52
|
before { query.pattern = "christmas" }
|
@@ -104,15 +104,14 @@ describe Query do
|
|
104
104
|
|
105
105
|
describe "#execute" do
|
106
106
|
context "when called" do
|
107
|
-
let(:client) { instance_double("Client", "api_key") }
|
108
107
|
subject do
|
109
|
-
query =
|
108
|
+
query = described_class.new(client_double)
|
110
109
|
query.pattern = 'something'
|
111
110
|
query
|
112
111
|
end
|
113
112
|
|
114
113
|
it "should send the query to the client" do
|
115
|
-
expect(
|
114
|
+
expect(client_double).to receive(:execute_query).with(subject)
|
116
115
|
|
117
116
|
subject.execute
|
118
117
|
end
|
@@ -120,7 +119,7 @@ describe Query do
|
|
120
119
|
|
121
120
|
context "when searching for spotify" do
|
122
121
|
subject {
|
123
|
-
query =
|
122
|
+
query = described_class.new(Client.new('api_key'))
|
124
123
|
query.pattern = 'spotify page-size:10'
|
125
124
|
query.language = 'sv'
|
126
125
|
query
|
data/spec/result_spec.rb
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.platform = Gem::Platform::RUBY
|
10
10
|
spec.authors = ["Twingly AB"]
|
11
11
|
spec.email = ["support@twingly.com"]
|
12
|
-
spec.homepage = "
|
12
|
+
spec.homepage = "https://github.com/twingly/twingly-search-api-ruby"
|
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'
|
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: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Twingly AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- spec/fixtures/service_unavailable_result.xml
|
175
175
|
- spec/fixtures/unauthorized_api_key_result.xml
|
176
176
|
- spec/fixtures/undefined_error_result.xml
|
177
|
+
- spec/fixtures/valid_non_blog_result.xml
|
177
178
|
- spec/fixtures/valid_result.xml
|
178
179
|
- spec/fixtures/vcr_cassettes/search_for_spotify_on_sv_blogs.yml
|
179
180
|
- spec/fixtures/vcr_cassettes/search_without_valid_api_key.yml
|
@@ -184,7 +185,7 @@ files:
|
|
184
185
|
- spec/spec_helper.rb
|
185
186
|
- spec/vcr_setup.rb
|
186
187
|
- twingly-search-api-ruby.gemspec
|
187
|
-
homepage:
|
188
|
+
homepage: https://github.com/twingly/twingly-search-api-ruby
|
188
189
|
licenses:
|
189
190
|
- MIT
|
190
191
|
metadata: {}
|
@@ -216,6 +217,7 @@ test_files:
|
|
216
217
|
- spec/fixtures/service_unavailable_result.xml
|
217
218
|
- spec/fixtures/unauthorized_api_key_result.xml
|
218
219
|
- spec/fixtures/undefined_error_result.xml
|
220
|
+
- spec/fixtures/valid_non_blog_result.xml
|
219
221
|
- spec/fixtures/valid_result.xml
|
220
222
|
- spec/fixtures/vcr_cassettes/search_for_spotify_on_sv_blogs.yml
|
221
223
|
- spec/fixtures/vcr_cassettes/search_without_valid_api_key.yml
|