Skip to content

Commit

Permalink
Merge pull request #55 from cmengler/feature/custom-events
Browse files Browse the repository at this point in the history
Custom event support
  • Loading branch information
CognitiveDisson authored Apr 16, 2018
2 parents 0cf3bf8 + 2c96510 commit 5535356
Show file tree
Hide file tree
Showing 13 changed files with 2,225 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,28 @@ Obtains an array of all versions for a given application.

Obtains an array of top versions for a given application.

### Events

#### `client.app.all_custom_events(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build')`

Obtains list of all custom event types.

#### `client.app.custom_event_total(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build', event_type: 'event_type')`

Obtains the total count for the specified custom event type.

#### `client.app.custom_event_unique_devices(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build', event_type: 'event_type')`

Obtains the unique device count for the specified custom event type.

#### `client.app.all_custom_event_attribute(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', event_type: 'event_type')`

Obtains list of all attributes for the specified custom event type.

#### `client.app.custom_event_attribute(organization_id: 'organization_id', app_id: 'app_id', start_time: 'start_timestamp', end_time: 'end_timestamp', build: 'build', event_type: 'event_type', event_attribute: 'event_attribute', selected_time: 'selected_timestamp')`

Obtains the attribute count for the specified custom event type.

## Additional Info

Fabric.io API:
Expand Down
20 changes: 20 additions & 0 deletions lib/fabricio/models/custom_event_attribute_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'fabricio/models/abstract_model'

module Fabricio
module Model
# This model represents a custom event attribute name
class CustomEventAttributeName < AbstractModel
attr_reader :type, :name

# Returns a CustomEventAttributeName model object
#
# @param attributes [Hash]
# @return [Fabricio::Model::CustomEventAttributeName]
def initialize(attributes)
@type = attributes['attribute_type']
@name = attributes['attribute_name']
@json = attributes
end
end
end
end
25 changes: 25 additions & 0 deletions lib/fabricio/models/custom_event_attribute_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'fabricio/models/abstract_model'

module Fabricio
module Model
# This model represents a custom event attribute value
class CustomEventAttributeValue < AbstractModel
attr_reader :attribute_value,
:count,
:percent,
:week_ago_delta

# Returns a CustomEventAttributeValue model object
#
# @param attributes [Hash]
# @return [Fabricio::Model::CustomEventAttributeValue]
def initialize(attributes)
@attribute_value = attributes['attribute_value']
@count = attributes['count']
@percent = attributes['percent']
@week_ago_delta = attributes['week_ago_delta']
@json = attributes
end
end
end
end
21 changes: 21 additions & 0 deletions lib/fabricio/models/custom_event_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'fabricio/models/abstract_model'

module Fabricio
module Model
# This model represents a custom event type
class CustomEventType < AbstractModel
attr_reader :type, :key, :count

# Returns a CustomEventType model object
#
# @param attributes [Hash]
# @return [Fabricio::Model::CustomEventType]
def initialize(attributes)
@type = attributes['event_type']
@count = attributes['event_count']
@key = attributes['event_key']
@json = attributes
end
end
end
end
162 changes: 162 additions & 0 deletions lib/fabricio/networking/app_request_model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,134 @@ def oom_count_request_model(options = {})
model
end

# Returns a request model for obtaining the list of all custom event types
#
# @param organization_id [String] Organization identifier
# @param app_id [String]
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @return [Fabricio::Networking::RequestModel]
def all_custom_event_request_model(options = {})
options = {
:organization_id => stored_organization_id,
:app_id => stored_app_id,
:start_time => week_ago_timestamp,
:end_time => today_timestamp,
:build => 'all'
}.merge(options)
validate_options(options)
path = growth_analytics_endpoint(options[:organization_id], options[:app_id], 'event_types_with_data')
params = time_range_params(options[:start_time], options[:end_time])
params['build'] = options[:build]
model = Fabricio::Networking::RequestModel.new do |config|
config.type = :GET
config.base_url = FABRIC_API_URL
config.api_path = path
config.params = params
end
model
end

# Returns a request model for obtaining the total count of specified custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String]
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
# @param event_type [String] The custom event name. E.g. 'Custom Event Name'
# @return [Fabricio::Networking::RequestModel]
def custom_event_total_request_model(options = {})
options = { :name => 'ce_total_events' }.merge(options)
custom_event_request_model(options)
end

# Returns a request model for obtaining the unique devices count of specified custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String]
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
# @param event_type [String] The custom event name. E.g. 'Custom Event Name'
# @return [Fabricio::Networking::RequestModel]
def custom_event_unique_devices_request_model(options = {})
options = { :name => 'ce_unique_devices' }.merge(options)
custom_event_request_model(options)
end

# Returns a request model for obtaining the list of all attributes of specified custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String]
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param event_type [String] The custom event name. E.g. 'Custom Event Name'
# @return [Fabricio::Networking::RequestModel]
def all_custom_event_attribute_request_model(options = {})
options = {
:organization_id => stored_organization_id,
:app_id => stored_app_id,
:start_time => week_ago_timestamp,
:end_time => today_timestamp,
:event_type => nil
}.merge(options)
validate_options(options)
path = growth_analytics_endpoint(options[:organization_id], options[:app_id], 'ce_attribute_metadata')
params = time_range_params(options[:start_time], options[:end_time])
params['event_type'] = options[:event_type]
model = Fabricio::Networking::RequestModel.new do |config|
config.type = :GET
config.base_url = FABRIC_API_URL
config.api_path = path
config.params = params
end
model
end

# Returns a request model for obtaining the attribute counts of specified custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String]
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
# @param event_type [String] The custom event name. E.g. 'Custom Event Name'
# @param event_attribute [String] The custom event attribute. E.g. 'Custom Attribute'
# @param selected_time [String] Timestamp of the selected date
# @return [Fabricio::Networking::RequestModel]
def custom_event_attribute_request_model(options = {})
options = {
:organization_id => stored_organization_id,
:app_id => stored_app_id,
:start_time => week_ago_timestamp,
:end_time => today_timestamp,
:build => 'all',
:event_type => nil,
:event_attribute => nil,
:selected_time => nil,
:limit => 10
}.merge(options)
validate_options(options)
path = growth_analytics_endpoint(options[:organization_id], options[:app_id], 'ce_category_attribute_data')
params = {
'timeseries_start' => options[:start_time],
'timeseries_end' => options[:end_time],
'build' => options[:build],
'event_type' => options[:event_type],
'attribute' => options[:event_attribute],
'limit' => options[:limit],
'selected_day' => options[:selected_time]
}
model = Fabricio::Networking::RequestModel.new do |config|
config.type = :GET
config.base_url = FABRIC_API_URL
config.api_path = path
config.params = params
end
model
end

private

# Returns a request model for obtaining the count of active users
Expand Down Expand Up @@ -404,6 +532,40 @@ def active_request_model(options = {})
model
end

# Returns a request model for obtaining the custom event metrics
#
# @param organization_id [String] Organization identifier
# @param app_id [String]
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param build [String] The version of the build. E.g. '4.0.1 (38)'
# @param event_type [String] The custom event name. E.g. 'Custom Event Name'
# @param name [String] Custom event type: total_events, unique_devices
# @return [Fabricio::Networking::RequestModel]
def custom_event_request_model(options = {})
options = {
:organization_id => stored_organization_id,
:app_id => stored_app_id,
:start_time => week_ago_timestamp,
:end_time => today_timestamp,
:build => 'all',
:event_type => nil,
:name => nil
}.merge(options)
validate_options(options)
path = growth_analytics_endpoint(options[:organization_id], options[:app_id], options[:name])
params = time_range_params(options[:start_time], options[:end_time])
params['build'] = options[:build]
params['event_type'] = options[:event_type]
model = Fabricio::Networking::RequestModel.new do |config|
config.type = :GET
config.base_url = FABRIC_API_URL
config.api_path = path
config.params = params
end
model
end

# Returns an API path to some issue session
#
# @param organization_id [String] Organization identifier
Expand Down
80 changes: 80 additions & 0 deletions lib/fabricio/services/app_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
require 'fabricio/models/point'
require 'fabricio/models/issue'
require 'fabricio/models/issue_session'
require 'fabricio/models/custom_event_type'
require 'fabricio/models/custom_event_attribute_name'
require 'fabricio/models/custom_event_attribute_value'

module Fabricio
module Service
Expand Down Expand Up @@ -234,6 +237,83 @@ def oomfree(options = {})
1 - ooms.to_f / sessions
end

# Obtains the list of all custom event types
#
# @param organization_id [String] Organization identifier
# @param app_id [String] Application identifier
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @return [Array<Fabricio::Model::CustomEventType>]
def all_custom_events(options = {})
request_model = @request_model_factory.all_custom_event_request_model(options)
response = @network_client.perform_request(request_model)
JSON.parse(response.body)['custom_events'].map do |array|
Fabricio::Model::CustomEventType.new(array)
end
end

# Obtains the total count of a custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String] Application identifier
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param event_type [String] Custom Event Name
# @return [Array<Fabricio::Model::Point>]
def custom_event_total(options = {})
request_model = @request_model_factory.custom_event_total_request_model(options)
response = @network_client.perform_request(request_model)
parse_point_response(response)
end

# Obtains the unique device count of a custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String] Application identifier
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param event_type [String] Custom Event Name
# @return [Array<Fabricio::Model::Point>]
def custom_event_unique_devices(options = {})
request_model = @request_model_factory.custom_event_unique_devices_request_model(options)
response = @network_client.perform_request(request_model)
parse_point_response(response)
end

# Obtains the list of all attributes for a custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String] Application identifier
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param event_type [String] Custom Event Name
# @return [Array<Fabricio::Model::CustomEventAttributeName>]
def all_custom_event_attribute(options = {})
request_model = @request_model_factory.all_custom_event_attribute_request_model(options)
response = @network_client.perform_request(request_model)
JSON.parse(response.body)['attribute_metadata'].map do |array|
Fabricio::Model::CustomEventAttributeName.new(array)
end
end

# Obtains the attribute counts of a custom event type
#
# @param organization_id [String] Organization identifier
# @param app_id [String] Application identifier
# @param start_time [String] Timestamp of the start date
# @param end_time [String] Timestamp of the end date
# @param event_type [String] Custom Event Name
# @param event_attribute [String] Custom Event Attribute
# @param selected_time [String] Timestamp of the selected date
# @return [Array<Fabricio::Model::CustomEventAttributeValue>]
def custom_event_attribute(options = {})
request_model = @request_model_factory.custom_event_attribute_request_model(options)
response = @network_client.perform_request(request_model)
JSON.parse(response.body)['selected_day_top_values'].map do |array|
Fabricio::Model::CustomEventAttributeValue.new(array)
end
end

private

def parse_point_response(response)
Expand Down
Loading

0 comments on commit 5535356

Please sign in to comment.