twingly-search 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.twingly.com/analytics/Analytics.ashx?documentlang&key=wrong&searchpattern=something&ts&tsTo&xmloutputversion=2
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Twingly Analytics Ruby Client/2.0.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Tue, 03 Nov 2015 09:29:04 GMT
25
+ Content-Type:
26
+ - text/xml; charset=utf-8
27
+ Content-Length:
28
+ - '183'
29
+ Connection:
30
+ - keep-alive
31
+ Cache-Control:
32
+ - private
33
+ Set-Cookie:
34
+ - SERVERID=web01; path=/
35
+ body:
36
+ encoding: UTF-8
37
+ string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><blogstream xmlns=\"http://www.twingly.com\">\r\n
38
+ \ <operationResult resultType=\"failure\">The API key does not exist.</operationResult>\r\n</blogstream>"
39
+ http_version:
40
+ recorded_at: Tue, 03 Nov 2015 09:29:04 GMT
41
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ include Twingly::Search
4
+
5
+ describe Parser do
6
+ it { should respond_to(:parse) }
7
+
8
+ let(:document) { File.read('spec/fixtures/valid_result.xml') }
9
+
10
+ describe "#parse" do
11
+ subject { Parser.new.parse(document) }
12
+ it { should be_a Result }
13
+ end
14
+ end
data/spec/post_spec.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ include Twingly::Search
4
+
5
+ describe Post do
6
+ it { should respond_to :url }
7
+ it { should respond_to :title }
8
+ it { should respond_to :summary }
9
+ it { should respond_to :language_code }
10
+ it { should respond_to :indexed }
11
+ it { should respond_to :published }
12
+ it { should respond_to :blog_url }
13
+ it { should respond_to :blog_name }
14
+ it { should respond_to :authority }
15
+ it { should respond_to :blog_rank }
16
+ it { should respond_to :tags }
17
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+ require 'vcr_setup'
3
+
4
+ include Twingly::Search
5
+
6
+ describe Query do
7
+
8
+ it "BASE_URL should be parsable" do
9
+ expect(URI(Query::BASE_URL).to_s).to eq(Query::BASE_URL)
10
+ end
11
+
12
+ context "without client" do
13
+ subject { Query.new }
14
+
15
+ it "should not work" do
16
+ expect { subject }.to raise_error(ArgumentError)
17
+ end
18
+ end
19
+
20
+ before(:each) do
21
+ @client = double('client')
22
+ allow(@client).to receive(:api_key).and_return('api_key')
23
+ end
24
+
25
+ subject { Query.new(@client) }
26
+
27
+ it { should respond_to(:pattern) }
28
+ it { should respond_to(:language) }
29
+ it { should respond_to(:start_time) }
30
+ it { should respond_to(:end_time) }
31
+ it { should respond_to(:execute) }
32
+ it { should respond_to(:client) }
33
+
34
+ describe "#url" do
35
+ let(:query) { Query.new(@client) }
36
+
37
+ context "with valid pattern" do
38
+ before { query.pattern = "christmas" }
39
+ subject { query.url }
40
+
41
+ it { should include("xmloutputversion=2") }
42
+ end
43
+
44
+ context "without valid pattern" do
45
+ it "raises an error" do
46
+ expect { query.url }.to raise_error(RuntimeError, "Missing pattern")
47
+ end
48
+ end
49
+
50
+ context "with empty pattern" do
51
+ before { query.pattern = "" }
52
+
53
+ it "raises an error" do
54
+ expect { query.url }.to raise_error(RuntimeError, "Missing pattern")
55
+ end
56
+ end
57
+ end
58
+
59
+ context "with valid pattern" do
60
+ before { subject.pattern = "christmas" }
61
+
62
+ it "should add language" do
63
+ subject.language = "en"
64
+ expect(subject.request_parameters).to include(documentlang: 'en')
65
+ end
66
+
67
+ it "should add start_time" do
68
+ subject.start_time = Time.new(2012, 12, 28, 9, 01, 22)
69
+ expect(subject.request_parameters).to include(ts: '2012-12-28 09:01:22')
70
+ end
71
+
72
+ it "should add end_time" do
73
+ subject.end_time = Time.new(2013, 12, 28, 9, 01, 22)
74
+ expect(subject.request_parameters).to include(tsTo: '2013-12-28 09:01:22')
75
+ end
76
+
77
+ it "should encode url paramters" do
78
+ subject.end_time = Time.new(2013, 12, 28, 9, 01, 22)
79
+ expect(subject.url_parameters).to include('tsTo=2013-12-28+09%3A01%3A22')
80
+ end
81
+ end
82
+
83
+ describe "#pattern" do
84
+ before { subject.pattern = "spotify" }
85
+
86
+ it "should add searchpattern" do
87
+ expect(subject.url_parameters).to include("searchpattern=spotify")
88
+ end
89
+ end
90
+
91
+ describe "#execute" do
92
+ context "with invalid API key" do
93
+ subject {
94
+ query = Query.new(Client.new('wrong'))
95
+ query.pattern = 'something'
96
+ query
97
+ }
98
+
99
+ it "should raise error on invalid API key" do
100
+ VCR.use_cassette('search_without_valid_api_key') do
101
+ expect { subject.execute }.to raise_error(RuntimeError, "The API key does not exist.")
102
+ end
103
+ end
104
+ end
105
+
106
+ context "when searching for spotify" do
107
+ subject {
108
+ query = Query.new(Client.new('api_key'))
109
+ query.pattern = 'spotify page-size:10'
110
+ query.language = 'sv'
111
+ query
112
+ }
113
+
114
+ it "should get posts when searching for spotify" do
115
+ VCR.use_cassette('search_for_spotify_on_sv_blogs') do
116
+ result = subject.execute
117
+ expect(result.posts).not_to be_empty
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'rspec/its'
3
+ require 'uri'
4
+
5
+ include Twingly::Search
6
+
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
+
14
+ context "before query has populated responses" do
15
+ its(:posts) { should be_empty }
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/../lib/twingly/search'
data/spec/vcr_setup.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ c.hook_into :webmock
6
+ c.filter_sensitive_data('api_key') { ENV['TWINGLY_SEARCH_KEY'] }
7
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'twingly/search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twingly-search"
8
+ spec.version = Twingly::Search::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["Twingly AB"]
11
+ spec.email = ["support@twingly.com"]
12
+ spec.homepage = "http://github.com/twingly/twingly-search-api-ruby"
13
+ spec.summary = "Ruby API client for Twingly Search"
14
+ spec.description = "Twingly Search is a product from Twingly AB"
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = ">= 1.9.3"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "faraday", ['>= 0.9.2', '< 0.10']
23
+ spec.add_dependency "nokogiri", "~> 1.0"
24
+ spec.add_development_dependency "rspec", "~> 3"
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", "~> 0"
29
+ spec.add_development_dependency "github_changelog_generator", "~> 1.8"
30
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twingly-search
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Twingly AB
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.10'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.10'
33
+ - !ruby/object:Gem::Dependency
34
+ name: nokogiri
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec-its
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1'
75
+ - !ruby/object:Gem::Dependency
76
+ name: vcr
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.6'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.6'
89
+ - !ruby/object:Gem::Dependency
90
+ name: webmock
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: github_changelog_generator
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.8'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.8'
131
+ description: Twingly Search is a product from Twingly AB
132
+ email:
133
+ - support@twingly.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".travis.yml"
140
+ - CHANGELOG.md
141
+ - Gemfile
142
+ - LICENSE
143
+ - README.md
144
+ - Rakefile
145
+ - examples/Gemfile
146
+ - examples/find_all_posts_mentioning_github.rb
147
+ - examples/hello_world.rb
148
+ - lib/twingly/search.rb
149
+ - lib/twingly/search/client.rb
150
+ - lib/twingly/search/parser.rb
151
+ - lib/twingly/search/post.rb
152
+ - lib/twingly/search/query.rb
153
+ - lib/twingly/search/result.rb
154
+ - lib/twingly/search/version.rb
155
+ - spec/client_spec.rb
156
+ - spec/fixtures/invalid_result.xml
157
+ - spec/fixtures/valid_result.xml
158
+ - spec/fixtures/vcr_cassettes/search_for_spotify_on_sv_blogs.yml
159
+ - spec/fixtures/vcr_cassettes/search_without_valid_api_key.yml
160
+ - spec/parser_spec.rb
161
+ - spec/post_spec.rb
162
+ - spec/query_spec.rb
163
+ - spec/result_spec.rb
164
+ - spec/spec_helper.rb
165
+ - spec/vcr_setup.rb
166
+ - twingly-search-api-ruby.gemspec
167
+ homepage: http://github.com/twingly/twingly-search-api-ruby
168
+ licenses:
169
+ - MIT
170
+ metadata: {}
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: 1.9.3
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 2.5.0
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Ruby API client for Twingly Search
191
+ test_files:
192
+ - spec/client_spec.rb
193
+ - spec/fixtures/invalid_result.xml
194
+ - spec/fixtures/valid_result.xml
195
+ - spec/fixtures/vcr_cassettes/search_for_spotify_on_sv_blogs.yml
196
+ - spec/fixtures/vcr_cassettes/search_without_valid_api_key.yml
197
+ - spec/parser_spec.rb
198
+ - spec/post_spec.rb
199
+ - spec/query_spec.rb
200
+ - spec/result_spec.rb
201
+ - spec/spec_helper.rb
202
+ - spec/vcr_setup.rb