class GymFinder::Client::Conn

Attributes

Public Class Methods

new() click to toggle source
# File lib/gym_finder/client.rb, line 19
def initialize
  @conn = EventMachine::HttpRequest.new('https://scr.cyc.org.tw/', tls: { verify_peer: true })
  @pending = 0
  @processed = 0
end

Public Instance Methods

done(&block) click to toggle source
# File lib/gym_finder/client.rb, line 44
def done(&block)
  @done = block
end
get(**params, &block) click to toggle source
# File lib/gym_finder/client.rb, line 40
def get(**params, &block)
  request(:get, **params, &block)
end
post(**params, &block) click to toggle source
# File lib/gym_finder/client.rb, line 36
def post(**params, &block)
  request(:post, **params, &block)
end
request(method, **params) { |client| ... } click to toggle source
# File lib/gym_finder/client.rb, line 25
def request(method, **params)
  client = @conn.send(method, keepalive: true, head: { 'cookie' => @cookie }, **params)
  @pending += 1
  client.callback do
    @processed += 1
    yield client
    print "\t#{(@processed.to_f / @pending * 100).round}%\r" if STDOUT.tty?
    @done.call if @pending == @processed && @done
  end
end