niconico-mylist 0.2.0 → 0.2.1
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 +4 -4
- data/.rubocop.yml +0 -5
- data/Gemfile.lock +1 -1
- data/lib/niconico-mylist.rb +3 -0
- data/lib/niconico/mylist.rb +48 -46
- data/lib/niconico/mylist/client.rb +21 -16
- data/lib/niconico/mylist/config.rb +16 -12
- data/lib/niconico/mylist/error.rb +15 -11
- data/lib/niconico/mylist/item.rb +33 -29
- data/lib/niconico/mylist/version.rb +1 -1
- data/lib/niconico/mylist/xpathable.rb +11 -7
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27031836f30d1fc948d6b37fb8a78d96f70c8d8c996db3244bb64aacb2e16f40
|
4
|
+
data.tar.gz: 64da92c982dcce0167854a0988b9a34b480947ad675dc83d58775afe8c758a93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91694d39f14c0786642c5f72999029b18088e6e68ce2bdaab5562b1a89f38755b7209d4c952fa6c5800c70bb11104753c0ee420eafda46dd95f6e4258102a77c
|
7
|
+
data.tar.gz: c76dbd8c73441a9679f0ca12b41bc0eb0695a210ec7d12a7e091ad643fe2cf19bb320774f29dde00e06df1f63f7a22e566876294f50d74ff2782bf3087246ee3
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/niconico/mylist.rb
CHANGED
@@ -10,68 +10,70 @@ require 'niconico/mylist/version'
|
|
10
10
|
|
11
11
|
require 'time'
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
module Niconico
|
14
|
+
class Mylist
|
15
|
+
include Xpathable
|
15
16
|
|
16
|
-
|
17
|
+
ENDPOINT = 'http://www.nicovideo.jp'
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
class << self
|
20
|
+
def config
|
21
|
+
@config ||= Niconico::Mylist::Config.new
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def configure
|
25
|
+
yield(config) if block_given?
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def find(id)
|
29
|
+
new(client.find_xml(id))
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
+
private
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
def client
|
35
|
+
Thread.current[:mylist_client] ||= begin
|
36
|
+
client = Niconico::Mylist::Client.new
|
37
|
+
config.faraday_configure.call(client)
|
38
|
+
client
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
40
|
-
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def initialize(data)
|
44
|
+
@data = data
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def title
|
48
|
+
@title ||= xpath_text('channel/title').match(%r{マイリスト (.+?)‐ニコニコ動画})[1]
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def link
|
52
|
+
@link ||= xpath_text('channel/link')
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def description
|
56
|
+
@description ||= xpath_text('channel/description')
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def pub_date
|
60
|
+
@pub_date ||= Time.parse(xpath_text('channel/pubDate'))
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def last_build_date
|
64
|
+
@last_build_date ||= Time.parse(xpath_text('channel/lastBuildDate'))
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
def creator
|
68
|
+
@creator ||= xpath_text('channel/dc:creator')
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
def items
|
72
|
+
@items ||= xpath_match('channel/item').map { |item| Niconico::Mylist::Item.new(item) }
|
73
|
+
end
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
def inspect
|
76
|
+
"#<#{self.class.name} title: #{title} creator: #{creator}>"
|
77
|
+
end
|
76
78
|
end
|
77
79
|
end
|
@@ -4,24 +4,29 @@ require 'faraday'
|
|
4
4
|
require 'faraday-encoding'
|
5
5
|
require 'rexml/document'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
module Niconico
|
8
|
+
class Mylist
|
9
|
+
class Client
|
10
|
+
def find_xml(id)
|
11
|
+
response = faraday.get("/mylist/#{id}?rss=2.0")
|
12
|
+
REXML::Document.new(response.body).root
|
13
|
+
rescue Faraday::Error::ResourceNotFound
|
14
|
+
raise Niconico::Mylist::Error::NotFoundError, id
|
15
|
+
rescue Faraday::Error::ClientError => e
|
16
|
+
raise Niconico::Mylist::Error::ForbiddenError, id if e.response.status == 403
|
17
|
+
|
18
|
+
raise e
|
19
|
+
end
|
17
20
|
|
18
|
-
|
21
|
+
private
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def faraday
|
24
|
+
@faraday ||= Faraday.new(url: Niconico::Mylist.config.endpoint) do |faraday|
|
25
|
+
faraday.response :encoding
|
26
|
+
faraday.response :raise_error
|
27
|
+
faraday.adapter Faraday.default_adapter
|
28
|
+
end
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -1,18 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Niconico
|
4
|
+
class Mylist
|
5
|
+
class Config
|
6
|
+
attr_writer :endpoint
|
7
|
+
def endpoint
|
8
|
+
@endpoint ||= Niconico::Mylist::ENDPOINT
|
9
|
+
end
|
10
|
+
|
11
|
+
def faraday_configure(&block)
|
12
|
+
if block
|
13
|
+
@faraday_configure = block
|
14
|
+
else
|
15
|
+
@faraday_configure ||= proc {}
|
16
|
+
end
|
17
|
+
end
|
8
18
|
|
9
|
-
|
10
|
-
if block
|
11
|
-
@faraday_configure = block
|
12
|
-
else
|
13
|
-
@faraday_configure ||= proc {}
|
19
|
+
attr_writer :faraday_configure
|
14
20
|
end
|
15
21
|
end
|
16
|
-
|
17
|
-
attr_writer :faraday_configure
|
18
22
|
end
|
@@ -1,17 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module Niconico
|
4
|
+
class Mylist
|
5
|
+
class Error < StandardError
|
6
|
+
class NotFoundError < StandardError
|
7
|
+
def initialize(id)
|
8
|
+
@id = id
|
9
|
+
super("Couldn't find Niconico Mylist with 'id'=#{@id}")
|
10
|
+
end
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
class ForbiddenError < StandardError
|
14
|
+
def initialize(id)
|
15
|
+
@id = id
|
16
|
+
super("Niconico Mylist with 'id'=#{@id} is forbidden")
|
17
|
+
end
|
18
|
+
end
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/niconico/mylist/item.rb
CHANGED
@@ -4,34 +4,38 @@ require 'niconico/mylist/xpathable'
|
|
4
4
|
|
5
5
|
require 'time'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
7
|
+
module Niconico
|
8
|
+
class Mylist
|
9
|
+
class Item
|
10
|
+
include Niconico::Mylist::Xpathable
|
11
|
+
|
12
|
+
def initialize(data)
|
13
|
+
@data = data
|
14
|
+
end
|
15
|
+
|
16
|
+
def title
|
17
|
+
@title ||= xpath_text('title')
|
18
|
+
end
|
19
|
+
|
20
|
+
def link
|
21
|
+
@link ||= xpath_text('link')
|
22
|
+
end
|
23
|
+
|
24
|
+
def guid
|
25
|
+
@guid ||= xpath_text('guid')
|
26
|
+
end
|
27
|
+
|
28
|
+
def pub_date
|
29
|
+
@pub_date ||= Time.parse(xpath_text('pubDate'))
|
30
|
+
end
|
31
|
+
|
32
|
+
def description
|
33
|
+
@description ||= xpath_text('description')
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
"#<#{self.class.name} title: #{title}>"
|
38
|
+
end
|
39
|
+
end
|
36
40
|
end
|
37
41
|
end
|
@@ -2,14 +2,18 @@
|
|
2
2
|
|
3
3
|
require 'rexml/document'
|
4
4
|
|
5
|
-
module Niconico
|
6
|
-
|
5
|
+
module Niconico
|
6
|
+
class Mylist
|
7
|
+
module Xpathable
|
8
|
+
private
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
def xpath_text(path)
|
11
|
+
REXML::XPath.first(@data, path).text
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
def xpath_match(path)
|
15
|
+
REXML::XPath.match(@data, path)
|
16
|
+
end
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niconico-mylist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- naari3
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- Rakefile
|
126
126
|
- bin/console
|
127
127
|
- bin/setup
|
128
|
+
- lib/niconico-mylist.rb
|
128
129
|
- lib/niconico/mylist.rb
|
129
130
|
- lib/niconico/mylist/client.rb
|
130
131
|
- lib/niconico/mylist/config.rb
|