From ffb82d4f7203752914ae82516992f947c90a0be0 Mon Sep 17 00:00:00 2001 From: Christian Mengler Date: Sun, 15 Apr 2018 14:52:44 +1000 Subject: [PATCH] Implemented fetching list of all custom events --- README.md | 4 +++ lib/fabricio/models/custom_event_type.rb | 21 ++++++++++++++ .../networking/app_request_model_factory.rb | 28 +++++++++++++++++++ lib/fabricio/services/app_service.rb | 16 +++++++++++ 4 files changed, 69 insertions(+) create mode 100644 lib/fabricio/models/custom_event_type.rb diff --git a/README.md b/README.md index 197f956..af2b8f8 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/fabricio/models/custom_event_type.rb b/lib/fabricio/models/custom_event_type.rb new file mode 100644 index 0000000..31f03a0 --- /dev/null +++ b/lib/fabricio/models/custom_event_type.rb @@ -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 diff --git a/lib/fabricio/networking/app_request_model_factory.rb b/lib/fabricio/networking/app_request_model_factory.rb index 2bfaf6f..53c2665 100644 --- a/lib/fabricio/networking/app_request_model_factory.rb +++ b/lib/fabricio/networking/app_request_model_factory.rb @@ -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 diff --git a/lib/fabricio/services/app_service.rb b/lib/fabricio/services/app_service.rb index bef9e58..fee2b29 100644 --- a/lib/fabricio/services/app_service.rb +++ b/lib/fabricio/services/app_service.rb @@ -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' @@ -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] + 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