Skip to content

Commit

Permalink
Implemented fetching custom events
Browse files Browse the repository at this point in the history
  • Loading branch information
cmengler committed Apr 15, 2018
1 parent 0cf3bf8 commit 0b0d86a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ Obtains an array of all versions for a given application.

Obtains an array of top versions for a given application.

### Events

#### `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.

## Additional Info

Fabric.io API:
Expand Down
62 changes: 62 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 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

private

# Returns a request model for obtaining the count of active users
Expand Down Expand Up @@ -404,6 +432,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 => 'event_type',
: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
28 changes: 28 additions & 0 deletions lib/fabricio/services/app_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,34 @@ def oomfree(options = {})
1 - ooms.to_f / sessions
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

private

def parse_point_response(response)
Expand Down

0 comments on commit 0b0d86a

Please sign in to comment.