Class: Civility
- Inherits:
-
Thor
- Object
- Thor
- Civility
- Defined in:
- lib/civility.rb
Constant Summary collapse
- VERSION =
'2'- SAVE_DIRECTORY =
"/Documents/Aspyr/Sid\ Meier\'s\ Civilization\ 5/Saves/hotseat/"- FILE_PREFIX =
'civility'- FILE_EXT =
'Civ5Save'- API =
'http://multiplayerrobot.com/api/Diplomacy/'- CONFIG_FILE =
'.civility.yml'
Instance Method Summary collapse
- #auth(key = nil) ⇒ Object
- #complete(*name) ⇒ Object
- #games ⇒ Object
-
#initialize(*args) ⇒ Civility
constructor
A new instance of Civility.
- #play(*name) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Civility
Returns a new instance of Civility.
15 16 17 18 |
# File 'lib/civility.rb', line 15 def initialize(*args) @config = load_config super(*args) end |
Instance Method Details
#auth(key = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/civility.rb', line 21 def auth(key = nil) if key.nil? url = 'http://multiplayerrobot.com/download' puts "Grab your Authentication Key from #{url}" system('open', url) else @config[:version] = VERSION @config[:auth] = key @config[:user] = user self.config = @config puts "Hello, #{user['PersonaName']}, your auth is all configured!" end end |
#complete(*name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/civility.rb', line 55 def complete(*name) name = name.join(' ') return missing_auth_error unless auth_key game = game_by_name(name) return missing_game_error(name) unless game path = game_path(game) response = upload_file('SubmitTurn', {authKey: auth_key, turnId: game['CurrentTurn']['TurnId']}, path) response = JSON.parse(response) case response['ResultType'] when 0 puts "UnexpectedError: #{response}" when 1 puts "You earned #{response['PointsEarned']} points completing #{game['Name']} from #{path}" when 2 puts "It's not your turn" when 3 puts 'You already submitted your turn' else puts 'UnexpectedError' end end |
#games ⇒ Object
36 37 38 39 40 |
# File 'lib/civility.rb', line 36 def games return missing_auth_error unless auth_key games = api_games output_games(games) end |
#play(*name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/civility.rb', line 43 def play(*name) name = name.join(' ') return missing_auth_error unless auth_key game = game_by_name(name) return missing_game_error(name) unless game path = game_path(game) file('GetLatestSaveFileBytes', {authKey: auth_key, gameID: game['GameId']}, path) puts "Saved #{game['Name']} to #{path}" api_games end |