analytics-psw 0.0.3 → 0.0.4
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 +98 -98
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59bd6ee99df8ab35f64909e1ebd76d9df91890d5
|
4
|
+
data.tar.gz: a500ffd54a6e840aa334ffa3ce1c13c35134fbbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d7d4eeed01aa3cce64b36d715e05a5ef7c36150199e72bb1b0253c788c06dc3ee62d2f1c4b1c7dcc2cefd70227f06c106915c7a7824e66acdf7a0eecca0eb6
|
7
|
+
data.tar.gz: ffe957ebbf65c8e1e4ddb18cc9c79358d031d1f59bab4209aadcc3ba45a9f0aedfde626a604c911a1271a181891bc2b8b922f20d01ad50dd131d2451cfd5e41c
|
data/lib/analytics-psw.rb
CHANGED
@@ -1,99 +1,99 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
class AnalyticsPSW
|
5
|
-
|
6
|
-
VERSION = "0.0.1"
|
7
|
-
API_VERSION = "v#{VERSION}"
|
8
|
-
API_URL = "/api/#{API_VERSION}/services"
|
9
|
-
JSON_CONTENT_TYPE = 'application/json'
|
10
|
-
|
11
|
-
attr_accessor :service_location
|
12
|
-
|
13
|
-
def initialize(opts = {})
|
14
|
-
@server_url = opts['server_url']
|
15
|
-
service_name = opts['service']
|
16
|
-
raise "Please ensure you have provided the appropriate server url and service name" unless @server_url && service_name
|
17
|
-
@proxy =
|
18
|
-
@
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
req.
|
50
|
-
req.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
json_object
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
service_location
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
all_services
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Faraday.new(@server_url, {:proxy => {:uri => @proxy}})
|
97
|
-
end
|
98
|
-
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class AnalyticsPSW
|
5
|
+
|
6
|
+
VERSION = "0.0.1"
|
7
|
+
API_VERSION = "v#{VERSION}"
|
8
|
+
API_URL = "/api/#{API_VERSION}/services"
|
9
|
+
JSON_CONTENT_TYPE = 'application/json'
|
10
|
+
|
11
|
+
attr_accessor :service_location
|
12
|
+
|
13
|
+
def initialize(opts = {})
|
14
|
+
@server_url = opts['server_url']
|
15
|
+
service_name = opts['service']
|
16
|
+
raise "Please ensure you have provided the appropriate server url and service name" unless @server_url && service_name
|
17
|
+
@proxy = "" if @server_url.start_with?("http://127.0.0.1") or @server_url.start_with?("http://localhost")
|
18
|
+
@conn = faraday_connection
|
19
|
+
@service_location = find_or_create_service(service_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def record_event(event_type, metadata = {})
|
23
|
+
metadata[:event_type] = event_type
|
24
|
+
post_json("#{@service_location}/events", "event", metadata)
|
25
|
+
end
|
26
|
+
|
27
|
+
def query_analytics(query_parameters)
|
28
|
+
resp = get_with_hash("#{@service_location}/reports/query.json", query_parameters)
|
29
|
+
raise "Problem with your query. Please check the required parameters and try again" if resp.status == 400
|
30
|
+
JSON.parse(resp.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_event_type(name, description = "")
|
34
|
+
metadata = create_metadata({:name => name, :description => description})
|
35
|
+
post_json("#{@service_location}/event_types", "event_type", metadata)
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_dimension(name, data_type, units = "", description = "")
|
39
|
+
metadata = create_metadata({:name => name, :description => description, :data_type => data_type, :units => units})
|
40
|
+
post_json("#{@service_location}/dimensions", "dimension", metadata)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def post_json(url, object_type, metadata)
|
46
|
+
json_object = create_json_object(object_type, metadata)
|
47
|
+
@conn.post do |req|
|
48
|
+
req.url url
|
49
|
+
req.headers['Content-Type'] = JSON_CONTENT_TYPE
|
50
|
+
req.body = json_object
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_with_hash(url, hash_object = {})
|
55
|
+
@conn.get url, hash_object
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_json_object(object_type, metadata = {})
|
59
|
+
json_object= {object_type => metadata}
|
60
|
+
json_object.to_json
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_metadata(hashmap)
|
64
|
+
metadata = {}
|
65
|
+
hashmap.each do |key, value|
|
66
|
+
metadata[key] = value unless value == ""
|
67
|
+
end
|
68
|
+
metadata
|
69
|
+
end
|
70
|
+
|
71
|
+
def find_or_create_service(service_name)
|
72
|
+
service_location = find_service_location(service_name)
|
73
|
+
if !service_location
|
74
|
+
resp = create_service(service_name)
|
75
|
+
service_location = resp["location"]
|
76
|
+
end
|
77
|
+
service_location
|
78
|
+
end
|
79
|
+
|
80
|
+
def find_service_location(service_name)
|
81
|
+
service_location = nil
|
82
|
+
all_services = JSON.parse(get_with_hash("#{API_URL}.json").body)
|
83
|
+
all_services["services"].each do |service|
|
84
|
+
service_location = service["location"] if service["name"] == service_name
|
85
|
+
end
|
86
|
+
service_location
|
87
|
+
end
|
88
|
+
|
89
|
+
def create_service(name, description = "")
|
90
|
+
metadata = create_metadata({:name => name, :description => description})
|
91
|
+
post_json(API_URL, "service", metadata)
|
92
|
+
end
|
93
|
+
|
94
|
+
def faraday_connection
|
95
|
+
return Faraday.new(@server_url) unless @proxy == ""
|
96
|
+
Faraday.new(@server_url, {:proxy => {:uri => @proxy}})
|
97
|
+
end
|
98
|
+
|
99
99
|
end
|
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.4
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.0.14
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Perceptive Cloud Platform Analytics Service Wrapper
|