nowtv 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.nowtv +50 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +6 -0
- data/bin/nowtv +23 -0
- data/lib/nowtv.rb +6 -0
- data/lib/nowtv/client.rb +61 -0
- data/lib/nowtv/version.rb +3 -0
- data/nowtv.gemspec +27 -0
- data/spec/fixtures/fixtures.rb +89 -0
- data/spec/lib/nowtv/client_spec.rb +97 -0
- data/spec/spec_helper.rb +22 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0a4da7370a94335359641039bfc869774d5a7ed
|
4
|
+
data.tar.gz: b50ee77e4e6f01f99dc70f4036734c4e08078728
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2a8b904d2dcdd1d034c0179e51fdbbe19170283fb00bb7caf7fa4cb46fd2925fda829b5a7056940a375e628f27cc944e31c64037ea717d0af2dc14a2c39774c
|
7
|
+
data.tar.gz: baa8be89893c8fbd125f51e6486a6d3a547e04f8ab37b0b9d2a56840e594574ae5c744aec738562080ac587ba1e7d22254ab01ea1b4d3204fd639193397f9d08
|
data/.gitignore
ADDED
data/.nowtv
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
東京
|
2
|
+
|
3
|
+
### region_code ###
|
4
|
+
北海道: hokk
|
5
|
+
青森: aomori
|
6
|
+
岩手: iwate
|
7
|
+
宮城: miya
|
8
|
+
秋田: akita
|
9
|
+
山形: yamagata
|
10
|
+
福島: fuku
|
11
|
+
茨城: ibaraki
|
12
|
+
栃木: tochigi
|
13
|
+
群馬: gunma
|
14
|
+
埼玉: saitama
|
15
|
+
千葉: chiba
|
16
|
+
東京: tokyo
|
17
|
+
神奈川: kanagawa
|
18
|
+
新潟: niigata
|
19
|
+
富山: toyama
|
20
|
+
石川: ishikawa
|
21
|
+
福井: fukui
|
22
|
+
山梨: yamanasi
|
23
|
+
長野: nagano
|
24
|
+
岐阜: gifu
|
25
|
+
静岡: sizu
|
26
|
+
愛知: aichi
|
27
|
+
三重: mie
|
28
|
+
滋賀: siga
|
29
|
+
京都: kyoto
|
30
|
+
大阪: osaka
|
31
|
+
兵庫: hyougo
|
32
|
+
奈良: nara
|
33
|
+
和歌山: wakayama
|
34
|
+
鳥取: tottori
|
35
|
+
島根: shimane
|
36
|
+
岡山: okayama
|
37
|
+
広島: hirosima
|
38
|
+
山口: yamagchi
|
39
|
+
徳島: tokusima
|
40
|
+
香川: kagawa
|
41
|
+
愛媛: ehime
|
42
|
+
高知: kouchi
|
43
|
+
福岡: fukuoka
|
44
|
+
佐賀: saga
|
45
|
+
長崎: nagasaki
|
46
|
+
熊本: kumamoto
|
47
|
+
大分: oita
|
48
|
+
宮崎: miyazaki
|
49
|
+
鹿児島: kagosima
|
50
|
+
沖縄: nawa
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 dtan4
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Nowtv
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/dtan4/nowtv.png?branch=master)](https://travis-ci.org/dtan4/nowtv)
|
4
|
+
|
5
|
+
Show current TV programs
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'nowtv'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nowtv
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
With no argument, list of programs currently broadcasted is shown. Default region is Tokyo Metropolitan.
|
23
|
+
|
24
|
+
$ nowtv
|
25
|
+
NHK総合: 仕事ハッケン伝 [16:05 -> 16:55]
|
26
|
+
NHK Eテレ: 第68回国民体育大会~スポーツ祭東京2013~ [16:00 -> 17:00]
|
27
|
+
日本テレビ: 特選ぶらり途中下車の旅 [15:55 -> 16:53]
|
28
|
+
テレビ朝日: 相棒セレクション [15:57 -> 16:53]
|
29
|
+
TBSテレビ: Nスタ [15:50 -> 19:00]
|
30
|
+
テレビ東京: L4YOU! [16:00 -> 16:52]
|
31
|
+
フジテレビ: 踊る大捜査線 [15:50 -> 16:50]
|
32
|
+
TOKYO MX: スマイルプリキュア! [16:30 -> 17:00]
|
33
|
+
放送大学テレビ: 高齢者の生活保障第1回 [16:00 -> 16:45]
|
34
|
+
|
35
|
+
You can specify the default region code/name in `~/.nowtv`. If you set the default region code/name in the first line, `nowtv` command show list of programs in the specified region.
|
36
|
+
|
37
|
+
With the region code, list of programs broadcasted in the specified region is shown.
|
38
|
+
|
39
|
+
$ nowtv osaka
|
40
|
+
NHK総合: 仕事ハッケン伝 [16:05 -> 16:55]
|
41
|
+
NHK Eテレ: 第68回国民体育大会~スポーツ祭東京2013~ [16:00 -> 17:00]
|
42
|
+
MBSテレビ: ちちんぷいぷい [14:55 -> 17:50]
|
43
|
+
ABCテレビ: 相棒season7 [15:55 -> 16:50]
|
44
|
+
関西テレビ: CHANGE [15:53 -> 16:48]
|
45
|
+
読売テレビ: かんさい情報ネットten. 1部 [15:50 -> 17:53]
|
46
|
+
テレビ大阪: L4YOU! [16:00 -> 16:52]
|
47
|
+
|
48
|
+
You can also specify the prefecture name.
|
49
|
+
|
50
|
+
$ nowtv 愛知
|
51
|
+
NHK総合: 仕事ハッケン伝 [16:05 -> 16:55]
|
52
|
+
NHK Eテレ: 第68回国民体育大会~スポーツ祭東京2013~ [16:00 -> 17:00]
|
53
|
+
東海テレビ: リーガル・ハイ [15:54 -> 16:49]
|
54
|
+
中京テレビ: キャッチ! [15:50 -> 17:53]
|
55
|
+
CBCテレビ: 水戸黄門 [15:56 -> 16:50]
|
56
|
+
メ~テレ: 科捜研の女12 [15:49 -> 16:49]
|
57
|
+
テレビ愛知: L4YOU! [16:00 -> 16:52]
|
58
|
+
|
59
|
+
There is sample `.nowtv` in this repository. In this file, you can check the region code.
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/nowtv
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require 'nowtv'
|
6
|
+
|
7
|
+
CONFIGURE_PATH = ENV["HOME"] + '/.nowtv'
|
8
|
+
|
9
|
+
region_code =
|
10
|
+
File.exists?(CONFIGURE_PATH) ? open(CONFIGURE_PATH).read.lines[0].strip : 'tokyo'
|
11
|
+
|
12
|
+
if ARGV.length > 1
|
13
|
+
$stderr.puts 'Too many arguments.'
|
14
|
+
elsif ARGV.length == 1
|
15
|
+
region_code = ARGV[0]
|
16
|
+
end
|
17
|
+
|
18
|
+
client = Nowtv::Client.new
|
19
|
+
programs = client.get_program_list(region_code)
|
20
|
+
|
21
|
+
programs.each do |program|
|
22
|
+
puts "#{program[:station]}: #{program[:title]} [#{program[:start_time]} -> #{program[:end_time]}]"
|
23
|
+
end if programs
|
data/lib/nowtv.rb
ADDED
data/lib/nowtv/client.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'time'
|
5
|
+
require 'nkf'
|
6
|
+
|
7
|
+
module Nowtv
|
8
|
+
class Client
|
9
|
+
API_URL = 'http://asp.tvguide.or.jp/api/broadcasting?region_code='
|
10
|
+
REGION_URL = 'http://asp.tvguide.or.jp/api/regions'
|
11
|
+
|
12
|
+
def get_program_list(region)
|
13
|
+
programs = get_programs(region)
|
14
|
+
|
15
|
+
unless programs.length > 1
|
16
|
+
region_code_by_name = get_region_code(region)
|
17
|
+
|
18
|
+
unless region_code_by_name
|
19
|
+
$stderr.puts 'Failed to get programs!'
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
|
23
|
+
programs = get_programs(region_code_by_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
restruct_program_list(programs)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_programs(region_code)
|
30
|
+
url = API_URL + region_code
|
31
|
+
JSON.parse(open(url).read.sub(/^\(/, '').sub(/\)$/, ''))['programs']
|
32
|
+
rescue
|
33
|
+
[]
|
34
|
+
end
|
35
|
+
|
36
|
+
def restruct_program_list(programs)
|
37
|
+
programs.map do |program|
|
38
|
+
{
|
39
|
+
station: NKF.nkf("-wZ0", program["station_name"]),
|
40
|
+
title: NKF.nkf("-wZ0", program["title"]).gsub(" ", " "),
|
41
|
+
start_time: Time.parse(program["start"]).strftime("%H:%M"),
|
42
|
+
end_time: Time.parse(program["end"]).strftime("%H:%M")
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_region_list
|
48
|
+
regions = JSON.parse(open(REGION_URL).read.sub(/^\(/, '').sub(/\)$/, ''))['regions']
|
49
|
+
result = {}
|
50
|
+
regions.each { |region| result[region["name"].to_sym] = region["code"] }
|
51
|
+
result
|
52
|
+
rescue
|
53
|
+
{}
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_region_code(region_name)
|
57
|
+
region_list = get_region_list
|
58
|
+
region_list[region_name.to_sym]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/nowtv.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nowtv/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nowtv"
|
8
|
+
spec.version = Nowtv::VERSION
|
9
|
+
spec.authors = ["dtan4"]
|
10
|
+
spec.email = ["dtanshi45@gmail.com"]
|
11
|
+
spec.description = %q{Show current TV programs}
|
12
|
+
spec.summary = %q{Show current TV programs}
|
13
|
+
spec.homepage = "https://github.com/dtan4/nowtv"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
25
|
+
spec.add_development_dependency "webmock"
|
26
|
+
spec.add_development_dependency "simplecov"
|
27
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
EXAMPLE_VALID_PROGRAMS_BODY = <<-EOS
|
3
|
+
({"error":0,"ccode":null,"region_code":"tokyo","media":{"code":"02","name":"\u5730\u4e0a\u6ce2"},"region":{"code":"tokyo","name":"\u6771\u4eac"},"programs":[{"station_code":"02-*01","station_name":"NHK\u7dcf\u5408","start":"201309131930","end":"201309131955","title":"\u7279\u5831\u9996\u90fd\u570f"},{"station_code":"02-#01","station_name":"NHK E\u30c6\u30ec","start":"201309131925","end":"201309131948","title":"\u8ab2\u5916\u6388\u696d\u3000\u3088\u3046\u3053\u305d\u5148\u8f29\u30fb\u9078"},{"station_code":"02-NTV","station_name":"\u65e5\u672c\u30c6\u30ec\u30d3","start":"201309131900","end":"201309132054","title":"\u7dca\u6025\u51fa\u52d5\uff01\u9003\u8d70\u8eca\u3092\u8ffd\u3048\uff01\u4ea4\u901a\u8b66\u5bdf\u3000\u771f\u590f\u306e\u5927\u635c\u67fb\u7dda"},{"station_code":"02-EX ","station_name":"\u30c6\u30ec\u30d3\u671d\u65e5","start":"201309131900","end":"201309131954","title":"\u30c9\u30e9\u3048\u3082\u3093\u8a95\u751f\u65e5\uff11\u6642\u9593\u30b9\u30da\u30b7\u30e3\u30eb"},{"station_code":"02-TBS","station_name":"TBS\u30c6\u30ec\u30d3","start":"201309131900","end":"201309131956","title":"\u7206\u5831\uff01\uff34\uff28\uff25\u3000\u30d5\u30e9\u30a4\u30c7\u30fc"},{"station_code":"02-TX ","station_name":"\u30c6\u30ec\u30d3\u6771\u4eac","start":"201309131830","end":"201309131950","title":"\u304a\u91d1\u304c\u306a\u304f\u3066\u3082\u5e78\u305b\u30e9\u30a4\u30d5\u3000\u304c\u3093\u3070\u308c\u30d7\u30a2\u30fc\u30ba\uff01"},{"station_code":"02-CX","station_name":"\u30d5\u30b8\u30c6\u30ec\u30d3","start":"201309131900","end":"201309131957","title":"\u30da\u30b1\u30dd\u30f3"},{"station_code":"02-MX ","station_name":"TOKYO MX","start":"201309131930","end":"201309132000","title":"\u3081\u305e\u3093\u4e00\u523b"},{"station_code":"02-HDT","station_name":"\u653e\u9001\u5927\u5b66\u30c6\u30ec\u30d3","start":"201309131900","end":"201309131945","title":"\u6587\u5316\u4eba\u985e\u5b66\u7b2c\uff11\uff11\u56de"}]})
|
4
|
+
EOS
|
5
|
+
|
6
|
+
EXAMPLE_INVALID_PROGRAMS_BODY = <<-EOS
|
7
|
+
({"error":0,"ccode":null,"region_code":"aaa","media":{"code":"02","name":"\u5730\u4e0a\u6ce2"},"region":{"code":null,"name":null},"programs":[]})
|
8
|
+
EOS
|
9
|
+
|
10
|
+
EXAMPLE_PROGRAMS =
|
11
|
+
[
|
12
|
+
{"station_code"=>"02-*01", "station_name"=>"NHK総合", "start"=>"201309131930", "end"=>"201309131955", "title"=>"特報首都圏"},
|
13
|
+
{"station_code"=>"02-#01", "station_name"=>"NHK Eテレ", "start"=>"201309131925", "end"=>"201309131948", "title"=>"課外授業 ようこそ先輩・選"},
|
14
|
+
{"station_code"=>"02-NTV", "station_name"=>"日本テレビ", "start"=>"201309131900", "end"=>"201309132054", "title"=>"緊急出動!逃走車を追え!交通警察 真夏の大捜査線"},
|
15
|
+
{"station_code"=>"02-EX ", "station_name"=>"テレビ朝日", "start"=>"201309131900", "end"=>"201309131954", "title"=>"ドラえもん誕生日1時間スペシャル"},
|
16
|
+
{"station_code"=>"02-TBS", "station_name"=>"TBSテレビ", "start"=>"201309131900", "end"=>"201309131956", "title"=>"爆報!THE フライデー"},
|
17
|
+
{"station_code"=>"02-TX ", "station_name"=>"テレビ東京", "start"=>"201309131830", "end"=>"201309131950", "title"=>"お金がなくても幸せライフ がんばれプアーズ!"},
|
18
|
+
{"station_code"=>"02-CX", "station_name"=>"フジテレビ", "start"=>"201309131900", "end"=>"201309131957", "title"=>"ペケポン"},
|
19
|
+
{"station_code"=>"02-MX ", "station_name"=>"TOKYO MX", "start"=>"201309131930", "end"=>"201309132000", "title"=>"めぞん一刻"},
|
20
|
+
{"station_code"=>"02-HDT", "station_name"=>"放送大学テレビ", "start"=>"201309131900", "end"=>"201309131945", "title"=>"文化人類学第11回"}
|
21
|
+
]
|
22
|
+
|
23
|
+
EXAMPLE_RESTRUCTED_PROGRAMS =
|
24
|
+
[
|
25
|
+
{station: "NHK総合", title: "特報首都圏", start_time: "19:30", end_time: "19:55"},
|
26
|
+
{station: "NHK Eテレ", title: "課外授業 ようこそ先輩・選", start_time: "19:25", end_time: "19:48"},
|
27
|
+
{station: "日本テレビ", title: "緊急出動!逃走車を追え!交通警察 真夏の大捜査線", start_time: "19:00", end_time: "20:54"},
|
28
|
+
{station: "テレビ朝日", title: "ドラえもん誕生日1時間スペシャル", start_time: "19:00", end_time: "19:54"},
|
29
|
+
{station: "TBSテレビ", title: "爆報!THE フライデー", start_time: "19:00", end_time: "19:56"},
|
30
|
+
{station: "テレビ東京", title: "お金がなくても幸せライフ がんばれプアーズ!", start_time: "18:30", end_time: "19:50"},
|
31
|
+
{station: "フジテレビ", title: "ペケポン", start_time: "19:00", end_time: "19:57"},
|
32
|
+
{station: "TOKYO MX", title: "めぞん一刻", start_time: "19:30", end_time: "20:00"},
|
33
|
+
{station: "放送大学テレビ", title: "文化人類学第11回", start_time: "19:00", end_time: "19:45"}
|
34
|
+
]
|
35
|
+
|
36
|
+
EXAMPLE_REGION_BODY = <<-EOS
|
37
|
+
({"error":0,"ccode":null,"media_code":null,"regions":[{"code":"hokk","name":"\u5317\u6d77\u9053","pack_code":null},{"code":"aomori","name":"\u9752\u68ee","pack_code":null},{"code":"iwate","name":"\u5ca9\u624b","pack_code":null},{"code":"miya","name":"\u5bae\u57ce","pack_code":null},{"code":"akita","name":"\u79cb\u7530","pack_code":null},{"code":"yamagata","name":"\u5c71\u5f62","pack_code":null},{"code":"fuku","name":"\u798f\u5cf6","pack_code":null},{"code":"ibaraki","name":"\u8328\u57ce","pack_code":null},{"code":"tochigi","name":"\u6803\u6728","pack_code":null},{"code":"gunma","name":"\u7fa4\u99ac","pack_code":null},{"code":"saitama","name":"\u57fc\u7389","pack_code":null},{"code":"chiba","name":"\u5343\u8449","pack_code":null},{"code":"tokyo","name":"\u6771\u4eac","pack_code":null},{"code":"kanagawa","name":"\u795e\u5948\u5ddd","pack_code":null},{"code":"niigata","name":"\u65b0\u6f5f","pack_code":null},{"code":"toyama","name":"\u5bcc\u5c71","pack_code":null},{"code":"ishikawa","name":"\u77f3\u5ddd","pack_code":null},{"code":"fukui","name":"\u798f\u4e95","pack_code":null},{"code":"yamanasi","name":"\u5c71\u68a8","pack_code":null},{"code":"nagano","name":"\u9577\u91ce","pack_code":null},{"code":"gifu","name":"\u5c90\u961c","pack_code":null},{"code":"sizu","name":"\u9759\u5ca1","pack_code":null},{"code":"aichi","name":"\u611b\u77e5","pack_code":null},{"code":"mie","name":"\u4e09\u91cd","pack_code":null},{"code":"siga","name":"\u6ecb\u8cc0","pack_code":null},{"code":"kyoto","name":"\u4eac\u90fd","pack_code":null},{"code":"osaka","name":"\u5927\u962a","pack_code":null},{"code":"hyougo","name":"\u5175\u5eab","pack_code":null},{"code":"nara","name":"\u5948\u826f","pack_code":null},{"code":"wakayama","name":"\u548c\u6b4c\u5c71","pack_code":null},{"code":"tottori","name":"\u9ce5\u53d6","pack_code":null},{"code":"shimane","name":"\u5cf6\u6839","pack_code":null},{"code":"okayama","name":"\u5ca1\u5c71","pack_code":null},{"code":"hirosima","name":"\u5e83\u5cf6","pack_code":null},{"code":"yamagchi","name":"\u5c71\u53e3","pack_code":null},{"code":"tokusima","name":"\u5fb3\u5cf6","pack_code":null},{"code":"kagawa","name":"\u9999\u5ddd","pack_code":null},{"code":"ehime","name":"\u611b\u5a9b","pack_code":null},{"code":"kouchi","name":"\u9ad8\u77e5","pack_code":null},{"code":"fukuoka","name":"\u798f\u5ca1","pack_code":null},{"code":"saga","name":"\u4f50\u8cc0","pack_code":null},{"code":"nagasaki","name":"\u9577\u5d0e","pack_code":null},{"code":"kumamoto","name":"\u718a\u672c","pack_code":null},{"code":"oita","name":"\u5927\u5206","pack_code":null},{"code":"miyazaki","name":"\u5bae\u5d0e","pack_code":null},{"code":"kagosima","name":"\u9e7f\u5150\u5cf6","pack_code":null},{"code":"nawa","name":"\u6c96\u7e04","pack_code":null}]})
|
38
|
+
EOS
|
39
|
+
|
40
|
+
EXAMPLE_REGION_LIST =
|
41
|
+
{
|
42
|
+
北海道: "hokk",
|
43
|
+
青森: "aomori",
|
44
|
+
岩手: "iwate",
|
45
|
+
宮城: "miya",
|
46
|
+
秋田: "akita",
|
47
|
+
山形: "yamagata",
|
48
|
+
福島: "fuku",
|
49
|
+
茨城: "ibaraki",
|
50
|
+
栃木: "tochigi",
|
51
|
+
群馬: "gunma",
|
52
|
+
埼玉: "saitama",
|
53
|
+
千葉: "chiba",
|
54
|
+
東京: "tokyo",
|
55
|
+
神奈川: "kanagawa",
|
56
|
+
新潟: "niigata",
|
57
|
+
富山: "toyama",
|
58
|
+
石川: "ishikawa",
|
59
|
+
福井: "fukui",
|
60
|
+
山梨: "yamanasi",
|
61
|
+
長野: "nagano",
|
62
|
+
岐阜: "gifu",
|
63
|
+
静岡: "sizu",
|
64
|
+
愛知: "aichi",
|
65
|
+
三重: "mie",
|
66
|
+
滋賀: "siga",
|
67
|
+
京都: "kyoto",
|
68
|
+
大阪: "osaka",
|
69
|
+
兵庫: "hyougo",
|
70
|
+
奈良: "nara",
|
71
|
+
和歌山: "wakayama",
|
72
|
+
鳥取: "tottori",
|
73
|
+
島根: "shimane",
|
74
|
+
岡山: "okayama",
|
75
|
+
広島: "hirosima",
|
76
|
+
山口: "yamagchi",
|
77
|
+
徳島: "tokusima",
|
78
|
+
香川: "kagawa",
|
79
|
+
愛媛: "ehime",
|
80
|
+
高知: "kouchi",
|
81
|
+
福岡: "fukuoka",
|
82
|
+
佐賀: "saga",
|
83
|
+
長崎: "nagasaki",
|
84
|
+
熊本: "kumamoto",
|
85
|
+
大分: "oita",
|
86
|
+
宮崎: "miyazaki",
|
87
|
+
鹿児島: "kagosima",
|
88
|
+
沖縄: "nawa"
|
89
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
WebMock.allow_net_connect!
|
6
|
+
|
7
|
+
API_URL = 'http://asp.tvguide.or.jp/api/broadcasting?region_code='
|
8
|
+
REGION_URL = 'http://asp.tvguide.or.jp/api/regions'
|
9
|
+
|
10
|
+
module Nowtv
|
11
|
+
describe Client do
|
12
|
+
before(:all) do
|
13
|
+
load File.expand_path("../../fixtures/fixtures.rb", __dir__)
|
14
|
+
@client = Nowtv::Client.new
|
15
|
+
@valid_region_code = 'tokyo'
|
16
|
+
@valid_region_name = '東京'
|
17
|
+
@invalid_region_code = 'nihon'
|
18
|
+
@invalid_region_name = '日本'
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_request(:get, API_URL + @valid_region_code)
|
23
|
+
.to_return(body: EXAMPLE_VALID_PROGRAMS_BODY, status: 200)
|
24
|
+
stub_request(:get, API_URL + @invalid_region_code)
|
25
|
+
.to_return(body: EXAMPLE_INVALID_PROGRAMS_BODY, status: 200)
|
26
|
+
stub_request(:get, REGION_URL).to_return(body: EXAMPLE_REGION_BODY, status: 200)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#get_programs' do
|
30
|
+
context 'with valid region code' do
|
31
|
+
subject { @client.get_programs(@valid_region_code) }
|
32
|
+
it { should be_instance_of Array }
|
33
|
+
it { should have_at_least(1).items }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with invalid region' do
|
37
|
+
subject { @client.get_programs(@invalid_region_code) }
|
38
|
+
it { should be_instance_of Array }
|
39
|
+
it { should have(0).items }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#get_program_list' do
|
44
|
+
context 'with valid region code' do
|
45
|
+
subject { @client.get_program_list(@valid_region_code) }
|
46
|
+
it { should be_instance_of Array }
|
47
|
+
it 'should be equal to example data' do
|
48
|
+
should eql EXAMPLE_RESTRUCTED_PROGRAMS
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with valid region name' do
|
53
|
+
subject { @client.get_program_list(@valid_region_name) }
|
54
|
+
it { should be_instance_of Array }
|
55
|
+
it 'should be equal to example data' do
|
56
|
+
should eql EXAMPLE_RESTRUCTED_PROGRAMS
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with invalid region code' do
|
61
|
+
it 'should put error message in STDERR' do
|
62
|
+
$stderr.should_receive(:puts).with('Failed to get programs!')
|
63
|
+
@program_list = @client.get_program_list(@invalid_region_code)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#restrct_program_list' do
|
69
|
+
subject { @client.restruct_program_list(EXAMPLE_PROGRAMS) }
|
70
|
+
it { should be_instance_of Array }
|
71
|
+
it 'should be equal to example data' do
|
72
|
+
should eql EXAMPLE_RESTRUCTED_PROGRAMS
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#get_region_list' do
|
77
|
+
subject { @client.get_region_list }
|
78
|
+
it { should be_instance_of Hash }
|
79
|
+
it { should have(47).items }
|
80
|
+
it 'should be equal to example data' do
|
81
|
+
should eq EXAMPLE_REGION_LIST
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#get_region_code' do
|
86
|
+
context 'with valid name' do
|
87
|
+
subject { @client.get_region_code(@valid_region_name) }
|
88
|
+
it { should == @valid_region_code }
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'with invalid name' do
|
92
|
+
subject { @client.get_region_code(@invalid_region_name) }
|
93
|
+
it { should be_nil }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
5
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
7
|
+
# loaded once.
|
8
|
+
#
|
9
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'nowtv'
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nowtv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dtan4
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: rspec
|
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: guard-rspec
|
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: webmock
|
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: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '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'
|
97
|
+
description: Show current TV programs
|
98
|
+
email:
|
99
|
+
- dtanshi45@gmail.com
|
100
|
+
executables:
|
101
|
+
- nowtv
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .nowtv
|
107
|
+
- .rspec
|
108
|
+
- .travis.yml
|
109
|
+
- Gemfile
|
110
|
+
- Guardfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/nowtv
|
115
|
+
- lib/nowtv.rb
|
116
|
+
- lib/nowtv/client.rb
|
117
|
+
- lib/nowtv/version.rb
|
118
|
+
- nowtv.gemspec
|
119
|
+
- spec/fixtures/fixtures.rb
|
120
|
+
- spec/lib/nowtv/client_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: https://github.com/dtan4/nowtv
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.1.0
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Show current TV programs
|
146
|
+
test_files:
|
147
|
+
- spec/fixtures/fixtures.rb
|
148
|
+
- spec/lib/nowtv/client_spec.rb
|
149
|
+
- spec/spec_helper.rb
|