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.
-
#add_comment(id, issue_external_id, message) ⇒ JSON
Add comment to issue.
-
#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.
-
#issue_session(id, issue_external_id, session_id) ⇒ Fabricio::Model::Issue
Obtains single issue.
-
#monthly_active(id, start_time, end_time, build) ⇒ Array<Fabricio::Model::Point>
Obtains the count of monhtly active users.
-
#oomfree(id, start_time, end_time, builds) ⇒ Float
Obtains application OOM-free (Out of Memory).
-
#single_issue(id, issue_external_id, start_time, end_time) ⇒ Fabricio::Model::Issue
Obtains single issue.
-
#top_issues(id, start_time, end_time, builds, count) ⇒ Array<Fabricio::Model::Issue>
Obtains top issues.
-
#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.
18 19 20 21 22 23 |
# File 'lib/fabricio/services/app_service.rb', line 18 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
50 51 52 53 54 |
# File 'lib/fabricio/services/app_service.rb', line 50 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 |
#add_comment(id, issue_external_id, message) ⇒ JSON
Add comment to issue
201 202 203 204 205 |
# File 'lib/fabricio/services/app_service.rb', line 201 def add_comment(id, issue_external_id, ) request_model = @request_model_factory.add_comment_request_model(id, issue_external_id, ) response = @network_client.perform_request(request_model) JSON.parse(response.body) end |
#all ⇒ Array<Fabricio::Model::App>
Obtains the list of all apps
28 29 30 31 32 33 34 |
# File 'lib/fabricio/services/app_service.rb', line 28 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
120 121 122 123 124 |
# File 'lib/fabricio/services/app_service.rb', line 120 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.
135 136 137 138 139 |
# File 'lib/fabricio/services/app_service.rb', line 135 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
77 78 79 80 81 82 83 |
# File 'lib/fabricio/services/app_service.rb', line 77 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
62 63 64 65 66 67 68 |
# File 'lib/fabricio/services/app_service.rb', line 62 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
40 41 42 43 44 |
# File 'lib/fabricio/services/app_service.rb', line 40 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 |
#issue_session(id, issue_external_id, session_id) ⇒ Fabricio::Model::Issue
Obtains single issue
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/fabricio/services/app_service.rb', line 176 def issue_session(id, issue_external_id, session_id) request_model = @request_model_factory.issue_session_request_model(id, issue_external_id, session_id) response = @network_client.perform_request(request_model) json = JSON.parse(response.body) link = response.headers['Link'] unless link.nil? json['header_link'] = link link_parts = link.split(", ") link_parts.each do |part| if part.include? 'rel="prev"' json['prev_session_id'] = part.sub('>; rel="prev"', "").sub('<', "").split("sessions/")[1] elsif part.include? 'rel="next"' json['next_session_id'] = part.sub('>; rel="next"', "").sub('<', "").split("sessions/")[1] end end end Fabricio::Model::IssueSession.new(json) end |
#monthly_active(id, start_time, end_time, build) ⇒ Array<Fabricio::Model::Point>
Obtains the count of monhtly active users
92 93 94 95 96 97 98 |
# File 'lib/fabricio/services/app_service.rb', line 92 def monthly_active(id, start_time, end_time, build) request_model = @request_model_factory.monthly_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 |
#oomfree(id, start_time, end_time, builds) ⇒ Float
Obtains application OOM-free (Out of Memory).
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/fabricio/services/app_service.rb', line 214 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 |
#single_issue(id, issue_external_id, start_time, end_time) ⇒ Fabricio::Model::Issue
Obtains single issue
164 165 166 167 168 |
# File 'lib/fabricio/services/app_service.rb', line 164 def single_issue(id, issue_external_id, start_time, end_time) request_model = @request_model_factory.single_issue_request_model(id, issue_external_id, start_time, end_time) response = @network_client.perform_request(request_model) Fabricio::Model::Issue.new(JSON.parse(response.body)['data']['project']['crashlytics']['_issueeUsmi']) end |
#top_issues(id, start_time, end_time, builds, count) ⇒ Array<Fabricio::Model::Issue>
Obtains top issues
149 150 151 152 153 154 155 |
# File 'lib/fabricio/services/app_service.rb', line 149 def top_issues(id, start_time, end_time, builds, count) request_model = @request_model_factory.top_issues_request_model(id, start_time, end_time, builds, count) response = @network_client.perform_request(request_model) JSON.parse(response.body)['data']['project']['crashlytics']['_issues4Eg1Tv']['edges'].map do |edge| Fabricio::Model::Issue.new(edge['node']) end end |
#total_sessions(id, start_time, end_time, build) ⇒ Integer
Obtains the count of sessions
107 108 109 110 111 |
# File 'lib/fabricio/services/app_service.rb', line 107 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 |