Class: Supply::AbstractGoogleServiceClient

Inherits:
Object
  • Object
show all
Defined in:
supply/lib/supply/client.rb

Direct Known Subclasses

PlaycustomappClient, Client

Constant Summary collapse

SCOPE =
nil
SERVICE =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_account_json: nil, params: nil) ⇒ AbstractGoogleServiceClient

Initializes the service and its auth_client using the specified information

Parameters:

  • service_account_json: (defaults to: nil)

    The raw service account Json data



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'supply/lib/supply/client.rb', line 36

def initialize(service_account_json: nil, params: nil)
  auth_client = Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: , scope: self.class::SCOPE)

  UI.verbose("Fetching a new access token from Google...")

  auth_client.fetch_access_token!

  if FastlaneCore::Env.truthy?("DEBUG")
    Google::Apis.logger.level = Logger::DEBUG
  end

  Google::Apis::ClientOptions.default.application_name = "fastlane (supply client)"
  Google::Apis::ClientOptions.default.application_version = Fastlane::VERSION
  Google::Apis::ClientOptions.default.read_timeout_sec = params[:timeout]
  Google::Apis::ClientOptions.default.open_timeout_sec = params[:timeout]
  Google::Apis::ClientOptions.default.send_timeout_sec = params[:timeout]
  Google::Apis::RequestOptions.default.retries = 5

  service = self.class::SERVICE.new
  service.authorization = auth_client

  if params[:root_url]
    # Google's client expects the root_url string to end with "/".
    params[:root_url] << '/' unless params[:root_url].end_with?('/')
    service.root_url = params[:root_url]
  end

  self.client = service
end

Instance Attribute Details

#clientObject

Connecting with Google



13
14
15
# File 'supply/lib/supply/client.rb', line 13

def client
  @client
end

Class Method Details

.make_from_config(params: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'supply/lib/supply/client.rb', line 15

def self.make_from_config(params: nil)
  unless params[:json_key] || params[:json_key_data]
    UI.important("To not be asked about this value, you can specify it using 'json_key'")
    json_key_path = UI.input("The service account json file used to authenticate with Google: ")
    json_key_path = File.expand_path(json_key_path)

    UI.user_error!("Could not find service account json file at path '#{json_key_path}'") unless File.exist?(json_key_path)
    params[:json_key] = json_key_path
  end

  if params[:json_key]
     = File.open(File.expand_path(params[:json_key]))
  elsif params[:json_key_data]
     = StringIO.new(params[:json_key_data])
  end

  return self.new(service_account_json: , params: params)
end