google-apis 0.1.0 → 0.1.1

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: 73ecd62e8a070f3007d0a70e89fba19c10fc5add
4
- data.tar.gz: 07cdd1042f1446a7f7420269ac6b285d3188b7e3
3
+ metadata.gz: a7e91a00208cd6eccdb174d912834823f8e1238e
4
+ data.tar.gz: dd9df318acff7c25053e606bc1d0cf89e6084b4c
5
5
  SHA512:
6
- metadata.gz: 2fdd5bc568744355390ba7fa05aa1045aae105a8d05d6c2283234a6f73d471338654e7e3da8bd95eb55555d1fff085ac56e29e78fdf67bbd4d873c692fb68d63
7
- data.tar.gz: ddb5c0ac76e8232a72cfbc10113e8355995115516ba613c1c6c711778bac20229ef5b987f0a18edbd135713b6659d42eac8dc8f4c3bc8deb78e453b78d624e95
6
+ metadata.gz: 3938e0f06f08f049b874abebc73008781e56c33611260141517e8fc22bd81e507d0777528006218003834146dde2259a92b8f5d77b8a50feb63fbf1177e0ab2d
7
+ data.tar.gz: 028c5b6c2d45ec3de407a206462fd54320b0edae9a31667877d852a2bbb7117d3464c74f1ea62c7b8f6fb7979224c024d218f178f79cbde31e11f62340e69f4c
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,12 @@
1
1
  = Google APIs CHANGELOG
2
2
 
3
+ == Version 0.1.1 (February 10, 2015)
4
+
5
+ * Fixed bug: made options optional when invoking `.connect`
6
+ * Overridden GoogleApis::Connection.inspect for better info
7
+ * Fixed switching APIs using one global connection
8
+ * Being able to delegate resource invocation on API class to its connection
9
+
3
10
  == Version 0.1.0 (February 10, 2015)
4
11
 
5
12
  * Initial release
data/README.md CHANGED
@@ -18,11 +18,13 @@ The easiest setup is to define an application-wide Google API connection followe
18
18
 
19
19
  Make sure you have created a Client ID (application type "Service account") at your projects API credentials page (https://console.developers.google.com/project/your_project_id/apiui/credential).
20
20
 
21
+ Enable the API at your Console API page (https://console.developers.google.com/project/your_project_id/apiui/api).
22
+
21
23
  Do not forget to download the private key by generating a P12 key file.
22
24
 
23
25
  ```ruby
24
26
  [1] pry(main)> GoogleApis.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
25
- => true
27
+ => #<GoogleApis::Connection:0x007fa5a4743668 [lorem@developer.gserviceaccount.com]>
26
28
  [2] pry(main)> bq = Google::BigQuery.new :projectId => "your_project_id", :datasetId => "your_dataset_id"
27
29
  => #<Google::BigQuery:0x007fc5c68647a8 v2:[datasets,jobs,projects,tabledata,tables] {projectId:"your_project_id",datasetId:"your_dataset_id"}>
28
30
  [3] pry(main)> bq.tables.list
@@ -65,7 +67,9 @@ GoogleApis quickly displays the resources and methods a certain API provides.
65
67
  "scopes"=>["https://www.googleapis.com/auth/bigquery", "https://www.googleapis.com/auth/cloud-platform"]}
66
68
  ```
67
69
 
68
- #### Application-wide API connections (e.g. Google::BigQuery.connection)
70
+ #### Application-wide API connections
71
+
72
+ ##### Google::BigQuery.connection
69
73
 
70
74
  You can also configure an application-wide API connection. Let's say you also stored the connection configuration in `config/bigquery.yml`:
71
75
 
@@ -82,15 +86,53 @@ You can also configure an application-wide API connection. Let's say you also st
82
86
  => true
83
87
  [2] pry(main)> Google::BigQuery.connect YAML.load_file("config/bigquery.yml")
84
88
  => #<Google::BigQuery:0x007fdc1c6823b0 v2:[datasets,jobs,projects,tabledata,tables] {projectId:"your_project_id",datasetId:"your_dataset_id"}>
85
- [3] pry(main)> Google::BigQuery.connection.jobs
89
+ [3] pry(main)> Google::BigQuery.jobs
86
90
  => #<Google::BigQuery::Resource:0x007fdc1e94d5c0 v2:jobs:[get,getQueryResults,insert,list,query]>
87
- [4] pry(main)> Google::BigQuery.connection.select_rows "SELECT * FROM [your_dataset_id.awesome_table_19820801] LIMIT 2"
91
+ [4] pry(main)> Google::BigQuery.select_rows "SELECT * FROM [your_dataset_id.awesome_table_19820801] LIMIT 4"
88
92
  => [["1982-08-01", "Paul is awesome", "Paul", "Engel", 19],
89
93
  ["1982-08-01", "GoogleApis is cool", "Google", "Apis", 82],
90
94
  ["1982-08-01", "Hello world!", "Foo", "Bar", 8],
91
95
  ["1982-08-01", "Try out this gem :)", "It's", "very easy", 1]]
92
96
  ```
93
97
 
98
+ Please note that `Google::BigQuery.connection` is provided with several methods resembling ActiveRecord: `#select_rows`, `#select_values` and `#select_value`.
99
+
100
+ ##### Google::Drive.connection
101
+
102
+ 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).
103
+
104
+ ```ruby
105
+ [1] pry(main)> Google::Drive.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
106
+ => #<Google::Drive:0x007f83ee39fcc8 v2:[about,apps,changes,channels,children,comments,files,parents,permissions,properties,realtime,replies,revisions] {}>
107
+ [2] pry(main)> Google::Drive.files.list
108
+ => {"kind"=>"drive#fileList",
109
+ "etag"=>"\"4GaIn/LoR3M-1pSuM-D0loR-s1T-AM3t\"",
110
+ "selfLink"=>"https://www.googleapis.com/drive/v2/files",
111
+ "items"=>
112
+ [{"kind"=>"drive#file",
113
+ "id"=>"12-On3Tw0w4ntO0-0neTh0",
114
+ ...
115
+ ```
116
+
117
+ #### One Google API connection to rule them all
118
+
119
+ If it isn't already clear, you can specify a global Google API connection and use different APIs:
120
+
121
+ ```ruby
122
+ [1] pry(main)> GoogleApis.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
123
+ => #<GoogleApis::Connection:0x007ffe0aa95d70 [lorem@developer.gserviceaccount.com]>
124
+ [2] pry(main)> Google::Drive.connect
125
+ => #<Google::Drive:0x007fcfec1265b0 v2:[about,apps,changes,channels,children,comments,files,parents,permissions,properties,realtime,replies,revisions] {}>
126
+ [3] pry(main)> Google::Drive.files.list
127
+ => {"kind"=>"drive#fileList",
128
+ ...
129
+ [4] pry(main)> Google::BigQuery.connect :projectId => "your_project_id", :datasetId => "your_dataset_id"
130
+ => #<Google::BigQuery:0x007ffe0b1fb240 v2:[datasets,jobs,projects,tabledata,tables] {projectId:"your_project_id",datasetId:"your_dataset_id"}>
131
+ [5] pry(main)> Google::BigQuery.tables.list
132
+ => {"kind"=>"bigquery#tableList",
133
+ ...
134
+ ```
135
+
94
136
  ### Using the console
95
137
 
96
138
  The GoogleApis repo is provided with `script/console` which you can use for development / testing purposes.
@@ -100,8 +142,8 @@ Run the following command in your console:
100
142
  ```ruby
101
143
  $ script/console
102
144
  Loading Google APIs development environment (0.1.0)
103
- [1] pry(main)> GoogleApis.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
104
- => true
145
+ [1] pry(main)> GoogleApis.connect :email_address => "", :private_key => "/path/to/private/key.p12"
146
+ => #<GoogleApis::Connection:0x007ff3d356cbf0 [lorem@developer.gserviceaccount.com]>
105
147
  [2] pry(main)> bq = Google::BigQuery.new :projectId => "your_project_id", :datasetId => "your_dataset_id"
106
148
  => #<Google::BigQuery:0x007f8c09a05338 v2:[datasets,jobs,projects,tabledata,tables] {projectId:"your_project_id",datasetId:"your_dataset_id"}>
107
149
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -27,7 +27,7 @@ module GoogleApis
27
27
  end
28
28
  end
29
29
 
30
- def connect(options)
30
+ def connect(options = {})
31
31
  @connection = new(options)
32
32
  end
33
33
 
@@ -47,6 +47,14 @@ module GoogleApis
47
47
  name
48
48
  end
49
49
 
50
+ def method_missing(name, *args)
51
+ if connection && (connection.class.instance_methods(false).include?(name) || connection.send(:find, name))
52
+ connection.send(name, *args)
53
+ else
54
+ super
55
+ end
56
+ end
57
+
50
58
  end
51
59
  end
52
60
  end
@@ -16,7 +16,7 @@ module GoogleApis
16
16
 
17
17
  @asserter = Google::APIClient::JWTAsserter.new(
18
18
  options[:email_address],
19
- nil,
19
+ "",
20
20
  key
21
21
  )
22
22
  end
@@ -43,11 +43,15 @@ module GoogleApis
43
43
  parse! @client.execute(options)
44
44
  end
45
45
 
46
+ def inspect
47
+ "#<#{self.class}:#{object_hexid} [#{@asserter.issuer}]>"
48
+ end
49
+
46
50
  private
47
51
 
48
52
  def authenticate!(api)
49
- if !@client.authorization.access_token || @client.authorization.expired?
50
- @asserter.scope = api.auth_scope
53
+ if !@asserter.scope.include?(api.auth_scope) || @client.authorization.expired?
54
+ @asserter.scope = (@asserter.scope.split(" ") << api.auth_scope).uniq
51
55
  @client.authorization = @asserter.authorize
52
56
  end
53
57
  end
@@ -1,7 +1,7 @@
1
1
  module GoogleApis
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 0
4
+ TINY = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -13,7 +13,7 @@ module Unit
13
13
 
14
14
  File.expects(:open).with("< private_key >", "rb").returns("< file >")
15
15
  Google::APIClient::PKCS12.expects(:load_key).with("< file >", "notasecret").returns("< key >")
16
- Google::APIClient::JWTAsserter.expects(:new).with("< email_address >", nil, "< key >").returns("< asserter >")
16
+ Google::APIClient::JWTAsserter.expects(:new).with("< email_address >", "", "< key >").returns("< asserter >")
17
17
 
18
18
  connection = GoogleApis::Connection.new(
19
19
  :email_address => "< email_address >",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-apis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel