ansa 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c217b6d57a27027b10594e0401c359b0def592a68a6629a2d0679ee34ccfc2c
4
+ data.tar.gz: 4a204b46891b022dabfa6caf9b62f7d81bbff8eb5463a527a8f9923587548c4b
5
+ SHA512:
6
+ metadata.gz: '0159e31e3db91b102001c16143ddf1ddce2be35f49c6b3d6316b6e460a708d2823c90f16c6af3d7bfccede516e97c8b9241e5aea8d27765603eb90043ac1b0f6'
7
+ data.tar.gz: 955d193ec61f2c6420996271a4e935b195bbdc8a1576fcd45b72ecbdcba9c314ce31d34a76757250f06372380becc40edb074d8e63906f61dc741a99da13eac7
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2018 Andrea Stagi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # Ansa Library for Ruby
2
+
3
+ Read news from [Ansa](http://www.ansa.it) 🗞
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/ansa.svg)](https://badge.fury.io/rb/ansa)
6
+ [![Build Status](https://travis-ci.org/astagi/ruby-ansa.svg?branch=master)](https://travis-ci.org/astagi/ruby-ansa)
7
+ [![codecov](https://codecov.io/gh/astagi/ruby-ansa/branch/master/graph/badge.svg)](https://codecov.io/gh/astagi/ruby-ansa)
8
+
9
+ ## Install
10
+
11
+ Add to your Gemfile
12
+
13
+ gem 'ansa'
14
+
15
+ ## Examples
16
+
17
+ Get all the news about soccer
18
+
19
+ news = Ansa::get_soccer_news()
20
+ p news[0].title
21
+
22
+ You can also use `get_news` method, specifying the category you want
23
+
24
+ news = Ansa::get_news(Ansa::SOCCER)
25
+
26
+ For more see the [documentation](https://www.rubydoc.info/gems/ansa).
@@ -0,0 +1,29 @@
1
+ require 'rake/testtask'
2
+ require 'yard'
3
+ require 'fileutils'
4
+
5
+ require './lib/ansa/constants'
6
+ require './lib/ansa/docs/versions'
7
+
8
+
9
+ Rake::TestTask.new(:test) do |test|
10
+ test.libs << 'lib' << 'test'
11
+ test.pattern = 'test/test_ansa.rb'
12
+ end
13
+
14
+ YARD::Rake::YardocTask.new do |t|
15
+ dynamic_dir = File.join('lib', 'ansa', 'docs')
16
+ dynamic_file = File.join('lib', 'ansa', 'docs', 'dynamic_docs.rb')
17
+ FileUtils.mkdir_p dynamic_dir
18
+ f = File.new(dynamic_file, 'w')
19
+ f.write("module Ansa")
20
+ Ansa::LINKS.each do |key, value|
21
+ f.write("\n generate_get_news '#{key}', '#{value}', '#{AUTOGENERATED_METHODS_VERSIONS[key]}'")
22
+ end
23
+ f.write("\nend")
24
+ t.files = ['lib/**/*.rb']
25
+ t.stats_options = ['--list-undoc']
26
+ end
27
+
28
+ desc "Run tests"
29
+ task :default => :test
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "ansa"
5
+ s.version = "1.1.1"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Andrea Stagi"]
8
+ s.email = ["stagi.andrea@gmail.com"]
9
+ s.description = "Read all the news from http://www.ansa.it"
10
+ s.homepage = "https://github.com/astagi/ruby-ansa"
11
+ s.summary = "Read all the news from http://www.ansa.it"
12
+ s.rubyforge_project = "ansa"
13
+ s.require_paths = ["lib"]
14
+
15
+ s.add_development_dependency "simplecov"
16
+ s.add_development_dependency "webmock"
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "minitest"
19
+ s.add_development_dependency "yard"
20
+ s.add_development_dependency "codecov", ">= 0.1.10"
21
+
22
+ s.extra_rdoc_files = ['README.md']
23
+ s.rdoc_options = ['--charset=UTF-8']
24
+
25
+ s.files = [
26
+ 'LICENSE',
27
+ 'README.md',
28
+ 'lib/ansa.rb',
29
+ 'lib/ansa/client.rb',
30
+ 'lib/ansa/constants.rb',
31
+ 'lib/ansa/errors.rb',
32
+ 'lib/ansa/news.rb',
33
+ 'lib/ansa/docs/dynamic_docs.rb',
34
+ 'lib/ansa/docs/versions.rb',
35
+ 'Rakefile',
36
+ 'ansa.gemspec'
37
+ ]
38
+
39
+ end
@@ -0,0 +1,9 @@
1
+
2
+ require 'rubygems'
3
+
4
+ require "ansa/constants"
5
+ require "ansa/client"
6
+
7
+
8
+ module Ansa
9
+ end
@@ -0,0 +1,59 @@
1
+ require 'net/http'
2
+ require 'rss'
3
+ require "ansa/news"
4
+ require "ansa/errors"
5
+
6
+
7
+ module Ansa
8
+
9
+ private
10
+ def self.get_news_by_url(url)
11
+ news = []
12
+ begin
13
+ rss = RSS::Parser.parse(open(url).read, false).items
14
+ rescue NoMethodError
15
+ raise AnsaError.new("Url #{url} is not a valid RSS source")
16
+ rescue StandardError
17
+ raise AnsaError.new("Error fetching news")
18
+ end
19
+ rss.each do |result|
20
+ news.push(
21
+ News.new(result.title, result.description, result.date, result.link)
22
+ )
23
+ end
24
+ return news
25
+ end
26
+
27
+ # @!macro [attach] generate_get_news
28
+ # @method get_$1_news
29
+ # @!scope class
30
+ # @note This method is autogenerated, it fetches $2
31
+ # Get news for "$1" category.
32
+ # @since $3
33
+ # @raise [Ansa::AnsaError] when errors occour fetching news
34
+ # @return [Array<Ansa::News>] all the news of category "$1".
35
+ def self.generate_get_news(category, value)
36
+ define_singleton_method("get_#{category}_news") do
37
+ get_news_by_url(value)
38
+ end
39
+ end
40
+
41
+ public
42
+ # Get news given a category.
43
+ #
44
+ # @param category name, `:text`
45
+ # @raise [Ansa::AnsaError] when errors occour fetching news
46
+ # @since 1.0.0
47
+ # @return [Array<Ansa::News>] all the news of the given category.
48
+ def self.get_news(category)
49
+ if not LINKS.include? category
50
+ raise AnsaError.new("Category #{category} not available")
51
+ end
52
+ get_news_by_url(LINKS[category])
53
+ end
54
+
55
+ LINKS.each do |key, value|
56
+ generate_get_news key, value
57
+ end
58
+
59
+ end
@@ -0,0 +1,53 @@
1
+ require 'uri'
2
+
3
+
4
+ module Ansa
5
+
6
+ public
7
+ # Constant for homepage news.
8
+ #
9
+ # @since 1.0.0
10
+ HOMEPAGE = 'homepage'
11
+
12
+ # Constant for main news.
13
+ #
14
+ # @since 1.0.0
15
+ NEWS = 'news'
16
+
17
+ # Constant for politics news.
18
+ #
19
+ # @since 1.0.0
20
+ POLITICS = 'politics'
21
+
22
+ # Constant for world news.
23
+ #
24
+ # @since 1.0.0
25
+ WORLD = 'world'
26
+
27
+ # Constant for economy news.
28
+ #
29
+ # @since 1.0.0
30
+ ECONOMY = 'economy'
31
+
32
+ # Constant for soccer news.
33
+ #
34
+ # @since 1.0.0
35
+ SOCCER = 'soccer'
36
+
37
+ # Constant for sport news.
38
+ #
39
+ # @since 1.0.0
40
+ SPORT = 'sport'
41
+
42
+ private
43
+ BASE_URL = 'http://www.ansa.it/sito/'
44
+ LINKS = {
45
+ HOMEPAGE => BASE_URL + 'ansait_rss.xml',
46
+ NEWS => BASE_URL + 'notizie/cronaca/cronaca_rss.xml',
47
+ POLITICS => BASE_URL + 'notizie/politica/politica_rss.xml',
48
+ WORLD => BASE_URL + 'notizie/mondo/mondo_rss.xml',
49
+ ECONOMY => BASE_URL + 'notizie/economia/economia_rss.xml',
50
+ SOCCER => BASE_URL + 'notizie/sport/calcio/calcio_rss.xml',
51
+ SPORT => BASE_URL + 'notizie/sport/sport_rss.xml'
52
+ }
53
+ end
@@ -0,0 +1,9 @@
1
+ module Ansa
2
+ generate_get_news 'homepage', 'http://www.ansa.it/sito/ansait_rss.xml', '1.0.0'
3
+ generate_get_news 'news', 'http://www.ansa.it/sito/notizie/cronaca/cronaca_rss.xml', '1.0.0'
4
+ generate_get_news 'politics', 'http://www.ansa.it/sito/notizie/politica/politica_rss.xml', '1.0.0'
5
+ generate_get_news 'world', 'http://www.ansa.it/sito/notizie/mondo/mondo_rss.xml', '1.0.0'
6
+ generate_get_news 'economy', 'http://www.ansa.it/sito/notizie/economia/economia_rss.xml', '1.0.0'
7
+ generate_get_news 'soccer', 'http://www.ansa.it/sito/notizie/sport/calcio/calcio_rss.xml', '1.0.0'
8
+ generate_get_news 'sport', 'http://www.ansa.it/sito/notizie/sport/sport_rss.xml', '1.0.0'
9
+ end
@@ -0,0 +1,12 @@
1
+ require 'ansa/constants'
2
+
3
+
4
+ AUTOGENERATED_METHODS_VERSIONS = {
5
+ Ansa::HOMEPAGE => '1.0.0',
6
+ Ansa::NEWS => '1.0.0',
7
+ Ansa::POLITICS => '1.0.0',
8
+ Ansa::WORLD => '1.0.0',
9
+ Ansa::ECONOMY => '1.0.0',
10
+ Ansa::SOCCER => '1.0.0',
11
+ Ansa::SPORT => '1.0.0'
12
+ }
@@ -0,0 +1,10 @@
1
+ module Ansa
2
+
3
+ # Base class for errors
4
+ class AnsaError < StandardError
5
+ def initialize(msg="General error")
6
+ super
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,34 @@
1
+
2
+ module Ansa
3
+
4
+ # Base class representing a news
5
+ class News
6
+ def initialize(title, description, date, link)
7
+ @title = title
8
+ @description = description
9
+ @date = date
10
+ @link = link
11
+ end
12
+
13
+ # @return [String] the title of the news
14
+ def title
15
+ @title
16
+ end
17
+
18
+ # @return [String] the description of the news
19
+ def description
20
+ @description
21
+ end
22
+
23
+ # @return [Time] the date of the news
24
+ def date
25
+ @date
26
+ end
27
+
28
+ # @return [String] the link of the news
29
+ def link
30
+ @link
31
+ end
32
+
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansa
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrea Stagi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
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: minitest
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: yard
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: codecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.10
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.10
97
+ description: Read all the news from http://www.ansa.it
98
+ email:
99
+ - stagi.andrea@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files:
103
+ - README.md
104
+ files:
105
+ - LICENSE
106
+ - README.md
107
+ - Rakefile
108
+ - ansa.gemspec
109
+ - lib/ansa.rb
110
+ - lib/ansa/client.rb
111
+ - lib/ansa/constants.rb
112
+ - lib/ansa/docs/dynamic_docs.rb
113
+ - lib/ansa/docs/versions.rb
114
+ - lib/ansa/errors.rb
115
+ - lib/ansa/news.rb
116
+ homepage: https://github.com/astagi/ruby-ansa
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options:
121
+ - "--charset=UTF-8"
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project: ansa
136
+ rubygems_version: 2.7.6
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Read all the news from http://www.ansa.it
140
+ test_files: []