metonym 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +34 -4
- data/README.md +193 -142
- data/lib/metonym.rb +12 -2
- data/lib/metonym/lib/gnews.rb +49 -47
- data/lib/metonym/lib/news_api.rb +45 -56
- data/lib/metonym/lib/presenters/base_response_presenter.rb +18 -0
- data/lib/metonym/lib/presenters/gnews_response_presenter.rb +5 -0
- data/lib/metonym/lib/presenters/news_api_response_presenter.rb +3 -0
- data/lib/metonym/lib/repositories/base_repository.rb +9 -0
- data/lib/metonym/lib/repositories/gnews_repository.rb +31 -0
- data/lib/metonym/lib/repositories/news_api_repository.rb +31 -0
- data/lib/metonym/lib/validators/base_validator.rb +25 -0
- data/lib/metonym/lib/validators/gnews_query_validator.rb +55 -0
- data/lib/metonym/lib/validators/news_api_query_validator.rb +61 -0
- data/lib/metonym/version.rb +3 -1
- data/metonym.gemspec +24 -22
- metadata +39 -18
- data/lib/metonym/lib/validate.rb +0 -124
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e7e7ae3fc9fcae26d9e24fa705a49d54d71f63de6839a71129768680b7a2cd
|
4
|
+
data.tar.gz: bb0f1a50c11b52a64e81c388caddd442c6d35bc9768e287f609221cd74e2f1c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0b080f2ca21daea2b80f8be418476479e19a38680c6bc19f648f4e328e96c2a9adabe679ec851db88b686f7788b8f2fa2670b1fe37c737eb88ada3883b9a973
|
7
|
+
data.tar.gz: 17ef419348b5e1da15dc2856aca2b36dff92efb8bedcc6abec2ab5d7ef30f0e07449cd7670b154de2aac2762f814c1b341cfd4ada0f431c2e6f438190f819a09
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
metonym (0.
|
4
|
+
metonym (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
byebug (11.0.1)
|
10
|
+
coderay (1.1.2)
|
10
11
|
diff-lcs (1.3)
|
11
|
-
|
12
|
+
ffi (1.12.2)
|
13
|
+
formatador (0.2.5)
|
14
|
+
guard (2.16.1)
|
15
|
+
formatador (>= 0.2.4)
|
16
|
+
listen (>= 2.7, < 4.0)
|
17
|
+
lumberjack (>= 1.0.12, < 2.0)
|
18
|
+
nenv (~> 0.1)
|
19
|
+
notiffany (~> 0.0)
|
20
|
+
pry (>= 0.9.12)
|
21
|
+
shellany (~> 0.0)
|
22
|
+
thor (>= 0.18.1)
|
23
|
+
listen (3.2.1)
|
24
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
25
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
26
|
+
lumberjack (1.2.4)
|
27
|
+
method_source (0.9.2)
|
28
|
+
nenv (0.3.0)
|
29
|
+
notiffany (0.1.3)
|
30
|
+
nenv (~> 0.1)
|
31
|
+
shellany (~> 0.0)
|
32
|
+
pry (0.12.2)
|
33
|
+
coderay (~> 1.1.0)
|
34
|
+
method_source (~> 0.9.0)
|
35
|
+
rake (12.3.3)
|
36
|
+
rb-fsevent (0.10.3)
|
37
|
+
rb-inotify (0.10.1)
|
38
|
+
ffi (~> 1.0)
|
12
39
|
rspec (3.8.0)
|
13
40
|
rspec-core (~> 3.8.0)
|
14
41
|
rspec-expectations (~> 3.8.0)
|
@@ -22,6 +49,8 @@ GEM
|
|
22
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
23
50
|
rspec-support (~> 3.8.0)
|
24
51
|
rspec-support (3.8.0)
|
52
|
+
shellany (0.0.1)
|
53
|
+
thor (1.0.1)
|
25
54
|
|
26
55
|
PLATFORMS
|
27
56
|
ruby
|
@@ -29,9 +58,10 @@ PLATFORMS
|
|
29
58
|
DEPENDENCIES
|
30
59
|
bundler (~> 2.0)
|
31
60
|
byebug
|
61
|
+
guard
|
32
62
|
metonym!
|
33
|
-
rake (~>
|
63
|
+
rake (~> 12.3.3)
|
34
64
|
rspec (~> 3.0)
|
35
65
|
|
36
66
|
BUNDLED WITH
|
37
|
-
2.
|
67
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# Metonym
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/viccarrasco/metonym.svg?branch=master)](https://travis-ci.org/viccarrasco/metonym)
|
4
|
+
|
3
5
|
A ruby gem for [GNews API](https://gnews.io) and [NewsApi](https://newsapi.org/)
|
4
6
|
|
7
|
+
## Important
|
8
|
+
|
9
|
+
I've decided to revive this project based on the fact that misinformation is a huge problem when facing a world threat. Covid-19 is an unprecedented thread that is
|
10
|
+
affecting the world.
|
11
|
+
|
12
|
+
[Please take some time to contribute](https://www.endcoronavirus.org/)
|
5
13
|
|
6
14
|
## Installation
|
7
15
|
|
@@ -19,16 +27,55 @@ Or install it yourself as:
|
|
19
27
|
|
20
28
|
$ gem install metonym
|
21
29
|
|
22
|
-
## Usage
|
30
|
+
## Typical Usage
|
23
31
|
|
24
32
|
To be able to send requests to the GNews API, you first must create an account to receive a token [here](https://gnews.io/register.php).
|
25
33
|
|
26
34
|
To be able to send requests to NewsApi, you first must create an account to receive a token [here](https://newsapi.org/).
|
27
35
|
|
36
|
+
## COVID-19
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# Establish parameters for query
|
40
|
+
args = { q: 'Covid-19', country: 'DE', mindate: (DateTime.now - 2), max: 1 }
|
41
|
+
|
42
|
+
# Send Request
|
43
|
+
gnews = Gnews::Query.new('my-secret-key')
|
44
|
+
response = gnews.search(args)
|
45
|
+
|
46
|
+
puts response
|
47
|
+
|
48
|
+
# =>
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
```json
|
53
|
+
{
|
54
|
+
"status": "ok",
|
55
|
+
"totalResults": 1,
|
56
|
+
"articles": [
|
57
|
+
{
|
58
|
+
"source": {
|
59
|
+
"id": "die-zeit",
|
60
|
+
"name": "Die Zeit"
|
61
|
+
},
|
62
|
+
"author": "Bettina Schulz",
|
63
|
+
"title": "Covid-19: Massenisolation statt HerdenimmunitxC3xA4t - ZEIT ONLINE",
|
64
|
+
"description": "Die britische Regierung gibt ihre Strategie im Kampf gegen Covid-19 auf. Statt eine Erkrankung von Millionen Menschen in Kauf zu nehmen, setzt sie nun auf Isolation.",
|
65
|
+
"url": "https://www.zeit.de/politik/ausland/2020-03/covid-19-grossbritannien-herdenimmunitaet-virusbekaempfung",
|
66
|
+
"urlToImage": "https://img.zeit.de/politik/ausland/2020-03/covid-19-grossbritannien-herdenimmunitaet-virusbekaempfung-london/wide__1300x731",
|
67
|
+
"publishedAt": "2020-03-15T19:39:58Z",
|
68
|
+
"content": "InhaltrnAuf einer Seite lesenrn Inhaltrn<ol><li>Seite 1Massenisolation statt HerdenimmunitxC3xA4trn</li><li>Seite 2Das britische Gesundheitssystem ist fxC3xBCr ErnstfxC3xA4lle nicht gerxC3xBCstet</li></ol>rnNach deutlicher Kritik aus wissenschaftlichen Kreisen hat die britische xE2x80xA6 [+3845 chars]"
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
28
74
|
## Query Gnews API
|
75
|
+
|
29
76
|
```ruby
|
30
77
|
# Establish parameters for query
|
31
|
-
args = {
|
78
|
+
args = { q: 'Dragon Ball Super', country: 'MX', mindate: (DateTime.now - 2), max: 1 }
|
32
79
|
|
33
80
|
# Send Request
|
34
81
|
gnews = Gnews::Query.new('my-secret-key')
|
@@ -40,20 +87,20 @@ puts response
|
|
40
87
|
```
|
41
88
|
|
42
89
|
```json
|
43
|
-
{
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
90
|
+
{
|
91
|
+
"timestamp": 1558081205,
|
92
|
+
"count_results": 1,
|
93
|
+
"articles": [
|
94
|
+
{
|
95
|
+
"title": "'Dragon Ball Super' Chapter 48 Release Date, Predictions: Moro Not the Real Villain, Truth Revealed?",
|
96
|
+
"desc": "It has been quite a long wait, but it wou ld appear that Dragon Ball Super Chapter 48 will be coming out soon. Along with it is rumored to be a huge bombshell ...",
|
97
|
+
"link": "https://www.econotimes.com/Dragon-Ball-Super-Chapter-48-Release-Date-Predictions-Moro-Not-the-Real-Villain-Truth-Revealed-1538175",
|
98
|
+
"website": "https://www.econotimes.com",
|
99
|
+
"source": "EconoTimes",
|
100
|
+
"date": "Fri, 17 May 2019 05:43:46 GMT",
|
101
|
+
"image": "https://lh4.googleusercontent.com/proxy/CDTeHID-9i5aNWFXTOImYAOOBAFyv8R_QewR4cwP38bycKmVpNS8W-dawVxxumt8FhuzPjXhql8c1y36tkmTaEBW5bCUhryqWH-RBtLnScf_-X8QNL-899A9Sxh2BRpN4Pkp=-c"
|
102
|
+
}
|
103
|
+
]
|
57
104
|
}
|
58
105
|
```
|
59
106
|
|
@@ -61,25 +108,25 @@ You can also send a second parmeter to the search method to indicate that the re
|
|
61
108
|
|
62
109
|
```ruby
|
63
110
|
# Establish parameters for query
|
64
|
-
args = {
|
111
|
+
args = { q: 'Game of Thrones', country: 'DE', max: 1 }
|
65
112
|
|
66
113
|
# Send Request with HASH response property
|
67
|
-
gnews = Gnews::Query.new('my-secret-key'
|
68
|
-
response = gnews.search(args)
|
114
|
+
gnews = Gnews::Query.new('my-secret-key')
|
115
|
+
response = gnews.search(args, format: 'hash')
|
69
116
|
|
70
117
|
puts response
|
71
118
|
# =>
|
72
119
|
|
73
120
|
{
|
74
|
-
"timestamp"=>1558094332,
|
75
|
-
"count_results"=>1,
|
121
|
+
"timestamp"=>1558094332,
|
122
|
+
"count_results"=>1,
|
76
123
|
"articles"=>[
|
77
124
|
{
|
78
|
-
"title"=>"'Game of Thrones' finale: How will it end? Here are a few theories",
|
79
|
-
"desc"=>"", "link"=>"https://www.goodmorningamerica.com/culture/story/game-thrones-finale-popular-theories-end-63057785",
|
80
|
-
"website"=>"https://www.goodmorningamerica.com",
|
81
|
-
"source"=>"GMA",
|
82
|
-
"date"=>"Fri, 17 May 2019 08:06:11 GMT",
|
125
|
+
"title"=>"'Game of Thrones' finale: How will it end? Here are a few theories",
|
126
|
+
"desc"=>"", "link"=>"https://www.goodmorningamerica.com/culture/story/game-thrones-finale-popular-theories-end-63057785",
|
127
|
+
"website"=>"https://www.goodmorningamerica.com",
|
128
|
+
"source"=>"GMA",
|
129
|
+
"date"=>"Fri, 17 May 2019 08:06:11 GMT",
|
83
130
|
"image"=>"https://lh4.googleusercontent.com/proxy/KI8XVNS35Y9hvR55LjjCwpjB4zTUcQxQb5N3H41bc4JRvdcz5qZCIDG2bFHyO6WxqhdVQ5qc5TxPsoqaObiZsY9sqjZRvrsQ7qEdLewSS272opiVWH5S
|
84
131
|
MydvTAug0D-dSSDfZDG9oywTEcfQXsWXtzBHULFJzLYwJDjmnxza=-c"
|
85
132
|
}
|
@@ -91,72 +138,76 @@ MydvTAug0D-dSSDfZDG9oywTEcfQXsWXtzBHULFJzLYwJDjmnxza=-c"
|
|
91
138
|
```
|
92
139
|
|
93
140
|
## Search Parameters
|
94
|
-
|
95
|
-
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
141
|
+
|
142
|
+
| Parameter | Info | Description |
|
143
|
+
| --------- | ---------------------------------------- | --------------------------------------------------------------------------------------------- |
|
144
|
+
| q | Required | Your search |
|
145
|
+
| max | Optional (default value : 10) | The number of items you want (max possible : 100) |
|
146
|
+
| lang | Optional (default value : english) | The article language ([list of all languages](https://gnews.io/documentation.php#NationList)) |
|
147
|
+
| country | Optional (default value : United-States) | The article origin ([list of all countries](https://gnews.io/documentation.php#NationList)) |
|
148
|
+
| mindate | Optional (Date/DateTime) | Get articles that are more recent than the min date |
|
149
|
+
| maxdate | Optional (Date/DateTime) | Get articles that are less recent than the max date |
|
150
|
+
| in | Optional | Get articles that contains q in the specified article section |
|
103
151
|
|
104
152
|
## Query NewsApi
|
105
153
|
|
106
154
|
### Top Headlines
|
155
|
+
|
107
156
|
Source: [NewsApi documentation.](https://www.newsapi.org/docs/endpoints)
|
108
157
|
|
109
|
-
> Returns breaking news headlines for a country and category, or currently running on a single or multiple sources. This is perfect for use with news tickers or anywhere you want to display live up-to-date news headlines and images.
|
158
|
+
> Returns breaking news headlines for a country and category, or currently running on a single or multiple sources. This is perfect for use with news tickers or anywhere you want to display live up-to-date news headlines and images.
|
110
159
|
|
111
160
|
```ruby
|
112
|
-
args = {
|
161
|
+
args = { q: 'Brexit', country: 'DE' }
|
113
162
|
|
114
|
-
news = NewsApi::Query.new(
|
163
|
+
news = NewsApi::Query.new('my-secret-key')
|
115
164
|
|
116
165
|
response = news.top_headlines(args)
|
117
166
|
|
118
167
|
# =>
|
119
168
|
```
|
169
|
+
|
120
170
|
```json
|
121
|
-
{
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
171
|
+
{
|
172
|
+
"status": "ok",
|
173
|
+
"totalResults": 1,
|
174
|
+
"articles": [
|
175
|
+
{
|
176
|
+
"source": {
|
177
|
+
"id": null,
|
178
|
+
"name": "Faz.net"
|
179
|
+
},
|
180
|
+
"author": "Klaus-Dieter Frankenberger",
|
181
|
+
"title": "Brexit-Opfer - FAZ - Frankfurter Allgemeine Zeitung",
|
182
|
+
"description": "Das Brexit-Thema wurde May wie zuvor schon Cameron zum politischen Verhängnis – und es ist eine Last, die auch die kommende Regierung nicht einfach abschütteln kann. Die EU allerdings auch nicht.",
|
183
|
+
"url": "https://www.faz.net/aktuell/brexit/theresa-may-ist-wie-david-cameron-zum-brexit-opfer-geworden-16204205.html",
|
184
|
+
"urlToImage": "https://media1.faz.net/ppmedia/aktuell/112808907/1.6204201/facebook_teaser/theresa-may-am-freitag-bei.jpg",
|
185
|
+
"publishedAt": "2019-05-24T11:07:00Z",
|
186
|
+
"content": "David Cameron führt die Liste der Brexit-Opfer an, und nun wird auch seine Nachfolgerin einen Platz darauf finden, zunächst, am 7. Juni, als Parteichefin der Konservativen, etwas später dann auch als Premierministerin. Cameron trat zurück, weil er seine Absti… [+2771 chars]"
|
187
|
+
}
|
188
|
+
]
|
139
189
|
}
|
140
190
|
```
|
141
191
|
|
142
|
-
#### Search Parameters for
|
143
|
-
|
144
|
-
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
192
|
+
#### Search Parameters for _Top Headlines_
|
193
|
+
|
194
|
+
| Parameter | Info/Description | Additional Notes |
|
195
|
+
| --------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
|
196
|
+
| q | Required | Keywords or a phrase to search for. |
|
197
|
+
| country | The 2-letter ISO 3166-1 code of the country | You can't mix this param with the _sources_ param. |
|
198
|
+
| category | Options: _business, entertainment, general, health, science, sports, technology_ | You can't mix this param with the _sources_ param. |
|
199
|
+
| sources | A comma-seperated string of identifiers for the news sources or blogs you want headlines from | You can't mix this param with the country or category params. |
|
200
|
+
| pageSize | The number of results to return per page (request). 20 is the default, 100 is the maximum. |
|
201
|
+
| page | Use this to page through the results if the total results found is greater than the page size. |
|
151
202
|
|
152
203
|
### Everything
|
153
|
-
Source: [NewsApi documentation.](https://www.newsapi.org/docs/endpoints)
|
154
204
|
|
205
|
+
Source: [NewsApi documentation.](https://www.newsapi.org/docs/endpoints)
|
155
206
|
|
156
207
|
> We index every recent news and blog article published by over 30,000 different sources large and small, and you can search through them with this endpoint. This endpoint is better suited for news analysis and article discovery, but can be used to retrieve articles for display too.
|
157
208
|
|
158
209
|
```ruby
|
159
|
-
args = {
|
210
|
+
args = { q: 'Huawei', from: (DateTime.now - 2)}
|
160
211
|
|
161
212
|
news = NewsApi::Query.new('my-secret-key')
|
162
213
|
|
@@ -166,115 +217,116 @@ response = news.everything(args)
|
|
166
217
|
```
|
167
218
|
|
168
219
|
```json
|
169
|
-
{
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
220
|
+
{
|
221
|
+
"status": "ok",
|
222
|
+
"totalResults": 4599,
|
223
|
+
"articles": [
|
224
|
+
{
|
225
|
+
"source": {
|
226
|
+
"id": "techcrunch",
|
227
|
+
"name": "TechCrunch"
|
228
|
+
},
|
229
|
+
"author": "Catherine Shu",
|
230
|
+
"title": "Semiconductor startup CNEX Labs alleged Huawei’s deputy chairman conspired to steal its intellectual property",
|
231
|
+
"description": "A San Jose-based semiconductor startup being sued by Huawei for stealing trade secrets has hit back in court documents, accusing the Chinese firm’s deputy chairman of conspiring to steal its intellectual property, reports the Wall Street Journal. In court fil…",
|
232
|
+
"url": "http://techcrunch.com/2019/05/22/semiconductor-startup-cnex-labs-alleged-huaweis-deputy-chairman-conspired-to-steal-its-intellectual-property/",
|
233
|
+
"urlToImage": "https://techcrunch.com/wp-content/uploads/2019/05/GettyImages-1150756100.jpg?w=600",
|
234
|
+
"publishedAt": "2019-05-23T06:01:44Z",
|
235
|
+
"content": "A San Jose-based semiconductor startup being sued by Huawei for stealing trade secrets has hit back in court documents, accusing the Chinese firms deputy chairman of conspiring to steal its intellectual property, reports the Wall Street Journal. In court fili… [+3077 chars]"
|
236
|
+
}
|
237
|
+
]
|
187
238
|
}
|
188
239
|
```
|
189
|
-
#### Search Parameters for *Everything*
|
190
|
-
| Parameter | Info/Description | Additional Notes
|
191
|
-
|--- |--- |---
|
192
|
-
| q |Required |Keywords or a phrase to search for.
|
193
|
-
| sources |A comma-seperated string of identifiers (maximum 20) for the news sources or blogs you want headlines from. |
|
194
|
-
| domains |A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to. |
|
195
|
-
| excludeDomains|A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to remove from the results. |
|
196
|
-
| from |A date and optional time for the oldest article allowed. This should be in ISO 8601 format. |
|
197
|
-
| to |A date and optional time for the newest article allowed. This should be in ISO 8601 format |
|
198
|
-
| language |The 2-letter ISO-639-1 code of the language you want to get headlines for. Possible options: *ar de en es fr he it nl no pt ru se ud zh*. |Default: All languages returned
|
199
|
-
| sortBy |Options: *relevancy, popularity, publishedAt.* |Default: publishedAt
|
200
|
-
| pageSize |The number of results to return per page. 20 is the default, 100 is the maximum. |
|
201
|
-
| page |Use this to page through the results. |
|
202
|
-
|
203
240
|
|
241
|
+
#### Search Parameters for _Everything_
|
242
|
+
|
243
|
+
| Parameter | Info/Description | Additional Notes |
|
244
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
|
245
|
+
| q | Required | Keywords or a phrase to search for. |
|
246
|
+
| sources | A comma-seperated string of identifiers (maximum 20) for the news sources or blogs you want headlines from. |
|
247
|
+
| domains | A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to. |
|
248
|
+
| excludeDomains | A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to remove from the results. |
|
249
|
+
| from | A date and optional time for the oldest article allowed. This should be in ISO 8601 format. |
|
250
|
+
| to | A date and optional time for the newest article allowed. This should be in ISO 8601 format |
|
251
|
+
| language | The 2-letter ISO-639-1 code of the language you want to get headlines for. Possible options: _ar de en es fr he it nl no pt ru se ud zh_. | Default: All languages returned |
|
252
|
+
| sortBy | Options: _relevancy, popularity, publishedAt._ | Default: publishedAt |
|
253
|
+
| pageSize | The number of results to return per page. 20 is the default, 100 is the maximum. |
|
254
|
+
| page | Use this to page through the results. |
|
204
255
|
|
205
256
|
### Sources
|
257
|
+
|
206
258
|
Source: [NewsApi documentation.](https://www.newsapi.org/docs/endpoints)
|
207
259
|
|
208
260
|
> Returns information (including name, description, and category) about the most notable sources we index. This list could be piped directly through to your users when showing them some of the options available.
|
209
261
|
|
210
262
|
```ruby
|
211
|
-
news = NewsApi::Query.new(
|
263
|
+
news = NewsApi::Query.new('my-secret-key')
|
212
264
|
response = news.sources(args)
|
213
265
|
|
214
266
|
# =>
|
215
267
|
```
|
216
268
|
|
217
|
-
|
218
269
|
```json
|
219
|
-
{
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
270
|
+
{
|
271
|
+
"status": "ok",
|
272
|
+
"sources": [
|
273
|
+
{
|
274
|
+
"id": "abc-news",
|
275
|
+
"name": "ABC News",
|
276
|
+
"description": "Your trusted source for breaking news, analysis, exclusive interviews, headlines, and videos at ABCNews.com.",
|
277
|
+
"url": "https://abcnews.go.com",
|
278
|
+
"category": "general",
|
279
|
+
"language": "en",
|
280
|
+
"country": "us"
|
281
|
+
},
|
282
|
+
{
|
283
|
+
"id": "abc-news-au",
|
284
|
+
"name": "ABC News (AU)",
|
285
|
+
"description": "Australia's most trusted source of local, national and world news. Comprehensive, independent, in-depth analysis, the latest business, sport, weather and more.",
|
286
|
+
"url": "http://www.abc.net.au/news",
|
287
|
+
"category": "general",
|
288
|
+
"language": "en",
|
289
|
+
"country": "au"
|
290
|
+
}
|
291
|
+
]
|
241
292
|
}
|
242
|
-
|
243
293
|
```
|
244
294
|
|
245
|
-
#### Search Parameters for
|
246
|
-
|
247
|
-
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
295
|
+
#### Search Parameters for _Sources_
|
296
|
+
|
297
|
+
| Parameter | Info/Description |
|
298
|
+
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
299
|
+
| country | Find sources that display news in a specific country |
|
300
|
+
| category | Options: _business, entertainment, general, health, science, sports, technology_ |
|
301
|
+
| language | The 2-letter ISO-639-1 code of the language you want to get headlines for. Possible options: _ar de en es fr he it nl no pt ru se ud zh_ |
|
251
302
|
|
252
303
|
## Format
|
304
|
+
|
253
305
|
Additionaly, just like with the Gnews module, you may send a second parmeter to specify the format you may want to receive the response.
|
254
306
|
|
255
307
|
Supported types: **json** and **hash**
|
256
308
|
|
257
309
|
```ruby
|
258
|
-
args = {
|
310
|
+
args = { q: 'Brexit', country: 'DE' }
|
259
311
|
|
260
|
-
news = NewsApi::Query.new(
|
312
|
+
news = NewsApi::Query.new('my-secrety-key')
|
261
313
|
|
262
314
|
response = news.top_headlines(args, 'hash')
|
263
315
|
# =>
|
264
316
|
{
|
265
|
-
"status"=>"ok",
|
266
|
-
"totalResults"=>1,
|
317
|
+
"status"=>"ok",
|
318
|
+
"totalResults"=>1,
|
267
319
|
"articles"=>[
|
268
320
|
{
|
269
321
|
"source"=> {
|
270
|
-
"id"=>nil,
|
322
|
+
"id"=>nil,
|
271
323
|
"name"=>"Tagesschau.de"
|
272
|
-
},
|
273
|
-
"author"=>"tagesschau.de",
|
274
|
-
"title"=>"Mays Rücktritt: \"Sie hätte Nationalheldin werden können\" - tagesschau.de", "description"=>"Premierministerin May wollte den Brexit mit aller Kraft. Doch nun hat sie überraschend emotional aufgegeben. Ihre möglichen Nachfolger bringen sich schon in Stellung. Von Imke Köhler.",
|
275
|
-
"url"=>"https://www.tagesschau.de/ausland/may-ruecktritt-103.html",
|
276
|
-
"urlToImage"=>"https://www.tagesschau.de/multimedia/bilder/may-741~_v-videowebm.jpg",
|
277
|
-
"publishedAt"=>"2019-05-24T15:52:00Z",
|
324
|
+
},
|
325
|
+
"author"=>"tagesschau.de",
|
326
|
+
"title"=>"Mays Rücktritt: \"Sie hätte Nationalheldin werden können\" - tagesschau.de", "description"=>"Premierministerin May wollte den Brexit mit aller Kraft. Doch nun hat sie überraschend emotional aufgegeben. Ihre möglichen Nachfolger bringen sich schon in Stellung. Von Imke Köhler.",
|
327
|
+
"url"=>"https://www.tagesschau.de/ausland/may-ruecktritt-103.html",
|
328
|
+
"urlToImage"=>"https://www.tagesschau.de/multimedia/bilder/may-741~_v-videowebm.jpg",
|
329
|
+
"publishedAt"=>"2019-05-24T15:52:00Z",
|
278
330
|
"content"=>"Premierministerin May wollte den Brexit mit aller Kraft. Doch nun hat sie überraschend emotional aufgegeben. Ihre möglichen Nachfolger bringen sich schon in Stellung. \r\nVon Imke Köhler, ARD-Studio London\r\n Theresa May hat selten Gefühle gezeigt in den vergang…"
|
279
331
|
]
|
280
332
|
}
|
@@ -282,7 +334,6 @@ response = news.top_headlines(args, 'hash')
|
|
282
334
|
|
283
335
|
```
|
284
336
|
|
285
|
-
|
286
337
|
## Contributing
|
287
338
|
|
288
339
|
Bug reports and pull requests are welcome on GitHub at https://github.com/viccarrasco/metonym. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|