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 +4 -4
 - data/README.md +8 -0
 - data/lib/{illust.rb → nico_util/illust.rb} +13 -3
 - data/lib/{live.rb → nico_util/live.rb} +13 -3
 - data/lib/nico_util/service.rb +22 -0
 - data/lib/nico_util/version.rb +1 -1
 - data/lib/{video.rb → nico_util/video.rb} +14 -4
 - data/lib/nico_util.rb +4 -3
 - metadata +5 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2e50a482b74234d9f4cacdfd40c848c5cfce9c29
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d01e06e23740203a4052d6410f937f910985c68c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 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
         
     | 
    
        data/lib/nico_util/version.rb
    CHANGED
    
    
| 
         @@ -1,15 +1,25 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 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 ' 
     | 
| 
       67 
     | 
    
         
            -
            require_relative ' 
     | 
| 
       68 
     | 
    
         
            -
            require_relative ' 
     | 
| 
      
 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. 
     | 
| 
      
 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:
         
     |