Class: Botcore::Sakenote

Inherits:
Object
  • Object
show all
Defined in:
lib/botcore/sakenote_api.rb

Instance Method Summary collapse

Constructor Details

#initializeSakenote

Returns a new instance of Sakenote.



10
11
12
13
14
15
16
17
18
# File 'lib/botcore/sakenote_api.rb', line 10

def initialize
  File.open('config.txt') do |f|
    f.each_line do |txt|
      if txt =~ /sakenote_apitoken:(.+)/
        @apitoken = $1
      end
    end
  end
end

Instance Method Details

#invest_maker(place) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/botcore/sakenote_api.rb', line 24

def invest_maker(place)
  sake_list = Hash.new
  if place =~ /(.+)(都|道|府|県)/
    place = $1
  end
  tf = Botcore::SakenoteApi::Todofuken.new
  prefecture_code = tf.get_fukennum(place)
  url_text = 'https://www.sakenote.com/api/v1/sakes'
  uri = URI.parse(url_text)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  options = {
    token:            @apitoken,
    prefecture_code:  prefecture_code,
    page:             0,
  }.select{ |k, v| !v.nil? }
  begin
    options[:page] += 1
    req = Net::HTTP::Get.new(uri.request_uri, initheader = { 'Content-Type' => 'application/json' })
    req.body = options.to_json
    res = http.request(req)
    body = JSON.parse(res.body)
    sakes = body["sakes"]
    sakes.each do |s|
      sake_list[s["sake_name"]] = s["maker_name"]
    end
    puts options[:page]
  end while options[:page] < body["num_pages"]
  sake_list
end

#loaded_apitoken?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/botcore/sakenote_api.rb', line 20

def loaded_apitoken?
  @apitoken ? true : false
end