Skip to content
Permalink
Browse files

Import refactored library. See MIGRATING.MD for details

  • Loading branch information...
sqrrrl committed Apr 17, 2015
1 parent 9b78091 commit f584a2cec862169fc2005b16f028dc548336301d
Showing 373 changed files with 255,685 additions and 444 deletions.
2 .rspec
@@ -1,2 +1,2 @@
--colour
--color
--format documentation
@@ -0,0 +1,7 @@
inherit_from: .rubocop_todo.yml

Metrics/LineLength:
Max: 120

Style/FormatString:
EnforcedStyle: sprintf
@@ -0,0 +1,63 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-03-25 23:30:36 -0700 using RuboCop version 0.29.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 19
Metrics/AbcSize:
Max: 79

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 220

# Offense count: 5
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 99
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 127

# Offense count: 18
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 43

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 6

# Offense count: 4
Metrics/PerceivedComplexity:
Max: 11

# Offense count: 14
Style/Documentation:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/EmptyLines:
Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/EmptyLinesAroundClassBody:
Enabled: false

# Offense count: 2
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next:
Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
Style/RedundantSelf:
Enabled: false
@@ -3,15 +3,13 @@ rvm:
- 2.2
- 2.0.0
- 2.1
- 1.9.3
- rbx-2
- jruby
- jruby-9000
env:
- RAILS_VERSION="~>3.2"
- RAILS_VERSION="~>4.0.0"
- RAILS_VERSION="~>4.1.0"
- RAILS_VERSION="~>4.2.0"
script: "bundle exec rake spec:all"
script: "rake spec:all"
before_install:
- sudo apt-get update
- sudo apt-get install idn
@@ -1,7 +1,12 @@
--markup markdown
--hide-void-return
--no-private
--verbose
--markup-provider=redcarpet
--markup=markdown
lib/**/*.rb
ext/**/*.c
generated/**/*.rb
-
README.md
CHANGELOG.md
MIGRATING.md
CONTRIBUTING.md
LICENSE
@@ -1,3 +1,9 @@
# 0.9.0
* WARNING: Please see [MIGRATING](MIGRATING.md) for important information.
* API classes are now generated ahead of time instead of at runtime.
* Drop support for Ruby versions < 2.0
* Switch from Faraday to Hurley for HTTP client

# 0.8.6
* Use discovered 'rootUrl' as base URI for services
* Respect discovered methods with colons in path
@@ -27,7 +33,7 @@
* Batch requests with the service interface now inherit the service's connection
* `register_discover_document` now returns the API instance
* Added `:proxy` option to set Faraday's HTTP proxy setting
* Added `:faraday_options` option to allow passthrough settings to Faraday connection
* Added `:faraday_option` option to allow passthrough settings to Faraday connection
* Drop 1.8.x support
* This will be the last release with 1.9.x support

@@ -2,7 +2,7 @@

## Contributor License Agreements

We'd love to accept your sample apps and patches! Before we can take them, we
We'd love to accept your sample apps and patches! Before we can take them, we
have to jump a couple of legal hurdles.

Please fill out either the individual or corporate Contributor License Agreement
@@ -29,4 +29,3 @@ accept your pull requests.
1. Ensure that your code is clear and comprehensible.
1. Ensure that your code has an appropriate set of unit tests which all pass.
1. Submit a pull request.

30 Gemfile
@@ -1,9 +1,35 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in google-apis.gemspec
gemspec

gem 'jruby-openssl', :platforms => :jruby

group :development do
gem 'bundler', '~> 1.7'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.1'
gem 'json_spec', '~> 1.1'
gem 'webmock', '~> 1.21'
gem 'simplecov', '~> 0.9'
gem 'coveralls', '~> 0.7.11'
gem 'rubocop', '~> 0.29'
gem 'launchy', '~> 2.4'
end

platforms :jruby do
group :development do
gem 'jruby-openssl'
end
end

platforms :ruby do
group :development do
gem 'yard', '~> 0.8'
gem 'redcarpet', '~> 3.2'
gem 'github-markup', '~> 1.3'
end
end

if ENV['RAILS_VERSION']
gem 'rails', ENV['RAILS_VERSION']
end
end
@@ -0,0 +1,171 @@
# Migrating from version `0.8.x` to `0.9`

Many changes and improvements have been made to the `google-api-ruby-client`
library to bring it to `0.9`. If you are starting a new project or haven't used
this library before version `0.9`, see the [README][readme] to get started
as you won't need to migrate anything.

Code written against the `0.8.x` version of this library will not work with the `0.9`
version without modification.

## Discovery

In `0.8.x` the library would "discover" APIs on the fly, introducing
additional network calls and instability. That has been fixed in `0.9`.

To get the `drive` client in `0.8.x` required this:

```ruby
require 'google/api_client'
client = Google::APIClient.new
drive = client.discovered_api('drive', 'v2')
```

In `0.9` the same thing can be accomplished like this:

```ruby
require 'google/apis/drive_v2'
drive = Google::Apis::DriveV2::DriveService.new
```

All APIs are immediately accessible without requiring additional network calls or runtime code generation.

## API Methods

The calling style for API methods has changed. In `0.8.x` all calls were via a generic `execute` method. In `0.9`
the generated services have fully defined method signatures for all available methods.

To get a file using the Google Drive API in `0.8.x` required this:

```ruby
file = client.execute(:api_method => drive.file.get, :parameters => { 'id' => 'abc123' })
```

In `0.9` the same thing can be accomplished like this:

```ruby
file = drive.get_file('abc123')
```

Full API definitions including available methods, parameters, and data classes can be found in the `generated` directory.

## Authorization

In the 0.9 version of this library, the authentication and authorization code was moved
to the new [googleauth](https://github.com/google/google-auth-library-ruby) library. While the new library provides
significantly simpler APIs for some use cases, not all features have been migrated. Missing features
are expected to be added by end of Q2 2015.

The underlying [Signet](https://github.com/google/signet) is still used for authorization. OAuth 2 credentials obtained
previously will continue to work with the `0.9` version. OAuth 1 is no longer supported.

## Media uploads

Media uploads are significantly simpler in `0.9`.

The old `0.8.x` way of uploading media:

```ruby
media = Google::APIClient::UploadIO.new('mymovie.m4v', 'video/mp4')
metadata = {
'title' => 'My movie',
'description' => 'The best home movie ever made'
}
client.execute(:api_method => drive.files.insert,
:parameters => { 'uploadType' => 'multipart' },
:body_object => metadata,
:media => media )
```

The new way in `0.9` using `upload_source` and `content_type` parameters:

```ruby
metadata = {
title: 'My movie',
description: 'The best home movie ever made'
}
drive.insert_file(metadata, upload_source: 'mymovie.m4v', content_type: 'video/mp4')
```

`upload_source` can be either a path to a file, an `IO` stream, or a `StringIO` instance.

Uploads are resumable and will be automatically retried if interrupted.

## Media downloads

`0.9` introduces support for media downloads (`alt=media`). To download content, use the `download_dest` parameter:

```ruby
drive.get_file('abc123', download_dest: '/tmp/myfile.txt')
```

`download_dest` may be either a path to a file or an `IO` stream.

## Batch Requests

The old `0.8.x` way of performing batch requests:

```ruby
client = Google::APIClient.new
urlshortener = client.discovered_api('urlshortener')
batch = Google::APIClient::BatchRequest.new do |result|
puts result.data
end
batch.add(:api_method => urlshortener.url.insert,
:body_object => { 'longUrl' => 'http://example.com/foo' })
batch.add(:api_method => urlshortener.url.insert,
:body_object => { 'longUrl' => 'http://example.com/bar' })
client.execute(batch)
```

In `0.9`, the equivalent code is:

```ruby
require 'google/apis/urlshortner_v1'
urlshortener = Google::Apis::UrlshortenerV1::UrlshortenerService.new
urlshortener.batch do |urlshortener|
urlshortner.insert_url({long_url: 'http://example.com/foo'}) do |res, err|
puts res
end
urlshortner.insert_url({long_url: 'http://example.com/bar'}) do |res, err|
puts res
end
end
```

Or if sharing the same block:

```ruby
require 'google/apis/urlshortner_v1'
urlshortener = Google::Apis::UrlshortenerV1::UrlshortenerService.new
callback = lambda { |res, err| puts res }
urlshortener.batch do |urlshortener|
urlshortner.insert_url({long_url: 'http://example.com/foo'}, &callback)
urlshortner.insert_url({long_url: 'http://example.com/bar'}, &callback)
end
```

## JRuby

Jruby 1.7.4 in 2.0 compatibility mode is supported. To enable for a specific script:

```
jruby --2.0 myscript.rb
```

Or set as the default:

```
export JRUBY_OPTS=--2.0
```

JRuby 9000 will be supported once released.

0 comments on commit f584a2c

Please sign in to comment.
You can’t perform that action at this time.