twingly-analytics 1.0.1 → 2.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 +15 -5
- data/README.md +10 -2
- data/examples/find_all_posts_mentioning_github.rb +20 -20
- data/examples/hello_world.rb +11 -0
- data/lib/twingly-analytics/query.rb +12 -13
- data/lib/twingly-analytics/result.rb +4 -0
- data/lib/twingly-analytics/version.rb +1 -1
- data/spec/result_spec.rb +1 -0
- data/twingly-analytics-api-ruby.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5c4ddb79208dbda2a2171067fe2c31cabff9fbc
|
4
|
+
data.tar.gz: 8ce553588c30aba41aecf0b3a469abe2419c33d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccaef06060bbb5f9c155d6582e8f8a1a43bc557dd0f9de6eb89d6af76755b1e7711c87c77ce541c1e55f9b873678690f228857a31d001102833477e27d9f61d7
|
7
|
+
data.tar.gz: c46959a67fcb05237e4cb3af84674822335cb841bd4b526523cd173e4039bc3033404c46a527f30d31ea184cfec45344f7b4a83d824709cddf1708103a66d437
|
data/.travis.yml
CHANGED
@@ -1,17 +1,27 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- 2.1
|
7
|
+
- 2.2
|
8
8
|
deploy:
|
9
9
|
provider: rubygems
|
10
10
|
api_key:
|
11
|
-
secure:
|
11
|
+
secure: QxMWXTQ3/T+0IQZl3pk3hmdoX8FcXTXEhH7Jn7Ub1A1D5faa8VNnfYsWAPjP6+VRgVfKEjAsHNMyZQNTvudpPPC/2kAwwzPvStyS+y7KnRkjZ9acC7sYVVel6cZ2lcl+t8iHY+19NRBFBWpq/P0eCAcR/Ew0XXaLZnig5h/1mQo=
|
12
12
|
gem: twingly-analytics
|
13
13
|
gemspec: twingly-analytics-api-ruby.gemspec
|
14
14
|
on:
|
15
15
|
tags: true
|
16
16
|
rvm: 2.2
|
17
17
|
repo: twingly/twingly-analytics-api-ruby
|
18
|
+
notifications:
|
19
|
+
email: false
|
20
|
+
hipchat:
|
21
|
+
on_success: never
|
22
|
+
on_failure: change
|
23
|
+
template:
|
24
|
+
- '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Details</a>/<a href="%{compare_url}">Change view</a>)'
|
25
|
+
format: html
|
26
|
+
rooms:
|
27
|
+
secure: KU2mE9mcqvBczfiCTgTsgMmJPyW02AH/0Rzcli7oj3HVbiHGw8t5JlBQWYROF5TPht0kFhGkiwVPl6HUt/VAGxOIBsOp+/8MXR6aK5FkdIw6g8DMKlDjm9a2QijOT9rvat5bZ3l6hm3snojgkI3s9pLKmLq9l+KalAsPcevwKAQ=
|
data/README.md
CHANGED
@@ -7,10 +7,16 @@ A Ruby gem for Twingly's Analytics API. Twingly is a blog search service that pr
|
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
|
10
|
+
Install via RubyGems
|
11
|
+
|
12
|
+
```Shell
|
13
|
+
gem install twingly-analytics
|
14
|
+
```
|
15
|
+
|
16
|
+
Or add to your application's [Gemfile](http://bundler.io/gemfile.html) and then run `bundle`
|
11
17
|
|
12
18
|
```Ruby
|
13
|
-
gem 'twingly-analytics'
|
19
|
+
gem 'twingly-analytics'
|
14
20
|
```
|
15
21
|
|
16
22
|
## Usage
|
@@ -29,6 +35,8 @@ result.posts # will include all returned posts
|
|
29
35
|
|
30
36
|
The `twinlgy-analytics` gem talks to a commercial blog search API and requires an API key. Best practice is to set the `TWINGLY_ANALYTICS_KEY` environment variable to the obtained key. `Twingly::Analytics::Client` can be passed a key at initialization if your setup does not allow environment variables.
|
31
37
|
|
38
|
+
Example code can be found in [examples/](examples/).
|
39
|
+
|
32
40
|
Too learn more about the capabilities of this API you should read the [Twingly Analytics API documentation](https://developer.twingly.com/resources/analytics/).
|
33
41
|
|
34
42
|
## Requirements
|
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'bundler'
|
3
1
|
Bundler.require
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
class AnalyticsPostStream
|
4
|
+
def initialize(keyword, language: nil)
|
5
|
+
# Set environment variable TWINGLY_ANALYTICS_KEY
|
6
|
+
client = Twingly::Analytics::Client.new
|
7
|
+
@query = client.query
|
8
|
+
@query.language = language
|
9
|
+
@query.pattern = "sort-order:asc sort:published #{keyword}"
|
10
|
+
end
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
def each
|
13
|
+
loop do
|
14
|
+
result = @query.execute
|
15
|
+
result.posts.each do |post|
|
16
|
+
yield post
|
17
|
+
end
|
11
18
|
|
12
|
-
|
13
|
-
query = client.query
|
14
|
-
query.pattern = "sort-order:asc sort:published github"
|
15
|
-
query.start_time = start_time
|
16
|
-
query.language = 'sv'
|
17
|
-
result = query.execute
|
19
|
+
break if result.all_results_returned?
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
@query.start_time = result.posts.last.published
|
22
|
+
end
|
21
23
|
end
|
22
|
-
|
23
|
-
finished = start_time == result.posts.last.published
|
24
|
-
start_time = result.posts.last.published
|
25
24
|
end
|
26
25
|
|
27
|
-
|
28
|
-
|
26
|
+
stream = AnalyticsPostStream.new("(github) AND (hipchat OR slack)")
|
27
|
+
stream.each do |post|
|
28
|
+
puts post.url
|
29
29
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Bundler.require
|
2
|
+
|
3
|
+
# Set environment variable TWINGLY_ANALYTICS_KEY
|
4
|
+
client = Twingly::Analytics::Client.new
|
5
|
+
query = client.query
|
6
|
+
query.pattern = '"hello world"'
|
7
|
+
query.start_time = Time.now - (24 * 3600) # search last day
|
8
|
+
result = query.execute
|
9
|
+
result.posts.each do |post|
|
10
|
+
puts post.url
|
11
|
+
end
|
@@ -3,8 +3,7 @@ require 'faraday'
|
|
3
3
|
module Twingly
|
4
4
|
module Analytics
|
5
5
|
class Query
|
6
|
-
attr_accessor :pattern, :language, :client
|
7
|
-
attr_reader :start_time, :end_time
|
6
|
+
attr_accessor :pattern, :language, :client, :start_time, :end_time
|
8
7
|
|
9
8
|
BASE_URL = 'https://api.twingly.com'
|
10
9
|
ANALYTICS_PATH = '/analytics/Analytics.ashx'
|
@@ -21,14 +20,6 @@ module Twingly
|
|
21
20
|
Parser.new.parse(get_response.body)
|
22
21
|
end
|
23
22
|
|
24
|
-
def start_time=(time)
|
25
|
-
@start_time = time.strftime("%F %T")
|
26
|
-
end
|
27
|
-
|
28
|
-
def end_time=(time)
|
29
|
-
@end_time = time.strftime("%F %T")
|
30
|
-
end
|
31
|
-
|
32
23
|
def url_parameters
|
33
24
|
Faraday::Utils.build_query(request_parameters)
|
34
25
|
end
|
@@ -40,20 +31,28 @@ module Twingly
|
|
40
31
|
:key => client.api_key,
|
41
32
|
:searchpattern => pattern,
|
42
33
|
:documentlang => language,
|
43
|
-
:ts =>
|
44
|
-
:tsTo =>
|
34
|
+
:ts => ts,
|
35
|
+
:tsTo => ts_to,
|
45
36
|
:xmloutputversion => 2
|
46
37
|
}
|
47
38
|
end
|
48
39
|
|
49
40
|
private
|
50
41
|
|
42
|
+
def ts
|
43
|
+
start_time.to_time.strftime("%F %T") if start_time
|
44
|
+
end
|
45
|
+
|
46
|
+
def ts_to
|
47
|
+
end_time.to_time.strftime("%F %T") if end_time
|
48
|
+
end
|
49
|
+
|
51
50
|
def get_response
|
52
51
|
connection = Faraday.new(:url => BASE_URL) do |faraday|
|
53
52
|
faraday.request :url_encoded
|
54
53
|
faraday.adapter Faraday.default_adapter
|
55
54
|
end
|
56
|
-
connection.headers[:user_agent] =
|
55
|
+
connection.headers[:user_agent] = "Twingly Analytics Ruby Client/#{VERSION}"
|
57
56
|
connection.get(ANALYTICS_PATH, request_parameters)
|
58
57
|
end
|
59
58
|
end
|
@@ -8,6 +8,10 @@ module Twingly
|
|
8
8
|
@posts ||= []
|
9
9
|
end
|
10
10
|
|
11
|
+
def all_results_returned?
|
12
|
+
number_of_matches_returned.to_i == number_of_matches_total.to_i
|
13
|
+
end
|
14
|
+
|
11
15
|
def inspect
|
12
16
|
matches = "@posts, "
|
13
17
|
matches << "@number_of_matches_returned=#{self.number_of_matches_returned}, "
|
data/spec/result_spec.rb
CHANGED
@@ -9,6 +9,7 @@ describe Result do
|
|
9
9
|
it { should respond_to :number_of_matches_returned }
|
10
10
|
it { should respond_to :number_of_matches_total }
|
11
11
|
it { should respond_to :seconds_elapsed }
|
12
|
+
it { should respond_to :all_results_returned? }
|
12
13
|
|
13
14
|
context "before query has populated responses" do
|
14
15
|
its(:posts) { should be_empty }
|
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "rspec-its", "~> 1"
|
26
26
|
spec.add_development_dependency "vcr", "~> 2.6"
|
27
27
|
spec.add_development_dependency "webmock", "~> 1.0"
|
28
|
-
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rake", "~> 0"
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twingly-analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Eckerström
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -104,14 +104,14 @@ dependencies:
|
|
104
104
|
name: rake
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- - "
|
107
|
+
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- - "
|
114
|
+
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
description: Twingly Analytics is a product from Twingly AB
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- Rakefile
|
130
130
|
- examples/Gemfile
|
131
131
|
- examples/find_all_posts_mentioning_github.rb
|
132
|
+
- examples/hello_world.rb
|
132
133
|
- lib/twingly-analytics.rb
|
133
134
|
- lib/twingly-analytics/client.rb
|
134
135
|
- lib/twingly-analytics/parser.rb
|
@@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
169
|
version: '0'
|
169
170
|
requirements: []
|
170
171
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.4.5
|
172
|
+
rubygems_version: 2.4.5.1
|
172
173
|
signing_key:
|
173
174
|
specification_version: 4
|
174
175
|
summary: Ruby API client for Twingly Analytics
|
@@ -184,4 +185,3 @@ test_files:
|
|
184
185
|
- spec/result_spec.rb
|
185
186
|
- spec/spec_helper.rb
|
186
187
|
- spec/vcr_setup.rb
|
187
|
-
has_rdoc:
|