webtrekk_connector 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webtrekk_connector.rb +49 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b819a855afac8ba9abefaccf438506ed01fde548121ac78a7315d70d7559e3b
4
- data.tar.gz: 59c47922b57c4530b20c40b0e7456926c27df94b6b9e7118e63863f8ff83ed9a
3
+ metadata.gz: 0a0994104ef677b582c381c9551c5e69810722c814ef10c700d4a3f8cff90f88
4
+ data.tar.gz: 753a1052acb21d43b3c1aa9fca32fac7eeb262df06f6d630687ccfa30d97b014
5
5
  SHA512:
6
- metadata.gz: 95008b5939109ca8f7697f168757bcec605472acf2ea166f2b31dcebb371835c3fc03313b712f8ae0d18d385e73f9dbf0a83063f32e52f1880db9c4430ec5dbf
7
- data.tar.gz: '082831f7230ec827ecb5ef97716f05631181a7f1a8687150fd362b184a03daa0f220cff04abe4acb7ef2b66691a199901ea2995c86ded8af098385c95e3922e3'
6
+ metadata.gz: 95c843b3abc88691ec607b5af66db42dc0ec1c4118f10818f2e53f1d6ac0735a4c5f88f996f86a3a38dc2550ffb9fb64d83e7f13b45af721bfc46163acce2291
7
+ data.tar.gz: 06f4e36e67b93eaad35952e6e1f0218d983ad183b30c3c5582a44092657c804c111bd55fc9d6d598a75ea57e200461a5069b5586b804cb47cb3ef2910ec8abca
@@ -3,7 +3,19 @@ require 'openssl'
3
3
  require 'logger'
4
4
  require 'json'
5
5
 
6
+ # This class is a wrapper around the Webtrekk/Mapp Analytics JSON/RPC API.
7
+
6
8
  class WebtrekkConnector
9
+
10
+ # Create an instance of WebtrekkConnector.
11
+ #
12
+ # @param conf[Hash] the configuration object for the connector
13
+ # @option conf [String] :endpoint the API endpoint, e.g. +https://xyz.webtrekk.com/cgi-bin/wt/JSONRPC.cgi+ (*required*)
14
+ # @option conf [String] :user the user name to use with the API (*required*)
15
+ # @option conf [String] :pwd the password for +:user+ (*required*)
16
+ # @option conf [String] :customerId the customer Id to used for all requests (optional).
17
+ # If not set, the id of the first account retrieved via +getAccountList+ will be used.
18
+ # @option conf [Logger] :logger the logging object to use for logging output (optional, _defaults_ _to_ +Logger.new(STDERR)+)
7
19
  def initialize(conf)
8
20
  @endpoint = conf[:endpoint]
9
21
  @user = conf[:user]
@@ -13,6 +25,13 @@ class WebtrekkConnector
13
25
  @logger.info("Connector set up for #{@endpoint}.")
14
26
  end
15
27
 
28
+ # Send the actual HTTP(s) request.
29
+ #
30
+ # @param uri[URI] where to send the request
31
+ # @param payload[Object] the payload to be sent, will be converted by calling +payload.to_json+
32
+ #
33
+ # @return [String] the response body
34
+ # @raise [Net::HTTPError] if the response code is not 200
16
35
  def make_https_request(uri, payload=nil)
17
36
  @logger.info("sending request (method #{payload[:method]}) ...")
18
37
  Net::HTTP.start(uri.host, uri.port,
@@ -32,6 +51,12 @@ class WebtrekkConnector
32
51
  end
33
52
  end
34
53
 
54
+ # Call a method on the API.
55
+ #
56
+ # @param method[String] the method name
57
+ # @param params[Hash] the method parameters
58
+ #
59
+ # @return [Object] the response body converted to a Ruby object by calling +JSON.parse(response)+
35
60
  def call_method(method, params={})
36
61
  @logger.info("call_method: #{method}")
37
62
  payload = {
@@ -44,10 +69,16 @@ class WebtrekkConnector
44
69
  data['result']
45
70
  end
46
71
 
72
+ # Call the +getConnectionTest+ method.
73
+ #
74
+ # @return [Object] the response body as a Ruby object
47
75
  def get_connection_test
48
76
  response = call_method('getConnectionTest')
49
77
  end
50
78
 
79
+ # Get a token from the API by calling the +login+ method.
80
+ #
81
+ # @return [String] the token returned by the API
51
82
  def get_token
52
83
  unless @customerId
53
84
  @customerId = self.get_first_account['customerId']
@@ -60,12 +91,17 @@ class WebtrekkConnector
60
91
  }
61
92
  response = call_method('login', params)
62
93
  end
63
-
64
-
94
+
95
+ # Log into the API by setting the \@token attribute.
96
+ #
97
+ # @return [String] the token returned by the API
65
98
  def login
66
99
  @token = get_token
67
100
  end
68
101
 
102
+ # Get the list of accounts associated with \@user.
103
+ #
104
+ # @return [Array] the list of accounts
69
105
  def get_account_list
70
106
  params = {
71
107
  :login => @user,
@@ -74,11 +110,19 @@ class WebtrekkConnector
74
110
  response = call_method('getAccountList', params)
75
111
  end
76
112
 
113
+ # Get the first account associated with \@user.
114
+ #
115
+ # @return [Hash] the first account as a Hash
77
116
  def get_first_account
78
117
  account_list = get_account_list
79
118
  account_list.first
80
119
  end
81
120
 
121
+ # Call the +getAnalysisData+ method.
122
+ #
123
+ # @param analysis_config[Hash] the +analysisConfig+ object as a Ruby Hash.
124
+ #
125
+ # @return [Hash] the response body converted as a Hash
82
126
  def request_analysis(analysis_config)
83
127
  params = {
84
128
  :token => @token ,
@@ -87,6 +131,9 @@ class WebtrekkConnector
87
131
  response = call_method("getAnalysisData", params)
88
132
  end
89
133
 
134
+ # Call the +getAnalysisObjectsAndMetricsList+ method.
135
+ #
136
+ # @return [Hash] the response body as a Hash
90
137
  def get_analysis_objects_and_metrics_list
91
138
  params = {
92
139
  :token => @token
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webtrekk_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Knud Möller
@@ -17,7 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/webtrekk_connector.rb
20
- homepage: https://rubygems.org/gems/webtrekk_connector
20
+ homepage: https://github.com/berlinonline/webtrekk_connector
21
21
  licenses:
22
22
  - MIT
23
23
  metadata: {}