class Google::ClientBuilder

Attributes

authorize[RW]
scopes[RW]
user_email[RW]

Public Class Methods

key() click to toggle source
# File lib/google/client_builder.rb, line 10
def self.key
  OpenSSL::PKey::RSA.new(ENV.fetch("GOOGLE_API_PRIVATE_KEY").gsub("\\n", "\n"),
                         "notasecret") # static default for Google P12 auth
end
new() { |self| ... } click to toggle source
# File lib/google/client_builder.rb, line 15
def initialize
  yield(self) if block_given?
end

Public Instance Methods

authorize!() click to toggle source
# File lib/google/client_builder.rb, line 19
def authorize!
  @authorize = true
end
build() click to toggle source
# File lib/google/client_builder.rb, line 23
def build
  Google::APIClient.new(application_name: "google-wrapper", application_version: Google::Wrapper::VERSION).tap do |client|
    client.authorization = asserter.authorize(user_email) if authorize?
  end
end

Private Instance Methods

asserter() click to toggle source
# File lib/google/client_builder.rb, line 31
def asserter
  Google::APIClient::JWTAsserter.new(ENV.fetch("GOOGLE_API_SERVICE_ACCOUNT"), scopes, self.class.key)
end
authorize?() click to toggle source
# File lib/google/client_builder.rb, line 35
def authorize?
  @authorize === true
end