nicoapi 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85a27a872f8f739e54f3625c7e5e7d94f7e22d0c
4
+ data.tar.gz: d61b31a878ac05fe5d641d277cd88a86088b7f90
5
+ SHA512:
6
+ metadata.gz: e1de2052d855fdfe12a5434d299502c23f0004c242ced4717d2287ecc479efeea6955c9ed89869c7945c5842546469e7d2eb9e0887915e667704d132406156d8
7
+ data.tar.gz: 88e5b5305a79fb3ef63979fe2159b4e4d0ae6b4ad7871411639d87cb7cf6fd9536d6729db8fe15b06eb3e80a1e0c9d49081f41de3715423a0b2570186715123c
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rest-client'
4
+ gem 'active_support'
5
+ gem 'i18n'
6
+ gem 'nori'
7
+ gem 'nokogiri'
8
+
9
+ group :development, :test do
10
+ gem 'pry'
11
+ gem 'watchr'
12
+ end
13
+
14
+ group :test do
15
+ gem 'rspec'
16
+ gem 'factory_girl'
17
+ end
18
+
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ active_support (3.0.0)
5
+ activesupport (= 3.0.0)
6
+ activesupport (3.0.0)
7
+ coderay (1.0.9)
8
+ diff-lcs (1.2.4)
9
+ factory_girl (4.2.0)
10
+ activesupport (>= 3.0.0)
11
+ i18n (0.6.4)
12
+ method_source (0.8.1)
13
+ mime-types (1.23)
14
+ mini_portile (0.5.1)
15
+ nokogiri (1.6.0)
16
+ mini_portile (~> 0.5.0)
17
+ nori (2.2.0)
18
+ pry (0.9.12.2)
19
+ coderay (~> 1.0.5)
20
+ method_source (~> 0.8)
21
+ slop (~> 3.4)
22
+ rest-client (1.6.7)
23
+ mime-types (>= 1.16)
24
+ rspec (2.14.1)
25
+ rspec-core (~> 2.14.0)
26
+ rspec-expectations (~> 2.14.0)
27
+ rspec-mocks (~> 2.14.0)
28
+ rspec-core (2.14.3)
29
+ rspec-expectations (2.14.0)
30
+ diff-lcs (>= 1.1.3, < 2.0)
31
+ rspec-mocks (2.14.1)
32
+ slop (3.4.5)
33
+ watchr (0.7)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ active_support
40
+ factory_girl
41
+ i18n
42
+ nokogiri
43
+ nori
44
+ pry
45
+ rest-client
46
+ rspec
47
+ watchr
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/autorun.rb ADDED
@@ -0,0 +1,5 @@
1
+ watch( 'app/(.*)\.rb' ) {|md| system("bundle exec rspec spec/#{md[1]}_spec.rb") }
2
+ watch( 'spec/(.*)\.rb' ) {|md| system("bundle exec rspec spec/#{md[1]}.rb") }
3
+
4
+
5
+
@@ -0,0 +1,33 @@
1
+ require 'nicoapi/http_client'
2
+
3
+
4
+ module NicoAPI
5
+ module Base
6
+ def scheme
7
+ 'http'
8
+ end
9
+
10
+ def params
11
+ @params_array.join('&')
12
+ end
13
+
14
+ def path
15
+ if @dynamic_segment.present?
16
+ static_segment + '/' + @dynamic_segment
17
+ else
18
+ static_segment
19
+ end
20
+ end
21
+
22
+ def uri
23
+ _uri = scheme + "://" + [ ([host, path].join('/')), params].join('?')
24
+ URI.escape _uri
25
+ end
26
+
27
+ def get
28
+ http_client = NicoAPI::HttpClient.instance
29
+ http_client.set_params uri.to_s
30
+ http_client.get
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ require 'nicoapi/base'
2
+
3
+
4
+ module NicoAPI
5
+ class GetThumbInfo
6
+ include NicoAPI::Base
7
+
8
+ def set(video_id)
9
+ @dynamic_segment = video_id
10
+ @params_array = []
11
+ end
12
+
13
+ private
14
+ def host
15
+ 'ext.nicovideo.jp'
16
+ end
17
+
18
+ def static_segment
19
+ 'api/getthumbinfo'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ require 'nori'
2
+
3
+
4
+ module NicoAPI
5
+ module HashMapper
6
+ def map_to_hash(xml)
7
+ (Nori.new).parse xml
8
+ end
9
+
10
+ module_function :map_to_hash
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'rest_client'
2
+ require 'singleton'
3
+
4
+
5
+ module NicoAPI
6
+ class HttpClient
7
+ include Singleton
8
+
9
+ def set_params(uri) @uri = uri end
10
+
11
+ def get
12
+ RestClient.get @uri.to_s
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,59 @@
1
+ require 'active_support/core_ext'
2
+ require 'nicoapi/base'
3
+
4
+
5
+ module NicoAPI
6
+ class TagSearch
7
+ include NicoAPI::Base
8
+
9
+ def set(tag: tag, sort: sort, order: order)
10
+ @dynamic_segment = tag
11
+ @params_array = params_array(sort, order)
12
+ end
13
+
14
+ private
15
+ def host
16
+ 'www.nicovideo.jp'
17
+ end
18
+
19
+ def static_segment
20
+ 'tag'
21
+ end
22
+
23
+ def params_array(sort, order)
24
+ array = []
25
+
26
+ array.push sort_param(sort)
27
+ array.push order_param(order)
28
+ array.push "rss=2.0"
29
+
30
+ array
31
+ end
32
+
33
+ def format
34
+ "rss=2.0"
35
+ end
36
+
37
+ def sort_param(sort)
38
+ sort_string = case sort
39
+ when 'commented_at' then nil
40
+ when 'view_count' then 'v'
41
+ when 'comment_num' then 'r'
42
+ when 'mylist_count' then 'm'
43
+ when 'published_at' then 'f'
44
+ when 'length' then 'l'
45
+ end
46
+
47
+ sort_string.present? ? "sort=#{sort_string}" : ''
48
+ end
49
+
50
+ def order_param(order)
51
+ order_string = case order
52
+ when 'asc' then 'order=a'
53
+ else nil
54
+ end
55
+
56
+ order_string.present? ? 'order=a' : ''
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Nicoapi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'nicoapi/base'
2
+
3
+
4
+ module NicoAPI
5
+ class VideoArray
6
+ include NicoAPI::Base
7
+
8
+ def set(video_id_array)
9
+ @dynamic_segment = ''
10
+ @params_array = params_array video_id_array
11
+ end
12
+
13
+ private
14
+ def host
15
+ 'i.nicovideo.jp'
16
+ end
17
+
18
+ def static_segment
19
+ 'v3/video.array'
20
+ end
21
+
22
+ # video.array APIは動的セグメントではなく、URIパラメータとして動画を指定する。
23
+ def params_array(video_id_array)
24
+ ['v=' + video_id_array.join(',')]
25
+ end
26
+ end
27
+ end
data/lib/nicoapi.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "nicoapi/version"
2
+
3
+ require "nicoapi/getthumbinfo"
4
+ require "nicoapi/tag_search"
5
+ require "nicoapi/video_array"
6
+
7
+
8
+ module NicoAPI
9
+ def getthumbinfo(video_id)
10
+ instance = NicoAPI::GetThumbInfo.new
11
+ instance.set video_id
12
+ instance.get
13
+ end
14
+
15
+ def video_array(video_id_array)
16
+ instance = NicoAPI::VideoArray.new
17
+ instance.set video_id_array
18
+ instance.get
19
+ end
20
+
21
+ def tag_search(tag: tag, sort: sort, order: order)
22
+ instance = NicoAPI::TagSearch.new
23
+ instance.set tag: tag, sort: sort, order: order
24
+ instance.get
25
+ end
26
+
27
+ module_function :getthumbinfo
28
+ module_function :video_array
29
+ module_function :tag_search
30
+ end
data/nicoapi.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nicoapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nicoapi"
8
+ spec.version = Nicoapi::VERSION
9
+ spec.authors = ["Masami Yonehara"]
10
+ spec.email = ["zeitdiebe@gmail.com"]
11
+ spec.description = %q{niconico low level api library}
12
+ spec.summary = %q{niconico low level api library}
13
+ spec.homepage = ""
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
+ end
@@ -0,0 +1,16 @@
1
+ require './app/getthumbinfo'
2
+
3
+
4
+ describe "getthumbinfo" do
5
+ describe "get" do
6
+ before do
7
+ @instance = NicoAPI::GetThumbInfo.new
8
+ @instance.set video_id: 'sm9'
9
+ end
10
+
11
+ subject { @instance.uri }
12
+ specify {
13
+ expect(subject).to match /http:\/\/ext\.nicovideo\.jp\/api\/getthumbinfo\/(sm|nm)\d/
14
+ }
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,20 @@
1
+ require './app/tag_search'
2
+
3
+
4
+ describe "tag_search" do
5
+ before do
6
+ @instance = NicoAPI::TagSearch.new
7
+ @instance.set tag: 'ゆっくり実況プレイ', sort: 'published_at', order: 'asc'
8
+ end
9
+
10
+ describe "uri" do
11
+ subject { @instance.uri }
12
+ specify {
13
+ # host and path
14
+ expect(subject).to match /http:\/\/www\.nicovideo\.jp\/tag/
15
+ # uri parameter
16
+ expect(subject).to match /\?(sort=(v|r|m|f|l)){0,}/
17
+ expect(subject).to match /\?(order=(a|d)){0,}/
18
+ }
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require './app/video_array'
2
+
3
+ describe "VideoArray" do
4
+ before do
5
+ @instance = NicoAPI::VideoArray.new
6
+ @instance.set ['sm9', 'sm14']
7
+ end
8
+
9
+ describe "uri" do
10
+ subject { @instance.uri }
11
+ specify {
12
+ expect(subject).to match /http:\/\/i\.nicovideo\.jp\/v3\/video\.array\?v=((sm\d|nm\d),{0,}){1,}/
13
+ }
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nicoapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masami Yonehara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-28 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
+ description: niconico low level api library
42
+ email:
43
+ - zeitdiebe@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .ruby-version
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - Rakefile
53
+ - autorun.rb
54
+ - lib/nicoapi.rb
55
+ - lib/nicoapi/base.rb
56
+ - lib/nicoapi/getthumbinfo.rb
57
+ - lib/nicoapi/hash_mapper.rb
58
+ - lib/nicoapi/http_client.rb
59
+ - lib/nicoapi/tag_search.rb
60
+ - lib/nicoapi/version.rb
61
+ - lib/nicoapi/video_array.rb
62
+ - nicoapi.gemspec
63
+ - spec/getthumbinfo_spec.rb
64
+ - spec/spec_helper.rb
65
+ - spec/tag_search_spec.rb
66
+ - spec/video_array_spec.rb
67
+ homepage: ''
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.0.3
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: niconico low level api library
91
+ test_files:
92
+ - spec/getthumbinfo_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/tag_search_spec.rb
95
+ - spec/video_array_spec.rb