Class: LogsTF::Upload
- Inherits:
-
Object
- Object
- LogsTF::Upload
- Defined in:
- lib/logs_tf/upload.rb
Defined Under Namespace
Classes: Error, GuruMeditationError, InvalidAPIKeyError, InvalidLogError, LogIsEmptyError, MissingAPIKeyOrLoginError, MissingLogError, NoValidRoundsError, NotAuthenticatedError, NotEnoughPlayersError, ParsingFailedError, RequestError, UnknownLogsTfError
Instance Attribute Summary collapse
-
#api_key ⇒ Object
writeonly
Sets the attribute api_key.
-
#log ⇒ Object
Returns the value of attribute log.
-
#logs_tf_url ⇒ Object
Returns the value of attribute logs_tf_url.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_body ⇒ Object
writeonly
Sets the attribute response_body.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(log, logs_tf_url = 'http://logs.tf') ⇒ Upload
constructor
A new instance of Upload.
- #raise_logs_tf_error ⇒ Object
- #send ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(log, logs_tf_url = 'http://logs.tf') ⇒ Upload
Returns a new instance of Upload.
10 11 12 13 |
# File 'lib/logs_tf/upload.rb', line 10 def initialize(log, logs_tf_url = 'http://logs.tf') @log = log @logs_tf_url = logs_tf_url end |
Instance Attribute Details
#api_key=(value) ⇒ Object
Sets the attribute api_key
8 9 10 |
# File 'lib/logs_tf/upload.rb', line 8 def api_key=(value) @api_key = value end |
#log ⇒ Object
Returns the value of attribute log.
8 9 10 |
# File 'lib/logs_tf/upload.rb', line 8 def log @log end |
#logs_tf_url ⇒ Object
Returns the value of attribute logs_tf_url.
8 9 10 |
# File 'lib/logs_tf/upload.rb', line 8 def logs_tf_url @logs_tf_url end |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/logs_tf/upload.rb', line 8 def response @response end |
#response_body=(value) ⇒ Object
Sets the attribute response_body
8 9 10 |
# File 'lib/logs_tf/upload.rb', line 8 def response_body=(value) @response_body = value end |
Instance Method Details
#error ⇒ Object
59 60 61 |
# File 'lib/logs_tf/upload.rb', line 59 def error response_body["error"] end |
#raise_logs_tf_error ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/logs_tf/upload.rb', line 30 def raise_logs_tf_error error_class = case error when "Invalid log file" InvalidLogError when "No file" MissingLogError when "Not authenticated" NotAuthenticatedError when "Invalid API key" InvalidAPIKeyError when "Log has no valid rounds (at least one needed)" NoValidRoundsError when "Not enough players (2 needed)" NotEnoughPlayersError when "Log is empty" LogIsEmptyError when /^Parsing failed in line \d+$/ ParsingFailedError when "Missing API key or login" MissingAPIKeyOrLoginError when "Guru Meditation" GuruMeditationError else UnknownLogsTfError end raise error_class, response_body["error"] end |
#send ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/logs_tf/upload.rb', line 15 def send @response = connection.post('/upload', ) if request_success? if !upload_success? raise_logs_tf_error end else raise RequestError, response.body end end |
#url ⇒ Object
26 27 28 |
# File 'lib/logs_tf/upload.rb', line 26 def url logs_tf_url + response_body["url"] end |