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_APPS_ENDPOINT =
'/apps'
FABRIC_ORGANIZATIONS_ENDPOINT =
'/organizations'

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:

[View source]

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

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

#all_apps_request_modelFabricio::Networking::RequestModel

Returns a request model for obtaining the list of all apps

[View source]

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

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:

[View source]

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 128

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:

[View source]

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

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:

[View source]

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

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:

[View source]

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

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

#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:

[View source]

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/fabricio/networking/app_request_model_factory.rb', line 157

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

#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:

[View source]

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

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