nico_search 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +52 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +135 -0
- data/Rakefile +6 -0
- data/lib/nico_search/client.rb +72 -0
- data/lib/nico_search/version.rb +3 -0
- data/lib/nico_search.rb +3 -0
- data/nico_search.gemspec +38 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b310857d9ed1c09d750a0fa04246e87a9133cec8
|
4
|
+
data.tar.gz: 804d1a945517e23c49984659016cadf3e1b8d266
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 682c800aa9f3143235be94e9c7bedace1dc70456bb3301ce0cd2aa4f2a8a5a6979b2219abf11b55313e03bfa9938d74a20ecf160199f8d86014dda650a996a26
|
7
|
+
data.tar.gz: '090e1e5d9d84d1c1f7e4f0e5fee12c1caa63cb2e83cd053ae3c07928bf69acf4e1910e3d4c762107032586c3a625daa071544558fc96a9e172069c402c880088'
|
data/.gitignore
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
### https://raw.github.com/github/gitignore/f5875713439b01eb9dd4c50188c7805d4670f4e9/Ruby.gitignore
|
14
|
+
|
15
|
+
*.gem
|
16
|
+
*.rbc
|
17
|
+
/.config
|
18
|
+
/coverage/
|
19
|
+
/InstalledFiles
|
20
|
+
/pkg/
|
21
|
+
/spec/reports/
|
22
|
+
/spec/examples.txt
|
23
|
+
/test/tmp/
|
24
|
+
/test/version_tmp/
|
25
|
+
/tmp/
|
26
|
+
|
27
|
+
## Specific to RubyMotion:
|
28
|
+
.dat*
|
29
|
+
.repl_history
|
30
|
+
build/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalisation:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
|
52
|
+
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 itkq
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# NicoSearch
|
2
|
+
|
3
|
+
Ruby interface for Niconico search API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'nico_search'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nico_search
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### `NicoSearch::Client#search(service, params)`
|
24
|
+
- `service` (String)
|
25
|
+
- Select one from the following:
|
26
|
+
- `video`, `live`, `illust`, `manga`, `book`, `channel`, `channelarticle`, `news`
|
27
|
+
- `params` (Hash)
|
28
|
+
- [**required**] `q` (String)
|
29
|
+
- Search keyword (you can use multiple keyword like Google search)
|
30
|
+
- [**required**] `targets` (Array)
|
31
|
+
- Target field to search.
|
32
|
+
- [**required**] `fields` (Array)
|
33
|
+
- Field to be acquired.
|
34
|
+
- [**required**] `_sort` (String)
|
35
|
+
- Field to be used for sorting.
|
36
|
+
- `filters` (Hash)
|
37
|
+
- `_offset` (Integer)
|
38
|
+
- Maximum: 1600
|
39
|
+
- Default: 0
|
40
|
+
- `_limit` (Integer)
|
41
|
+
- Default: 10
|
42
|
+
- `_context` (String)
|
43
|
+
- Application name.
|
44
|
+
|
45
|
+
### field
|
46
|
+
- contentId
|
47
|
+
- title
|
48
|
+
- description
|
49
|
+
- tags
|
50
|
+
- tagsExact
|
51
|
+
- categoryTags
|
52
|
+
- viewCounter (Integer)
|
53
|
+
- mylistCounter (Integer)
|
54
|
+
- startTime (Time)
|
55
|
+
- thumbnailUrl
|
56
|
+
- communityIcon
|
57
|
+
- scoreTimeshiftReserved
|
58
|
+
- liveStatus
|
59
|
+
|
60
|
+
Detailed in: https://www59.atwiki.jp/nicoapi/pages/51.html (Japanese)
|
61
|
+
|
62
|
+
### filtering
|
63
|
+
#### String
|
64
|
+
Example:
|
65
|
+
```ruby
|
66
|
+
params = {
|
67
|
+
tags: [
|
68
|
+
'hoge', 'fuga'
|
69
|
+
]
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Integer or Time
|
74
|
+
It can be narrowed down by range. Example:
|
75
|
+
```ruby
|
76
|
+
params = {
|
77
|
+
filters: {
|
78
|
+
# 1000000 <= viewCounter < 2000000
|
79
|
+
viewCounter: {
|
80
|
+
gte: 1000000,
|
81
|
+
lt: 2000000,
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
## Example
|
89
|
+
- Get scheduled live broadcast
|
90
|
+
- include '小澤亜李' in title or description or tags
|
91
|
+
- order by startTime limit 2
|
92
|
+
```ruby
|
93
|
+
require 'nico_search'
|
94
|
+
params = {
|
95
|
+
q: '小澤亜李',
|
96
|
+
targets: %w(title description tags),
|
97
|
+
fields: %w(contentId title description tags start_time thumbnailUrl),
|
98
|
+
filters: {
|
99
|
+
startTime: {
|
100
|
+
gte: '2017-03-29T00:00:00-09:00',
|
101
|
+
},
|
102
|
+
liveStatus: 'reserved',
|
103
|
+
},
|
104
|
+
_sort: '+startTime',
|
105
|
+
_limit: 2,
|
106
|
+
_context: 'nigo_search gem',
|
107
|
+
}
|
108
|
+
NicoSearch::Client.search('live', params)
|
109
|
+
# => {"meta"=>{"status"=>200, "totalCount"=>2, "id"=>"c7b7f1cf-e92d-4111-8044-6b9c01a2252c"},
|
110
|
+
# "data"=>
|
111
|
+
# [{"startTime"=>"2017-03-30T21:00:00+09:00",
|
112
|
+
# "description"=>
|
113
|
+
# "自他ともに認めるマイペース声優?大橋彩香が、自由な進行に合わせてくれる優しいゲストを招き、<br />\r\nMCとなって“気楽に”&“等身大で”まわしていく番組、それが…「大橋彩香の へごまわし!」\r\n<br />\r\n大橋彩香自身が興味・関心のあるものだけをクローズアップしつつ極めてマイペースな“まわし”ぶりをお楽しみいただく1時間番組です!<br /><br />\r\n<b>『大橋彩香の へごまわし!』はチャンネル会員向けの生放送番組です。冒頭15分はどなたでも無料でご覧いただけます。チャンネル会員になると最後までご覧いただくことができます。</b><br /><br />\r\n<b>■出演</b><br />\r\nメインMC:大橋彩香<br />\r\nゲスト:小澤亜李<br /><br />\r\n<b>■メッセージ募集中!</b><br />\r\n宛先→hegomawashi@bouncy.jp<br /><br />\r\n<b>■Twitter</b><br />\r\nhttps://twitter.com/hegomawashi<br />\r\n番組ハッシュタグ #へごまわし",
|
114
|
+
# "tags"=>"一般(その他) 大橋彩香 へごまわし バラエティ 大橋彩香のへごまわし! 声優 小澤亜李 一般",
|
115
|
+
# "contentId"=>"lv294290727",
|
116
|
+
# "title"=>"【ゲスト:小澤亜李】大橋彩香の へごまわし! 第4回",
|
117
|
+
# "thumbnailUrl"=>"http://nicolive.cdn.nimg.jp/live/simg/img/a382/1145962.999d5e.jpg"},
|
118
|
+
# {"startTime"=>"2017-04-02T19:00:00+09:00",
|
119
|
+
# "description"=>
|
120
|
+
# "<b>名古屋の魅力を発信する『project758』</b> <br /> \r\n<br /> \r\n今回の放送は羽二重 きよめ役小澤亜李さんをゲストにお招きします。\r\n<br />\r\nお楽しみに!\r\n<br /> \r\n<br /> \r\nTwitterアカウント<br /> \r\nhttp://twitter.com/prj758<br /> \r\n<br /> \r\nWebサイト<br /> \r\nhttp://p758.jp<br /> \r\n<br /></b></b>",
|
121
|
+
# "tags"=>"Project758 小澤亜李 一般(その他) 一般",
|
122
|
+
# "contentId"=>"lv294246759",
|
123
|
+
# "title"=>"【ゲスト:小澤亜李】project758 おめでとうSP",
|
124
|
+
# "thumbnailUrl"=>"http://nicolive.cdn.nimg.jp/live/simg/img/a382/1145794.92f99a.jpg"}]}
|
125
|
+
```
|
126
|
+
|
127
|
+
## Contributing
|
128
|
+
|
129
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/itkq/nico_search.
|
130
|
+
|
131
|
+
|
132
|
+
## License
|
133
|
+
|
134
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
135
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'cgi'
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module NicoSearch
|
7
|
+
class Client
|
8
|
+
ENDPOINT = "http://api.search.nicovideo.jp/api/v2/%s/contents/search".freeze
|
9
|
+
SERVICES = %w(video live illust manga book channel channelarticle news).freeze
|
10
|
+
|
11
|
+
class UnavailableServiceError < StandardError; end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def search(service, params = {})
|
15
|
+
check_available_service(service)
|
16
|
+
url = ENDPOINT % service
|
17
|
+
get_json(url, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def get_json(url, params)
|
23
|
+
uri = URI.parse(url)
|
24
|
+
resp = Net::HTTP.start(uri.host, uri.port) do |http|
|
25
|
+
http.open_timeout = 5
|
26
|
+
http.read_timeout = 10
|
27
|
+
http.get(uri.request_uri + query_string(params))
|
28
|
+
end
|
29
|
+
|
30
|
+
resp.value # raise if status code is not 2xx
|
31
|
+
|
32
|
+
json = resp.body
|
33
|
+
JSON.parse(json)
|
34
|
+
end
|
35
|
+
|
36
|
+
def query_string(params)
|
37
|
+
return '' if params.empty?
|
38
|
+
|
39
|
+
'?' + params.map{|k,v|
|
40
|
+
if k == :filters
|
41
|
+
filter_string(v)
|
42
|
+
else
|
43
|
+
"#{k}=#{CGI::escape([v].flatten.join(','))}"
|
44
|
+
end
|
45
|
+
}.join('&')
|
46
|
+
end
|
47
|
+
|
48
|
+
def filter_string(filters)
|
49
|
+
filters.map{|k,v|
|
50
|
+
if v.is_a?(Hash)
|
51
|
+
v.map{|kk,vv|
|
52
|
+
"[#{k}][#{kk}]=#{CGI::escape(vv.to_s)}"
|
53
|
+
}
|
54
|
+
elsif v.is_a?(Array)
|
55
|
+
v.map{|vv|
|
56
|
+
"[#{k}][]=#{CGI::escape(vv.to_s)}"
|
57
|
+
}
|
58
|
+
else
|
59
|
+
"[#{k}][]=#{CGI::escape(v.to_s)}"
|
60
|
+
end
|
61
|
+
}.flatten.map{|s| 'filters' + s}.join('&')
|
62
|
+
end
|
63
|
+
|
64
|
+
def check_available_service(service)
|
65
|
+
unless SERVICES.include?(service)
|
66
|
+
raise UnavailableServiceError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/nico_search.rb
ADDED
data/nico_search.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nico_search/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nico_search"
|
8
|
+
spec.version = NicoSearch::VERSION
|
9
|
+
spec.authors = ["itkq"]
|
10
|
+
spec.email = ["kuogsi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby interface for Niconico search API"
|
13
|
+
spec.description = "Ruby interface for Niconico search API"
|
14
|
+
spec.homepage = "https://github.com/itkq/nico_search"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_runtime_dependency "thor"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nico_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- itkq
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Ruby interface for Niconico search API
|
70
|
+
email:
|
71
|
+
- kuogsi@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/nico_search.rb
|
84
|
+
- lib/nico_search/client.rb
|
85
|
+
- lib/nico_search/version.rb
|
86
|
+
- nico_search.gemspec
|
87
|
+
homepage: https://github.com/itkq/nico_search
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.5.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Ruby interface for Niconico search API
|
111
|
+
test_files: []
|