nico_util 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 9a4d9ec0e1077cf48fb35c88da752f5fd87160e6
4
- data.tar.gz: 1cb82c774e49de56cf11dba57f6d9de6ded01ac0
3
+ metadata.gz: 2e50a482b74234d9f4cacdfd40c848c5cfce9c29
4
+ data.tar.gz: d01e06e23740203a4052d6410f937f910985c68c
5
5
  SHA512:
6
- metadata.gz: 95f6dd28c0b30be41493abedede888195af6b482374b9bab87b951180ccb80894f746d0c2adcd888e2d401ce10ee6d7c1fad635b4b5cd50c97e4f65fc5aba522
7
- data.tar.gz: 28dcf6b59eb9260199dab9a15888011e266203c4695c609418750df2915c2776d9aae7cd7c6fb6d2c8738aadb55e40889fd49336a0bfea1ad991d2b7e8e4f6ea
6
+ metadata.gz: 655712a772adfc6893b76248c9ad03111f1594a2073e16562b08bb256e45569d8ac716d614349ba0b3ad73549282ead6027959507d74e94c0167a535936148d8
7
+ data.tar.gz: 6803372ab757570237cf705a7f82f67fc2f71d8d191b06d75b54c0b3fb3fd3425f9dae5b3546ac111bd2989eeb31de327fd25cdecd2a1e53223ad0f3572b2e13
data/README.md CHANGED
@@ -4,6 +4,7 @@ Utility API for niconico (<http://www.nicovideo.jp>)
4
4
 
5
5
  ## Features
6
6
 
7
+ * Use official search API easily
7
8
  * Sign in to niconico
8
9
  * Get comments of video
9
10
  * Get comments of live
@@ -31,6 +32,13 @@ $ gem install nico_util
31
32
  ```ruby
32
33
  require 'nico_util'
33
34
 
35
+ # Official Search API
36
+ # See <http://search.nicovideo.jp/docs/api/search.html> for parameters.
37
+ p NicoUtil::Video.search 'ボカロ'
38
+ p NicoUtil::Illust.search '東方', 'filters[viewCounter][gte]': 10000, _limit: 3
39
+ p NicoUtil::Live.search 'ゲーム'
40
+
41
+
34
42
  # write your account of niconico
35
43
  email = 'niconico@example.com'
36
44
  pass = 'password'
@@ -1,8 +1,10 @@
1
1
  require 'json'
2
2
 
3
- class NicoUtil::Niconico
4
- def illust illust_id
5
- Illust.new self, illust_id
3
+ module NicoUtil
4
+ class Niconico
5
+ def illust illust_id
6
+ Illust.new self, illust_id
7
+ end
6
8
  end
7
9
 
8
10
  class Illust
@@ -15,6 +17,14 @@ class NicoUtil::Niconico
15
17
  end
16
18
  end
17
19
 
20
+ def url
21
+ "http://seiga.nicovideo.jp/seiga/im#{@id}"
22
+ end
23
+
24
+ def self.search query, params={}
25
+ Service.search 'illust', query, params
26
+ end
27
+
18
28
  def comments
19
29
  return @comments if @comments
20
30
 
@@ -1,6 +1,8 @@
1
- class NicoUtil::Niconico
2
- def live live_id
3
- Live.new self, live_id
1
+ module NicoUtil
2
+ class Niconico
3
+ def live live_id
4
+ Live.new self, live_id
5
+ end
4
6
  end
5
7
 
6
8
  class Live
@@ -10,6 +12,14 @@ class NicoUtil::Niconico
10
12
  playerstatus
11
13
  end
12
14
 
15
+ def url
16
+ "http://live.nicovideo.jp/watch/#{@id}"
17
+ end
18
+
19
+ def self.search query, params={}
20
+ Service.search 'live', query, params
21
+ end
22
+
13
23
  def playerstatus
14
24
  return @playerstatus if @playerstatus
15
25
 
@@ -0,0 +1,22 @@
1
+ module NicoUtil
2
+ class Service
3
+ def self.search service, query, params={}
4
+ params[:q] = query
5
+ params[:targets] = 'title,description,tags' unless params.key? :targets
6
+ params[:fields] = 'contentId,title,description,tags' unless params.key? :fields
7
+ params[:_sort] = '-viewCounter' unless params.key? :_sort
8
+ params[:_context] = 'aniguide' unless params.key? :_context
9
+ params = URI.encode_www_form(params)
10
+
11
+ host = 'api.search.nicovideo.jp'
12
+ path = "/api/v2/#{service}/contents/search?#{params}"
13
+
14
+ response = Net::HTTP.new(host).start do |http|
15
+ request = Net::HTTP::Get.new(path)
16
+ http.request(request)
17
+ end
18
+
19
+ JSON.parse response.body, symbolize_names: true
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module NicoUtil
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,15 +1,25 @@
1
- class NicoUtil::Niconico
2
- def video video_id
3
- Video.new self, video_id
1
+ module NicoUtil
2
+ class Niconico
3
+ def video video_id
4
+ Video.new self, video_id
5
+ end
4
6
  end
5
7
 
6
- class Video
8
+ class Video < Service
7
9
  def initialize owner, video_id
8
10
  @owner = owner
9
11
  @id = video_id
10
12
  flv_info
11
13
  end
12
14
 
15
+ def url
16
+ "http://www.nicovideo.jp/watch/#{@id}"
17
+ end
18
+
19
+ def self.search query, params={}
20
+ Service.search 'video', query, params
21
+ end
22
+
13
23
  def flv_info
14
24
  return @flv_info if @flv_info
15
25
 
data/lib/nico_util.rb CHANGED
@@ -63,7 +63,8 @@ module NicoUtil
63
63
  end
64
64
  end
65
65
 
66
- require_relative 'video.rb'
67
- require_relative 'live.rb'
68
- require_relative 'illust.rb'
66
+ require_relative 'nico_util/service.rb'
67
+ require_relative 'nico_util/video.rb'
68
+ require_relative 'nico_util/live.rb'
69
+ require_relative 'nico_util/illust.rb'
69
70
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nico_util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Tanaka (tattn)
@@ -68,11 +68,12 @@ files:
68
68
  - Rakefile
69
69
  - bin/console
70
70
  - bin/setup
71
- - lib/illust.rb
72
- - lib/live.rb
73
71
  - lib/nico_util.rb
72
+ - lib/nico_util/illust.rb
73
+ - lib/nico_util/live.rb
74
+ - lib/nico_util/service.rb
74
75
  - lib/nico_util/version.rb
75
- - lib/video.rb
76
+ - lib/nico_util/video.rb
76
77
  - nico_util.gemspec
77
78
  homepage: https://github.com/tattn/nico_util
78
79
  licenses: