class SimpleGoogleDrive::Client

Attributes

access_token[RW]

Public Class Methods

new(oauth2_access_token) click to toggle source
# File lib/simple_google_drive/client.rb, line 7
def initialize(oauth2_access_token)

  if oauth2_access_token.is_a?(String)
    @access_token = oauth2_access_token
  else
    raise ArgumentError, "oauth2_access_token doesn't have a valid type"
  end

end

Public Instance Methods

about() click to toggle source
# File lib/simple_google_drive/client.rb, line 19
def about
  url = build_url("/about")
  request = build_request(url)
  response = send_request(url, request)

  parse_response(response)
end
files_copy(file_id, body = nil, params = nil) click to toggle source
# File lib/simple_google_drive/client.rb, line 73
def files_copy(file_id, body = nil, params = nil)
  url = build_url("/files/#{file_id}/copy", params)
  request = build_request(url, 'post', body)
  response = send_request(url, request)

  parse_response(response)
end
files_delete(file_id) click to toggle source
# File lib/simple_google_drive/client.rb, line 81
def files_delete(file_id)
  url = build_url("/files/#{file_id}")
  request = build_request(url, 'delete')
  response = send_request(url, request)

  parse_response(response)
end
files_get(file_id, params = nil) click to toggle source
# File lib/simple_google_drive/client.rb, line 27
def files_get(file_id, params = nil)
  url = build_url("/files/#{file_id}", params)
  request = build_request(url)
  response = send_request(url, request)

  parse_response(response)
end
files_insert(body = {}, params = nil) click to toggle source
# File lib/simple_google_drive/client.rb, line 35
def files_insert(body = {}, params = nil)
  url = build_url("/files", params)
  request = build_request(url, 'post', body.to_json)
  response = send_request(url, request)

  parse_response(response)
end
files_list(params = nil) click to toggle source
# File lib/simple_google_drive/client.rb, line 89
def files_list(params = nil)
  url = build_url("/files", params)
  request = build_request(url)
  response = send_request(url, request)

  parse_response(response)
end
files_patch(file_id, body = nil, params = nil) click to toggle source
# File lib/simple_google_drive/client.rb, line 65
def files_patch(file_id, body = nil, params = nil)
  url = build_url("/files/#{file_id}", params)
  request = build_request(url, 'patch', body)
  response = send_request(url, request)

  parse_response(response)
end
files_touch(file_id) click to toggle source
# File lib/simple_google_drive/client.rb, line 97
def files_touch(file_id)
  url = build_url("/files/#{file_id}/touch")
  request = build_request(url, 'post')
  response = send_request(url, request)

  parse_response(response)
end
files_trash(file_id) click to toggle source
# File lib/simple_google_drive/client.rb, line 105
def files_trash(file_id)
  url = build_url("/files/#{file_id}/trash")
  request = build_request(url, 'post')
  response = send_request(url, request)

  parse_response(response)
end
files_untrash(file_id) click to toggle source
# File lib/simple_google_drive/client.rb, line 113
def files_untrash(file_id)
  url = build_url("/files/#{file_id}/untrash")
  request = build_request(url, 'post')
  response = send_request(url, request)

  parse_response(response)
end
files_upload(file_object, args = {}) click to toggle source
# File lib/simple_google_drive/client.rb, line 43
def files_upload(file_object, args = {})
  raise ArgumentError, "Invalid upload type. Choose between media, multipart or resumable." if args[:uploadType].nil?

  case args[:uploadType].to_s
    when 'media'
      body = file_object
      content_type = MIME::Types.type_for(file_object.path).first.to_s
    when 'multipart'
      body = build_multipart_body(file_object, args[:body_object])
      content_type = "multipart/related;boundary=simple_google_drive_boundary"
    when 'resumable'
      body = build_resumable_body(file_object, args[:body_object])
      content_type = ""
  end

  url = build_url("/files", args[:parameters], true)
  request = build_request(url, 'post', body, content_type)
  response = send_request(url, request)

  parse_response(response)
end
files_watch(file_id, body = nil) click to toggle source
# File lib/simple_google_drive/client.rb, line 121
def files_watch(file_id, body = nil)
  url = build_url("/files/#{file_id}/watch")
  request = build_request(url, 'post', body.to_json)
  response = send_request(url, request)

  parse_response(response)
end