- Notifications
You must be signed in to change notification settings - Fork0
REST client for Google APIs
License
yoshi-code-bot/google-api-ruby-client
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This repository contains a set of simple client libraries for various Google APIs. These libraries are generated automatically fromDiscovery Documents, and the code generator is also hosted here in this repository.
Each client provides:
- A client object that connects to the HTTP/JSON REST endpoint for the service.
- Ruby objects for data structures related to the service.
- Integration with the googleauth gem for authentication using OAuth, API keys, and service accounts.
- Control of retry, pagination, and timeouts.
These client libraries are officially supported by Google, and are updated regularly to track changes to the service. However, many Google services, especially Google Cloud Platform services such as Cloud Storage, Pub/Sub, and BigQuery, may provide a more modern client that is easier to use and more performant. See the section below titled"Which client should I use?" for more information.
The client gems are named according to the patterngoogle-apis-<servicename>_<serviceversion>. For example, the client for the Google Drive V3 API isgoogle-apis-drive_v3.
Install the client usinggem install or by adding it to yourGemfile. Then, to use it, require the file and instantiate the service. For example to use the Drive API:
require'google/apis/drive_v3'drive=Google::Apis::DriveV3::DriveService.newdrive.authorization= ...# See Googleauth or Signet libraries# Search for files in Drive (first page only)files=drive.list_files(q:"title contains 'finances'")files.items.eachdo |file|putsfile.titleend# Upload a filemetadata=Google::Apis::DriveV3::File.new(name:'test.txt')metadata=drive.create_file(metadata,upload_source:'/tmp/test.txt',content_type:'text/plain')# Download a filedrive.get_file(metadata.id,download_dest:'/tmp/downloaded-test.txt')
Following is another example using the Content API (Google Merchant Center), provided by thegoogle-apis-content_v2_1 gem:
require'google/apis/content_v2_1'require'googleauth'# https://github.com/googleapis/google-auth-library-rubycontent=Google::Apis::ContentV2_1::ShoppingContentService.newscope='https://www.googleapis.com/auth/content'merchant_id=# Merchant ID found on dashboardcontent.authorization=Google::Auth::ServiceAccountCredentials.make_creds(json_key_io:File.open('./content-api-key.json'),scope:scope)content.authorization.fetch_access_token!# Service methods: https://rubydoc.info/gems/google-apis-content_v2_1/Google/Apis/ContentV2_1/ShoppingContentServicecontent.list_datafeeds(merchant_id)# Returns Google::Apis::ContentV2_1::ListDatafeedsResponse
For more detailed information, see theUsage Guide.
Google provides two types of Ruby API client libraries:simple REST clients andmodern clients.
The libraries in this repo aresimple REST clients. These clients connect to HTTP/JSON REST endpoints and are automatically generated from service discovery documents. They support most API functionality, but their class interfaces are sometimes awkward.
Modern clients are produced by a modern code generator, combined with hand-crafted functionality for some services. Most modern clients connect to high-performance gRPC endpoints, although a few are backed by REST services. Modern clients are available for many Google services, especially Cloud Platform services, but do not yet support all the services covered by the simple clients. Most modern clients live in thehttps://github.com/googleapis/google-cloud-ruby repository.
For most users, we recommend the modern client, if one is available. Compared with simple clients, modern clients are generally much easier to use and more Ruby-like, support more advanced features such as streaming and long-running operations, and often provide much better performance. You may consider using a simple client instead, if a modern client is not yet available for the service you want to use, or if you are not able to use gRPC on your infrastructure.
The documentation for the particular Google service you are working with, may provide guidance regarding the preferred client library to use.
OpenCensus support with gems is now deprecated. Please migrate to usingOpenTelemetry instead. Currently instrumented span data from core gem can be got by enabling Http and HttpClient auto-instrumentation of OpenTelemetry. To enable instrumentation for HTTP and HttpClient, and export it toCloud Trace configure OpenTelemetry like below,
gem"opentelemetry-sdk"gem"opentelemetry-exporter-google_cloud_trace"gem"opentelemetry-instrumentation-http"gem"opentelemetry-instrumentation-http_client"require"opentelemetry-sdk"require"opentelemetry/instrumentation/http_client"require"opentelemetry/instrumentation/http"require"opentelemetry/exporter/google_cloud_trace"OpenTelemetry::SDK.configuredo |c|c.service_name="ServiceName"c.add_span_processor(OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(OpenTelemetry::Exporter::GoogleCloudTrace::SpanExporter.new))c.use"OpenTelemetry::Instrumentation::Http"c.use"OpenTelemetry::Instrumentation::HttpClient"end
See thesamples for examples on how to use the client library for variousservices.
This library is supported on Ruby 3.1+.
Google provides official support for Ruby versions that are actively supported by Ruby Core -- that is, Ruby versions that are either in normal maintenance or in security maintenance, and not end of life. Currently, this means Ruby 2.7 and later. Older versions of Rubymay still work, but are unsupported and not recommended. Seehttps://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby support schedule.
This library is licensed under Apache 2.0. Full license text is available in theLICENSE.
SeeCONTRIBUTING.
Pleasereport bugs at the project on Github. Don't hesitate toask questions about the client or APIs onStackOverflow.
About
REST client for Google APIs
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Ruby100.0%