google-apis 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea78fc750c376284814fe0fb104144d9815a115b
4
- data.tar.gz: 25ea95f6f6c5aa5481a2edd48391a7e05cd0d4be
3
+ metadata.gz: b8abfe8e90b604e1864519024ff89a4202b9ff73
4
+ data.tar.gz: aee2ebae2543cba7bed7e20712be3d3d218cf249
5
5
  SHA512:
6
- metadata.gz: 796038a79d21bf2ff602b79c5f6fa15f905a51e80db9b3a28032f2918ef14b83d8b7041d2a0d502dc64936a3f4162f91b87b848ea96e2a3d4d29d7640bfd44cd
7
- data.tar.gz: 0a45ed7db4210bb5485b59652f7b4bbff757e39e91a690a85bbbeac43d595b778dd9acea2942f127354351c9c74c6ecc661c911e3dec867678afd6a79b983a73
6
+ metadata.gz: 773bbb888a374a15f06ef18dc6297251507d4b08e35781effd4268771c1d87ba4825fb0446563a9259a193b492125a9a718f009a6e79036270f9339cdc73a085
7
+ data.tar.gz: 7429aa5f1ca2848b5b87712c94d13a919008e771aad9200618755a35624ab2722d6a50ce8244b7b09e40b0bed5c2fa7c55ef20ef96ef76e60d5f9f6223a6d0d6
data/.gitignore CHANGED
@@ -6,6 +6,7 @@ Gemfile.lock
6
6
  doc
7
7
  pkg
8
8
  *.log
9
+ *.json
9
10
  *.p12
10
11
  *.yml
11
12
  test/coverage
@@ -1,5 +1,10 @@
1
1
  = Google APIs CHANGELOG
2
2
 
3
+ == Version 0.2.0 (December 31, 2017)
4
+
5
+ * Tackle gzip error for when using Faraday >= 0.9.2
6
+ * Solve "Invalid JWT Signature" by using JSON private key
7
+
3
8
  == Version 0.1.7 (July 16, 2015)
4
9
 
5
10
  * Respecting (optionally) passed :content_type or :mime_type option when dealing with upload media
data/README.md CHANGED
@@ -20,10 +20,10 @@ Make sure you have created a Client ID (application type "Service account") at y
20
20
 
21
21
  Enable the API at your Console API page (https://console.developers.google.com/project/your_project_id/apiui/api).
22
22
 
23
- Do not forget to download the private key by generating a P12 key file.
23
+ Do not forget to download the private key by generating a JSON key file.
24
24
 
25
25
  ```ruby
26
- [1] pry(main)> GoogleApis.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
26
+ [1] pry(main)> GoogleApis.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.json"
27
27
  => #<GoogleApis::Connection:0x007fa5a4743668 [lorem@developer.gserviceaccount.com]>
28
28
  [2] pry(main)> bq = Google::BigQuery.new :project_id => "your_project_id", :dataset_id => "your_dataset_id"
29
29
  => #<Google::BigQuery:0x007fc5c68647a8 v2:[datasets,jobs,projects,tabledata,tables] {projectId:"your_project_id",datasetId:"your_dataset_id"}>
@@ -76,7 +76,7 @@ You can also configure an application-wide API connection. Let's say you also st
76
76
  ```yaml
77
77
  ---
78
78
  email_address: lorem@developer.gserviceaccount.com
79
- private_key: "/path/to/private/key.p12"
79
+ private_key: "/path/to/private/key.json"
80
80
  project_id: your_project_id
81
81
  dataset_id: your_dataset_id
82
82
  ```
@@ -102,7 +102,7 @@ Please note that `Google::BigQuery.connection` is provided with several methods
102
102
  The following example demonstrates how to download and upload a file from Google Storage:
103
103
 
104
104
  ```ruby
105
- [1] pry(main)> Google::Storage.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
105
+ [1] pry(main)> Google::Storage.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.json"
106
106
  => #<Google::Storage:0x007fe522024f68 v1:[bucketAccessControls,buckets,channels,defaultObjectAccessControls,objectAccessControls,objects] {}>
107
107
  [2] pry(main)> metadata = Google::Storage.objects.list :bucket => "your-bucket", :prefix => "path/to/your/file/awesome.tsv"
108
108
  => {"kind"=>"storage#objects",
@@ -154,7 +154,7 @@ Easy, huh? :)
154
154
  Please make sure that you also have created a "Public API access" server key and added your IP to the allowed IPs at the [API credentials page](https://console.developers.google.com/project/your_project_id/apiui/credential).
155
155
 
156
156
  ```ruby
157
- [1] pry(main)> Google::Drive.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
157
+ [1] pry(main)> Google::Drive.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.json"
158
158
  => #<Google::Drive:0x007f83ee39fcc8 v2:[about,apps,changes,channels,children,comments,files,parents,permissions,properties,realtime,replies,revisions] {}>
159
159
  [2] pry(main)> Google::Drive.files.list
160
160
  => {"kind"=>"drive#fileList",
@@ -173,7 +173,7 @@ If it isn't already clear, you can specify a global Google API connection and us
173
173
  ```yaml
174
174
  ---
175
175
  email_address: lorem@developer.gserviceaccount.com
176
- private_key: "/path/to/private/key.p12"
176
+ private_key: "/path/to/private/key.json"
177
177
  project_id: your_project_id
178
178
  dataset_id: your_dataset_id
179
179
  bucket: your_bucket
@@ -205,8 +205,8 @@ Run the following command in your console:
205
205
 
206
206
  ```ruby
207
207
  $ script/console
208
- Loading Google APIs development environment (0.1.5)
209
- [1] pry(main)> GoogleApis.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
208
+ Loading Google APIs development environment (0.2.0)
209
+ [1] pry(main)> GoogleApis.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.json"
210
210
  => #<GoogleApis::Connection:0x007ff3d356cbf0 [lorem@developer.gserviceaccount.com]>
211
211
  [2] pry(main)> bq = Google::BigQuery.new :project_id => "your_project_id", :dataset_id => "your_dataset_id"
212
212
  => #<Google::BigQuery:0x007f8c09a05338 v2:[datasets,jobs,projects,tabledata,tables] {projectId:"your_project_id",datasetId:"your_dataset_id"}>
@@ -217,7 +217,7 @@ You can also define `script/config.yml` containing the connection config:
217
217
  ```yaml
218
218
  ---
219
219
  email_address: lorem@developer.gserviceaccount.com
220
- private_key: "/path/to/private/key.p12"
220
+ private_key: "/path/to/private/key.json"
221
221
  project_id: your_project_id
222
222
  dataset_id: your_dataset_id
223
223
  ```
@@ -226,7 +226,7 @@ And immediately start instantiating a Google API:
226
226
 
227
227
  ```ruby
228
228
  $ script/console
229
- Loading Google APIs development environment (0.1.5)
229
+ Loading Google APIs development environment (0.2.0)
230
230
  [1] pry(main)> Google::BigQuery.connection
231
231
  => #<Google::BigQuery:0x007fa6c9cc3450 v2:[datasets,jobs,projects,tabledata,tables] {projectId:"your_project_id",datasetId:"your_dataset_id"}>
232
232
  ```
@@ -248,11 +248,10 @@ Please feel free to fork this repository and send in pull requests to help impro
248
248
  ### TODO
249
249
 
250
250
  * Add more Google API definitions (see [google-apis/lib/google_apis/api](https://github.com/archan937/google-apis/tree/master/lib/google_apis/api))
251
- * Add more tests
252
251
 
253
252
  ### License
254
253
 
255
- Copyright (c) 2015 Paul Engel, released under the MIT License
254
+ Copyright (c) 2017 Paul Engel, released under the MIT License
256
255
 
257
256
  http://github.com/archan937 – http://twitter.com/archan937 – http://gettopup.com – pm_engel@icloud.com
258
257
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.2.0
@@ -1,4 +1,5 @@
1
1
  require "google/api_client"
2
+ require "googleauth"
2
3
 
3
4
  require "google_apis/core_ext"
4
5
  require "google_apis/connection"
@@ -24,4 +25,11 @@ module GoogleApis
24
25
 
25
26
  end
26
27
 
28
+ # Use httpclient to avoid broken pipe errors with large uploads
27
29
  Faraday.default_adapter = :httpclient
30
+
31
+ # Only add the following statement if using Faraday >= 0.9.2
32
+ # Override gzip middleware with no-op for httpclient
33
+ if (Faraday::VERSION.split(".").collect(&:to_i) <=> [0, 9, 2]) > -1
34
+ Faraday::Response.register_middleware :gzip => Faraday::Response::Middleware
35
+ end
@@ -12,15 +12,9 @@ module GoogleApis
12
12
  :application_version => GoogleApis::VERSION
13
13
  )
14
14
 
15
- key = Google::APIClient::PKCS12.load_key(
16
- File.open(options[:private_key], "rb"),
17
- options[:passphrase] || "notasecret"
18
- )
19
-
20
- @asserter = Google::APIClient::JWTAsserter.new(
21
- options[:email_address],
22
- "",
23
- key
15
+ @client.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
16
+ json_key_io: File.open(options[:private_key], "rb"),
17
+ scope: []
24
18
  )
25
19
  end
26
20
 
@@ -79,9 +73,9 @@ module GoogleApis
79
73
  end
80
74
 
81
75
  def authenticate!(api)
82
- if !@asserter.scope.include?(api.auth_scope) || @client.authorization.expired?
83
- @asserter.scope = (@asserter.scope.split(" ") << api.auth_scope).uniq
84
- @client.authorization = @asserter.authorize
76
+ if !@client.authorization.scope.include?(api.auth_scope) || @client.authorization.expired?
77
+ @client.authorization.scope.push(api.auth_scope).uniq!
78
+ @client.authorization.fetch_access_token!
85
79
  end
86
80
  end
87
81
 
@@ -1,7 +1,7 @@
1
1
  module GoogleApis
2
2
  MAJOR = 0
3
- MINOR = 1
4
- TINY = 7
3
+ MINOR = 2
4
+ TINY = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -6,22 +6,23 @@ module Unit
6
6
  describe GoogleApis::Connection do
7
7
  describe "#initialize" do
8
8
  it "instantiates a Google::APIClient and Google::APIClient::JWTAsserter" do
9
+ client = mock()
10
+ client.expects(:authorization=).with("< authorization >")
11
+
9
12
  Google::APIClient.expects(:new).with({
10
13
  :application_name => "rubygem:google-apis",
11
14
  :application_version => GoogleApis::VERSION
12
- }).returns("< client >")
15
+ }).returns(client)
13
16
 
14
17
  File.expects(:open).with("< private_key >", "rb").returns("< file >")
15
- Google::APIClient::PKCS12.expects(:load_key).with("< file >", "notasecret").returns("< key >")
16
- Google::APIClient::JWTAsserter.expects(:new).with("< email_address >", "", "< key >").returns("< asserter >")
18
+ Google::Auth::ServiceAccountCredentials.expects(:make_creds).returns("< authorization >")
17
19
 
18
20
  connection = GoogleApis::Connection.new(
19
21
  :email_address => "< email_address >",
20
22
  :private_key => "< private_key >"
21
23
  )
22
24
 
23
- assert_equal "< client >", connection.instance_variable_get(:@client)
24
- assert_equal "< asserter >", connection.instance_variable_get(:@asserter)
25
+ assert_equal client, connection.instance_variable_get(:@client)
25
26
  end
26
27
  end
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-apis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  version: '0'
185
185
  requirements: []
186
186
  rubyforge_project:
187
- rubygems_version: 2.4.3
187
+ rubygems_version: 2.4.5.1
188
188
  signing_key:
189
189
  specification_version: 4
190
190
  summary: A thin layer on top of Google::APIClient (google-api-client) for a more intuitive
@@ -200,4 +200,3 @@ test_files:
200
200
  - test/unit/core_ext/test_kernel.rb
201
201
  - test/unit/test_connection.rb
202
202
  - test/unit/test_google_apis.rb
203
- has_rdoc: