Class: Fabricio::Service::AppService
- Inherits:
-
Object
- Object
- Fabricio::Service::AppService
- Defined in:
- lib/fabricio/services/app_service.rb
Overview
Service responsible for fetching different App information
Instance Method Summary collapse
-
#active_now(id) ⇒ Integer
Obtains the count of active users at the current moment.
-
#all ⇒ Array<Fabricio::Model::App>
Obtains the list of all apps.
-
#crashes(id, start_time, end_time, builds) ⇒ Integer
Obtains the number of crashes.
-
#crashfree(id, start_time, end_time, build) ⇒ Float
Obtains application crashfree.
-
#daily_active(id, start_time, end_time, build) ⇒ Array<Fabricio::Model::Point>
Obtains the count of daily active users.
-
#daily_new(id, start_time, end_time) ⇒ Array<Fabricio::Model::Point>
Obtains the count of daily new users.
-
#get(id) ⇒ Fabricio::Model::App
Obtains a specific app.
-
#initialize(session, network_client) ⇒ Fabricio::Service::AppService
constructor
Initializes a new AppService object.
-
#oomfree(id, start_time, end_time, builds) ⇒ Float
Obtains application OOM-free (Out of Memory).
-
#total_sessions(id, start_time, end_time, build) ⇒ Integer
Obtains the count of sessions.
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
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 |
#all ⇒ Array<Fabricio::Model::App>
Obtains the list of all apps
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
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.
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
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
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
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).
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
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 |