Skip to content

Commit

Permalink
Implemented fetching list of all custom event attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmengler committed Apr 15, 2018
1 parent 91837b8 commit 03c6d91
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ Obtains the total count for the specified custom 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.
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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

# Returns a CustomEventAttribute model object
# Returns a CustomEventAttributeValue model object
#
# @param attributes [Hash]
# @return [Fabricio::Model::CustomEventAttribute]
# @return [Fabricio::Model::CustomEventAttributeValue]
def initialize(attributes)
@attribute_value = attributes['attribute_value']
@count = attributes['count']
Expand Down
33 changes: 31 additions & 2 deletions lib/fabricio/networking/app_request_model_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,35 @@ def custom_event_unique_devices_request_model(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
Expand All @@ -417,7 +446,7 @@ def custom_event_attribute_request_model(options = {})
:start_time => week_ago_timestamp,
:end_time => today_timestamp,
:build => 'all',
:event_type => 'event_type',
:event_type => nil,
:event_attribute => nil,
:selected_time => nil,
:limit => 10
Expand Down Expand Up @@ -492,7 +521,7 @@ def custom_event_request_model(options = {})
:start_time => week_ago_timestamp,
:end_time => today_timestamp,
:build => 'all',
:event_type => 'event_type',
:event_type => nil,
:name => nil
}.merge(options)
validate_options(options)
Expand Down
23 changes: 20 additions & 3 deletions lib/fabricio/services/app_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
require 'fabricio/models/point'
require 'fabricio/models/issue'
require 'fabricio/models/issue_session'
require 'fabricio/models/custom_event_attribute'
require 'fabricio/models/custom_event_attribute_name'
require 'fabricio/models/custom_event_attribute_value'

module Fabricio
module Service
Expand Down Expand Up @@ -263,6 +264,22 @@ def custom_event_unique_devices(options = {})
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
Expand All @@ -272,12 +289,12 @@ def custom_event_unique_devices(options = {})
# @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>]
# @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::CustomEventAttribute.new(array)
Fabricio::Model::CustomEventAttributeValue.new(array)
end
end

Expand Down

0 comments on commit 03c6d91

Please sign in to comment.