Class: GoshrineBot::GoshrineRequest
- Inherits:
-
Object
- Object
- GoshrineBot::GoshrineRequest
- Defined in:
- lib/goshrine_bot/goshrine_request.rb
Class Method Summary collapse
Instance Method Summary collapse
- #do_http(verb, options) ⇒ Object
- #get(options = {}) ⇒ Object
-
#initialize(path) ⇒ GoshrineRequest
constructor
A new instance of GoshrineRequest.
- #post(options = {}) ⇒ Object
Constructor Details
#initialize(path) ⇒ GoshrineRequest
Returns a new instance of GoshrineRequest.
9 10 11 12 13 |
# File 'lib/goshrine_bot/goshrine_request.rb', line 9 def initialize(path) @url = "#{@@base_url}#{path}" @conn = EventMachine::HttpRequest.new(@url) @cookie_persist = CookiePersist.new end |
Class Method Details
.base_url=(url) ⇒ Object
5 6 7 |
# File 'lib/goshrine_bot/goshrine_request.rb', line 5 def self.base_url=(url) @@base_url = url end |
Instance Method Details
#do_http(verb, options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/goshrine_bot/goshrine_request.rb', line 15 def do_http(verb,) [:head] = {'Accept' => 'application/json', 'cookie' => @cookie_persist..} http = @conn.send verb, defer = EM::DefaultDeferrable.new http.callback { @cookie_persist. << http.response_header[EM::HttpClient::SET_COOKIE] defer.succeed(http) } http.errback { puts "failed goshrine request" defer.fail(http) } defer end |
#get(options = {}) ⇒ Object
38 39 40 |
# File 'lib/goshrine_bot/goshrine_request.rb', line 38 def get( = {}) do_http(:get, ) end |
#post(options = {}) ⇒ Object
34 35 36 |
# File 'lib/goshrine_bot/goshrine_request.rb', line 34 def post( = {}) do_http(:post, ) end |