Class: Civility
- Inherits:
-
Thor
- Object
- Thor
- Civility
- Defined in:
- lib/civility.rb,
lib/civility/gmr.rb
Defined Under Namespace
Classes: GMR
Constant Summary collapse
- VERSION =
'3'- SAVE_DIRECTORY =
"/Documents/Aspyr/Sid\ Meier\'s\ Civilization\ 5/Saves/hotseat/"- FILE_PREFIX =
'civility'- FILE_EXT =
'Civ5Save'- CONFIG_FILE =
'.civility.yml'
Instance Method Summary collapse
- #auth(auth_key = nil) ⇒ Object
- #complete(*name) ⇒ Object
- #games ⇒ Object
-
#initialize(*args) ⇒ Civility
constructor
A new instance of Civility.
- #play(*name) ⇒ Object
Constructor Details
Instance Method Details
#auth(auth_key = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/civility.rb', line 21 def auth(auth_key = nil) if auth_key.nil? auth_url = Civility::GMR.auth_url puts "Grab your Authentication Key from #{auth_url}" system('open', auth_url) else @gmr = Civility::GMR.new(auth_key) @config[:version] = VERSION @config[:auth] = auth_key @config[:user] = user self.config = @config puts "Hello, #{user['PersonaName']}, your auth is all configured!" end end |
#complete(*name) ⇒ Object
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 56 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 = save_path(game) response = @gmr.upload(game['CurrentTurn']['TurnId'], File.read(path)) 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
37 38 39 40 |
# File 'lib/civility.rb', line 37 def games return missing_auth_error unless auth_key output_games sync_games end |
#play(*name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# 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 = save_path(game) data = @gmr.download(game['GameId']) save_file(path, data) puts "Saved #{game['Name']} to #{path}" sync_games end |