uniq_logger 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/uniq_logger.rb +3 -0
- data/lib/uniq_logger/base.rb +12 -2
- data/lib/uniq_logger/configuration.rb +5 -1
- data/lib/uniq_logger/version.rb +1 -1
- data/spec/lib/uniq_logger_spec.rb +8 -0
- data/template/uniq_logger.yml +3 -0
- data/uniq_logger.gemspec +1 -0
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/uniq_logger.rb
CHANGED
data/lib/uniq_logger/base.rb
CHANGED
@@ -83,10 +83,20 @@ module UniqLogger
|
|
83
83
|
endpoint = config[:remote][:endpoint]
|
84
84
|
param_id = config[:remote][:url_param_for_id]
|
85
85
|
param_data = config[:remote][:url_param_for_data]
|
86
|
-
|
87
|
-
|
86
|
+
|
87
|
+
uri = URI.parse("#{server_name}#{endpoint}?auth_token=#{auth_token}")
|
88
|
+
puts "URI: #{uri.inspect}"
|
89
|
+
|
90
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
88
91
|
request = Net::HTTP::Post.new(uri.request_uri)
|
92
|
+
|
93
|
+
if !config[:remote][:basic_auth][:username].nil? && !config[:remote][:basic_auth][:password].nil? && !config[:remote][:basic_auth][:username].empty? && !config[:remote][:basic_auth][:password].empty?
|
94
|
+
request.basic_auth config[:remote][:basic_auth][:username], config[:remote][:basic_auth][:password]
|
95
|
+
end
|
96
|
+
|
97
|
+
request.body = { param_id.to_sym => uniq_id, param_data.to_sym => data_to_save }.to_s
|
89
98
|
response = http.request(request)
|
99
|
+
|
90
100
|
json = JSON.parse response.body
|
91
101
|
if json['response'] == "true"
|
92
102
|
return true
|
@@ -13,7 +13,11 @@ module UniqLogger
|
|
13
13
|
:server => "http://www.server.de",
|
14
14
|
:endpoint => "/api/v1/logger",
|
15
15
|
:url_param_for_id => "id",
|
16
|
-
:url_param_for_data => "data"
|
16
|
+
:url_param_for_data => "data",
|
17
|
+
:basic_auth => {
|
18
|
+
:username => "",
|
19
|
+
:password => ""
|
20
|
+
}
|
17
21
|
},
|
18
22
|
:csv => {
|
19
23
|
:encoding => "UTF8",
|
data/lib/uniq_logger/version.rb
CHANGED
@@ -60,5 +60,13 @@ describe UniqLogger::Base do
|
|
60
60
|
expect(@logger.create("12346", ["Vorname3", "Nachname3", "Strasse3"])).to eq(true)
|
61
61
|
end
|
62
62
|
|
63
|
+
it 'sould send data to remote api' do
|
64
|
+
@logger.config[:logfile_destination] = "remote"
|
65
|
+
@logger.config[:remote][:auth_token] = "QviQAtx1mq1ZCWC12RUy"
|
66
|
+
@logger.config[:remote][:server] = "http://localhost:3000"
|
67
|
+
@logger.config[:remote][:endpoint] = "/crm/api/v1/loggers.json"
|
68
|
+
expect(@logger.create("1111", ["Remote", "Server", "Strasse3"])).to eq(true)
|
69
|
+
end
|
70
|
+
|
63
71
|
|
64
72
|
end
|
data/template/uniq_logger.yml
CHANGED
data/uniq_logger.gemspec
CHANGED