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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd9953d1e03a6e3b8876f3a4b86580ddcfeeeccf
4
- data.tar.gz: 36f8ccb71ca25e1016d00e366652e06dc71b6321
3
+ metadata.gz: a62fb19132e1def965555e328f84667e5588a4c3
4
+ data.tar.gz: 9d04745eba432e6d60676c9ff5ce517d20f539fe
5
5
  SHA512:
6
- metadata.gz: 525c3009c34290b6a86a6a397c9e907d9defbf7089e82e0786274d0c46146d79d4bf9d69cb673120ebd50ea1f10626a13b94d5e113590095f1c557edbc6380ef
7
- data.tar.gz: 3df9d3ddd711c7185005a81c93ce3fb4b362a7a526698a2203e475c2e6234054e054269ebb2d45aedb44bc4c31ea88d083598952debd78af2c63f38dcc680edd
6
+ metadata.gz: 9d2c2e6d94f4748e78bb355d60376afa52abda4249bee1ccd1654c8a5e16995baf7d5b272ce09748c5eead3f777d4d41a3db48c4256b1e0fe93ae9232413a24a
7
+ data.tar.gz: 6094058ff17173434ee61da5251f47d9777625e6a49a2485b64741925ef192f9120170263f6d79d093b1a4d42752ba75c446529c3805c096282d715e036c7d26
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem update bundler
2
4
  cache: bundler
3
5
  rvm:
4
6
  - 1.9.3
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](http://www.twingly.com/try-for-free/) to get one
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
 
@@ -1,5 +1,5 @@
1
1
  module Twingly
2
2
  module Search
3
- VERSION = "4.0.0"
3
+ VERSION = "4.0.1"
4
4
  end
5
5
  end
data/spec/client_spec.rb CHANGED
@@ -1,44 +1,36 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  include Twingly::Search
4
4
 
5
5
  describe Client do
6
- subject { Client.new('api_key') }
6
+ let(:valid_api_key) { "api_key" }
7
7
 
8
8
  describe ".new" do
9
- context 'with API key as arguments' do
10
- it { should be_a Client }
11
- end
9
+ context "with API key as argument" do
10
+ subject { described_class.new(valid_api_key) }
12
11
 
13
- it "BASE_URL should be parsable" do
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 'with API key from ENV variable' do
18
- before { allow_any_instance_of(Client).to receive(:env_api_key).and_return('api_key') }
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
- context 'without valid API key' do
24
- before { allow_any_instance_of(Client).to receive(:env_api_key).and_return(nil) }
25
- subject { Client.new }
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 optional :user_agent given" do
30
- let(:user_agent) { "TwinglySearchTest/1.0" }
31
- subject { Client.new('api_key', user_agent: user_agent) }
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 "should use that user agent" do
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 = Client.new("api_key") do |c|
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
- Client.new do |client|
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 '#query' do
69
- subject { Client.new('api_key').query }
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 { Client.new("api_key") }
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
- subject { Client.new("wrong") }
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 { Client.new("api_key").endpoint_url }
106
- let(:expected) { "#{Client::BASE_URL}#{Client::SEARCH_PATH}" }
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
@@ -15,7 +15,7 @@ describe Twingly::Search::Error do
15
15
  context "when given a server error message" do
16
16
  let(:server_response_message) { "An error occured." }
17
17
 
18
- it { is_expected.to be_an(ServerError) }
18
+ it { is_expected.to be_a(ServerError) }
19
19
  end
20
20
  end
21
21
 
@@ -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 { Parser.new.parse(document) }
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(:document) { Fixture.get(:valid) }
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(:document) { Fixture.get(:nonexistent_api_key) }
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(:document) { Fixture.get(:unauthorized_api_key) }
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(:document) { Fixture.get(:service_unavailable) }
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(:document) { Fixture.get(:undefined_error) }
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(:document) { Fixture.get(:non_xml) }
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) { double("Client") }
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 { Query.new(client_double) }
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 { Query.new }
24
+ subject { described_class.new }
25
25
 
26
- it "should not work" do
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 = Query.new(client_double) do |q|
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) { Query.new(client_double) }
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 = Query.new(client)
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(client).to receive(:execute_query).with(subject)
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 = Query.new(Client.new('api_key'))
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
@@ -13,5 +13,6 @@ describe Result do
13
13
 
14
14
  context "before query has populated responses" do
15
15
  its(:posts) { should be_empty }
16
+ its(:all_results_returned?) { should be_truthy }
16
17
  end
17
18
  end
@@ -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 = "http://github.com/twingly/twingly-search-api-ruby"
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.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: 2015-12-02 00:00:00.000000000 Z
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: http://github.com/twingly/twingly-search-api-ruby
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