analytics-psw 0.1.2 → 0.1.3
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 +4 -4
- data/LICENSE.txt +22 -0
- data/README.md +133 -0
- data/lib/analytics_dimension_properties.rb +87 -0
- data/lib/analytics_dimensions.rb +24 -0
- data/lib/analytics_event_types.rb +19 -0
- data/lib/analytics_reports.rb +35 -0
- data/lib/analytics_services.rb +26 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4fa2b78f7161b203949aaec9147366adac7386d
|
4
|
+
data.tar.gz: 0751907236b4d8818631a3d05abaa7e921f17ee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ceb1eda25f11c5d400f64f89f062673c68b8d9e188a7dc2d3a9ac6767201b8f5f943e50f81b9c3ccf2962673f82c901b498cc2936abfeb0c5b6cb5a338ec5ea
|
7
|
+
data.tar.gz: 89e882fa97e60d5b6f037eb6134698820c8f8b3d8b9625e0ee2a73f0fe5b473e761637762ce9754f3058a46f700bcb7a3dea839691eed052006ad5995918423e
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jordan Keyes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# Analytics::Psw
|
2
|
+
|
3
|
+
Analytics-psw is a wrapper providing access to the Perceptive Cloud Platform Analytics service
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'analytics-psw'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install analytics-psw
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
require 'analytics-psw'
|
23
|
+
require 'yaml' #optional, for importing information used to connect to the Analytics service
|
24
|
+
```
|
25
|
+
###Options in .rb file
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
opts = {}
|
29
|
+
opts['server_url'] = "http://my.server.url" #required. No trailing slash needed
|
30
|
+
opts['service'] = "MyServiceName" #required. Calling AnalyticsPSW.new will search for your service, and if it isn't found, create it
|
31
|
+
opts['proxy'] = "http://proxy.server.address" #optional, not required if you don't use a proxy server or if you set the http_proxy environment variable
|
32
|
+
opts['event_types'] = ["event_one", "event_two", "event_three"] #optional, will create event types to associate with your service if they don't already exist
|
33
|
+
opts['dimensions'] = [{"dimension_name" => "string"}, {"dimension_2" => "integer"}] #optional, will create dimensions to describe your events if they don't already exist
|
34
|
+
|
35
|
+
ap = AnalyticsPSW.new(opts)
|
36
|
+
```
|
37
|
+
|
38
|
+
### Options in separate .yml file
|
39
|
+
``` ruby
|
40
|
+
ap = AnalyticsPSW.new(YAML.load_file(analytics_settings.yml))
|
41
|
+
```
|
42
|
+
|
43
|
+
### Sample YAML file
|
44
|
+
```
|
45
|
+
---
|
46
|
+
server_url: http://127.0.0.1:3000
|
47
|
+
service: my_service
|
48
|
+
event_types:
|
49
|
+
- event_one
|
50
|
+
- event_two
|
51
|
+
|
52
|
+
dimensions:
|
53
|
+
- dimension_one: string
|
54
|
+
- dimension_two: integer
|
55
|
+
```
|
56
|
+
|
57
|
+
## Available Methods
|
58
|
+
|
59
|
+
``` ruby
|
60
|
+
ap.record_event(event_type, metadata = {}) # sends an event to the Analytics service. Event_type must exist on the Analytics system
|
61
|
+
|
62
|
+
ap.query_analytics(query_parameters) # sends a hashmap query to the Analytics service. Possible keys include: required: one or more of :sum, :avg, :fields, optional: :customer, :where, :group_by, :order_by, :iterage_by. Use comma-separated strings if multiple values are needed
|
63
|
+
ap.create_report(name, query_parameters) # create a report query to be ran later. 'query_parameters' same as above.
|
64
|
+
ap.list_reports # list all reports for a service
|
65
|
+
ap.show_report(report_id) # list the properties for a report
|
66
|
+
ap.run_report(report_id, where_criteria) # run a stored report. 'where_criteria' are options 'where' paramters to replace in the stored report when running.
|
67
|
+
ap.delete_report(report_id) # delete a stored report
|
68
|
+
|
69
|
+
ap.create_service(name) # creates a new service
|
70
|
+
ap.list_service # list all available services
|
71
|
+
ap.show_service_resource(service_id) # list available resources for a service
|
72
|
+
ap.show_service_metadata(service_id) # list the properties of a service
|
73
|
+
ap.delete_service(service_id) # delete a report
|
74
|
+
|
75
|
+
ap.create_event_type(name, description = "") # creates an event type for the service being used
|
76
|
+
ap.list_event_types #list all event types for a service
|
77
|
+
ap.show_event_type(event_type_id) # list properties of an event type
|
78
|
+
|
79
|
+
ap.create_dimension(name, data_type, units = "", description = "") # creates a new dimension (field that describes an event, but isn't tied to any one event). Only name and data_type are required.
|
80
|
+
ap.list_dimensions # list all dimensions for a service
|
81
|
+
ap.show_dimension_resources(dimension_id) # list available resources for a dimension
|
82
|
+
ap.show_dimension_metadata(dimension_id) # list metadata for a dimension
|
83
|
+
|
84
|
+
ap.create_dimension_properties(dimension_name, dimension_value, property_hash) # adds properties to a dimension value. This will return status=409 if properties already exist. Use this method to add mutable string data to dimensions. For example: add a title to a video by adding a title property to the video's guid.
|
85
|
+
ap.update_dimension_properties(dimension_name, dimension_value, property_hash) # updates properties created for a dimension value. The hash replaces all properties currently set.
|
86
|
+
ap.create_or_update_dimension_properties(dimension_name, dimension_value, property_hash) # adds propertie to a dimension value if they already exist. Updates the properties otherwise. This will return status=409 if properties already exist. Use this method to add mutable string data to dimensions. For example: add a title to a video by adding a title property to the video's guid.
|
87
|
+
ap.show_dimension_properties(dimension_name, dimension_value) # get the properties currently set for a dimension value. The body will be json.
|
88
|
+
ap.list_dimension_properties(dimension_name) # list all values that have properties set. This will return a json object with an array of json/location pairs.
|
89
|
+
```
|
90
|
+
|
91
|
+
## Query Parameters
|
92
|
+
|
93
|
+
| Parameter | Values | Examples |
|
94
|
+
| -------------------| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
|
95
|
+
| ` sum ` |` any event or number dimension ` | ` { "sum" => "plays" } or { "sum" => "plays,process_time" } ` |
|
96
|
+
| ` avg ` | ` any event or number dimension ` | ` { "avg" => "plays" } or { "avg" => "plays,process_time" } ` |
|
97
|
+
| ` fields ` | ` any mapped dimension ` | ` { "fields" => "user_name } or { "fields" => "user_name,location" } ` |
|
98
|
+
| ` customer ` | ` any customer associated with a service ` | ` { "customer" => "lexmark" } ` |
|
99
|
+
| ` where ` | ` <dimension> <operator> <value> ` | ` { "where" => [ "begin_date gt 2013-12-10", "end_date lt 2013-12-20", "user_name eq bob", "location is null" ] }` |
|
100
|
+
| ` - <dimension> ` | ` any mapped dimension ` | |
|
101
|
+
| ` - <operator> ` | ` any valid operator ` | |
|
102
|
+
| ` - - ls ` | ` less than operator ` | ` { "where" => [ "end_date lt 2013-12-10" ] }` |
|
103
|
+
| ` - - gt ` | ` greater than operator ` | ` { "where" => [ "begin_date gt 2013-12-10" ] }` |
|
104
|
+
| ` - - eq ` | ` equal to operator ` | ` { "where" => [ "user_name eq bob" ] }` |
|
105
|
+
| ` - - lte ` | ` less than equal to operator ` | ` { "where" => [ "begin_date gte 2013-12-10" ] }` |
|
106
|
+
| ` - - gte` | ` greater than equal to operator ` | ` { "where" => [ "end_date lte 2013-12-10" ] }` |
|
107
|
+
| ` - - in ` | ` in operator for multiple values ` | ` { "where" => [ "user_name in bob,ted,allen" ] }` |
|
108
|
+
| ` - - is ` | ` is operator for boolean and null value ` | ` { "where" => [ "awesome is true" ] }` |
|
109
|
+
| ` group_by ` | ` any mapped dimension(s) ` | ` { "group_by" => "user_name" } or { "group_by" => "user_name,location" } ` |
|
110
|
+
| ` order_by ` | ` <dimension> <ascending or descending> ` | ` { "order_by" => "user_name ascending" } or { "order_by" => "user_name descending" } ` |
|
111
|
+
| ` iterate_by ` | ` YEAR, MONTH, DAY, or HOUR ` | ` { "iterate_by" => "MONTH" } or { "iterate_by" => "HOUR" } ` |
|
112
|
+
| ` limit ` | ` any integer value ` | ` { "limit" => 10 } ` |
|
113
|
+
|
114
|
+
**Required** `sum`, `avg`, and/or `fields`
|
115
|
+
|
116
|
+
**Optional** `customer`, `where`, `group_by`, `order_by`, and `iterate_by`
|
117
|
+
|
118
|
+
Note: `iterate_by` always uses the global `event_time` dimension.
|
119
|
+
|
120
|
+
**Examples**
|
121
|
+
``` ruby
|
122
|
+
{ "sum" => "plays", "customer" => "lexmark", "where" => [ "begin_date gt 2013-12-10", "end_date lt 2013-12-20"], "group_by" => "location", "order_by" => "location descending" }
|
123
|
+
{ "sum" => "plays,download", "avg" => "process_time", "where" => [ "location in kentucky,kansas,california"], "group_by" => "location", "order_by" => "location descending" }
|
124
|
+
{ "fields" => "location,user_name", "company" => "lexmark"}
|
125
|
+
{ "avg" => "plays", "customer" => "lexmark", "where" => [ "event_time gt 2013-12-10", "event_time lt 2013-12-20"], "iterate_by" => "DAY", "order_by" => "event_time descending" }
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
## License
|
132
|
+
|
133
|
+
2013 Lexmark International Technology S.A. All rights reserved.
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module AnalyticsDimensionProperties
|
2
|
+
|
3
|
+
SERVICE_NAME_PARAM = 'service_name'
|
4
|
+
DIMENSION_NAME_PARAM = 'dimension_name'
|
5
|
+
DIMENSION_PROPERTY_VALUE_PARAM = 'dimension_property_value'
|
6
|
+
|
7
|
+
def list_dimension_properties(dimension_name)
|
8
|
+
response = request_uri_to_dimension_properties(dimension_name)
|
9
|
+
if valid_uri_response?(response)
|
10
|
+
uri = uri_from_uri_response(response)
|
11
|
+
response = get_with_hash(uri)
|
12
|
+
end
|
13
|
+
parse_json_response(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_dimension_properties(dimension_name, dimension_value)
|
17
|
+
response = request_uri_to_dimension_properties(dimension_name, dimension_value)
|
18
|
+
if valid_uri_response?(response)
|
19
|
+
uri = uri_from_uri_response(response)
|
20
|
+
response = get_with_hash(uri)
|
21
|
+
end
|
22
|
+
parse_json_response(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_dimension_properties(dimension_name, dimension_value, properties = {})
|
26
|
+
metadata = create_dimension_properties_metadata(dimension_value, properties)
|
27
|
+
response = request_uri_to_dimension_properties(dimension_name)
|
28
|
+
if valid_uri_response?(response)
|
29
|
+
uri = uri_from_uri_response(response)
|
30
|
+
response = post_json(uri, "dimension_property", metadata)
|
31
|
+
end
|
32
|
+
parse_json_response(response)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_dimension_properties(dimension_name, dimension_value, properties = {})
|
36
|
+
metadata = create_dimension_properties_metadata(dimension_value, properties)
|
37
|
+
response = request_uri_to_dimension_properties(dimension_name, dimension_value)
|
38
|
+
if valid_uri_response?(response)
|
39
|
+
uri = uri_from_uri_response(response)
|
40
|
+
response = put_json(uri, "dimension_property", metadata)
|
41
|
+
end
|
42
|
+
parse_json_response(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_or_update_dimension_properties(dimension_name, dimension_value, properties = {})
|
46
|
+
response = request_uri_to_dimension_properties(dimension_name, dimension_value)
|
47
|
+
if valid_uri_response?(response)
|
48
|
+
return update_dimension_properties(dimension_name, dimension_value, properties)
|
49
|
+
end
|
50
|
+
create_dimension_properties(dimension_name, dimension_value, properties)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def create_dimension_properties_metadata(dimension_value, properties)
|
56
|
+
dimension_properties_body = {'value' => dimension_value, 'properties' => {}}
|
57
|
+
properties.each do |key, value|
|
58
|
+
dimension_properties_body['properties'][key] = value unless value == ""
|
59
|
+
end
|
60
|
+
dimension_properties_body
|
61
|
+
end
|
62
|
+
|
63
|
+
def request_uri_to_dimension_properties(dimension_name, dimension_value = nil)
|
64
|
+
uri_path = "#{@server_url}/uris/dimension_property"
|
65
|
+
uri_path_query_params = dimension_property_uri_query_params(dimension_name, dimension_value)
|
66
|
+
get_with_hash(uri_path, uri_path_query_params)
|
67
|
+
end
|
68
|
+
|
69
|
+
def valid_uri_response?(uri_response)
|
70
|
+
uri_response.status == 200
|
71
|
+
end
|
72
|
+
|
73
|
+
def uri_from_uri_response(uri_response)
|
74
|
+
parsed_json_body = JSON.parse(uri_response.body)
|
75
|
+
parsed_json_body['uri']['location']
|
76
|
+
end
|
77
|
+
|
78
|
+
def dimension_property_uri_query_params(dimension_name, dimension_value)
|
79
|
+
query_params = {
|
80
|
+
SERVICE_NAME_PARAM => @service_name,
|
81
|
+
DIMENSION_NAME_PARAM => dimension_name,
|
82
|
+
}
|
83
|
+
query_params[DIMENSION_PROPERTY_VALUE_PARAM] = dimension_value unless dimension_value.nil?
|
84
|
+
query_params
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AnalyticsDimensions
|
2
|
+
|
3
|
+
def create_dimension(name, data_type, units = "", description = "")
|
4
|
+
metadata = create_metadata({:name => name, :description => description, :data_type => data_type, :units => units})
|
5
|
+
resp = post_json("#{@service_location}/dimensions", "dimension", metadata)
|
6
|
+
parse_json_response(resp)
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_dimensions
|
10
|
+
resp = get_with_hash("#{@service_location}/dimensions")
|
11
|
+
parse_json_response(resp)
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_dimension_resources(dimension_id)
|
15
|
+
resp = get_with_hash("#{@service_location}/dimensions/#{dimension_id}")
|
16
|
+
parse_json_response(resp)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show_dimension_metadata(dimension_id)
|
20
|
+
resp = get_with_hash("#{@service_location}/dimensions/#{dimension_id}/metadata")
|
21
|
+
parse_json_response(resp)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module AnalyticsEventTypes
|
2
|
+
|
3
|
+
def create_event_type(name, description = "")
|
4
|
+
metadata = create_metadata({:name => name, :description => description})
|
5
|
+
resp = post_json("#{@service_location}/event_types", "event_type", metadata)
|
6
|
+
parse_json_response(resp)
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_event_types
|
10
|
+
resp = get_with_hash("#{@service_location}/event_types")
|
11
|
+
parse_json_response(resp)
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_event_type(event_type_id)
|
15
|
+
resp = get_with_hash("#{@service_location}/event_types/#{event_type_id}")
|
16
|
+
parse_json_response(resp)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module AnalyticsReports
|
2
|
+
|
3
|
+
def query_analytics(query_parameters)
|
4
|
+
resp = get_with_hash("#{@service_location}/reports/query.json", query_parameters)
|
5
|
+
raise "Problem with your query. Please check the required parameters and try again" if resp.status == 400
|
6
|
+
parse_json_response(resp)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_report(name, query_parameters)
|
10
|
+
query_parameters[:name] = name
|
11
|
+
resp = post_json("#{@service_location}/reports", "report", query_parameters )
|
12
|
+
parse_json_response(resp)
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_reports
|
16
|
+
resp = get_with_hash("#{@service_location}/reports")
|
17
|
+
parse_json_response(resp)
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_report(report_id)
|
21
|
+
resp = get_with_hash("#{@service_location}/reports/#{report_id}")
|
22
|
+
parse_json_response(resp)
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_report(report_id, where_criteria = {})
|
26
|
+
resp = get_with_hash("#{@service_location}/reports/#{report_id}/results", where_criteria)
|
27
|
+
parse_json_response(resp)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete_report(report_id)
|
31
|
+
resp = delete_resource("#{@service_location}/reports/#{report_id}")
|
32
|
+
parse_json_response(resp)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AnalyticsServices
|
2
|
+
|
3
|
+
def create_service(name)
|
4
|
+
create_service_private(name)
|
5
|
+
end
|
6
|
+
|
7
|
+
def list_services
|
8
|
+
resp = get_with_hash("/services")
|
9
|
+
parse_json_response(resp)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show_service_resources(service_id)
|
13
|
+
resp = get_with_hash("/services/#{service_id}")
|
14
|
+
parse_json_response(resp)
|
15
|
+
end
|
16
|
+
|
17
|
+
def show_service_metadata(service_id)
|
18
|
+
resp = get_with_hash("/services/#{service_id}/metadata")
|
19
|
+
parse_json_response(resp)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete_service(service_id)
|
23
|
+
resp = delete_resource("/services/#{service_id}")
|
24
|
+
parse_json_response(resp)
|
25
|
+
end
|
26
|
+
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.1.
|
4
|
+
version: 0.1.3
|
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-03-
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,13 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- lib/analytics-psw.rb
|
92
|
+
- lib/analytics_dimension_properties.rb
|
93
|
+
- lib/analytics_dimensions.rb
|
94
|
+
- lib/analytics_event_types.rb
|
95
|
+
- lib/analytics_reports.rb
|
96
|
+
- lib/analytics_services.rb
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
92
99
|
homepage:
|
93
100
|
licenses:
|
94
101
|
- 3-Clause BSD
|