newsmonitor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/README.md +71 -0
- data/Rakefile +8 -0
- data/lib/news_monitor/api.rb +44 -0
- data/lib/news_monitor/article.rb +26 -0
- data/lib/news_monitor/cluster.rb +8 -0
- data/lib/news_monitor/image.rb +9 -0
- data/lib/news_monitor/publisher.rb +12 -0
- data/lib/news_monitor/topic.rb +8 -0
- data/lib/news_monitor/version.rb +3 -0
- data/lib/news_monitor.rb +10 -0
- data/newsmonitor.gemspec +25 -0
- data/spec/api_spec.rb +55 -0
- data/spec/minitest_helper.rb +11 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a5d26f958b21da893945913ab46e9367b9d97b1
|
4
|
+
data.tar.gz: 9996547358ca4e95735dfe44ce9d7b3354a2ca4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2cb150d8eacc602e9c88b06658dafb7c3fb1c6e8bd743e884ccc7c4eba8e45421b014b065270c7fd50fa63e201a1745b69bff538a4d8ebf1d09d5ecf1250002f
|
7
|
+
data.tar.gz: 8e10b1ffba322e808f9cb1a55c09657830a69282eb974fed4a062b975e239d111007641f453ed0e1ab7a31d2d996afe0c275c2b8d002b862729e403429d44393
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# NewsMonitor
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/rainerborene/newsmonitor.svg)](https://travis-ci.org/rainerborene/newsmonitor)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/rainerborene/newsmonitor/badges/gpa.svg)](https://codeclimate.com/github/rainerborene/newsmonitor)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/rainerborene/newsmonitor/badges/coverage.svg)](https://codeclimate.com/github/rainerborene/newsmonitor/coverage)
|
6
|
+
|
7
|
+
NewsMonitor API wrapper.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'newsmonitor', require: 'news_monitor'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install newsmonitor
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# Create the API object
|
29
|
+
api = NewsMonitor::API.new username: 'jonhdoe', password: 'pwd'
|
30
|
+
|
31
|
+
# Search similar articles grouped by cluster
|
32
|
+
clusters = api.search("lavagem")
|
33
|
+
|
34
|
+
# Find article by id
|
35
|
+
api.find_article(72109310)
|
36
|
+
|
37
|
+
# Find cluster by id
|
38
|
+
api.find_cluster(7173190)
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/rainerborene/newsmonitor/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The MIT License (MIT)
|
52
|
+
|
53
|
+
Copyright (c) 2015 Rainer Borene
|
54
|
+
|
55
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
56
|
+
of this software and associated documentation files (the "Software"), to deal
|
57
|
+
in the Software without restriction, including without limitation the rights
|
58
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
59
|
+
copies of the Software, and to permit persons to whom the Software is
|
60
|
+
furnished to do so, subject to the following conditions:
|
61
|
+
|
62
|
+
The above copyright notice and this permission notice shall be included in
|
63
|
+
all copies or substantial portions of the Software.
|
64
|
+
|
65
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
66
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
67
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
68
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
69
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
70
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
71
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'httparty'
|
3
|
+
require 'nibbler/json'
|
4
|
+
|
5
|
+
module NewsMonitor
|
6
|
+
class API
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
base_uri 'https://api.spixdiscovery.com:8083'
|
10
|
+
|
11
|
+
def initialize(options={})
|
12
|
+
@auth = {}
|
13
|
+
@auth[:username] = options.fetch :username, ENV['NEWSMONITOR_USERNAME']
|
14
|
+
@auth[:password] = options.fetch :password, ENV['NEWSMONITOR_PASSWORD']
|
15
|
+
end
|
16
|
+
|
17
|
+
def search(query, options={})
|
18
|
+
conditions = ERB::Util.url_encode(query)
|
19
|
+
options.merge! basic_auth: @auth
|
20
|
+
response = get "/search/#{conditions}", options
|
21
|
+
response['results'].map! do |cluster|
|
22
|
+
Cluster.parse(cluster)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_article(article_id, options={})
|
27
|
+
options.merge! basic_auth: @auth
|
28
|
+
response = get "/article/#{article_id}", options
|
29
|
+
Article.parse(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_cluster(cluster_id, options={})
|
33
|
+
options.merge! basic_auth: @auth
|
34
|
+
response = get "/cluster/#{cluster_id}", options
|
35
|
+
Cluster.parse response['results'].first
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def get(path, options)
|
41
|
+
self.class.get(path, options).parsed_response
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NewsMonitor
|
2
|
+
class Article < NibblerJSON
|
3
|
+
element :id
|
4
|
+
element :created_at, with: -> (time) { Time.parse time }
|
5
|
+
element :type
|
6
|
+
element :title
|
7
|
+
element :language_code
|
8
|
+
element :url
|
9
|
+
element :published_at, with: -> (time) { Time.parse time }
|
10
|
+
element :directories
|
11
|
+
element :content
|
12
|
+
|
13
|
+
element '.social_metrics.facebook_likes' => :facebook_likes
|
14
|
+
element '.social_metrics.facebook_shares' => :facebook_shares
|
15
|
+
element '.social_metrics.facebook_comments' => :facebook_comments
|
16
|
+
element '.social_metrics.facebook_total' => :facebook_total
|
17
|
+
element '.social_metrics.twitter' => :twitter_shares
|
18
|
+
element '.social_metrics.pinterest' => :pinterest_shares
|
19
|
+
element '.social_metrics.linkedin' => :linkedin_shares
|
20
|
+
element '.social_metrics.google_plusones' => :google_plusones
|
21
|
+
|
22
|
+
elements :publishings, with: Publisher
|
23
|
+
elements :images, with: Image
|
24
|
+
elements :topics, with: Topic
|
25
|
+
end
|
26
|
+
end
|
data/lib/news_monitor.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'news_monitor/version'
|
2
|
+
|
3
|
+
module NewsMonitor
|
4
|
+
autoload :API, 'news_monitor/api'
|
5
|
+
autoload :Cluster, 'news_monitor/cluster'
|
6
|
+
autoload :Article, 'news_monitor/article'
|
7
|
+
autoload :Publisher, 'news_monitor/publisher'
|
8
|
+
autoload :Image, 'news_monitor/image'
|
9
|
+
autoload :Topic, 'news_monitor/topic'
|
10
|
+
end
|
data/newsmonitor.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require './lib/news_monitor/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'newsmonitor'
|
5
|
+
spec.version = NewsMonitor::VERSION
|
6
|
+
spec.authors = ['Rainer Borene']
|
7
|
+
spec.email = ['rainerborene@gmail.com']
|
8
|
+
spec.summary = %q{NewsMonitor API wrapper}
|
9
|
+
spec.description = spec.summary
|
10
|
+
spec.homepage = 'https://github.com/rainerborene/newsmonitor'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_dependency 'httparty'
|
19
|
+
spec.add_dependency 'nibbler'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'pry'
|
24
|
+
spec.add_development_dependency 'minitest'
|
25
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'minitest_helper'
|
2
|
+
|
3
|
+
describe NewsMonitor::API do
|
4
|
+
|
5
|
+
describe '#initialize' do
|
6
|
+
it 'setup authentication given username and password' do
|
7
|
+
api = described_class.new username: 'test', password: 'test2'
|
8
|
+
auth = api.instance_variable_get :@auth
|
9
|
+
auth[:username].must_equal 'test'
|
10
|
+
auth[:password].must_equal 'test2'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'fallback to environment variables' do
|
14
|
+
ENV['NEWSMONITOR_USERNAME'] = 'test2'
|
15
|
+
ENV['NEWSMONITOR_PASSWORD'] = 'test'
|
16
|
+
|
17
|
+
auth = described_class.new.instance_variable_get :@auth
|
18
|
+
auth[:username].must_equal 'test2'
|
19
|
+
auth[:password].must_equal 'test'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#search' do
|
24
|
+
it 'fetch clusters of articles given the query' do
|
25
|
+
api = described_class.new
|
26
|
+
results = api.search "lavagem", query: { with_info: true, cluster_size: 1 }
|
27
|
+
results.size.must_equal 50
|
28
|
+
results.must_be_instance_of Array
|
29
|
+
results.map(&:class).uniq.must_equal [NewsMonitor::Cluster]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#find_article' do
|
34
|
+
it 'find article with given id' do
|
35
|
+
api = described_class.new
|
36
|
+
article = api.find_article 164240971
|
37
|
+
article.must_be_instance_of NewsMonitor::Article
|
38
|
+
article.published_at.must_be_instance_of Time
|
39
|
+
article.created_at.must_be_instance_of Time
|
40
|
+
article.id.must_equal 164240971
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#find_cluster' do
|
45
|
+
it 'find cluster with given id' do
|
46
|
+
api = described_class.new
|
47
|
+
cluster = api.find_cluster 164240971, query: { with_info: true }
|
48
|
+
cluster.must_be_instance_of NewsMonitor::Cluster
|
49
|
+
cluster.id.must_equal 164240971
|
50
|
+
cluster.size.must_equal 1
|
51
|
+
cluster.articles.wont_be :empty?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'news_monitor'
|
3
|
+
require 'minitest/spec'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
class MiniTest::Spec
|
8
|
+
def described_class
|
9
|
+
@described_class ||= self.class.ancestors.select {|c| c.respond_to? :desc }[-2].desc
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newsmonitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rainer Borene
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nibbler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: NewsMonitor API wrapper
|
98
|
+
email:
|
99
|
+
- rainerborene@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/news_monitor.rb
|
110
|
+
- lib/news_monitor/api.rb
|
111
|
+
- lib/news_monitor/article.rb
|
112
|
+
- lib/news_monitor/cluster.rb
|
113
|
+
- lib/news_monitor/image.rb
|
114
|
+
- lib/news_monitor/publisher.rb
|
115
|
+
- lib/news_monitor/topic.rb
|
116
|
+
- lib/news_monitor/version.rb
|
117
|
+
- newsmonitor.gemspec
|
118
|
+
- spec/api_spec.rb
|
119
|
+
- spec/minitest_helper.rb
|
120
|
+
homepage: https://github.com/rainerborene/newsmonitor
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: NewsMonitor API wrapper
|
144
|
+
test_files:
|
145
|
+
- spec/api_spec.rb
|
146
|
+
- spec/minitest_helper.rb
|