google-apis 0.1.1 → 0.1.2

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: a7e91a00208cd6eccdb174d912834823f8e1238e
4
- data.tar.gz: dd9df318acff7c25053e606bc1d0cf89e6084b4c
3
+ metadata.gz: b8d1add3229c971662ab77620ca8b6a11021803e
4
+ data.tar.gz: ba08f0e27722cc5055ab23c6142777e7edbc2b60
5
5
  SHA512:
6
- metadata.gz: 3938e0f06f08f049b874abebc73008781e56c33611260141517e8fc22bd81e507d0777528006218003834146dde2259a92b8f5d77b8a50feb63fbf1177e0ab2d
7
- data.tar.gz: 028c5b6c2d45ec3de407a206462fd54320b0edae9a31667877d852a2bbb7117d3464c74f1ea62c7b8f6fb7979224c024d218f178f79cbde31e11f62340e69f4c
6
+ metadata.gz: 13de4d3734a4c18d8534c69478c2ce988648be0deb0475a3743343c6fd1e9f02bcdd13b9b96617a9f7de156dda5aed9683d1fbe6537c6b03a659e6d30187c70c
7
+ data.tar.gz: 83788437def396e77c72749567e75a54f570c14db8a1c0f2b2cced2bba0b9c7d5da98d94fda08b7cb785dfab780aa028761568565887128b2098a754d5004f15
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  = Google APIs CHANGELOG
2
2
 
3
+ == Version 0.1.2 (April 17, 2015)
4
+
5
+ * Added Google Storage API definition
6
+ * Being able to download files from Google Storage ^^
7
+
3
8
  == Version 0.1.1 (February 10, 2015)
4
9
 
5
10
  * Fixed bug: made options optional when invoking `.connect`
data/README.md CHANGED
@@ -97,6 +97,41 @@ You can also configure an application-wide API connection. Let's say you also st
97
97
 
98
98
  Please note that `Google::BigQuery.connection` is provided with several methods resembling ActiveRecord: `#select_rows`, `#select_values` and `#select_value`.
99
99
 
100
+ ##### Google::Storage.connection
101
+
102
+ The following example demonstrates how to download a file from Google Storage:
103
+
104
+ ```ruby
105
+ [1] pry(main)> Google::Storage.connect :email_address => "lorem@developer.gserviceaccount.com", :private_key => "/path/to/private/key.p12"
106
+ => #<Google::Storage:0x007fe522024f68 v1:[bucketAccessControls,buckets,channels,defaultObjectAccessControls,objectAccessControls,objects] {}>
107
+ [2] pry(main)> metadata = Google::Storage.objects.list :bucket => "your-bucket", :prefix => "path/to/your/file/awesome.tsv"
108
+ => {"kind"=>"storage#objects",
109
+ "items"=>
110
+ [{"kind"=>"storage#object",
111
+ "id"=>"your-bucket/path/to/your/file/awesome.tsv/1425499569141000",
112
+ "selfLink"=>"https://www.googleapis.com/storage/v1/b/your-bucket/o/path%2Fto%2Fyour%2Ffile%2Fawesome.tsv",
113
+ "name"=>"path/to/your/file/awesome.tsv",
114
+ "bucket"=>"your-bucket",
115
+ "generation"=>"1425499569141000",
116
+ "metageneration"=>"1",
117
+ "contentType"=>"text/tab-separated-values",
118
+ "updated"=>"2015-03-04T20:06:09.141Z",
119
+ "storageClass"=>"STANDARD",
120
+ "size"=>"5592792",
121
+ "md5Hash"=>"od4vAFihlDLs1k9kgo+U4CXhQ==",
122
+ "mediaLink"=>"https://www.googleapis.com/download/storage/v1/b/your-bucket/o/path%2Fto%2Fyour%2Ffile%2Fawesome.tsv?generation=1425499569141000&alt=media",
123
+ "owner"=>{"entity"=>"user-00b4903a97b10389ce680ca45ba5999e068c4d0c8ccbbfbb7094238bc85a567", "entityId"=>"00b4903a97b20004ce680ca5f5aeebe068c4d0c8ccbbfbb7094266d1b9787457"},
124
+ "crc32c"=>"P4UlsJQ==",
125
+ "etag"=>"EN93lyNu/j8QCEAE="}]}
126
+ [3] pry(main)> Google::Storage.download metadata["items"][0]["mediaLink"]
127
+ => 5592792
128
+ [4] pry(main)> puts `ls -l | grep awesome`
129
+ -rw-rw-r-- 1 paulengel paulengel 5592792 Apr 17 16:38 awesome.tsv
130
+ => nil
131
+ ```
132
+
133
+ Easy, huh? :)
134
+
100
135
  ##### Google::Drive.connection
101
136
 
102
137
  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).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/google-apis.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "google-apis"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = GoogleApis::VERSION
17
+ gem.licenses = ["MIT"]
17
18
 
18
19
  gem.add_dependency "google-api-client", "~> 0.8.2"
19
20
 
@@ -2,3 +2,4 @@ require "google_apis/api/base"
2
2
  require "google_apis/api/big_query"
3
3
  require "google_apis/api/drive"
4
4
  require "google_apis/api/plus"
5
+ require "google_apis/api/storage"
@@ -28,11 +28,15 @@ module GoogleApis
28
28
  end
29
29
 
30
30
  def connect(options = {})
31
- @connection = new(options)
31
+ @instance = new(options)
32
+ end
33
+
34
+ def instance
35
+ @instance
32
36
  end
33
37
 
34
38
  def connection
35
- @connection
39
+ instance
36
40
  end
37
41
 
38
42
  def name
@@ -48,8 +52,8 @@ module GoogleApis
48
52
  end
49
53
 
50
54
  def method_missing(name, *args)
51
- if connection && (connection.class.instance_methods(false).include?(name) || connection.send(:find, name))
52
- connection.send(name, *args)
55
+ if instance && (instance.respond_to?(name) || instance.send(:find, name))
56
+ instance.send(name, *args)
53
57
  else
54
58
  super
55
59
  end
@@ -22,6 +22,10 @@ module GoogleApis
22
22
  connection.execute self.class, api_method, *params
23
23
  end
24
24
 
25
+ def download(uri, to = nil)
26
+ connection.download self.class, uri, to
27
+ end
28
+
25
29
  def inspect
26
30
  "#<#{self.class}:#{object_hexid} #{discovered_api.version}:[#{discovered_api.discovered_resources.collect(&:name).sort.join(",")}] {#{@default_params.collect{|k, v| "#{k}:#{v.inspect}"}.join(",")}}>"
27
31
  end
@@ -0,0 +1,12 @@
1
+ module GoogleApis
2
+ class Api
3
+ class Storage
4
+ extend Base
5
+
6
+ api "storage"
7
+ version 1
8
+ auth_scope "https://www.googleapis.com/auth/devstorage.read_write"
9
+
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,5 @@
1
+ require "uri"
2
+
1
3
  module GoogleApis
2
4
  class Connection
3
5
 
@@ -43,6 +45,17 @@ module GoogleApis
43
45
  parse! @client.execute(options)
44
46
  end
45
47
 
48
+ def download(api, uri, to = nil)
49
+ authenticate!(api)
50
+
51
+ response = @client.execute Google::APIClient::Request.new(:uri => uri)
52
+ to ||= File.basename CGI.unescape(URI.parse(uri).path)
53
+
54
+ File.open(to, "wb") do |file|
55
+ file.write response.body
56
+ end
57
+ end
58
+
46
59
  def inspect
47
60
  "#<#{self.class}:#{object_hexid} [#{@asserter.issuer}]>"
48
61
  end
@@ -1,7 +1,7 @@
1
1
  module GoogleApis
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 1
4
+ TINY = 2
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  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.1
4
+ version: 0.1.2
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-02-10 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -133,6 +133,7 @@ files:
133
133
  - lib/google_apis/api/big_query.rb
134
134
  - lib/google_apis/api/drive.rb
135
135
  - lib/google_apis/api/plus.rb
136
+ - lib/google_apis/api/storage.rb
136
137
  - lib/google_apis/connection.rb
137
138
  - lib/google_apis/core_ext.rb
138
139
  - lib/google_apis/core_ext/hash.rb
@@ -150,7 +151,8 @@ files:
150
151
  - test/unit/test_connection.rb
151
152
  - test/unit/test_google_apis.rb
152
153
  homepage: https://github.com/archan937/google-apis
153
- licenses: []
154
+ licenses:
155
+ - MIT
154
156
  metadata: {}
155
157
  post_install_message:
156
158
  rdoc_options: []
@@ -168,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  version: '0'
169
171
  requirements: []
170
172
  rubyforge_project:
171
- rubygems_version: 2.2.2
173
+ rubygems_version: 2.4.3
172
174
  signing_key:
173
175
  specification_version: 4
174
176
  summary: A thin layer on top of Google::APIClient (google-api-client) for a more intuitive