Class: Narou::API
- Inherits:
-
Object
- Object
- Narou::API
- Defined in:
- lib/narou/api.rb
Overview
小説家になろうデベロッパーAPI操作クラス
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(setting, of = "") ⇒ API
constructor
A new instance of API.
- #request_api(of) ⇒ Object
Constructor Details
#initialize(setting, of = "") ⇒ API
Returns a new instance of API.
14 15 16 17 18 19 |
# File 'lib/narou/api.rb', line 14 def initialize(setting, of = "") @setting = setting @api_url = @setting["narou_api_url"] @ncode = @setting["ncode"] request_api(of) end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/narou/api.rb', line 21 def [](key) @api_result[key] end |
#request_api(of) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/narou/api.rb', line 25 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 |