analytics-psw 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/analytics-psw.rb +17 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9877623eec796b47a783fd16cb90027c01a1b1ad
|
4
|
+
data.tar.gz: fab8e47fc2b66d0437267b4a17b823590519b36e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12ae1f081ae762c56d562aaa1be836f68e313852ec8a4e28a21455d6bf0510bae474ab7bdc7ed84ea3303fc470dae6f9781481b86d1a504c9fc4d2a58604ec21
|
7
|
+
data.tar.gz: dcf354f78af91d7936613d21a6ce8d582dd2c264d8328e46cbcaf7f177ce5274dac7fbd11950db866e2983c3fb6a127cb645ee5fa98db851a812d7580559e9a1
|
data/lib/analytics-psw.rb
CHANGED
@@ -3,7 +3,7 @@ require 'json'
|
|
3
3
|
|
4
4
|
class AnalyticsPSW
|
5
5
|
|
6
|
-
VERSION = "0.0.
|
6
|
+
VERSION = "0.0.7"
|
7
7
|
API_VERSION = "v#{VERSION}"
|
8
8
|
API_URL = "/api/#{API_VERSION}/services"
|
9
9
|
JSON_CONTENT_TYPE = 'application/json'
|
@@ -14,6 +14,7 @@ class AnalyticsPSW
|
|
14
14
|
@server_url = opts['server_url']
|
15
15
|
service_name = opts['service']
|
16
16
|
raise "Please ensure you have provided the appropriate server url and service name" unless @server_url && service_name
|
17
|
+
@server_url = @server_url.chomp("/")
|
17
18
|
@proxy = opts['proxy']
|
18
19
|
@proxy = "" if @server_url.start_with?("http://127.0.0.1") or @server_url.start_with?("http://localhost")
|
19
20
|
@conn = faraday_connection
|
@@ -22,23 +23,26 @@ class AnalyticsPSW
|
|
22
23
|
|
23
24
|
def record_event(event_type, metadata = {})
|
24
25
|
metadata[:event_type] = event_type
|
25
|
-
post_json("#{@service_location}/events", "event", metadata)
|
26
|
+
resp = post_json("#{@service_location}/events", "event", metadata)
|
27
|
+
parse_json_response(resp)
|
26
28
|
end
|
27
29
|
|
28
30
|
def query_analytics(query_parameters)
|
29
31
|
resp = get_with_hash("#{@service_location}/reports/query.json", query_parameters)
|
30
32
|
raise "Problem with your query. Please check the required parameters and try again" if resp.status == 400
|
31
|
-
|
33
|
+
parse_json_response(resp)
|
32
34
|
end
|
33
35
|
|
34
36
|
def create_event_type(name, description = "")
|
35
37
|
metadata = create_metadata({:name => name, :description => description})
|
36
|
-
post_json("#{@service_location}/event_types", "event_type", metadata)
|
38
|
+
resp = post_json("#{@service_location}/event_types", "event_type", metadata)
|
39
|
+
parse_json_response(resp)
|
37
40
|
end
|
38
41
|
|
39
42
|
def create_dimension(name, data_type, units = "", description = "")
|
40
43
|
metadata = create_metadata({:name => name, :description => description, :data_type => data_type, :units => units})
|
41
|
-
post_json("#{@service_location}/dimensions", "dimension", metadata)
|
44
|
+
resp = post_json("#{@service_location}/dimensions", "dimension", metadata)
|
45
|
+
parse_json_response(resp)
|
42
46
|
end
|
43
47
|
|
44
48
|
private
|
@@ -92,8 +96,15 @@ class AnalyticsPSW
|
|
92
96
|
post_json(API_URL, "service", metadata)
|
93
97
|
end
|
94
98
|
|
99
|
+
def parse_json_response(json_response)
|
100
|
+
parsed_response = {}
|
101
|
+
parsed_response['status'] = json_response.status if json_response.status
|
102
|
+
parsed_response['body'] = json_response.body if json_response.body
|
103
|
+
parsed_response
|
104
|
+
end
|
105
|
+
|
95
106
|
def faraday_connection
|
96
|
-
return Faraday.new(@server_url) if @proxy ==
|
107
|
+
return Faraday.new(@server_url) if @proxy == nil
|
97
108
|
Faraday.new(@server_url, {:proxy => {:uri => @proxy}})
|
98
109
|
end
|
99
110
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: analytics-psw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Keyes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|