Class: AlacrityClient::Connection
- Inherits:
-
Object
- Object
- AlacrityClient::Connection
- Defined in:
- lib/alacrity_client/connection.rb
Instance Method Summary collapse
- #get_player_ranking(player) ⇒ Object
-
#get_player_ranking_async(player, callback_success, callback_err) ⇒ Object
using this method only makes sense if you are running event machine.
-
#initialize(server = "localhost", port = 8888) ⇒ Connection
constructor
A new instance of Connection.
- #update_player_ranking(player, rank, type) ⇒ Object
-
#update_player_ranking_async(player, rank, type, callback_success, callback_err) ⇒ Object
using this method only makes sense if you are running event machine.
Constructor Details
#initialize(server = "localhost", port = 8888) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 |
# File 'lib/alacrity_client/connection.rb', line 7 def initialize(server = "localhost",port = 8888) @server = server @port = port end |
Instance Method Details
#get_player_ranking(player) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/alacrity_client/connection.rb', line 12 def get_player_ranking(player) @http ||= Net::HTTP.new(@server, @port) path = "/getPlayerRanking?playerNum=#{player}" resp, data = @http.get(path, nil) return JSON(data) end |
#get_player_ranking_async(player, callback_success, callback_err) ⇒ Object
using this method only makes sense if you are running event machine
32 33 34 35 36 |
# File 'lib/alacrity_client/connection.rb', line 32 def get_player_ranking_async(player,callback_success,callback_err ) http = EventMachine::HttpRequest.new("http://#{@server}:#{@port}/getPlayerRanking").get :query => {'playerNum' => player} http.errback { callback_err.call(http)} http.callback { callback_success.call(http)} end |
#update_player_ranking(player, rank, type) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/alacrity_client/connection.rb', line 20 def update_player_ranking(player,rank,type) @http = Net::HTTP.new(@server, @port) path = '/updatePlayerRanking' data = "playerNum=#{player}&rank=#{rank}&type=#{type}" headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } resp, data = @http.post(path, data, headers) return JSON(data) end |
#update_player_ranking_async(player, rank, type, callback_success, callback_err) ⇒ Object
using this method only makes sense if you are running event machine
39 40 41 42 43 44 |
# File 'lib/alacrity_client/connection.rb', line 39 def update_player_ranking_async(player,rank,type,callback_success ,callback_err ) http = EventMachine::HttpRequest.new("http://#{@server}:#{@port}/updatePlayerRanking").post :body => {'playerNum' => player,'type' => type,'rank'=>rank} http.errback { callback_err.call(http)} http.callback { callback_success.call(http)} end |