newsarchives 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/newsarchives.rb +65 -0
- metadata +8 -8
- data/newsarchives.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2bae22ddf709fc6fbaffe050bf5cbcf0d3c7f7b
|
4
|
+
data.tar.gz: 664c0d23fa88e7ca80e32ccd8f75dc6e6ab31893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ab32f99dc10cddf1b06c1879f1d0297b002f5814ee6d408188fd945c2b3d638ce9b8a94fd072cac67184e11adc7ebfc2efcfe791500ef58269924325f6fe34f
|
7
|
+
data.tar.gz: 477a9a37875b8b942a6a81b31d8a97ed14a868bfe7c46db0aed6b0d99067618123231a6c83d204680f85bd384761311e7c9b5e13872f54d19210b10ad68b5af2
|
data/src/newsarchives.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module NewsArchives
|
2
|
+
require "uri"
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
class Non200Code < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
$uri = URI.parse("https://newsarchives.herokuapp.com/api/v1")
|
10
|
+
|
11
|
+
def NewsArchives.day(day)
|
12
|
+
$uri.query = URI.encode_www_form({:day => day})
|
13
|
+
res = JSON.parse(Net::HTTP.get($uri))
|
14
|
+
puts res["status"]
|
15
|
+
if res["status"] == 200
|
16
|
+
return res
|
17
|
+
else
|
18
|
+
raise Non200Code.new("The server responded with code #{res["status"]}: #{res["message"]}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def NewsArchives.month(month)
|
23
|
+
$uri.query = URI.encode_www_form({:month => month})
|
24
|
+
res = JSON.parse(Net::HTTP.get($uri))
|
25
|
+
if res["status"] == 200
|
26
|
+
return res
|
27
|
+
else
|
28
|
+
raise Non200Code.new("The server responded with code #{res["status"]}: #{res["message"]}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def NewsArchives.year(year)
|
33
|
+
$uri.query = URI.encode_www_form({:year => year})
|
34
|
+
res = JSON.parse(Net::HTTP.get($uri))
|
35
|
+
if res["status"] == 200
|
36
|
+
return res
|
37
|
+
else
|
38
|
+
raise Non200Code.new("The server responded with code #{res["status"]}: #{res["message"]}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def NewsArchives.keyword(keyword, day=nil, month=nil, year=nil, limit=nil)
|
43
|
+
params = {:keyword => keyword}
|
44
|
+
time_args = 0
|
45
|
+
if day
|
46
|
+
time_args = time_args + 1
|
47
|
+
params[:day] = day
|
48
|
+
end
|
49
|
+
if month
|
50
|
+
time_args = time_args + 1
|
51
|
+
params[:month] = month
|
52
|
+
end
|
53
|
+
if year
|
54
|
+
time_args = time_args + 1
|
55
|
+
params[:year] = year
|
56
|
+
end
|
57
|
+
$uri.query = URI.encode_www_form(params)
|
58
|
+
res = JSON.parse(Net::HTTP.get($uri))
|
59
|
+
if res["status"] == 200
|
60
|
+
return res
|
61
|
+
else
|
62
|
+
raise Non200Code.new("The server responded with code #{res["status"]}: #{res["message"]}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newsarchives
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aarav Borthakur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
email:
|
13
|
+
description:
|
14
|
+
email:
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- newsarchives.rb
|
20
|
-
homepage:
|
19
|
+
- src/newsarchives.rb
|
20
|
+
homepage:
|
21
21
|
licenses:
|
22
22
|
- MIT
|
23
23
|
metadata: {}
|
24
24
|
post_install_message:
|
25
25
|
rdoc_options: []
|
26
26
|
require_paths:
|
27
|
-
-
|
27
|
+
- src
|
28
28
|
required_ruby_version: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - ">="
|
@@ -40,5 +40,5 @@ rubyforge_project:
|
|
40
40
|
rubygems_version: 2.5.2.3
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
|
-
summary: The official
|
43
|
+
summary: The official Ruby client library for the News Archives API
|
44
44
|
test_files: []
|
data/newsarchives.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
'
|
2
|
-
newsarchives
|
3
|
-
The official ruby client library for the News Archives API.
|
4
|
-
By Aarav Borthakur
|
5
|
-
|
6
|
-
Docs: https://gadhagod.github.io/News-Archives
|
7
|
-
Github: https://github.com/gadhagod/News-Archives
|
8
|
-
'
|
9
|
-
|
10
|
-
require 'net/http'
|
11
|
-
require 'json'
|
12
|
-
|
13
|
-
def req(endpoint)
|
14
|
-
response = Net::HTTP.get_response(URI.parse('https://newsarchives.herokuapp.com/' + endpoint))
|
15
|
-
return JSON.parse(response.body)
|
16
|
-
end
|
17
|
-
|
18
|
-
class Time
|
19
|
-
def day(day)
|
20
|
-
return req('/day/' + day)
|
21
|
-
end
|
22
|
-
def month(month)
|
23
|
-
return req('/month/' + month)
|
24
|
-
end
|
25
|
-
def year(year)
|
26
|
-
return req('/year/' + year)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def keyword(keyword)
|
31
|
-
return req('/keyword/' + keyword)
|
32
|
-
end
|