Skip to content

Commit

Permalink
Implemented fetching custom event attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
cmengler committed Apr 15, 2018
1 parent 0b0d86a commit 9f398b8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/fabricio/models/custom_event_attribute.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
class CustomEventAttribute < AbstractModel
attr_reader :attribute_value,
:count,
:percent,
:week_ago_delta

# Returns a CustomEventAttribute model object
#
# @param attributes [Hash]
# @return [Fabricio::Model::CustomEventAttribute]
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
43 changes: 43 additions & 0 deletions lib/fabricio/networking/app_request_model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,49 @@ def custom_event_unique_devices_request_model(options = {})
custom_event_request_model(options)
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 => 'event_type',
: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
19 changes: 19 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_attribute'

module Fabricio
module Service
Expand Down Expand Up @@ -262,6 +263,24 @@ def custom_event_unique_devices(options = {})
parse_point_response(response)
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::CustomEventAttribute>]
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::CustomEventAttribute.new(array)
end
end

private

def parse_point_response(response)
Expand Down

0 comments on commit 9f398b8

Please sign in to comment.