Class: Google::ClientBuilder

Inherits:
Object
  • Object
show all
Extended by:
ConstructionHelper
Defined in:
lib/google/client_builder.rb,
lib/google/client_builder/scopes_helper.rb,
lib/google/client_builder/construction_helper.rb

Defined Under Namespace

Modules: ConstructionHelper Classes: ScopesHelper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConstructionHelper

calendar_client, directory_client

Constructor Details

#initialize {|_self| ... } ⇒ ClientBuilder

Returns a new instance of ClientBuilder.

Yields:

  • (_self)

Yield Parameters:



15
16
17
# File 'lib/google/client_builder.rb', line 15

def initialize
  yield(self) if block_given?
end

Instance Attribute Details

#authorizeObject

Returns the value of attribute authorize.



8
9
10
# File 'lib/google/client_builder.rb', line 8

def authorize
  @authorize
end

#scopesObject

Returns the value of attribute scopes.



8
9
10
# File 'lib/google/client_builder.rb', line 8

def scopes
  @scopes
end

#user_emailObject

Returns the value of attribute user_email.



8
9
10
# File 'lib/google/client_builder.rb', line 8

def user_email
  @user_email
end

Class Method Details

.keyObject



10
11
12
13
# 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

Instance Method Details

#authorize!Object



19
20
21
# File 'lib/google/client_builder.rb', line 19

def authorize!
  @authorize = true
end

#buildObject



23
24
25
26
27
# 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