Sha256: c40ed6d910ef334f9dd78352e4573c89447397eea79c865ee907d7799b02e923

Contents?: true

Size: 925 Bytes

Versions: 30

Compression:

Stored size: 925 Bytes

Contents

# -*- coding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#

require "open-uri"
require "yaml"

module Narou
  #
  # 小説家になろうデベロッパーAPI操作クラス
  #
  class API
    def initialize(setting, of = "")
      @setting = setting
      @api_url = @setting["narou_api_url"]
      @ncode = @setting["ncode"]
      request_api(of)
    end

    def [](key)
      @api_result[key]
    end

    def request_api(of)
      url = "#{@api_url}?ncode=#{@ncode}&of=#{of}"
      open(url) do |fp|
        result = YAML.load(fp.read)
        if result[0]["allcount"] == 1
          @api_result = result[1]
          if of.length > 0
            @api_result["novel_type"] = @api_result["noveltype"]
          end
        else
          error "なろうAPIから情報が取得出来ませんでした"
          exit 1
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
narou-1.4.3 lib/narou/api.rb
narou-1.4.2.rc2 lib/narou/api.rb
narou-1.4.2.rc1 lib/narou/api.rb
narou-1.4.1.1 lib/narou/api.rb
narou-1.4.1 lib/narou/api.rb
narou-1.4.0 lib/narou/api.rb
narou-1.3.5.1 lib/narou/api.rb
narou-1.3.5 lib/narou/api.rb
narou-1.3.4 lib/narou/api.rb
narou-1.3.3 lib/narou/api.rb
narou-1.3.2 lib/narou/api.rb
narou-1.3.1 lib/narou/api.rb
narou-1.3.0.1 lib/narou/api.rb
narou-1.3.0 lib/narou/api.rb
narou-1.2.9 lib/narou/api.rb
narou-1.2.9.rc1 lib/narou/api.rb
narou-1.2.8 lib/narou/api.rb
narou-1.2.7 lib/narou/api.rb
narou-1.2.6 lib/narou/api.rb
narou-1.2.5.1 lib/narou/api.rb