Class: Fabricio::Service::AppService

Inherits:
Object
  • Object
show all
Defined in:
lib/fabricio/services/app_service.rb

Overview

Service responsible for fetching different App information

Instance Method Summary collapse

Constructor Details

#initialize(session, network_client) ⇒ Fabricio::Service::AppService

Initializes a new AppService object.



16
17
18
19
20
21
# File 'lib/fabricio/services/app_service.rb', line 16

def initialize(session, network_client)
  @session = session

  @request_model_factory = Fabricio::Networking::AppRequestModelFactory.new
  @network_client = network_client
end

Instance Method Details

#active_now(id) ⇒ Integer

Obtains the count of active users at the current moment

Parameters:

  • id (String)

    Application identifier

Returns:

  • (Integer)


48
49
50
51
52
# File 'lib/fabricio/services/app_service.rb', line 48

def active_now(id)
  request_model = @request_model_factory.active_now_request_model(@session, id)
  response = @network_client.perform_request(request_model)
  JSON.parse(response.body)['cardinality']
end

#allArray<Fabricio::Model::App>

Obtains the list of all apps

Returns:



26
27
28
29
30
31
32
# File 'lib/fabricio/services/app_service.rb', line 26

def all
  request_model = @request_model_factory.all_apps_request_model
  response = @network_client.perform_request(request_model)
  JSON.parse(response.body).map do |app_hash|
    Fabricio::Model::App.new(app_hash)
  end
end

#crashes(id, start_time, end_time, builds) ⇒ Integer

Obtains the number of crashes

Parameters:

  • id (String)

    Application identifier

  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

  • builds (Array<String>)

    The versions of the app. E.g. [‘4.0.1 (38)’, ‘4.0.2 (45)’]

Returns:

  • (Integer)


103
104
105
106
107
# File 'lib/fabricio/services/app_service.rb', line 103

def crashes(id, start_time, end_time, builds)
  request_model = @request_model_factory.crash_count_request_model(id, start_time, end_time, builds)
  response = @network_client.perform_request(request_model)
  JSON.parse(response.body)['data']['project']['crashlytics']['scalars']['crashes']
end

#crashfree(id, start_time, end_time, build) ⇒ Float

Obtains application crashfree. It’s calculated using a simple formula: crashfree = 1 - total_crashes / total_sessions. AFAIK Fabric.io website uses the same calculations. However, mobile app behaves differently and shows another value.

Parameters:

  • id (String)

    Application identifier

  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

  • build (String)

    The version of the build. E.g. ‘4.0.1 (38)’

Returns:

  • (Float)


118
119
120
121
122
# File 'lib/fabricio/services/app_service.rb', line 118

def crashfree(id, start_time, end_time, build)
  sessions = total_sessions(id, start_time, end_time, build)
  crashes = crashes(id, start_time, end_time, [build])
  1 - crashes.to_f / sessions
end

#daily_active(id, start_time, end_time, build) ⇒ Array<Fabricio::Model::Point>

Obtains the count of daily active users

Parameters:

  • id (String)

    Application identifier

  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

  • build (String)

    The version of the build. E.g. ‘4.0.1 (38)’

Returns:



75
76
77
78
79
80
81
# File 'lib/fabricio/services/app_service.rb', line 75

def daily_active(id, start_time, end_time, build)
  request_model = @request_model_factory.daily_active_request_model(@session, id, start_time, end_time, build)
  response = @network_client.perform_request(request_model)
  JSON.parse(response.body)['series'].map do |array|
    Fabricio::Model::Point.new(array)
  end
end

#daily_new(id, start_time, end_time) ⇒ Array<Fabricio::Model::Point>

Obtains the count of daily new users

Parameters:

  • id (String)

    Application identifier

  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

Returns:



60
61
62
63
64
65
66
# File 'lib/fabricio/services/app_service.rb', line 60

def daily_new(id, start_time, end_time)
  request_model = @request_model_factory.daily_new_request_model(@session, id, start_time, end_time)
  response = @network_client.perform_request(request_model)
  JSON.parse(response.body)['series'].map do |array|
    Fabricio::Model::Point.new(array)
  end
end

#get(id) ⇒ Fabricio::Model::App

Obtains a specific app

Parameters:

  • id (String)

    Application identifier

Returns:



38
39
40
41
42
# File 'lib/fabricio/services/app_service.rb', line 38

def get(id)
  request_model = @request_model_factory.get_app_request_model(id)
  response = @network_client.perform_request(request_model)
  Fabricio::Model::App.new(JSON.parse(response.body))
end

#oomfree(id, start_time, end_time, builds) ⇒ Float

Obtains application OOM-free (Out of Memory).

Parameters:

  • id (String)

    Application identifier

  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

  • builds (Array<String>)

    The versions of the app. E.g. [‘4.0.1 (38)’, ‘4.0.2 (45)’]

Returns:

  • (Float)


131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/fabricio/services/app_service.rb', line 131

def oomfree(id, start_time, end_time, builds)
  start_date = Time.at(start_time.to_i).to_datetime
  end_date = Time.at(end_time.to_i).to_datetime
  days = (end_date - start_date).to_i + 1

  request_model = @request_model_factory.oom_count_request_model(id, days, builds)
  response = @network_client.perform_request(request_model)

  result = JSON.parse(response.body)
  sessions = result['data']['project']['crashlytics']['oomSessionCounts']['timeSeries'][0]['allTimeCount']
  ooms = result['data']['project']['crashlytics']['oomCounts']['timeSeries'][0]['allTimeCount']
  1 - ooms.to_f / sessions
end

#total_sessions(id, start_time, end_time, build) ⇒ Integer

Obtains the count of sessions

Parameters:

  • id (String)

    Application identifier

  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

  • build (String)

    The version of the build. E.g. ‘4.0.1 (38)’

Returns:

  • (Integer)


90
91
92
93
94
# File 'lib/fabricio/services/app_service.rb', line 90

def total_sessions(id, start_time, end_time, build)
  request_model = @request_model_factory.total_sessions_request_model(@session, id, start_time, end_time, build)
  response = @network_client.perform_request(request_model)
  JSON.parse(response.body)['sessions']
end