google/google-api-ruby-client — pull request #87 by sgomes (2013-10-07 17:50:16+00:00)
Title: New programming interface for the client library

This CL introduces an experimental less verbose programming interface for the client library. It's built on the concept of a Service, which is tied to a specific version of an API. Everything happens through this service:

```ruby
plus = Google::APIClient::Service.new('plus', 'v1')
```

The service is populated with API methods in runtime, which can be used directly:

```ruby
result = plus.activities.list(:userId => 'me', :collection => 'public').execute
```

Requests with bodies are easily supported:

```ruby
prediction = Google::APIClient::Service.new('prediction', 'v1.6')
result =
prediction.trainedmodels.insert(:project => '...').body('id' => '...').execute
```

As well as media uploads:

```ruby
metadata = { 'title' => '...', 'description' => '...' }
media = Google::APIClient::UploadIO.new(file, 'text/plain')

drive = Google::APIClient::Service.new('drive', 'v1')
drive.files.insert(:uploadType => 'multipart').body(metadata).media(media).execute
```

Batch calls have been simplified too:

```ruby
discovery = Google::APIClient::Service.new('discovery', 'v1')
calls = [
discovery.apis.get_rest(:api => 'plus', :version => 'v1'),
discovery.apis.get_rest(:api => 'drive', :version => 'v1')
]
batch = discovery.batch(calls) do |result|
# Do something with each call's result
end
batch.execute
```

or

```ruby
discovery = Google::APIClient::Service.new('discovery', 'v1')
batch = discovery.batch

batch.add(discovery.apis.get_rest(:api => 'plus', :version => 'v1')) do |result|
# Do something with 'plus' call result
end

batch.add(discovery.apis.get_rest(:api => 'drive', :version => 'v1')) do |result|
# Do something with 'drive' call result
end

batch.execute
```

Authorization is handled by an ```authorization``` property, similarly to how it's done in APIClient. The Service constructor also takes a hash of options, so you can still pass in most existing options:

```ruby
plus = Google::APIClient::Service.new('plus', 'v1', {
:application_name => 'My app',
:application_version => '0.1',
:gzip => true
})

flow = Google::APIClient::InstalledAppFlow.new(
:client_id => '...',
:client_secret => '...',
:scope => 'https://www.googleapis.com/auth/plus.me'
)

plus.authorization = flow.authorize
```