nhk-easy-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/nhk-easy-ruby.rb +96 -0
- data/nhk-easy-ruby.gemspec +15 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b490c83629756a5bf6ff2531a4ac1bfeb326f53
|
4
|
+
data.tar.gz: 603556b7258378a99bad159c1c4f0d4d270a704b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18ecb9457ece17ec43cac97667aa6288fbe70289fbe56c4a301034b16377e561a2b4f8c0e39319936c84d8b483cf80ba51114159e51e1ae3eea0a662fc5aad0a
|
7
|
+
data.tar.gz: e8b71d8e017a652bc89ab4d6207a988537694ed27fa161f000d0a048be00980b810391fc403e9cfc881c622ee04b54d602ff03486733f39b6684505a46c15cf4
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module NHK
|
5
|
+
module Easy
|
6
|
+
BASE_URI = URI("http://www3.nhk.or.jp/news/easy/")
|
7
|
+
BASE_MOVIE_URI = URI("rtmp://flv.nhk.or.jp/ondemand/flv/news/&movie=")
|
8
|
+
|
9
|
+
class Client
|
10
|
+
def news_list
|
11
|
+
# Encode ascii -> utf-8 and remove bom
|
12
|
+
data = Net::HTTP
|
13
|
+
.get(BASE_URI+"news-list.json")
|
14
|
+
.force_encoding('UTF-8')
|
15
|
+
.gsub("\xEF\xBB\xBF", '')
|
16
|
+
|
17
|
+
json = Parser.new(data).parse!
|
18
|
+
news_list = NewsList.new
|
19
|
+
json.map do |list|
|
20
|
+
list.keys.each do |date|
|
21
|
+
list[date].each do |item|
|
22
|
+
news_list.entries << News.new(date: date, item: item)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
return news_list
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class NewsList
|
32
|
+
attr_accessor :entries
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@entries = []
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class News
|
40
|
+
attr_reader :date
|
41
|
+
attr_accessor :news_id, :title, :news_publication_time,
|
42
|
+
:has_news_web_image, :has_news_web_movie, :has_news_easy_image,
|
43
|
+
:has_news_easy_movie, :has_news_easy_voice, :news_web_image_uri,
|
44
|
+
:news_web_movie_uri, :news_easy_image_uri, :news_easy_movie_uri,
|
45
|
+
:news_easy_voice_uri, :news_web_url
|
46
|
+
|
47
|
+
def initialize(date: Date.today.to_s, item: {})
|
48
|
+
@date = date
|
49
|
+
parse_item(item)
|
50
|
+
end
|
51
|
+
|
52
|
+
def news_web_image_url
|
53
|
+
NHK::Easy::BASE_URI+"#{news_id}/#{news_web_image_uri}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def news_web_movie_url
|
57
|
+
NHK::Easy::BASE_MOVIE_URI+news_web_movie_uri
|
58
|
+
end
|
59
|
+
|
60
|
+
def news_easy_image_url
|
61
|
+
NHK::Easy::BASE_URI+"#{news_id}/#{news_easy_image_uri}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def news_easy_movie_url
|
65
|
+
NHK::Easy::BASE_MOVIE_URI+news_easy_movie_uri
|
66
|
+
end
|
67
|
+
|
68
|
+
def news_easy_voice_url
|
69
|
+
NHK::Easy::BASE_URI+"#{news_id}/#{news_easy_voice_uri}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def has_news_web_image?; !!has_news_web_image; end
|
73
|
+
def has_news_web_movie?; !!has_news_web_movie; end
|
74
|
+
def has_news_easy_image?; !!has_news_easy_image; end
|
75
|
+
def has_news_easy_movie?; !!has_news_easy_movie; end
|
76
|
+
def has_news_easy_voice?; !!has_news_easy_voice; end
|
77
|
+
|
78
|
+
private
|
79
|
+
def parse_item(item)
|
80
|
+
item.each do |key, value|
|
81
|
+
self.send("#{key}=", value) rescue next
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class Parser
|
87
|
+
def initialize data={}
|
88
|
+
@data = data
|
89
|
+
end
|
90
|
+
|
91
|
+
def parse!
|
92
|
+
JSON.parse @data
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "nhk-easy-ruby"
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.authors = ["Zachary Scott"]
|
5
|
+
spec.email = ["e@zzak.io"]
|
6
|
+
|
7
|
+
spec.summary = %q{Ruby client library for NHK News Web Easy.}
|
8
|
+
spec.description = %q{Read the news with this Ruby interface for NHK's public API.}
|
9
|
+
spec.homepage = "https://rubygems.org/gems/nhk-easy-ruby"
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.files = Dir.glob(["lib/**/*", "nhk-easy-ruby.gemspec"])
|
13
|
+
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nhk-easy-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zachary Scott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Read the news with this Ruby interface for NHK's public API.
|
14
|
+
email:
|
15
|
+
- e@zzak.io
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/nhk-easy-ruby.rb
|
21
|
+
- nhk-easy-ruby.gemspec
|
22
|
+
homepage: https://rubygems.org/gems/nhk-easy-ruby
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.5
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Ruby client library for NHK News Web Easy.
|
46
|
+
test_files: []
|