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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fb3d35bc4c6960b0b9897405cb23a5642e008aa7fa45d53de3a946283e20e3c
4
- data.tar.gz: fa57492c2c96671c8318321a8f40d93193795ecfb60578506f28e6daee68c08b
3
+ metadata.gz: 27031836f30d1fc948d6b37fb8a78d96f70c8d8c996db3244bb64aacb2e16f40
4
+ data.tar.gz: 64da92c982dcce0167854a0988b9a34b480947ad675dc83d58775afe8c758a93
5
5
  SHA512:
6
- metadata.gz: 004cbc285a8a62381589346608fbff34843d0074e72af99a8dc1853134919a8c367c1209fbc6563c3c5f01f49bf377934359d80b46fc6cca8f610c14337e4449
7
- data.tar.gz: 2704f257ff083e1134ae6324f328eb0dc6359951749014bf812d91ae062ec7cadd4576bfbc4abab400e9b4e4018bacbbff88e265d2e4f243886a821731fc8cc7
6
+ metadata.gz: 91694d39f14c0786642c5f72999029b18088e6e68ce2bdaab5562b1a89f38755b7209d4c952fa6c5800c70bb11104753c0ee420eafda46dd95f6e4258102a77c
7
+ data.tar.gz: c76dbd8c73441a9679f0ca12b41bc0eb0695a210ec7d12a7e091ad643fe2cf19bb320774f29dde00e06df1f63f7a22e566876294f50d74ff2782bf3087246ee3
@@ -5,11 +5,6 @@ AllCops:
5
5
  Layout/AlignParameters:
6
6
  EnforcedStyle: with_fixed_indentation
7
7
 
8
- Style/ClassAndModuleChildren:
9
- EnforcedStyle: compact
10
- Exclude:
11
- - config/application.rb
12
-
13
8
  Style/Documentation:
14
9
  Enabled: false
15
10
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- niconico-mylist (0.2.0)
4
+ niconico-mylist (0.2.1)
5
5
  faraday
6
6
  faraday-encoding
7
7
 
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'niconico/mylist'
@@ -10,68 +10,70 @@ require 'niconico/mylist/version'
10
10
 
11
11
  require 'time'
12
12
 
13
- class Niconico::Mylist
14
- include Xpathable
13
+ module Niconico
14
+ class Mylist
15
+ include Xpathable
15
16
 
16
- ENDPOINT = 'http://www.nicovideo.jp'
17
+ ENDPOINT = 'http://www.nicovideo.jp'
17
18
 
18
- class << self
19
- def config
20
- @config ||= Niconico::Mylist::Config.new
21
- end
19
+ class << self
20
+ def config
21
+ @config ||= Niconico::Mylist::Config.new
22
+ end
22
23
 
23
- def configure
24
- yield(config) if block_given?
25
- end
24
+ def configure
25
+ yield(config) if block_given?
26
+ end
26
27
 
27
- def find(id)
28
- new(client.find_xml(id))
29
- end
28
+ def find(id)
29
+ new(client.find_xml(id))
30
+ end
30
31
 
31
- private
32
+ private
32
33
 
33
- def client
34
- Thread.current[:mylist_client] ||= begin
35
- client = Niconico::Mylist::Client.new
36
- config.faraday_configure.call(client)
37
- client
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
- def initialize(data)
43
- @data = data
44
- end
43
+ def initialize(data)
44
+ @data = data
45
+ end
45
46
 
46
- def title
47
- @title ||= xpath_text('channel/title').match(%r{マイリスト (.+?)‐ニコニコ動画})[1]
48
- end
47
+ def title
48
+ @title ||= xpath_text('channel/title').match(%r{マイリスト (.+?)‐ニコニコ動画})[1]
49
+ end
49
50
 
50
- def link
51
- @link ||= xpath_text('channel/link')
52
- end
51
+ def link
52
+ @link ||= xpath_text('channel/link')
53
+ end
53
54
 
54
- def description
55
- @description ||= xpath_text('channel/description')
56
- end
55
+ def description
56
+ @description ||= xpath_text('channel/description')
57
+ end
57
58
 
58
- def pub_date
59
- @pub_date ||= Time.parse(xpath_text('channel/pubDate'))
60
- end
59
+ def pub_date
60
+ @pub_date ||= Time.parse(xpath_text('channel/pubDate'))
61
+ end
61
62
 
62
- def last_build_date
63
- @last_build_date ||= Time.parse(xpath_text('channel/lastBuildDate'))
64
- end
63
+ def last_build_date
64
+ @last_build_date ||= Time.parse(xpath_text('channel/lastBuildDate'))
65
+ end
65
66
 
66
- def creator
67
- @creator ||= xpath_text('channel/dc:creator')
68
- end
67
+ def creator
68
+ @creator ||= xpath_text('channel/dc:creator')
69
+ end
69
70
 
70
- def items
71
- @items ||= xpath_match('channel/item').map { |item| Niconico::Mylist::Item.new(item) }
72
- end
71
+ def items
72
+ @items ||= xpath_match('channel/item').map { |item| Niconico::Mylist::Item.new(item) }
73
+ end
73
74
 
74
- def inspect
75
- "#<#{self.class.name} title: #{title} creator: #{creator}>"
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
- class Niconico::Mylist::Client
8
- def find_xml(id)
9
- response = faraday.get("/mylist/#{id}?rss=2.0")
10
- REXML::Document.new(response.body).root
11
- rescue Faraday::Error::ResourceNotFound
12
- raise Niconico::Mylist::Error::NotFoundError, id
13
- rescue Faraday::Error::ClientError => e
14
- raise Niconico::Mylist::Error::ForbiddenError, id if e.response.status == 403
15
- raise e
16
- end
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
- private
21
+ private
19
22
 
20
- def faraday
21
- @faraday ||= Faraday.new(url: Niconico::Mylist.config.endpoint) do |faraday|
22
- faraday.response :encoding
23
- faraday.response :raise_error
24
- faraday.adapter Faraday.default_adapter
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
- class Niconico::Mylist::Config
4
- attr_writer :endpoint
5
- def endpoint
6
- @endpoint ||= Niconico::Mylist::ENDPOINT
7
- end
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
- def faraday_configure(&block)
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
- class Niconico::Mylist::Error < StandardError
4
- class NotFoundError < StandardError
5
- def initialize(id)
6
- @id = id
7
- super("Couldn't find Niconico Mylist with 'id'=#{@id}")
8
- end
9
- end
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
- class ForbiddenError < StandardError
12
- def initialize(id)
13
- @id = id
14
- super("Niconico Mylist with 'id'=#{@id} is forbidden")
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
@@ -4,34 +4,38 @@ require 'niconico/mylist/xpathable'
4
4
 
5
5
  require 'time'
6
6
 
7
- class Niconico::Mylist::Item
8
- include Niconico::Mylist::Xpathable
9
-
10
- def initialize(data)
11
- @data = data
12
- end
13
-
14
- def title
15
- @title ||= xpath_text('title')
16
- end
17
-
18
- def link
19
- @link ||= xpath_text('link')
20
- end
21
-
22
- def guid
23
- @guid ||= xpath_text('guid')
24
- end
25
-
26
- def pub_date
27
- @pub_date ||= Time.parse(xpath_text('pubDate'))
28
- end
29
-
30
- def description
31
- @description ||= xpath_text('description')
32
- end
33
-
34
- def inspect
35
- "#<#{self.class.name} title: #{title}>"
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,6 +2,6 @@
2
2
 
3
3
  module Niconico
4
4
  class Mylist
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
@@ -2,14 +2,18 @@
2
2
 
3
3
  require 'rexml/document'
4
4
 
5
- module Niconico::Mylist::Xpathable
6
- private
5
+ module Niconico
6
+ class Mylist
7
+ module Xpathable
8
+ private
7
9
 
8
- def xpath_text(path)
9
- REXML::XPath.first(@data, path).text
10
- end
10
+ def xpath_text(path)
11
+ REXML::XPath.first(@data, path).text
12
+ end
11
13
 
12
- def xpath_match(path)
13
- REXML::XPath.match(@data, path)
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.0
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