news_api 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 +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +21 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +85 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/news_api.rb +20 -0
- data/lib/news_api/api_struct_settings.rb +10 -0
- data/lib/news_api/clients/everything.rb +11 -0
- data/lib/news_api/clients/sources.rb +11 -0
- data/lib/news_api/clients/top_headliners.rb +11 -0
- data/lib/news_api/entities/article.rb +8 -0
- data/lib/news_api/entities/source.rb +8 -0
- data/lib/news_api/everything.rb +9 -0
- data/lib/news_api/settings.rb +7 -0
- data/lib/news_api/sources.rb +9 -0
- data/lib/news_api/top_headliners.rb +9 -0
- data/lib/news_api/version.rb +3 -0
- data/news_api.gemspec +32 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f337c69630a74a785d7401def98479a1528ae40d
|
4
|
+
data.tar.gz: 59ed020d021f3735300e8a7946a5503bd31f5275
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa050a3443ed8d1eec61f25e63cadbafa0c9604dba816633b4a921091b38660396123abe28b27f04c7d4152490fa11342efff4235c6ee1e41b81e16e4e926b49
|
7
|
+
data.tar.gz: d27299581449b602c319eb477567ffe6bd54d3cb3a37df4a391cb512be3c34208311d7cb15586382943077fc2560579fc52fb15736fa592349af8610d592bb95
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
DisplayStyleGuide: true
|
4
|
+
StyleGuideCopsOnly: true
|
5
|
+
TargetRubyVersion: 2.5
|
6
|
+
|
7
|
+
Metrics/LineLength:
|
8
|
+
Max: 120
|
9
|
+
|
10
|
+
Documentation:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
FrozenStringLiteralComment:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/FileName:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/ModuleLength:
|
20
|
+
Exclude:
|
21
|
+
- spec/**/*_spec.rb
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
news_api (0.1.0)
|
5
|
+
api_struct (~> 0.1.0)
|
6
|
+
dry-configurable (~> 0.7.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
api_struct (0.1.0)
|
14
|
+
dry-configurable (~> 0.7.0)
|
15
|
+
dry-monads (~> 0.3.1)
|
16
|
+
hashie (~> 3.5, >= 3.5.6)
|
17
|
+
http (>= 2.0.3)
|
18
|
+
ast (2.4.0)
|
19
|
+
concurrent-ruby (1.0.5)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
domain_name (0.5.20180417)
|
22
|
+
unf (>= 0.0.5, < 1.0.0)
|
23
|
+
dry-configurable (0.7.0)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
dry-core (0.4.5)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
dry-equalizer (0.2.1)
|
28
|
+
dry-monads (0.3.1)
|
29
|
+
dry-core
|
30
|
+
dry-equalizer
|
31
|
+
hashie (3.5.7)
|
32
|
+
http (3.3.0)
|
33
|
+
addressable (~> 2.3)
|
34
|
+
http-cookie (~> 1.0)
|
35
|
+
http-form_data (~> 2.0)
|
36
|
+
http_parser.rb (~> 0.6.0)
|
37
|
+
http-cookie (1.0.3)
|
38
|
+
domain_name (~> 0.5)
|
39
|
+
http-form_data (2.1.0)
|
40
|
+
http_parser.rb (0.6.0)
|
41
|
+
parallel (1.12.1)
|
42
|
+
parser (2.5.1.0)
|
43
|
+
ast (~> 2.4.0)
|
44
|
+
powerpack (0.1.1)
|
45
|
+
public_suffix (3.0.2)
|
46
|
+
rainbow (3.0.0)
|
47
|
+
rake (10.5.0)
|
48
|
+
rspec (3.7.0)
|
49
|
+
rspec-core (~> 3.7.0)
|
50
|
+
rspec-expectations (~> 3.7.0)
|
51
|
+
rspec-mocks (~> 3.7.0)
|
52
|
+
rspec-core (3.7.1)
|
53
|
+
rspec-support (~> 3.7.0)
|
54
|
+
rspec-expectations (3.7.0)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.7.0)
|
57
|
+
rspec-mocks (3.7.0)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.7.0)
|
60
|
+
rspec-support (3.7.1)
|
61
|
+
rubocop (0.55.0)
|
62
|
+
parallel (~> 1.10)
|
63
|
+
parser (>= 2.5)
|
64
|
+
powerpack (~> 0.1)
|
65
|
+
rainbow (>= 2.2.2, < 4.0)
|
66
|
+
ruby-progressbar (~> 1.7)
|
67
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
68
|
+
ruby-progressbar (1.9.0)
|
69
|
+
unf (0.1.4)
|
70
|
+
unf_ext
|
71
|
+
unf_ext (0.0.7.5)
|
72
|
+
unicode-display_width (1.3.2)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
bundler (~> 1.16)
|
79
|
+
news_api!
|
80
|
+
rake (~> 10.0)
|
81
|
+
rspec (~> 3.0)
|
82
|
+
rubocop (~> 0.55.0)
|
83
|
+
|
84
|
+
BUNDLED WITH
|
85
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Kirill Shevchenko
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# NewsApi
|
2
|
+
|
3
|
+
An API wrapper for [News API v2](https://newsapi.org/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'news_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install news_api
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Add setting with your [API key](https://newsapi.org/register).
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
NewsApi::Settings.configure do |config|
|
27
|
+
config.api_key = 'your_api_key'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
News API has 2 main [endpoints](https://newsapi.org/docs/endpoints) and 1 minor endpoint.
|
34
|
+
|
35
|
+
[Read more](https://newsapi.org/docs/endpoints) about required and available params.
|
36
|
+
|
37
|
+
Each request below returns instance of [ApiStruct::Entity](https://github.com/rubygarage/api_struct#entity)
|
38
|
+
|
39
|
+
### [Top headlines](https://newsapi.org/docs/endpoints/top-headlines)
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
NewsApi::TopHeadliners.search(country: :us, pageSize: 2)
|
43
|
+
```
|
44
|
+
|
45
|
+
### [Everything](https://newsapi.org/docs/endpoints/everything)
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
NewsApi::Everything.search(q: 'bitcoin', pageSize: 2)
|
49
|
+
```
|
50
|
+
|
51
|
+
### [Sources](https://newsapi.org/docs/endpoints/sources)
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
NewsApi::Sources.search
|
55
|
+
```
|
56
|
+
|
57
|
+
## Errors handling
|
58
|
+
|
59
|
+
Each result respond on methods `.failure?` and '.success?'.
|
60
|
+
|
61
|
+
For example you have invalid API key:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
NewsApi::Settings.configure do |config|
|
65
|
+
config.api_key = 'fail_key'
|
66
|
+
end
|
67
|
+
|
68
|
+
NewsApi::Sources.search
|
69
|
+
=> #<Hashie::Mash body=#<Hashie::Mash code="apiKeyInvalid" message="Your API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key." status="error"> error=true status=#<HTTP::Response::Status 401 Unauthorized>>
|
70
|
+
```
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kirillshevch/news_api.
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'news_api'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/news_api.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'news_api/version'
|
2
|
+
require 'api_struct'
|
3
|
+
require 'dry-configurable'
|
4
|
+
|
5
|
+
require 'news_api/settings'
|
6
|
+
require 'news_api/api_struct_settings'
|
7
|
+
|
8
|
+
require 'news_api/clients/top_headliners'
|
9
|
+
require 'news_api/clients/everything'
|
10
|
+
require 'news_api/clients/sources'
|
11
|
+
|
12
|
+
require 'news_api/entities/article'
|
13
|
+
require 'news_api/entities/source'
|
14
|
+
|
15
|
+
require 'news_api/everything'
|
16
|
+
require 'news_api/top_headliners'
|
17
|
+
require 'news_api/sources'
|
18
|
+
|
19
|
+
module NewsApi
|
20
|
+
end
|
data/news_api.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'news_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'news_api'
|
8
|
+
spec.version = NewsApi::VERSION
|
9
|
+
spec.authors = ['Kirill Shevchenko']
|
10
|
+
spec.email = ['hello@kirillshevch.com']
|
11
|
+
|
12
|
+
spec.summary = 'An API wrapper for News API v2'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/kirillshevch/news_api'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'api_struct', '~> 0.1.0'
|
26
|
+
spec.add_dependency 'dry-configurable', '~> 0.7.0'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.55.0'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: news_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kirill Shevchenko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: api_struct
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.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.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-configurable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.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.7.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: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.55.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.55.0
|
97
|
+
description: An API wrapper for News API v2
|
98
|
+
email:
|
99
|
+
- hello@kirillshevch.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- lib/news_api.rb
|
115
|
+
- lib/news_api/api_struct_settings.rb
|
116
|
+
- lib/news_api/clients/everything.rb
|
117
|
+
- lib/news_api/clients/sources.rb
|
118
|
+
- lib/news_api/clients/top_headliners.rb
|
119
|
+
- lib/news_api/entities/article.rb
|
120
|
+
- lib/news_api/entities/source.rb
|
121
|
+
- lib/news_api/everything.rb
|
122
|
+
- lib/news_api/settings.rb
|
123
|
+
- lib/news_api/sources.rb
|
124
|
+
- lib/news_api/top_headliners.rb
|
125
|
+
- lib/news_api/version.rb
|
126
|
+
- news_api.gemspec
|
127
|
+
homepage: https://github.com/kirillshevch/news_api
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.6.13
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: An API wrapper for News API v2
|
151
|
+
test_files: []
|