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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uniq_logger (0.0.2)
4
+ uniq_logger (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/uniq_logger.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'csv'
2
2
  require 'yaml'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
3
6
  require "uniq_logger/configuration"
4
7
  require "uniq_logger/version"
5
8
 
@@ -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
- uri = URI.parse("#{server_name}#{endpoint}?auth_token=#{auth_token}&#{param_id}=#{uniq_id}&#{param_data}=#{data_to_save}")
87
- http = Net::HTTP.new(uri.host, 80)
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",
@@ -1,3 +1,3 @@
1
1
  module UniqLogger
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
@@ -31,6 +31,9 @@ remote:
31
31
  endpoint: "/api/v1/logger"
32
32
  url_param_for_id: "id"
33
33
  url_param_for_data: "data"
34
+ basic_auth:
35
+ username: ""
36
+ password: ""
34
37
 
35
38
  #CSV Export Settings: Encoding Type (default 'utf8'), Column Separator (default ';')
36
39
  csv:
data/uniq_logger.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "guard"
25
25
  spec.add_development_dependency 'guard-rspec'
26
+ #spec.add_development_dependency 'pry'
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uniq_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: