Class: Fabricio::Networking::AppRequestModelFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/fabricio/networking/app_request_model_factory.rb

Overview

This factory creates request models for fetching data for App model object

Constant Summary collapse

FABRIC_API_URL =

Server constants

'https://fabric.io'
FABRIC_GRAPHQL_API_URL =
'https://api-dash.fabric.io/graphql'
FABRIC_API_PATH =
'/api/v2'
FABRIC_API_3_PATH =
'/api/v3'
FABRIC_APPS_ENDPOINT =
'/apps'
FABRIC_ORGANIZATIONS_ENDPOINT =
'/organizations'
FABRIC_PROJECTS_ENDPOINT =
'/projects'

Instance Method Summary collapse

Instance Method Details

#active_now_request_model(session, app_id) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of active users at the current moment

Parameters:

Returns:



49
50
51
52
53
54
55
56
57
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 49

def active_now_request_model(session, app_id)
  path = growth_analytics_endpoint(session, app_id, 'active_now')
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :GET
    config.base_url = FABRIC_API_URL
    config.api_path = path
  end
  model
end

#add_comment_request_model(app_id, issue_external_id, message) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of ooms

Parameters:

  • app_id (String)
  • issue_external_id (String)

    Issue external identifier

  • message (String)

    Comment message

Returns:



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 269

def add_comment_request_model(app_id, issue_external_id, message)
  headers = {
      'Content-Type' => 'application/json'
  }
  body = {
    'body' => message,

  }.to_json
  path = add_comment_endpoint(app_id, issue_external_id)
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :POST
    config.base_url = FABRIC_API_URL
    config.api_path = path
    config.headers = headers
    config.body = body
  end
  model
end

#all_apps_request_modelFabricio::Networking::RequestModel

Returns a request model for obtaining the list of all apps



21
22
23
24
25
26
27
28
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 21

def all_apps_request_model
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :GET
    config.base_url = FABRIC_API_URL
    config.api_path = FABRIC_API_PATH + FABRIC_APPS_ENDPOINT
  end
  model
end

#crash_count_request_model(app_id, start_time, end_time, builds) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of app crashes

Parameters:

  • app_id (String)
  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

  • builds (Array)

    Multiple build versions. E.g. [‘4.0.1 (38)’]

Returns:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 151

def crash_count_request_model(app_id, start_time, end_time, builds)
  headers = {
      'Content-Type' => 'application/json'
  }
  builds_string = builds.map { |build|
    "\"#{build}\""
  }.join(',')
  body = {
    'query' => "query AppScalars($app_id:String!,$type:IssueType!) {project(externalId:$app_id) {crashlytics {scalars:scalars(synthesizedBuildVersions:[#{builds_string}],type:$type,start:#{start_time},end:#{end_time}) {crashes}}}}",
    'variables' => {
        'app_id' => app_id,
        'type' => 'crash'
    }
  }.to_json
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :POST
    config.base_url = FABRIC_GRAPHQL_API_URL
    config.headers = headers
    config.body = body
  end
  model
end

#daily_active_request_model(session, app_id, start_time, end_time, build) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of daily active users

Parameters:

  • session (Fabricio::Authorization::Session)
  • app_id (String)
  • 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:



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 86

def daily_active_request_model(session, app_id, start_time, end_time, build)
  path = growth_analytics_endpoint(session, app_id, 'daily_active')
  params = time_range_params(start_time, end_time)
  params['build'] = build
  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

#daily_new_request_model(session, app_id, start_time, end_time) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of daily new users

Parameters:

  • session (Fabricio::Authorization::Session)
  • app_id (String)
  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

Returns:



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 66

def daily_new_request_model(session, app_id, start_time, end_time)
  path = growth_analytics_endpoint(session, app_id, 'daily_new')
  params = time_range_params(start_time, end_time)
  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

#get_app_request_model(app_id) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining a specific app

Parameters:

  • app_id (String)

Returns:



34
35
36
37
38
39
40
41
42
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 34

def get_app_request_model(app_id)
  path = "#{FABRIC_API_PATH}#{app_endpoint(app_id)}"
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :GET
    config.base_url = FABRIC_API_URL
    config.api_path = path
  end
  model
end

#issue_session_request_model(app_id, issue_external_id, session_id) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of ooms

Parameters:

  • app_id (String)
  • issue_external_id (String)

    Issue external identifier

  • session_id (String)

    Session identifier

Returns:



249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 249

def issue_session_request_model(app_id, issue_external_id, session_id)
  headers = {
      'Content-Type' => 'application/json'
  }
  path = issue_session_endpoint(app_id, issue_external_id, session_id)
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :GET
    config.base_url = FABRIC_API_URL
    config.api_path = path
    config.headers = headers
  end
  model
end

#monthly_active_request_model(session, app_id, start_time, end_time, build) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of monhtly active users

Parameters:

  • session (Fabricio::Authorization::Session)
  • app_id (String)
  • 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:



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 107

def monthly_active_request_model(session, app_id, start_time, end_time, build)
  path = growth_analytics_endpoint(session, app_id, 'monthly_active')
  params = time_range_params(start_time, end_time)
  params['build'] = build
  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

#oom_count_request_model(app_id, days, builds) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of ooms

Parameters:

  • app_id (String)
  • days (Integer)

    Count of days for obtaining oomfree data

  • builds (Array)

    Multiple build versions. E.g. [‘4.0.1 (38)’]

Returns:



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 294

def oom_count_request_model(app_id, days, builds)
  headers = {
      'Content-Type' => 'application/json'
  }
  body = {
      'query' => 'query oomCountForDaysForBuild($app_id: String!, $builds: [String!]!, $days: Int!) { project(externalId: $app_id) { crashlytics{ oomCounts(builds: $builds, days: $days){ timeSeries{ allTimeCount } } oomSessionCounts(builds: $builds, days: $days){ timeSeries{ allTimeCount } } } } }',
      'variables' => {
          'app_id' => app_id,
          'days' => days,
          'builds' => builds
      }
  }.to_json
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :POST
    config.base_url = FABRIC_GRAPHQL_API_URL
    config.headers = headers
    config.body = body
  end
  model
end

#single_issue_request_model(app_id, issue_external_id, start_time, end_time) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining single issue

Parameters:

  • app_id (String)
  • issue_external_id (String)

    Issue external identifier

  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

Returns:



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 218

def single_issue_request_model(app_id, issue_external_id, start_time, end_time)
  headers = {
      'Content-Type' => 'application/json'
  }

  body = {
    'query' => "query SingleIssue($externalId_0:String!,$start_1:UnixTimestamp!,$end_2:UnixTimestamp!,$granularity_3:TimeseriesGranularity!,$filters_4:IssueFiltersType!) {project(externalId:$externalId_0) {crashlytics {_issueeUsmi:issue(externalId:\"#{issue_external_id}\") {externalId,createdAt,displayId,title,subtitle,type,state,isObfuscated,supportsCrossVersion,_occurrenceCount2I980d:occurrenceCount(start:$start_1,end:$end_2),_impactedDevices2oATOx:impactedDevices(start:$start_1,end:$end_2),shareLink,latestSessionId,lockedAt,resolvedAt,exportUserIdsUrl,buildVersionBreakdown {occurrenceCount,buildVersion {externalId,createdAt,name,synthesizedBuildVersion}},earliestBuildVersion {buildVersion {externalId,createdAt,name,synthesizedBuildVersion}},latestBuildVersion {buildVersion {externalId,createdAt,name,synthesizedBuildVersion}},notes {externalId,createdAt,body,account {id,name,email}},_timeseries1niuOE:timeseries(granularity:$granularity_3,start:$start_1,end:$end_2) {eventsCount,groupByDimension,dimensionKey},_scalars1YYKRB:scalars(start:$start_1,end:$end_2,filters:$filters_4) {deviceMetrics {eventsCount,jailbrokenRatio,inFocusRatio,proximityOnRatio,freeRamMean,freeDiskMean},topOs {value,label,groupKey,eventsCount},topDevices {value,label,groupKey,eventsCount},topCrashInsightsMatchers {value,label,groupKey,eventsCount,issuesCount,impactedDevicesCount}},id}},id}}",
    'variables' => {
        'externalId_0' => app_id,
        'start_1' => start_time,
        'end_2' => end_time,
        'granularity_3' => 'day',
        'filters_4' => {}
    }
  }.to_json
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :POST
    config.base_url = FABRIC_GRAPHQL_API_URL
    config.api_path = '?relayDebugName=SingleIssue'
    config.headers = headers
    config.body = body
  end
  model
end

#top_issues_request_model(app_id, start_time, end_time, builds, count) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining top issues

Parameters:

  • app_id (String)
  • start_time (String)

    Timestamp of the start date

  • end_time (String)

    Timestamp of the end date

  • builds (Array)

    Multiple build versions. E.g. [‘4.0.1 (38)’]

  • count (Int)

    Number of issue

Returns:



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 182

def top_issues_request_model(app_id, start_time, end_time, builds, count)
  headers = {
      'Content-Type' => 'application/json'
  }
  builds_string = builds.map { |build|
    "\"#{build}\""
  }.join(',')

  body = {
    'query' => "query TopIssues($externalId_0:String!,$type_1:IssueType!,$start_2:UnixTimestamp!,$end_3:UnixTimestamp!,$filters_4:IssueFiltersType!,$state_5:IssueState!) {project(externalId:$externalId_0) {crashlytics {_appDetails1JwAD1:appDetails(synthesizedBuildVersions:[#{builds_string}],type:$type_1,start:$start_2,end:$end_3,filters:$filters_4) {topCrashInsightsMatchers {groupKey}},_issues4Eg1Tv:issues(synthesizedBuildVersions:[#{builds_string}],eventType:$type_1,start:$start_2,end:$end_3,state:$state_5,first:#{count},filters:$filters_4) {edges {node {externalId,displayId,createdAt,resolvedAt,title,subtitle,state,type,impactLevel,isObfuscated,occurrenceCount,impactedDevices,latestSessionId,notesCount,earliestBuildVersion {buildVersion {name}},latestBuildVersion {buildVersion {name}},id},cursor},pageInfo {hasNextPage,hasPreviousPage}}},id}}",
    'variables' => {
        'externalId_0' => app_id,
        'type_1' => 'all',
        'start_2' => start_time,
        'end_3' => end_time,
        'filters_4' => { 'osMinorVersion' => [], 'deviceModel' => [] },
        'state_5' => 'open'
    }
  }.to_json
  model = Fabricio::Networking::RequestModel.new do |config|
    config.type = :POST
    config.base_url = FABRIC_GRAPHQL_API_URL
    config.api_path = '?relayDebugName=TopIssues'
    config.headers = headers
    config.body = body
  end
  model
end

#total_sessions_request_model(session, app_id, start_time, end_time, build) ⇒ Fabricio::Networking::RequestModel

Returns a request model for obtaining the count of sessions

Parameters:

  • session (Fabricio::Authorization::Session)
  • app_id (String)
  • 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:



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 128

def total_sessions_request_model(session, app_id, start_time, end_time, build)
  path = growth_analytics_endpoint(session, app_id, 'total_sessions_scalar')
  params = {
      'start' => start_time,
      'end' => end_time,
      'build' => build
  }
  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