twingly-search 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -10
- data/CHANGELOG.md +21 -0
- data/README.md +14 -2
- data/lib/twingly/search/post.rb +2 -2
- data/lib/twingly/search/query.rb +12 -2
- data/lib/twingly/search/version.rb +1 -1
- data/spec/fixtures/valid_empty_result.xml +2 -0
- data/spec/parser_spec.rb +10 -0
- data/spec/query_spec.rb +53 -11
- 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: 02b493d1ffc4f5ada3d5358efda0d1a109ea808f
|
4
|
+
data.tar.gz: c358cf6d79e121039b765dfe3b9133c1f67de916
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02a4a23e61a87504b8af957377448c0c0195100cb246d5b2c63bcce81eb27ffd7fca75c87ae06f43c967889b24377efff243d13ca59aa146f5ffa17227fed8e4
|
7
|
+
data.tar.gz: 46e0a56868dff241923f3461d69115e80877ee2cdda6ccd46af4684b2b32548df5aa0483050e1e4622e8a72514b69a4e1e8e16339223257b8ec951994d5d1f5d
|
data/.travis.yml
CHANGED
@@ -10,16 +10,6 @@ rvm:
|
|
10
10
|
- 2.2
|
11
11
|
- 2.3.0
|
12
12
|
- jruby-9.0.0.0
|
13
|
-
deploy:
|
14
|
-
provider: rubygems
|
15
|
-
api_key:
|
16
|
-
secure: QxMWXTQ3/T+0IQZl3pk3hmdoX8FcXTXEhH7Jn7Ub1A1D5faa8VNnfYsWAPjP6+VRgVfKEjAsHNMyZQNTvudpPPC/2kAwwzPvStyS+y7KnRkjZ9acC7sYVVel6cZ2lcl+t8iHY+19NRBFBWpq/P0eCAcR/Ew0XXaLZnig5h/1mQo=
|
17
|
-
gem: twingly-search
|
18
|
-
gemspec: twingly-search-api-ruby.gemspec
|
19
|
-
on:
|
20
|
-
tags: true
|
21
|
-
rvm: 2.2
|
22
|
-
repo: twingly/twingly-search-api-ruby
|
23
13
|
notifications:
|
24
14
|
email: false
|
25
15
|
hipchat:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v5.0.0](https://github.com/twingly/twingly-search-api-ruby/tree/v5.0.0) (2016-02-17)
|
4
|
+
[Full Changelog](https://github.com/twingly/twingly-search-api-ruby/compare/v4.0.1...v5.0.0)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- Use Time all the time [\#50](https://github.com/twingly/twingly-search-api-ruby/issues/50)
|
9
|
+
|
10
|
+
**Fixed bugs:**
|
11
|
+
|
12
|
+
- Missing require "time" [\#44](https://github.com/twingly/twingly-search-api-ruby/issues/44)
|
13
|
+
- Query\#start\_time and \#end\_time should be converted to UTC [\#43](https://github.com/twingly/twingly-search-api-ruby/issues/43)
|
14
|
+
|
15
|
+
**Merged pull requests:**
|
16
|
+
|
17
|
+
- Improve time handling [\#51](https://github.com/twingly/twingly-search-api-ruby/pull/51) ([dentarg](https://github.com/dentarg))
|
18
|
+
- Improve parser specs [\#49](https://github.com/twingly/twingly-search-api-ruby/pull/49) ([dentarg](https://github.com/dentarg))
|
19
|
+
- Sync documentation with PHP changes [\#47](https://github.com/twingly/twingly-search-api-ruby/pull/47) ([walro](https://github.com/walro))
|
20
|
+
- Automatically convert Query\#start\_time and \#end\_time to UTC [\#46](https://github.com/twingly/twingly-search-api-ruby/pull/46) ([roback](https://github.com/roback))
|
21
|
+
- Use require\_relative [\#45](https://github.com/twingly/twingly-search-api-ruby/pull/45) ([dentarg](https://github.com/dentarg))
|
22
|
+
- Test Ruby 2.3 on Travis CI [\#42](https://github.com/twingly/twingly-search-api-ruby/pull/42) ([walro](https://github.com/walro))
|
23
|
+
|
3
24
|
## [v4.0.1](https://github.com/twingly/twingly-search-api-ruby/tree/v4.0.1) (2016-01-28)
|
4
25
|
[Full Changelog](https://github.com/twingly/twingly-search-api-ruby/compare/v4.0.0...v4.0.1)
|
5
26
|
|
data/README.md
CHANGED
@@ -54,9 +54,21 @@ To learn more about the capabilities of the API, please read the [Twingly Search
|
|
54
54
|
* Ruby 1.9, 2.0, 2.1, 2.2, 2.3
|
55
55
|
* JRuby 9000
|
56
56
|
|
57
|
-
## Development
|
57
|
+
## Development
|
58
58
|
|
59
|
-
|
59
|
+
### Tests
|
60
|
+
|
61
|
+
Make sure you have all the dependencies
|
62
|
+
|
63
|
+
bundle
|
64
|
+
|
65
|
+
Run the tests
|
66
|
+
|
67
|
+
bundle exec rake
|
68
|
+
|
69
|
+
### Release
|
70
|
+
|
71
|
+
1. Make a commit bumping the version in `lib/twingly/search/version.rb`, follow [Semantic Versioning 2.0.0](http://semver.org/). No need to push as this will be taken care of automatically in the next step.
|
60
72
|
1. Build and the release gem with `bundle exec rake release`. This will create a git tag for the version and push the `.gem` file to [RubyGems.org].
|
61
73
|
1. Generate a changelog with `bundle exec rake changelog`. Set `CHANGELOG_GITHUB_TOKEN` to a personal access token to increase the API rate limit. (The changelog uses [GitHub Changelog Generator](https://github.com/skywinder/github-changelog-generator/))
|
62
74
|
1. Update release information on the [releases page]. This is done manually.
|
data/lib/twingly/search/post.rb
CHANGED
@@ -16,9 +16,9 @@ module Twingly
|
|
16
16
|
# @attr_reader [String] blog_url the blog URL.
|
17
17
|
# @attr_reader [String] blog_name name of the blog.
|
18
18
|
# @attr_reader [String] authority the blog's authority/influence.
|
19
|
-
# See https://developer.twingly.com/resources/
|
19
|
+
# See https://developer.twingly.com/resources/ranking/#authority
|
20
20
|
# @attr_reader [Integer] blog_rank the rank of the blog, based on authority and language.
|
21
|
-
# See https://developer.twingly.com/resources/
|
21
|
+
# See https://developer.twingly.com/resources/ranking/#blogrank
|
22
22
|
# @attr_reader [Array] tags
|
23
23
|
class Post
|
24
24
|
attr_reader :url, :title, :summary, :language_code, :indexed,
|
data/lib/twingly/search/query.rb
CHANGED
@@ -37,6 +37,8 @@ module Twingly
|
|
37
37
|
# Executes the query and returns the result.
|
38
38
|
#
|
39
39
|
# @raise [QueryError] if {#pattern} is empty.
|
40
|
+
# @raise [AuthError] if the API couldn't authenticate you. Make sure your API key is correct.
|
41
|
+
# @raise [ServerError] if the query could not be executed due to a server error.
|
40
42
|
# @return [Result] the result for this query.
|
41
43
|
def execute
|
42
44
|
@client.execute_query(self)
|
@@ -67,8 +69,9 @@ module Twingly
|
|
67
69
|
#
|
68
70
|
# @param [Time, #to_time] time an instance of the Time class
|
69
71
|
# or an object responding to #to_time.
|
72
|
+
# @raise [QueryError] if the object cannot be converted to a Time object.
|
70
73
|
def start_time=(time)
|
71
|
-
|
74
|
+
assert_valid_time(time)
|
72
75
|
|
73
76
|
@start_time = time
|
74
77
|
end
|
@@ -77,14 +80,21 @@ module Twingly
|
|
77
80
|
#
|
78
81
|
# @param [Time, #to_time] time an instance of the Time class
|
79
82
|
# or an object responding to #to_time.
|
83
|
+
# @raise [QueryError] if the object cannot be converted to a Time object.
|
80
84
|
def end_time=(time)
|
81
|
-
|
85
|
+
assert_valid_time(time)
|
82
86
|
|
83
87
|
@end_time = time
|
84
88
|
end
|
85
89
|
|
86
90
|
private
|
87
91
|
|
92
|
+
def assert_valid_time(time)
|
93
|
+
return if time.nil?
|
94
|
+
|
95
|
+
fail QueryError, "Not a Time object" unless time.respond_to?(:to_time)
|
96
|
+
end
|
97
|
+
|
88
98
|
def ts
|
89
99
|
start_time.to_time.utc.strftime("%F %T") if start_time
|
90
100
|
end
|
data/spec/parser_spec.rb
CHANGED
@@ -198,6 +198,16 @@ Swedish House Mafia gör succé i USA") }
|
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
+
context "with a valid empty result" do
|
202
|
+
let(:fixture) { :valid_empty }
|
203
|
+
|
204
|
+
it "should return an empty result" do
|
205
|
+
expect(subject.posts.size).to eq(0)
|
206
|
+
expect(subject.number_of_matches_total).to eq(0)
|
207
|
+
expect(subject.number_of_matches_returned).to eq(0)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
201
211
|
context "with a nonexistent api key result" do
|
202
212
|
let(:fixture) { :nonexistent_api_key }
|
203
213
|
|
data/spec/query_spec.rb
CHANGED
@@ -72,7 +72,7 @@ describe Query do
|
|
72
72
|
|
73
73
|
describe "#start_time=" do
|
74
74
|
before do
|
75
|
-
subject.pattern
|
75
|
+
subject.pattern = "semla"
|
76
76
|
end
|
77
77
|
|
78
78
|
context "when given time in UTC" do
|
@@ -80,40 +80,61 @@ describe Query do
|
|
80
80
|
subject.start_time = time
|
81
81
|
end
|
82
82
|
|
83
|
-
let(:
|
83
|
+
let(:timestamp) { "2016-02-09 09:01:22 UTC" }
|
84
|
+
let(:time) { Time.parse(timestamp) }
|
84
85
|
|
85
86
|
it "should not change timezone" do
|
86
87
|
expect(subject.request_parameters).to include(ts: "2016-02-09 09:01:22")
|
87
88
|
end
|
88
89
|
|
89
90
|
it "should not modify the given time object" do
|
90
|
-
expect(subject.start_time).to
|
91
|
+
expect(subject.start_time.to_s).to eq(timestamp)
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
94
95
|
context "when given time not in UTC" do
|
95
96
|
before do
|
97
|
+
@TZ = ENV["TZ"]
|
98
|
+
# set timezone matching the timestamp, needed for Ruby versions before 2.2
|
99
|
+
# see https://github.com/twingly/twingly-search-api-ruby/pull/52
|
100
|
+
ENV["TZ"] = "Etc/GMT-5"
|
101
|
+
|
96
102
|
subject.start_time = time
|
97
103
|
end
|
98
104
|
|
99
|
-
|
105
|
+
after do
|
106
|
+
ENV["TZ"] = @TZ
|
107
|
+
end
|
108
|
+
|
109
|
+
let(:timestamp) { "2016-02-09 09:01:22 +0500" }
|
110
|
+
let(:time) { Time.parse(timestamp) }
|
100
111
|
|
101
112
|
it "should convert to UTC" do
|
102
113
|
expect(subject.request_parameters).to include(ts: "2016-02-09 04:01:22")
|
103
114
|
end
|
104
115
|
|
105
116
|
it "should not modify the given time object" do
|
106
|
-
expect(subject.start_time).to
|
117
|
+
expect(subject.start_time.to_s).to eq(timestamp)
|
107
118
|
end
|
108
119
|
end
|
109
120
|
|
110
|
-
context "when given non-time object" do
|
121
|
+
context "when given non-time object (except nil)" do
|
111
122
|
let(:time) { "2013-12-28+09%3A01%3A22" }
|
112
123
|
|
113
124
|
it "should raise exception" do
|
114
125
|
expect { subject.start_time = time }.to raise_error(QueryError, "Not a Time object")
|
115
126
|
end
|
116
127
|
end
|
128
|
+
|
129
|
+
context "when given nil" do
|
130
|
+
before do
|
131
|
+
subject.start_time = nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should assign" do
|
135
|
+
expect(subject.start_time).to eq(nil)
|
136
|
+
end
|
137
|
+
end
|
117
138
|
end
|
118
139
|
|
119
140
|
describe "#end_time=" do
|
@@ -126,40 +147,61 @@ describe Query do
|
|
126
147
|
subject.end_time = time
|
127
148
|
end
|
128
149
|
|
129
|
-
let(:
|
150
|
+
let(:timestamp) { "2016-02-09 09:01:22 UTC" }
|
151
|
+
let(:time) { Time.parse(timestamp) }
|
130
152
|
|
131
153
|
it "should not change timezone" do
|
132
154
|
expect(subject.request_parameters).to include(tsTo: "2016-02-09 09:01:22")
|
133
155
|
end
|
134
156
|
|
135
157
|
it "should not modify the given time object" do
|
136
|
-
expect(subject.end_time).to
|
158
|
+
expect(subject.end_time.to_s).to eq(timestamp)
|
137
159
|
end
|
138
160
|
end
|
139
161
|
|
140
162
|
context "when given time not in UTC" do
|
141
163
|
before do
|
164
|
+
@TZ = ENV["TZ"]
|
165
|
+
# set timezone matching the timestamp, needed for Ruby versions before 2.2
|
166
|
+
# see https://github.com/twingly/twingly-search-api-ruby/pull/52
|
167
|
+
ENV["TZ"] = "Etc/GMT-5"
|
168
|
+
|
142
169
|
subject.end_time = time
|
143
170
|
end
|
144
171
|
|
145
|
-
|
172
|
+
after do
|
173
|
+
ENV["TZ"] = @TZ
|
174
|
+
end
|
175
|
+
|
176
|
+
let(:timestamp) { "2016-02-09 09:01:22 +0500" }
|
177
|
+
let(:time) { Time.parse(timestamp) }
|
146
178
|
|
147
179
|
it "should convert to UTC" do
|
148
180
|
expect(subject.request_parameters).to include(tsTo: "2016-02-09 04:01:22")
|
149
181
|
end
|
150
182
|
|
151
183
|
it "should not modify the given time object" do
|
152
|
-
expect(subject.end_time).to
|
184
|
+
expect(subject.end_time.to_s).to eq(timestamp)
|
153
185
|
end
|
154
186
|
end
|
155
187
|
|
156
|
-
context "when given non-time object" do
|
188
|
+
context "when given non-time object (except nil)" do
|
157
189
|
let(:time) { "2013-12-28+09%3A01%3A22" }
|
158
190
|
|
159
191
|
it "should raise exception" do
|
160
192
|
expect { subject.end_time = time }.to raise_error(QueryError, "Not a Time object")
|
161
193
|
end
|
162
194
|
end
|
195
|
+
|
196
|
+
context "when given nil" do
|
197
|
+
before do
|
198
|
+
subject.start_time = nil
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should assign" do
|
202
|
+
expect(subject.start_time).to eq(nil)
|
203
|
+
end
|
204
|
+
end
|
163
205
|
end
|
164
206
|
|
165
207
|
context "with valid pattern" do
|
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.0.
|
4
|
+
version: 5.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: 2016-
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- spec/fixtures/service_unavailable_result.xml
|
176
176
|
- spec/fixtures/unauthorized_api_key_result.xml
|
177
177
|
- spec/fixtures/undefined_error_result.xml
|
178
|
+
- spec/fixtures/valid_empty_result.xml
|
178
179
|
- spec/fixtures/valid_non_blog_result.xml
|
179
180
|
- spec/fixtures/valid_result.xml
|
180
181
|
- spec/fixtures/vcr_cassettes/search_for_spotify_on_sv_blogs.yml
|
@@ -206,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
207
|
version: '0'
|
207
208
|
requirements: []
|
208
209
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.
|
210
|
+
rubygems_version: 2.5.0
|
210
211
|
signing_key:
|
211
212
|
specification_version: 4
|
212
213
|
summary: Ruby API client for Twingly Search
|
@@ -219,6 +220,7 @@ test_files:
|
|
219
220
|
- spec/fixtures/service_unavailable_result.xml
|
220
221
|
- spec/fixtures/unauthorized_api_key_result.xml
|
221
222
|
- spec/fixtures/undefined_error_result.xml
|
223
|
+
- spec/fixtures/valid_empty_result.xml
|
222
224
|
- spec/fixtures/valid_non_blog_result.xml
|
223
225
|
- spec/fixtures/valid_result.xml
|
224
226
|
- spec/fixtures/vcr_cassettes/search_for_spotify_on_sv_blogs.yml
|