niconize 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e2fd449ecb1caea083c160e8d493ea5244f7837
4
- data.tar.gz: 72919a75160e374013f655af96058bbe1f33a650
3
+ metadata.gz: 2dd2227fcb3c2d07a558b2da07dc471c1793477e
4
+ data.tar.gz: 44f51cee9c2debfb64f305196943290aaed88cfe
5
5
  SHA512:
6
- metadata.gz: 43ba97c373cbf3f91be3d8c1bd6b612bad27e974028a04119d03f90c3cba207310c5f56952c436572fb6e7127bb6b7f7562c88c9eae3b24c438dde7f083cf53e
7
- data.tar.gz: c6bfa1f777404b2dce86e0de2a54c5796783ee05d21be04447269a4200948689118b3be20bb3d430bf01fdaec87659f47d1a7f2cf4c3623220b1e76a7dc3f510
6
+ metadata.gz: 2c00fbfce37a52e7c2f5dc0384e34c4fa8a7ad46de3de5a90a304bc32527ecf82789f500abfa0c15a10bbe656b2e20fe11ce229a2d7d3ce2924a918783c9ff72
7
+ data.tar.gz: dfe0b71dcb6b3a605f529e1c101f87278dd937ff70bfb7b7861062e1a157c37ec6731bd0b5cdd1f16cee3e382e37f498573c7d9c5584cb9c1e289a472d7336ba
data/README.md CHANGED
@@ -19,5 +19,5 @@ require 'niconize'
19
19
  niconize = Niconize.new('YOUR_MAIL_ADDRESS', 'PASSWORD')
20
20
 
21
21
  # timeshift reservation
22
- niconize.live('lvxxxxxx').reserve
22
+ niconize.program('lvxxxxxx').reserve
23
23
  ```
@@ -0,0 +1,44 @@
1
+ module Niconize
2
+ class Client
3
+ class LoginError < StandardError; end
4
+
5
+ URL = {
6
+ login: 'https://secure.nicovideo.jp/secure/login?site=niconico',
7
+ live_watch: 'http://live.nicovideo.jp/watch/',
8
+ reserve: 'http://live.nicovideo.jp/api/watchingreservation'
9
+ }
10
+
11
+ attr_reader :agent, :logined
12
+
13
+ def initialize(mail, password)
14
+ @mail = mail
15
+ @password = password
16
+
17
+ @logined = false
18
+
19
+ @agent = Mechanize.new
20
+ @agent.ssl_version = 'SSLv3'
21
+ @agent.request_headers = {
22
+ 'accept-language' => 'ja, ja-JP'
23
+ }
24
+ end
25
+
26
+ def login
27
+ page = @agent.post(URL[:login], 'mail' => @mail, 'password' => @password)
28
+
29
+ raise LoginError, 'Failed to login (x-niconico-authflag is 0)' if page.header['x-niconico-authflag'] == '0'
30
+ @logined = true
31
+ end
32
+
33
+ def program(lv)
34
+ login unless logined
35
+ Niconize::Program.new(self, lv)
36
+ end
37
+
38
+ def reserved_programs
39
+ query = { 'mode' => 'list' }
40
+ response = agent.get(URL[:reserve], query)
41
+ response.search('timeshift_reserved_list').children.map { |vid_element| Niconize::Program.new(self, 'lv' + vid_element.inner_text) }
42
+ end
43
+ end
44
+ end
@@ -1,17 +1,12 @@
1
- require_relative './live'
2
-
3
- class Niconize
4
- def program(lv)
5
- login unless @logined
6
- Program.new(self, lv)
7
- end
8
-
1
+ module Niconize
9
2
  class Program
3
+ class TimeshiftError < StandardError; end
4
+
10
5
  attr_reader :lv, :vid
11
6
 
12
- def initialize(parent, lv)
13
- @parent = parent
14
- @agent = parent.agent
7
+ def initialize(client, lv)
8
+ @client = client
9
+ @agent = client.agent
15
10
  @lv = lv
16
11
  @vid = lv.sub(/^lv/, '')
17
12
  end
@@ -26,13 +21,13 @@ class Niconize
26
21
  '_' => ''
27
22
  }
28
23
 
29
- @agent.post(URL[:reserve], data)
24
+ @agent.post(Niconize::Client::URL[:reserve], data)
30
25
  end
31
26
 
32
27
  private
33
28
 
34
29
  def reserved?
35
- !!@parent.live.reserved_programs.map { |program| program.vid }.include?(vid)
30
+ !!@client.reserved_programs.map { |program| program.vid }.include?(vid)
36
31
  end
37
32
 
38
33
  def live_page
@@ -49,11 +44,9 @@ class Niconize
49
44
  'vid' => vid,
50
45
  'token' => token
51
46
  }
52
- response = @agent.get(URL[:reserve], query)
47
+ response = @agent.get(Niconize::Client::URL[:reserve], query)
53
48
  raise TimeshiftError, 'It is the limit of the number of your reservation' unless response.at('div.reserve')
54
49
  response.at('div.reserve').inner_html.scan(/ulck_[0-9]+/)[0]
55
50
  end
56
-
57
- class TimeshiftError < StandardError; end
58
51
  end
59
52
  end
@@ -1,3 +1,3 @@
1
- class Niconize
2
- VERSION = "0.0.6"
1
+ module Niconize
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/niconize.rb CHANGED
@@ -1,36 +1,5 @@
1
- require "niconize/version"
2
1
  require "mechanize"
3
2
 
4
- class Niconize
5
- URL = {
6
- login: 'https://secure.nicovideo.jp/secure/login?site=niconico',
7
- live_watch: 'http://live.nicovideo.jp/watch/',
8
- reserve: 'http://live.nicovideo.jp/api/watchingreservation'
9
- }
10
-
11
- attr_reader :agent, :logined
12
-
13
- def initialize(mail, password)
14
- @mail = mail
15
- @password = password
16
-
17
- @logined = false
18
-
19
- @agent = Mechanize.new
20
- @agent.ssl_version = 'SSLv3'
21
- @agent.request_headers = {
22
- 'accept-language' => 'ja, ja-JP'
23
- }
24
- end
25
-
26
- def login
27
- page = @agent.post(URL[:login], 'mail' => @mail, 'password' => @password)
28
-
29
- raise LoginError, 'Failed to login (x-niconico-authflag is 0)' if page.header['x-niconico-authflag'] == '0'
30
- @logined = true
31
- end
32
- class LoginError < StandardError; end
33
- end
34
-
35
- require_relative 'niconize/program'
36
- require_relative 'niconize/live'
3
+ require "niconize/client"
4
+ require "niconize/program"
5
+ require "niconize/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: niconize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomohiro Suwa(tsuwatch)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -65,7 +65,7 @@ files:
65
65
  - README.md
66
66
  - Rakefile
67
67
  - lib/niconize.rb
68
- - lib/niconize/live.rb
68
+ - lib/niconize/client.rb
69
69
  - lib/niconize/program.rb
70
70
  - lib/niconize/version.rb
71
71
  - niconize.gemspec
data/lib/niconize/live.rb DELETED
@@ -1,21 +0,0 @@
1
- require_relative './program'
2
-
3
- class Niconize
4
- def live
5
- login unless @logined
6
- @live ||= Live.new(self)
7
- end
8
-
9
- class Live
10
- def initialize(parent)
11
- @parent = parent
12
- @agent = parent.agent
13
- end
14
-
15
- def reserved_programs
16
- query = { 'mode' => 'list' }
17
- response = @agent.get(URL[:reserve], query)
18
- response.search('timeshift_reserved_list').children.map { |vid_element| Program.new(@parent, 'lv' + vid_element.inner_text) }
19
- end
20
- end
21
- end