niconico-mylist 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b0b5545e5fadd0d93e9597f8d2355b91d428110ab7929b9fdb88abb8e71244bc
4
+ data.tar.gz: d4a7c2ffce36d5bb0734956682b7e6387da5714b487cbe1b5514199b535915ef
5
+ SHA512:
6
+ metadata.gz: d41149fc18bd683fe28d49ae2130206cedbb02e518c51572ab98230684f63ddde0e27864bccc5321c17de9a0310305d1db9b361a986cd02a95c98ff82764f2de
7
+ data.tar.gz: e254ffadd93291cf79527947ad7f77429064d785a0c67788927342baf791713fb452b77592fe9b17945c540a44f413fc7c7a0406f6be3b64ceed0c6c3553bd5d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,84 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+
5
+ Layout/AlignParameters:
6
+ EnforcedStyle: with_fixed_indentation
7
+
8
+ Style/ClassAndModuleChildren:
9
+ EnforcedStyle: compact
10
+ Exclude:
11
+ - config/application.rb
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Style/FrozenStringLiteralComment:
17
+ EnforcedStyle: always
18
+ Enabled: true
19
+
20
+ Style/RegexpLiteral:
21
+ EnforcedStyle: percent_r
22
+
23
+ #################### Metrics ###############################
24
+
25
+ Metrics/AbcSize:
26
+ Max: 15
27
+
28
+ Metrics/BlockLength:
29
+ CountComments: false
30
+ Max: 25
31
+ ExcludedMethods: []
32
+ Exclude:
33
+ - "*.gemspec"
34
+ - "spec/**/*"
35
+ - Guardfile
36
+
37
+ Metrics/BlockNesting:
38
+ CountBlocks: false
39
+ Max: 3
40
+
41
+ Metrics/ClassLength:
42
+ CountComments: false
43
+ Max: 200
44
+
45
+ Metrics/CyclomaticComplexity:
46
+ Max: 12
47
+
48
+ Metrics/LineLength:
49
+ Max: 180
50
+
51
+ Metrics/MethodLength:
52
+ Max: 20
53
+
54
+ Metrics/ModuleLength:
55
+ Max: 200
56
+
57
+ Metrics/ParameterLists:
58
+ Max: 5
59
+
60
+ Metrics/PerceivedComplexity:
61
+ Max: 7
62
+
63
+ #################### Lint ##################################
64
+
65
+ Lint/UnusedBlockArgument:
66
+ IgnoreEmptyBlocks: true
67
+ AllowUnusedKeywordArguments: true
68
+
69
+ Lint/UnusedMethodArgument:
70
+ AllowUnusedKeywordArguments: true
71
+ IgnoreEmptyMethods: true
72
+
73
+ #################### Performance ###########################
74
+
75
+ Performance/DoubleStartEndWith:
76
+ IncludeActiveSupportAliases: false
77
+
78
+ Performance/RedundantMerge:
79
+ MaxKeyValuePairs: 2
80
+
81
+ #################### Rails #################################
82
+
83
+ Rails/ActionFilter:
84
+ EnforcedStyle: action
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in niconico-mylist.gemspec
8
+ gemspec
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ niconico-mylist (0.1.0)
5
+ faraday
6
+ faraday-encoding
7
+ webmock
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.2)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ coderay (1.1.2)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ diff-lcs (1.3)
18
+ faraday (0.15.3)
19
+ multipart-post (>= 1.2, < 3)
20
+ faraday-encoding (0.0.5)
21
+ faraday
22
+ hashdiff (0.3.7)
23
+ method_source (0.9.0)
24
+ multipart-post (2.0.0)
25
+ pry (0.11.3)
26
+ coderay (~> 1.1.0)
27
+ method_source (~> 0.9.0)
28
+ public_suffix (3.0.3)
29
+ rake (10.5.0)
30
+ rspec (3.8.0)
31
+ rspec-core (~> 3.8.0)
32
+ rspec-expectations (~> 3.8.0)
33
+ rspec-mocks (~> 3.8.0)
34
+ rspec-core (3.8.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-expectations (3.8.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-mocks (3.8.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-support (3.8.0)
43
+ safe_yaml (1.0.4)
44
+ webmock (3.4.2)
45
+ addressable (>= 2.3.6)
46
+ crack (>= 0.3.2)
47
+ hashdiff
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 1.16)
54
+ niconico-mylist!
55
+ pry
56
+ rake (~> 10.0)
57
+ rspec (~> 3.0)
58
+
59
+ BUNDLED WITH
60
+ 1.16.1
@@ -0,0 +1,49 @@
1
+ # Niconico::Mylist
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/niconico/mylist`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'niconico-mylist'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install niconico-mylist
20
+
21
+ ## Usage
22
+
23
+ ``` ruby
24
+ require 'niconico/mylist'
25
+
26
+ mylist = Niconico::Mylist.find(42564899)
27
+ # => #<Niconico::Mylist title: 音MAD creator: 名有りさん>
28
+ mylist.title
29
+ # => "音MAD"
30
+ mylist.items
31
+ # => [#<Niconico::Mylist::Item title: 関東Trapper>,
32
+ #<Niconico::Mylist::Item title: Fricken Dope☆.mp4>,
33
+ #<Niconico::Mylist::Item title: ラジオ体操の歌神社.mp4>,
34
+ #<Niconico::Mylist::Item title: THE SAFARI(BEAST).mp3>]
35
+ mylist.items[0]
36
+ # => #<Niconico::Mylist::Item title: 関東Trapper>
37
+ mylist.items[0].link
38
+ # => "http://www.nicovideo.jp/watch/sm31834553"
39
+ ```
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/niconico-mylist.
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'niconico/mylist'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'niconico/mylist/config'
4
+ require 'niconico/mylist/client'
5
+ require 'niconico/mylist/item'
6
+ require 'niconico/mylist/xpathable'
7
+
8
+ require 'niconico/mylist/version'
9
+
10
+ require 'time'
11
+
12
+ class Niconico::Mylist
13
+ include Xpathable
14
+
15
+ ENDPOINT = 'http://www.nicovideo.jp'
16
+
17
+ class << self
18
+ def config
19
+ @config ||= Niconico::Mylist::Config.new
20
+ end
21
+
22
+ def configure
23
+ yield(config) if block_given?
24
+ end
25
+
26
+ def find(id)
27
+ new(client.find_xml(id))
28
+ end
29
+
30
+ private
31
+
32
+ def client
33
+ Thread.current[:mylist_client] ||= begin
34
+ client = Niconico::Mylist::Client.new
35
+ config.faraday_configure.call(client)
36
+ client
37
+ end
38
+ end
39
+ end
40
+
41
+ def initialize(data)
42
+ @data = data
43
+ end
44
+
45
+ def title
46
+ @title ||= xpath_text('channel/title').match(%r{マイリスト (.+?)‐ニコニコ動画})[1]
47
+ end
48
+
49
+ def link
50
+ @link ||= xpath_text('channel/link')
51
+ end
52
+
53
+ def description
54
+ @description ||= xpath_text('channel/description')
55
+ end
56
+
57
+ def pub_date
58
+ @pub_date ||= Time.parse(xpath_text('channel/pubDate'))
59
+ end
60
+
61
+ def last_build_date
62
+ @last_build_date ||= Time.parse(xpath_text('channel/lastBuildDate'))
63
+ end
64
+
65
+ def creator
66
+ @creator ||= xpath_text('channel/dc:creator')
67
+ end
68
+
69
+ def items
70
+ @items ||= xpath_match('channel/item').map { |item| Niconico::Mylist::Item.new(item) }
71
+ end
72
+
73
+ def inspect
74
+ "#<#{self.class.name} title: #{title} creator: #{creator}>"
75
+ end
76
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday-encoding'
5
+ require 'rexml/document'
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
+ end
12
+
13
+ private
14
+
15
+ def faraday
16
+ @faraday ||= Faraday.new(url: Niconico::Mylist.config.endpoint) do |faraday|
17
+ faraday.response :encoding
18
+ faraday.adapter Faraday.default_adapter
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Niconico::Mylist::Config
4
+ attr_writer :endpoint
5
+ def endpoint
6
+ @endpoint ||= Niconico::Mylist::ENDPOINT
7
+ end
8
+
9
+ def faraday_configure(&block)
10
+ if block
11
+ @faraday_configure = block
12
+ else
13
+ @faraday_configure ||= proc {}
14
+ end
15
+ end
16
+
17
+ attr_writer :faraday_configure
18
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'niconico/mylist/xpathable'
4
+
5
+ require 'time'
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}>"
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Niconico
4
+ class Mylist
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rexml/document'
4
+
5
+ module Niconico::Mylist::Xpathable
6
+ private
7
+
8
+ def xpath_text(path)
9
+ REXML::XPath.first(@data, path).text
10
+ end
11
+
12
+ def xpath_match(path)
13
+ REXML::XPath.match(@data, path)
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'niconico/mylist/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'niconico-mylist'
9
+ spec.version = Niconico::Mylist::VERSION
10
+ spec.authors = ['naari3']
11
+ spec.email = ['naari.named@gmail.com']
12
+
13
+ spec.summary = 'Fetch niconico mylist'
14
+ spec.description = spec.summary
15
+ spec.homepage = 'https://github.com/naari3/niconico-mylist'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'faraday'
25
+ spec.add_dependency 'faraday-encoding'
26
+ spec.add_dependency 'webmock'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: niconico-mylist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - naari3
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-encoding
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Fetch niconico mylist
112
+ email:
113
+ - naari.named@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/niconico/mylist.rb
129
+ - lib/niconico/mylist/client.rb
130
+ - lib/niconico/mylist/config.rb
131
+ - lib/niconico/mylist/item.rb
132
+ - lib/niconico/mylist/version.rb
133
+ - lib/niconico/mylist/xpathable.rb
134
+ - niconico-mylist.gemspec
135
+ homepage: https://github.com/naari3/niconico-mylist
136
+ licenses: []
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.7.3
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Fetch niconico mylist
158
+ test_files: []