twingly-search 4.0.1 → 5.0.0
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/CHANGELOG.md +9 -2
- data/README.md +7 -6
- data/lib/twingly/search/client.rb +1 -1
- data/lib/twingly/search/post.rb +4 -4
- data/lib/twingly/search/query.rb +35 -8
- data/lib/twingly/search/version.rb +1 -1
- data/lib/twingly/search.rb +7 -7
- data/spec/fixtures/minimal_valid_result.xml +52 -0
- data/spec/parser_spec.rb +176 -1
- data/spec/query_spec.rb +93 -11
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5fa690bb24c2c41b7f1c1141a636970c76b9057
|
4
|
+
data.tar.gz: 40ba48f85e4f1d255c0fb64b69aabac2b1e347c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43941210a16c5377a5858d1bc296145d92f23162168043b7a932bb9a60590ea938b267b2ba1d0ec8e21effe9735ec09a939c43a99e3d49e75d61ee57156407d8
|
7
|
+
data.tar.gz: a82b2cb9a89a6539093a4f8e72b8ee79c0afc8c11d61f3ee60f26a12fd312619e49ec08c08df4516769b207d090dd0d316779dd36fa1914f9643320516c105dc
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v4.0.
|
3
|
+
## [v4.0.1](https://github.com/twingly/twingly-search-api-ruby/tree/v4.0.1) (2016-01-28)
|
4
|
+
[Full Changelog](https://github.com/twingly/twingly-search-api-ruby/compare/v4.0.0...v4.0.1)
|
4
5
|
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Improve tests [\#38](https://github.com/twingly/twingly-search-api-ruby/pull/38) ([roback](https://github.com/roback))
|
9
|
+
- Take contenttype into account [\#37](https://github.com/twingly/twingly-search-api-ruby/pull/37) ([walro](https://github.com/walro))
|
10
|
+
|
11
|
+
## [v4.0.0](https://github.com/twingly/twingly-search-api-ruby/tree/v4.0.0) (2015-12-02)
|
5
12
|
[Full Changelog](https://github.com/twingly/twingly-search-api-ruby/compare/v3.0.0...v4.0.0)
|
6
13
|
|
7
14
|
**Implemented enhancements:**
|
@@ -99,4 +106,4 @@
|
|
99
106
|
|
100
107
|
|
101
108
|
|
102
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
109
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -51,17 +51,18 @@ To learn more about the capabilities of the API, please read the [Twingly Search
|
|
51
51
|
|
52
52
|
* API key, contact sales@twingly.com via [twingly.com](https://www.twingly.com/try-for-free/) to get one
|
53
53
|
* Ruby
|
54
|
-
* Ruby 1.9, 2.0, 2.1, 2.2
|
54
|
+
* Ruby 1.9, 2.0, 2.1, 2.2, 2.3
|
55
55
|
* JRuby 9000
|
56
56
|
|
57
57
|
## Development and release
|
58
58
|
|
59
|
-
1.
|
60
|
-
1.
|
61
|
-
1.
|
62
|
-
1. Update release information on the [releases page].
|
59
|
+
1. Bump 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
|
+
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
|
+
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
|
+
1. Update release information on the [releases page]. This is done manually.
|
63
63
|
|
64
64
|
[releases page]: https://github.com/twingly/twingly-search-api-ruby/releases
|
65
|
+
[RubyGems.org]: https://rubygems.org/
|
65
66
|
|
66
67
|
### Documentation
|
67
68
|
|
@@ -77,7 +78,7 @@ The YARD server reloads the documentation automatically so there is no need to r
|
|
77
78
|
|
78
79
|
The MIT License (MIT)
|
79
80
|
|
80
|
-
Copyright (c) 2013 Twingly AB
|
81
|
+
Copyright (c) 2013-2016 Twingly AB
|
81
82
|
|
82
83
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
83
84
|
this software and associated documentation files (the "Software"), to deal in
|
@@ -14,7 +14,7 @@ module Twingly
|
|
14
14
|
# Creates a new Twingly Search API client
|
15
15
|
#
|
16
16
|
# @param api_key [optional, String] the API key provided by Twingly.
|
17
|
-
# If nil, reads
|
17
|
+
# If nil, reads key from environment (TWINGLY_SEARCH_KEY).
|
18
18
|
# @param options [Hash]
|
19
19
|
# @option options [String] :user_agent the user agent to be used
|
20
20
|
# for all requests
|
data/lib/twingly/search/post.rb
CHANGED
@@ -11,8 +11,8 @@ module Twingly
|
|
11
11
|
# @attr_reader [String] summary the blog post text.
|
12
12
|
# @attr_reader [String] language_code ISO two letter language code for the
|
13
13
|
# language that the post was written in.
|
14
|
-
# @attr_reader [
|
15
|
-
# @attr_reader [
|
14
|
+
# @attr_reader [Time] indexed the time, in UTC, when the post was indexed by Twingly.
|
15
|
+
# @attr_reader [Time] published the time, in UTC, when the post was published.
|
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.
|
@@ -32,8 +32,8 @@ module Twingly
|
|
32
32
|
@title = params.fetch('title')
|
33
33
|
@summary = params.fetch('summary')
|
34
34
|
@language_code = params.fetch('languageCode')
|
35
|
-
@published =
|
36
|
-
@indexed =
|
35
|
+
@published = Time.parse(params.fetch('published'))
|
36
|
+
@indexed = Time.parse(params.fetch('indexed'))
|
37
37
|
@blog_url = params.fetch('blogUrl')
|
38
38
|
@blog_name = params.fetch('blogName')
|
39
39
|
@authority = params.fetch('authority').to_i
|
data/lib/twingly/search/query.rb
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
require "faraday"
|
2
|
+
require "time"
|
2
3
|
|
3
4
|
module Twingly
|
4
5
|
module Search
|
5
6
|
# Twingly Search API query
|
6
7
|
#
|
7
8
|
# @attr [String] pattern the search query.
|
8
|
-
# @attr [String] language
|
9
|
+
# @attr [String] language language to restrict the query to.
|
9
10
|
# @attr [Client] client the client that this query is connected to.
|
10
|
-
# @attr [Time, #to_time] start_time search for posts published after
|
11
|
-
# this time (inclusive).
|
12
|
-
# @attr [Time, #to_time] end_time search for posts published before
|
13
|
-
# this time (inclusive).
|
14
11
|
class Query
|
15
|
-
attr_accessor :pattern, :language, :client
|
12
|
+
attr_accessor :pattern, :language, :client
|
13
|
+
|
14
|
+
# @return [Time] the time that was set with {#start_time=}.
|
15
|
+
def start_time
|
16
|
+
@start_time
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Time] the time that was set with {#end_time=}.
|
20
|
+
def end_time
|
21
|
+
@end_time
|
22
|
+
end
|
16
23
|
|
17
24
|
# No need to call this method manually, instead use {Client#query}.
|
18
25
|
#
|
@@ -56,14 +63,34 @@ module Twingly
|
|
56
63
|
}
|
57
64
|
end
|
58
65
|
|
66
|
+
# Search for posts published after this time (inclusive).
|
67
|
+
#
|
68
|
+
# @param [Time, #to_time] time an instance of the Time class
|
69
|
+
# or an object responding to #to_time.
|
70
|
+
def start_time=(time)
|
71
|
+
fail QueryError, "Not a Time object" unless time.respond_to?(:to_time)
|
72
|
+
|
73
|
+
@start_time = time
|
74
|
+
end
|
75
|
+
|
76
|
+
# Search for posts published before this time (inclusive).
|
77
|
+
#
|
78
|
+
# @param [Time, #to_time] time an instance of the Time class
|
79
|
+
# or an object responding to #to_time.
|
80
|
+
def end_time=(time)
|
81
|
+
fail QueryError, "Not a Time object" unless time.respond_to?(:to_time)
|
82
|
+
|
83
|
+
@end_time = time
|
84
|
+
end
|
85
|
+
|
59
86
|
private
|
60
87
|
|
61
88
|
def ts
|
62
|
-
start_time.to_time.strftime("%F %T") if start_time
|
89
|
+
start_time.to_time.utc.strftime("%F %T") if start_time
|
63
90
|
end
|
64
91
|
|
65
92
|
def ts_to
|
66
|
-
end_time.to_time.strftime("%F %T") if end_time
|
93
|
+
end_time.to_time.utc.strftime("%F %T") if end_time
|
67
94
|
end
|
68
95
|
end
|
69
96
|
end
|
data/lib/twingly/search.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
require_relative "search/version"
|
2
|
+
require_relative "search/error"
|
3
|
+
require_relative "search/client"
|
4
|
+
require_relative "search/query"
|
5
|
+
require_relative "search/result"
|
6
|
+
require_relative "search/parser"
|
7
|
+
require_relative "search/post"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<twinglydata numberOfMatchesReturned="1" secondsElapsed="0.148" numberOfMatchesTotal="1">
|
3
|
+
<post contentType="blog">
|
4
|
+
<url>http://oppogner.blogg.no/1409602010_bare_m_ha.html</url>
|
5
|
+
<title><![CDATA[Bare MÅ ha!]]></title>
|
6
|
+
<summary><![CDATA[Ja, velkommen til høsten ...]]></summary>
|
7
|
+
<languageCode>no</languageCode>
|
8
|
+
<published>2014-09-02 06:53:26Z</published>
|
9
|
+
<indexed>2014-09-02 09:00:53Z</indexed>
|
10
|
+
<blogUrl>http://oppogner.blogg.no/</blogUrl>
|
11
|
+
<blogName><![CDATA[oppogner]]></blogName>
|
12
|
+
<authority>1</authority>
|
13
|
+
<blogRank>1</blogRank>
|
14
|
+
<tags>
|
15
|
+
<tag><![CDATA[Blogg]]></tag>
|
16
|
+
</tags>
|
17
|
+
</post><post contentType="blog">
|
18
|
+
<url>http://www.skvallernytt.se/hardtraning-da-galler-swedish-house-mafia</url>
|
19
|
+
<title><![CDATA[Hårdträning – då gäller Swedish House Mafia]]></title>
|
20
|
+
<summary><![CDATA[Träning. Och Swedish House Mafia. Det verkar vara ett lyckat koncept. "Don't you worry child" och "Greyhound" är nämligen de två mest spelade träningslåtarna under januari 2013 på Spotify.
|
21
|
+
|
22
|
+
Relaterade inlägg:
|
23
|
+
Swedish House Mafia – ny låt!
|
24
|
+
Ny knivattack på Swedish House Mafia-konsert
|
25
|
+
Swedish House Mafia gör succé i USA]]></summary>
|
26
|
+
<languageCode>sv</languageCode>
|
27
|
+
<published>2013-01-29 15:21:56Z</published>
|
28
|
+
<indexed>2013-01-29 15:22:52Z</indexed>
|
29
|
+
<blogUrl>http://www.skvallernytt.se/</blogUrl>
|
30
|
+
<blogName><![CDATA[Skvallernytt.se]]></blogName>
|
31
|
+
<authority>38</authority>
|
32
|
+
<blogRank>4</blogRank>
|
33
|
+
<tags>
|
34
|
+
<tag><![CDATA[Okategoriserat]]></tag>
|
35
|
+
<tag><![CDATA[Träning]]></tag>
|
36
|
+
<tag><![CDATA[greyhound]]></tag>
|
37
|
+
<tag><![CDATA[koncept]]></tag>
|
38
|
+
<tag><![CDATA[mafia]]></tag>
|
39
|
+
</tags>
|
40
|
+
</post><post contentType="blog">
|
41
|
+
<url>http://didriksinspesielleverden.blogg.no/1359472349_justin_bieber.html</url>
|
42
|
+
<title><![CDATA[Justin Bieber]]></title>
|
43
|
+
<summary><![CDATA[OMG! Justin Bieber Believe acoustic albumet er nå ute på spotify. Han er helt super. Love him. Personlig liker jeg best beauty and a beat og as long as you love me, kommenter gjerne hva dere synes! <3 #sus YOLO]]></summary>
|
44
|
+
<languageCode>no</languageCode>
|
45
|
+
<published>2013-01-29 15:12:29Z</published>
|
46
|
+
<indexed>2013-01-29 15:14:37Z</indexed>
|
47
|
+
<blogUrl>http://didriksinspesielleverden.blogg.no/</blogUrl>
|
48
|
+
<blogName><![CDATA[Didriksinspesielleverden]]></blogName>
|
49
|
+
<authority>0</authority>
|
50
|
+
<blogRank>1</blogRank>
|
51
|
+
</post>
|
52
|
+
</twinglydata>
|
data/spec/parser_spec.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
4
|
+
require 'date'
|
2
5
|
|
3
6
|
include Twingly::Search
|
4
7
|
|
@@ -6,8 +9,9 @@ describe Parser do
|
|
6
9
|
it { should respond_to(:parse) }
|
7
10
|
|
8
11
|
describe "#parse" do
|
9
|
-
subject { described_class.new.parse(document) }
|
10
12
|
let(:document) { Fixture.get(fixture) }
|
13
|
+
let(:result) { described_class.new.parse(document) }
|
14
|
+
subject { result }
|
11
15
|
|
12
16
|
context "with a valid result" do
|
13
17
|
let(:fixture) { :valid }
|
@@ -15,6 +19,177 @@ describe Parser do
|
|
15
19
|
it { is_expected.to be_a Result }
|
16
20
|
end
|
17
21
|
|
22
|
+
context "with a minimal valid result" do
|
23
|
+
let(:fixture) { :minimal_valid }
|
24
|
+
|
25
|
+
describe "#posts[0]" do
|
26
|
+
subject(:post) { result.posts[0] }
|
27
|
+
|
28
|
+
describe "#url" do
|
29
|
+
subject { post.url }
|
30
|
+
it { is_expected.to eq("http://oppogner.blogg.no/1409602010_bare_m_ha.html") }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#title" do
|
34
|
+
subject { post.title }
|
35
|
+
it { is_expected.to eq("Bare MÅ ha!") }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#summary" do
|
39
|
+
subject { post.summary }
|
40
|
+
it { is_expected.to eq("Ja, velkommen til høsten ...") }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#language_code" do
|
44
|
+
subject { post.language_code }
|
45
|
+
it { is_expected.to eq("no") }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#published" do
|
49
|
+
subject { post.published }
|
50
|
+
it { is_expected.to eq(Time.parse("2014-09-02 06:53:26Z")) }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#indexed" do
|
54
|
+
subject { post.indexed }
|
55
|
+
it { is_expected.to eq(Time.parse("2014-09-02 09:00:53Z")) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#blog_url" do
|
59
|
+
subject { post.blog_url }
|
60
|
+
it { is_expected.to eq("http://oppogner.blogg.no/") }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#authority" do
|
64
|
+
subject { post.authority }
|
65
|
+
it { is_expected.to eq(1) }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#blog_rank" do
|
69
|
+
subject { post.blog_rank }
|
70
|
+
it { is_expected.to eq(1) }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#tags" do
|
74
|
+
subject { post.tags }
|
75
|
+
it { is_expected.to eq(["Blogg"]) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#posts[1]" do
|
80
|
+
subject(:post) { result.posts[1] }
|
81
|
+
|
82
|
+
describe "#url" do
|
83
|
+
subject { post.url }
|
84
|
+
it { is_expected.to eq("http://www.skvallernytt.se/hardtraning-da-galler-swedish-house-mafia") }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#title" do
|
88
|
+
subject { post.title }
|
89
|
+
it { is_expected.to eq("Hårdträning – då gäller Swedish House Mafia") }
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#summary" do
|
93
|
+
subject { post.summary }
|
94
|
+
it { is_expected.to eq("Träning. Och Swedish House Mafia. Det verkar vara ett lyckat koncept. \"Don't you worry child\" och \"Greyhound\" är nämligen de två mest spelade träningslåtarna under januari 2013 på Spotify.
|
95
|
+
|
96
|
+
Relaterade inlägg:
|
97
|
+
Swedish House Mafia – ny låt!
|
98
|
+
Ny knivattack på Swedish House Mafia-konsert
|
99
|
+
Swedish House Mafia gör succé i USA") }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#language_code" do
|
103
|
+
subject { post.language_code }
|
104
|
+
it { is_expected.to eq("sv") }
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#published" do
|
108
|
+
subject { post.published }
|
109
|
+
it { is_expected.to eq(Time.parse("2013-01-29 15:21:56Z")) }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#indexed" do
|
113
|
+
subject { post.indexed }
|
114
|
+
it { is_expected.to eq(Time.parse("2013-01-29 15:22:52Z")) }
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#blog_url" do
|
118
|
+
subject { post.blog_url }
|
119
|
+
it { is_expected.to eq("http://www.skvallernytt.se/") }
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#authority" do
|
123
|
+
subject { post.authority }
|
124
|
+
it { is_expected.to eq(38) }
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#blog_rank" do
|
128
|
+
subject { post.blog_rank }
|
129
|
+
it { is_expected.to eq(4) }
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#tags" do
|
133
|
+
subject { post.tags }
|
134
|
+
it { is_expected.to eq(["Okategoriserat", "Träning", "greyhound", "koncept", "mafia"]) }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#posts[2]" do
|
139
|
+
subject(:post) { result.posts[2] }
|
140
|
+
|
141
|
+
describe "#url" do
|
142
|
+
subject { post.url }
|
143
|
+
it { is_expected.to eq("http://didriksinspesielleverden.blogg.no/1359472349_justin_bieber.html") }
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#title" do
|
147
|
+
subject { post.title }
|
148
|
+
it { is_expected.to eq("Justin Bieber") }
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#summary" do
|
152
|
+
subject { post.summary }
|
153
|
+
it { is_expected.to eq("OMG! Justin Bieber Believe acoustic albumet er nå ute på spotify. Han er helt super. Love him. Personlig liker jeg best beauty and a beat og as long as you love me, kommenter gjerne hva dere synes! <3 #sus YOLO") }
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "#language_code" do
|
157
|
+
subject { post.language_code }
|
158
|
+
it { is_expected.to eq("no") }
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "#published" do
|
162
|
+
subject { post.published }
|
163
|
+
it { is_expected.to eq(Time.parse("2013-01-29 15:12:29Z")) }
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#indexed" do
|
167
|
+
subject { post.indexed }
|
168
|
+
it { is_expected.to eq(Time.parse("2013-01-29 15:14:37Z")) }
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#blog_url" do
|
172
|
+
subject { post.blog_url }
|
173
|
+
it { is_expected.to eq("http://didriksinspesielleverden.blogg.no/") }
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "#authority" do
|
177
|
+
subject { post.authority }
|
178
|
+
it { is_expected.to eq(0) }
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#blog_rank" do
|
182
|
+
subject { post.blog_rank }
|
183
|
+
it { is_expected.to eq(1) }
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "#tags" do
|
187
|
+
subject { post.tags }
|
188
|
+
it { is_expected.to eq([]) }
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
18
193
|
context "with a valid result containing non-blogs" do
|
19
194
|
let(:fixture) { :valid_non_blog }
|
20
195
|
|
data/spec/query_spec.rb
CHANGED
@@ -70,6 +70,98 @@ describe Query do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
describe "#start_time=" do
|
74
|
+
before do
|
75
|
+
subject.pattern = "semla"
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when given time in UTC" do
|
79
|
+
before do
|
80
|
+
subject.start_time = time
|
81
|
+
end
|
82
|
+
|
83
|
+
let(:time) { Time.parse("2016-02-09 09:01:22 UTC") }
|
84
|
+
|
85
|
+
it "should not change timezone" do
|
86
|
+
expect(subject.request_parameters).to include(ts: "2016-02-09 09:01:22")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not modify the given time object" do
|
90
|
+
expect(subject.start_time).to equal(time)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when given time not in UTC" do
|
95
|
+
before do
|
96
|
+
subject.start_time = time
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:time) { Time.parse("2016-02-09 09:01:22 +05:00") }
|
100
|
+
|
101
|
+
it "should convert to UTC" do
|
102
|
+
expect(subject.request_parameters).to include(ts: "2016-02-09 04:01:22")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not modify the given time object" do
|
106
|
+
expect(subject.start_time).to equal(time)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "when given non-time object" do
|
111
|
+
let(:time) { "2013-12-28+09%3A01%3A22" }
|
112
|
+
|
113
|
+
it "should raise exception" do
|
114
|
+
expect { subject.start_time = time }.to raise_error(QueryError, "Not a Time object")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#end_time=" do
|
120
|
+
before do
|
121
|
+
subject.pattern = "semla"
|
122
|
+
end
|
123
|
+
|
124
|
+
context "when given time in UTC" do
|
125
|
+
before do
|
126
|
+
subject.end_time = time
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:time) { Time.parse("2016-02-09 09:01:22 UTC") }
|
130
|
+
|
131
|
+
it "should not change timezone" do
|
132
|
+
expect(subject.request_parameters).to include(tsTo: "2016-02-09 09:01:22")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should not modify the given time object" do
|
136
|
+
expect(subject.end_time).to equal(time)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when given time not in UTC" do
|
141
|
+
before do
|
142
|
+
subject.end_time = time
|
143
|
+
end
|
144
|
+
|
145
|
+
let(:time) { Time.parse("2016-02-09 09:01:22 +05:00") }
|
146
|
+
|
147
|
+
it "should convert to UTC" do
|
148
|
+
expect(subject.request_parameters).to include(tsTo: "2016-02-09 04:01:22")
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should not modify the given time object" do
|
152
|
+
expect(subject.end_time).to equal(time)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when given non-time object" do
|
157
|
+
let(:time) { "2013-12-28+09%3A01%3A22" }
|
158
|
+
|
159
|
+
it "should raise exception" do
|
160
|
+
expect { subject.end_time = time }.to raise_error(QueryError, "Not a Time object")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
73
165
|
context "with valid pattern" do
|
74
166
|
before { subject.pattern = "christmas" }
|
75
167
|
|
@@ -78,18 +170,8 @@ describe Query do
|
|
78
170
|
expect(subject.request_parameters).to include(documentlang: 'en')
|
79
171
|
end
|
80
172
|
|
81
|
-
it "should add start_time" do
|
82
|
-
subject.start_time = Time.new(2012, 12, 28, 9, 01, 22)
|
83
|
-
expect(subject.request_parameters).to include(ts: '2012-12-28 09:01:22')
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should add end_time" do
|
87
|
-
subject.end_time = Time.new(2013, 12, 28, 9, 01, 22)
|
88
|
-
expect(subject.request_parameters).to include(tsTo: '2013-12-28 09:01:22')
|
89
|
-
end
|
90
|
-
|
91
173
|
it "should encode url paramters" do
|
92
|
-
subject.end_time = Time.
|
174
|
+
subject.end_time = Time.parse("2013-12-28 09:01:22 UTC")
|
93
175
|
expect(subject.url_parameters).to include('tsTo=2013-12-28+09%3A01%3A22')
|
94
176
|
end
|
95
177
|
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:
|
4
|
+
version: 5.0.0
|
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-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- lib/twingly/search/version.rb
|
170
170
|
- spec/client_spec.rb
|
171
171
|
- spec/error_spec.rb
|
172
|
+
- spec/fixtures/minimal_valid_result.xml
|
172
173
|
- spec/fixtures/non_xml_result.xml
|
173
174
|
- spec/fixtures/nonexistent_api_key_result.xml
|
174
175
|
- spec/fixtures/service_unavailable_result.xml
|
@@ -212,6 +213,7 @@ summary: Ruby API client for Twingly Search
|
|
212
213
|
test_files:
|
213
214
|
- spec/client_spec.rb
|
214
215
|
- spec/error_spec.rb
|
216
|
+
- spec/fixtures/minimal_valid_result.xml
|
215
217
|
- spec/fixtures/non_xml_result.xml
|
216
218
|
- spec/fixtures/nonexistent_api_key_result.xml
|
217
219
|
- spec/fixtures/service_unavailable_result.xml
|