Skip to content

Commit

Permalink
Implemented fetching list of all custom events
Browse files Browse the repository at this point in the history
  • Loading branch information
cmengler committed Apr 15, 2018
1 parent 03c6d91 commit ffb82d4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ 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.
Expand Down
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
28 changes: 28 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,34 @@ 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
Expand Down
16 changes: 16 additions & 0 deletions lib/fabricio/services/app_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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'

Expand Down Expand Up @@ -236,6 +237,21 @@ 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
Expand Down

0 comments on commit ffb82d4

Please sign in to comment.