Class: Civility::GMR
- Inherits:
-
Object
- Object
- Civility::GMR
- Defined in:
- lib/civility/gmr.rb
Constant Summary collapse
- API_BASE =
'http://multiplayerrobot.com/api/Diplomacy'
Class Method Summary collapse
Instance Method Summary collapse
- #download(game_id) ⇒ Object
- #games ⇒ Object
-
#initialize(auth_key, user_id = nil) ⇒ GMR
constructor
A new instance of GMR.
- #upload(turn_id, save_file) ⇒ Object
- #user(user_id = nil) ⇒ Object
Constructor Details
#initialize(auth_key, user_id = nil) ⇒ GMR
Returns a new instance of GMR.
9 10 11 12 |
# File 'lib/civility/gmr.rb', line 9 def initialize(auth_key, user_id = nil) @auth_key = auth_key @user_id = user_id end |
Class Method Details
.auth_url ⇒ Object
14 15 16 |
# File 'lib/civility/gmr.rb', line 14 def self.auth_url 'http://multiplayerrobot.com/download' end |
Instance Method Details
#download(game_id) ⇒ Object
33 34 35 36 37 |
# File 'lib/civility/gmr.rb', line 33 def download(game_id) code, response = get('GetLatestSaveFileBytes', gameId: game_id) fail "Unable to download file #{response}" if code != 200 response end |
#games ⇒ Object
26 27 28 29 30 31 |
# File 'lib/civility/gmr.rb', line 26 def games code, response = get('GetGamesAndPlayers', playerIDText: current_user_id) fail "Unable to get games #{response}" if code != 200 data = JSON.parse(response) data['Games'] end |
#upload(turn_id, save_file) ⇒ Object
39 40 41 42 43 |
# File 'lib/civility/gmr.rb', line 39 def upload(turn_id, save_file) code, response = post('SubmitTurn', save_file, turnId: turn_id) fail "Unable to upload file #{response}" if code != 200 JSON.parse(response) end |
#user(user_id = nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/civility/gmr.rb', line 18 def user(user_id = nil) user_id = current_user_id if user_id.nil? code, response = get('GetGamesAndPlayers', playerIDText: user_id) fail "Unable to get user #{response}" if code != 200 data = JSON.parse(response) data['Players'].find { |player| player['SteamID'].to_i == user_id.to_i } end |