Class: GymFinder::Client::Conn
- Inherits:
-
Object
- Object
- GymFinder::Client::Conn
- Defined in:
- lib/gym_finder/client.rb
Instance Attribute Summary collapse
-
#cookie ⇒ Object
Returns the value of attribute cookie.
Instance Method Summary collapse
- #done(&block) ⇒ Object
- #get(**params, &block) ⇒ Object
-
#initialize ⇒ Conn
constructor
A new instance of Conn.
- #post(**params, &block) ⇒ Object
- #request(method, **params) ⇒ Object
Constructor Details
#initialize ⇒ Conn
Returns a new instance of Conn.
19 20 21 22 23 |
# 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 |
Instance Attribute Details
#cookie ⇒ Object
Returns the value of attribute cookie.
18 19 20 |
# File 'lib/gym_finder/client.rb', line 18 def @cookie end |
Instance Method Details
#done(&block) ⇒ Object
44 45 46 |
# File 'lib/gym_finder/client.rb', line 44 def done(&block) @done = block end |
#get(**params, &block) ⇒ Object
40 41 42 |
# File 'lib/gym_finder/client.rb', line 40 def get(**params, &block) request(:get, **params, &block) end |
#post(**params, &block) ⇒ Object
36 37 38 |
# File 'lib/gym_finder/client.rb', line 36 def post(**params, &block) request(:post, **params, &block) end |
#request(method, **params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# 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 |