Class: GoogleDrive::ApiClientFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/google_drive/api_client_fetcher.rb

Defined Under Namespace

Classes: Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authorization, client_options, request_options) ⇒ ApiClientFetcher

Returns a new instance of ApiClientFetcher


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/google_drive/api_client_fetcher.rb', line 21

def initialize(authorization, client_options, request_options)
  @drive = Google::Apis::DriveV3::DriveService.new
  @sheets = Google::Apis::SheetsV4::SheetsService.new

  [@drive, @sheets].each do |service|
    service.authorization = authorization

    # Make the timeout virtually infinite because some of the operations
    # (e.g., uploading a large file) can take very long.
    # This value is the maximal allowed timeout in seconds on JRuby.
    t = (2**31 - 1) / 1000
    service.client_options.open_timeout_sec = t
    service.client_options.read_timeout_sec = t
    service.client_options.send_timeout_sec = t

    if client_options
      service.client_options.members.each do |name|
        if !client_options[name].nil?
          service.client_options[name] = client_options[name]
        end
      end
    end

    if request_options
      service.request_options = service.request_options.merge(request_options)
    end
  end
end

Instance Attribute Details

#driveObject (readonly)

Returns the value of attribute drive


50
51
52
# File 'lib/google_drive/api_client_fetcher.rb', line 50

def drive
  @drive
end

#sheetsObject (readonly)

Returns the value of attribute sheets


51
52
53
# File 'lib/google_drive/api_client_fetcher.rb', line 51

def sheets
  @sheets
end

Instance Method Details

#request_raw(method, url, data, extra_header, _auth) ⇒ Object


53
54
55
56
57
# File 'lib/google_drive/api_client_fetcher.rb', line 53

def request_raw(method, url, data, extra_header, _auth)
  options = @drive.request_options.merge(header: extra_header)
  body = @drive.http(method, url, body: data, options: options)
  Response.new('200', body)
end