Skip to content

Instantly share code, notes, and snippets.

@dsignr
Created June 3, 2018 07:48
Show Gist options
  • Save dsignr/f5c6469c6e4a419862b6a19a9a886268 to your computer and use it in GitHub Desktop.
Save dsignr/f5c6469c6e4a419862b6a19a9a886268 to your computer and use it in GitHub Desktop.
Ruby syntax example
class DriveAPI
include HTTParty
base_uri 'https://www.googleapis.com'
#for debugging
debug_output $stdout
end
def create_file(file_name, parent_id)
check_token!
access_token = current_user.access_token
response = DriveAPI.post(
'/drive/v3/files',
:body => { "mimeType"=> "application/vnd.google-apps.document",
"name"=> "#{file_name}",
"parents"=> ["#{parent_id}"]
}.to_json,
:headers => {
"Authorization" => "Bearer #{access_token}",
"Content-Type" => "application/json"
}
)
response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment