webtrekk_connector 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/webtrekk_connector.rb +97 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5b819a855afac8ba9abefaccf438506ed01fde548121ac78a7315d70d7559e3b
|
4
|
+
data.tar.gz: 59c47922b57c4530b20c40b0e7456926c27df94b6b9e7118e63863f8ff83ed9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95008b5939109ca8f7697f168757bcec605472acf2ea166f2b31dcebb371835c3fc03313b712f8ae0d18d385e73f9dbf0a83063f32e52f1880db9c4430ec5dbf
|
7
|
+
data.tar.gz: '082831f7230ec827ecb5ef97716f05631181a7f1a8687150fd362b184a03daa0f220cff04abe4acb7ef2b66691a199901ea2995c86ded8af098385c95e3922e3'
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'openssl'
|
3
|
+
require 'logger'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class WebtrekkConnector
|
7
|
+
def initialize(conf)
|
8
|
+
@endpoint = conf[:endpoint]
|
9
|
+
@user = conf[:user]
|
10
|
+
@pwd = conf[:pwd]
|
11
|
+
@customerId = conf[:customerId]
|
12
|
+
@logger = conf[:logger] ? conf[:logger] : Logger.new(STDERR)
|
13
|
+
@logger.info("Connector set up for #{@endpoint}.")
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_https_request(uri, payload=nil)
|
17
|
+
@logger.info("sending request (method #{payload[:method]}) ...")
|
18
|
+
Net::HTTP.start(uri.host, uri.port,
|
19
|
+
:use_ssl => uri.scheme == 'https',
|
20
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
21
|
+
|
22
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
23
|
+
request.body = payload.to_json
|
24
|
+
|
25
|
+
response = http.request(request)
|
26
|
+
|
27
|
+
if response.code.eql?("200")
|
28
|
+
return response.body
|
29
|
+
else
|
30
|
+
raise Net::HTTPError.new(response.code, response.message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def call_method(method, params={})
|
36
|
+
@logger.info("call_method: #{method}")
|
37
|
+
payload = {
|
38
|
+
:params => params ,
|
39
|
+
:version => "1.1" ,
|
40
|
+
:method => method
|
41
|
+
}
|
42
|
+
response = make_https_request(URI(@endpoint), payload)
|
43
|
+
data = JSON.parse(response)
|
44
|
+
data['result']
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_connection_test
|
48
|
+
response = call_method('getConnectionTest')
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_token
|
52
|
+
unless @customerId
|
53
|
+
@customerId = self.get_first_account['customerId']
|
54
|
+
end
|
55
|
+
params = {
|
56
|
+
:login => @user,
|
57
|
+
:pass => @pwd ,
|
58
|
+
:customerId => @customerId ,
|
59
|
+
:language => "en"
|
60
|
+
}
|
61
|
+
response = call_method('login', params)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def login
|
66
|
+
@token = get_token
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_account_list
|
70
|
+
params = {
|
71
|
+
:login => @user,
|
72
|
+
:pass => @pwd ,
|
73
|
+
}
|
74
|
+
response = call_method('getAccountList', params)
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_first_account
|
78
|
+
account_list = get_account_list
|
79
|
+
account_list.first
|
80
|
+
end
|
81
|
+
|
82
|
+
def request_analysis(analysis_config)
|
83
|
+
params = {
|
84
|
+
:token => @token ,
|
85
|
+
:analysisConfig => analysis_config
|
86
|
+
}
|
87
|
+
response = call_method("getAnalysisData", params)
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_analysis_objects_and_metrics_list
|
91
|
+
params = {
|
92
|
+
:token => @token
|
93
|
+
}
|
94
|
+
response = call_method("getAnalysisObjectsAndMetricsList", params)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webtrekk_connector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Knud Möller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple Ruby wrapper around the Webtrekk/Mapp Analytics API
|
14
|
+
email: knud.moeller@berlinonline.de
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/webtrekk_connector.rb
|
20
|
+
homepage: https://rubygems.org/gems/webtrekk_connector
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.0.0
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Webtrekk Connector
|
43
|
+
test_files: []
|