Class: Fab::Library

Inherits:
Book show all
Defined in:
lib/fab.rb

Constant Summary collapse

NONE_APIKEY_TEMPLATE =
<<-EOS
not set apikey
fab registration -apikey,-a [APIKEY]
EOS

Constants inherited from Book

Book::SLEEP_TIME

Constants inherited from Output

Output::LINE_BREAK_TEMPLATE, Output::LINE_TEMPLATE

Instance Method Summary collapse

Methods inherited from Book

#book_get_params, #book_set_param

Methods inherited from Output

#echo_book

Constructor Details

#initializeLibrary

Returns a new instance of Library.



96
97
98
# File 'lib/fab.rb', line 96

def initialize()
  @library_send_param = "http://api.calil.jp/library?"
end

Instance Method Details

#library_get_paramsObject



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fab.rb', line 115

def library_get_params()
  encode_uri = URI.encode(@library_send_param)
  get_xml = open(encode_uri).read
  convert_json = Hash.from_xml(get_xml).to_json
  result = JSON.load(convert_json)
  @libraries = Hash.new { | h , k | h[k] = {} }
  count_id(result)
  for i in 0..@id_count
    @libraries[i]["systemid"] =  result["Libraries"]["Library"][i]["systemid"]
    @libraries[i]["formal"] = result["Libraries"]["Library"][i]["formal"]
  end
end

#library_set_param(pref, city) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/fab.rb', line 104

def library_set_param(pref,city)
  begin
    @library_send_param << "appkey=#{Fab::Apikey::APIKEY}"
  rescue
    puts NONE_APIKEY_TEMPLATE
    exit
  end
    @library_send_param << "&pref=#{pref}"
    @library_send_param << "&city=#{city}"
end