Class: Fastlane::Checks::GoogleChecksService

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/checks/helper/checks_service.rb

Constant Summary collapse

OAUTH_SCOPES =
["https://www.googleapis.com/auth/checks"]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials, project_id, account_id, app_id) ⇒ GoogleChecksService

Returns a new instance of GoogleChecksService.



30
31
32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 30

def initialize(credentials, project_id, , app_id)
  @account_id = 
  @app_id = app_id
  @auth = credentials.get_google_credential(OAUTH_SCOPES)
  @project_id ||= @auth.project_id

  default_headers = @auth.apply({})
  default_headers["X-Goog-User-Project"] = @project_id
  @connection = Faraday.new(url: BASE_URL, headers: default_headers)
end

Class Method Details

.operation_id_from_name(name) ⇒ Object



90
91
92
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 90

def self.operation_id_from_name(name)
  name.split("/").last
end

.report_id_from_name(name) ⇒ Object



94
95
96
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 94

def self.report_id_from_name(name)
  name.split("/").last
end

Instance Method Details

#apps_listObject



41
42
43
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 41

def apps_list
  get("/v1alpha/accounts/#{@account_id}/apps/")
end

#check_operation(operation_id) ⇒ Object



56
57
58
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 56

def check_operation(operation_id)
  get("/v1alpha/accounts/#{@account_id}/apps/#{@app_id}/operations/#{operation_id}")
end

#get(path, params = {}) ⇒ Object



67
68
69
70
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 67

def get(path, params = {})
  response = @connection.get(path, params)
  handle_response(response)
end

#report(report_id) ⇒ Object



60
61
62
63
64
65
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 60

def report(report_id)
  params = {
    "fields" => "name,checks(type,state,severity)"
  }
  get("/v1alpha/accounts/#{@account_id}/apps/#{@app_id}/reports/#{report_id}", params)
end

#upload_binary(binary_path) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 45

def upload_binary(binary_path)
  binary_data = File.binread(binary_path)
  path = "/upload/v1alpha/accounts/#{@account_id}/apps/#{@app_id}/reports:analyzeUpload"
  response = @connection.post(path) do |req|
    req.headers['X-Goog-Upload-Protocol'] = 'raw'
    req.headers['Content-Type'] = 'application/octet-stream'
    req.body = binary_data
  end
  handle_response(response)
end

#wait_for_report(operation_id) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fastlane/plugin/checks/helper/checks_service.rb', line 72

def wait_for_report(operation_id)
  started_at = Time.now
  operation_response = nil
  loop do
    operation_response = check_operation(operation_id)
    has_timeout = Time.now - started_at > DEFAULT_TIMEOUT
    break if operation_response["done"] || has_timeout

    sleep(CHECK_OPERATION_INTERVAL)
  end
  if operation_response["response"]
    [
      GoogleChecksService.report_id_from_name(operation_response["response"]["name"]),
      operation_response
    ]
  end
end