Class: LogsTF::Upload

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute api_key to.



8
9
10
# File 'lib/logs_tf/upload.rb', line 8

def api_key=(value)
  @api_key = value
end

#logObject

Returns the value of attribute log.



8
9
10
# File 'lib/logs_tf/upload.rb', line 8

def log
  @log
end

#logs_tf_urlObject

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

#responseObject

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

Parameters:

  • value

    the value to set the attribute response_body to.



8
9
10
# File 'lib/logs_tf/upload.rb', line 8

def response_body=(value)
  @response_body = value
end

Instance Method Details

#errorObject



59
60
61
# File 'lib/logs_tf/upload.rb', line 59

def error
  response_body["error"]
end

#raise_logs_tf_errorObject

Raises:

  • (error_class)


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

#sendObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/logs_tf/upload.rb', line 15

def send
  @response = connection.post('/upload', post_options)
  if request_success?
    if !upload_success?
      raise_logs_tf_error
    end
  else
    raise RequestError, response.body
  end
end

#urlObject



26
27
28
# File 'lib/logs_tf/upload.rb', line 26

def url
  logs_tf_url + response_body["url"]
end