logs_tf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +43 -0
- data/README.md +4 -0
- data/lib/logs_tf/log.rb +20 -0
- data/lib/logs_tf/upload.rb +104 -0
- data/lib/logs_tf/version.rb +3 -0
- data/lib/logs_tf.rb +6 -0
- data/logs_tf.gemspec +24 -0
- data/spec/fixtures/logs/broder_vs_epsilon.log +4539 -0
- data/spec/fixtures/logs/broken_log.log +1 -0
- data/spec/fixtures/vcr/upload.yml +6321 -0
- data/spec/logs_tf/upload_spec.rb +79 -0
- data/spec/spec_helper.rb +11 -0
- metadata +161 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "autotest/bundler"
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
logs_tf (0.0.0)
|
5
|
+
faraday (~> 0.8.0)
|
6
|
+
multipart-post (~> 1.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ZenTest (4.9.0)
|
12
|
+
coderay (1.0.8)
|
13
|
+
diff-lcs (1.1.3)
|
14
|
+
faraday (0.8.5)
|
15
|
+
multipart-post (~> 1.1)
|
16
|
+
method_source (0.8.1)
|
17
|
+
multipart-post (1.1.5)
|
18
|
+
pry (0.9.11.4)
|
19
|
+
coderay (~> 1.0.5)
|
20
|
+
method_source (~> 0.8)
|
21
|
+
slop (~> 3.4)
|
22
|
+
pry-nav (0.2.3)
|
23
|
+
pry (~> 0.9.10)
|
24
|
+
rspec (2.12.0)
|
25
|
+
rspec-core (~> 2.12.0)
|
26
|
+
rspec-expectations (~> 2.12.0)
|
27
|
+
rspec-mocks (~> 2.12.0)
|
28
|
+
rspec-core (2.12.2)
|
29
|
+
rspec-expectations (2.12.1)
|
30
|
+
diff-lcs (~> 1.1.3)
|
31
|
+
rspec-mocks (2.12.2)
|
32
|
+
slop (3.4.3)
|
33
|
+
vcr (2.4.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
ZenTest (~> 4.9.0)
|
40
|
+
logs_tf!
|
41
|
+
pry-nav (~> 0.2.3)
|
42
|
+
rspec (~> 2.12.0)
|
43
|
+
vcr (~> 2.4.0)
|
data/README.md
ADDED
data/lib/logs_tf/log.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module LogsTF
|
2
|
+
|
3
|
+
class Log
|
4
|
+
|
5
|
+
attr_accessor :file, :map_name, :title, :api_key
|
6
|
+
|
7
|
+
def initialize(file, map_name = "", title = "", api_key = LogsTF::API_KEY)
|
8
|
+
@file = file
|
9
|
+
@map_name = map_name
|
10
|
+
@title = title
|
11
|
+
@api_key = api_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def filename
|
15
|
+
File.basename(file)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module LogsTF
|
5
|
+
|
6
|
+
class Upload
|
7
|
+
|
8
|
+
attr_accessor :log, :logs_tf_url, :api_key, :response, :response_body
|
9
|
+
|
10
|
+
def initialize(log, logs_tf_url = 'http://logs.tf')
|
11
|
+
@log = log
|
12
|
+
@logs_tf_url = logs_tf_url
|
13
|
+
end
|
14
|
+
|
15
|
+
def send
|
16
|
+
@response = connection.post('/upload', post_options)
|
17
|
+
if request_success?
|
18
|
+
if !upload_success?
|
19
|
+
raise_logs_tf_error
|
20
|
+
end
|
21
|
+
else
|
22
|
+
raise RequestError, response.body
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
logs_tf_url + response_body["url"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def raise_logs_tf_error
|
31
|
+
error_class = case error
|
32
|
+
when "Invalid log file"
|
33
|
+
InvalidLogError
|
34
|
+
when "No file"
|
35
|
+
MissingLogError
|
36
|
+
when "Not authenticated"
|
37
|
+
NotAuthenticatedError
|
38
|
+
when "Invalid API key"
|
39
|
+
InvalidAPIKeyError
|
40
|
+
end
|
41
|
+
|
42
|
+
raise error_class, response_body["error"]
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def response_body
|
48
|
+
@response_body ||= JSON.parse(response.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def upload_success?
|
52
|
+
response_body["success"] == true
|
53
|
+
end
|
54
|
+
|
55
|
+
def request_success?
|
56
|
+
response.status == 200
|
57
|
+
end
|
58
|
+
|
59
|
+
def error
|
60
|
+
response_body["error"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def post_options
|
64
|
+
{ :key => api_key,
|
65
|
+
:title => title,
|
66
|
+
:map => map_name,
|
67
|
+
:logfile => logfile }
|
68
|
+
end
|
69
|
+
|
70
|
+
def logfile
|
71
|
+
Faraday::UploadIO.new(log.file, "text/plain", log.filename)
|
72
|
+
end
|
73
|
+
|
74
|
+
def title
|
75
|
+
log.title
|
76
|
+
end
|
77
|
+
|
78
|
+
def map_name
|
79
|
+
log.map_name
|
80
|
+
end
|
81
|
+
|
82
|
+
def api_key
|
83
|
+
log.api_key
|
84
|
+
end
|
85
|
+
|
86
|
+
def connection
|
87
|
+
Faraday.new(:url => logs_tf_url + '/upload') do |conn|
|
88
|
+
conn.request :multipart
|
89
|
+
conn.request :url_encoded
|
90
|
+
conn.adapter :net_http
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Error < StandardError; end
|
95
|
+
class RequestError < Error; end
|
96
|
+
class InvalidLogError < Error; end
|
97
|
+
class MissingLogError < Error; end
|
98
|
+
class NotAuthenticatedError < Error; end
|
99
|
+
class InvalidAPIKeyError < Error; end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|
data/lib/logs_tf.rb
ADDED
data/logs_tf.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/logs_tf/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'logs_tf'
|
6
|
+
gem.version = LogsTF::VERSION
|
7
|
+
gem.date = '2013-02-10'
|
8
|
+
gem.summary = "Logs.tf"
|
9
|
+
gem.description = "A gem to interface with the logs.tf API"
|
10
|
+
gem.authors = ["Arie"]
|
11
|
+
gem.email = 'rubygems@ariekanarie.nl'
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.homepage = 'http://github.com/Arie/logs_tf'
|
16
|
+
|
17
|
+
gem.add_dependency "faraday", "~> 0.8.0"
|
18
|
+
gem.add_dependency "multipart-post", "~> 1.1.0"
|
19
|
+
|
20
|
+
gem.add_development_dependency "vcr", "~> 2.4.0"
|
21
|
+
gem.add_development_dependency "pry-nav", "~> 0.2.3"
|
22
|
+
gem.add_development_dependency "rspec", "~> 2.12.0"
|
23
|
+
gem.add_development_dependency "ZenTest", "~> 4.9.0"
|
24
|
+
end
|