simple_google_drive 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84776c7a234eb7a66c4090869f9b64ea4a870d84
4
+ data.tar.gz: fba3c290c5028fbbb3950221e893ca0cc9754070
5
+ SHA512:
6
+ metadata.gz: 98a189859a7c10888692d774c3c1d11273c8ae45aa808a9824162d0bc06462c1946293b8fd04e336a780a9cf906c9c1e7c4bbc2fb6a339887450cfc91913ed56
7
+ data.tar.gz: 614edf0063a245424d0eb347483ce389d95571bf4ca53032887986094163c8c9467fb6fdf7ac0d171b72d61638b1519fd6469a35f313e23494e63407c92fe169
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ script: bundle exec rspec spec
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.0.0
6
+ addons:
7
+ code_climate:
8
+ repo_token: e3d4eec75183e6e43fedbde89ff6c9d138da09ed465c59d52108102c44f47cf7
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'mime-types'
6
+
7
+ group :development, :test do
8
+ gem 'rspec'
9
+ gem 'webmock'
10
+ end
11
+
12
+ group :test do
13
+ gem "codeclimate-test-reporter", :require => false
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Guilherme Vinicius Moreira
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,153 @@
1
+
2
+ # SimpleGoogleDrive
3
+
4
+ [![Build Status](https://travis-ci.org/guivinicius/simple_google_drive.png?branch=master)](https://travis-ci.org/guivinicius/simple_google_drive)
5
+ [![Code Climate](https://codeclimate.com/repos/52d5408f6956800ac6002687/badges/d52569719f4be221b7e5/gpa.png)](https://codeclimate.com/repos/52d5408f6956800ac6002687/feed)
6
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/guivinicius/simple_google_drive/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
7
+
8
+ A simple interface for Google Drive API
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'simple_google_drive'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install simple_google_drive
23
+
24
+ ## Getting Started
25
+
26
+ You need to create a new object and then call its methods. Simple like that.
27
+
28
+ ```ruby
29
+ oauth2_access_token = "YOUR ACCESS TOKEN"
30
+ client = SimpleGoogleDrive.new(oauth2_access_token)
31
+ client.about
32
+ ```
33
+
34
+ ## Methods
35
+
36
+ Each method name was made to be compliant with Google Drive API reference.
37
+
38
+ https://developers.google.com/drive/v2/reference/
39
+
40
+ ### About
41
+
42
+ ```ruby
43
+ client.about
44
+ # => {"kind": "drive#about", ... }
45
+ ```
46
+
47
+ ### Files methods
48
+
49
+ * **FILES_GET** (https://developers.google.com/drive/v2/reference/files/get)
50
+
51
+ ```ruby
52
+ optional_params = {:updateViewedDate => true}
53
+ client.files_get(file_id, optional_params)
54
+ ```
55
+
56
+ * **FILES_INSERT** (https://developers.google.com/drive/v2/reference/files/insert)
57
+
58
+ This method is only for metadata-only requests not to upload files.
59
+
60
+ ```ruby
61
+ body = {:title => "A thesis about how awesome I am", :description => "No need!", }
62
+ optional_params = { :convert => true, :ocr => true }
63
+ client.files_insert(body, optional_params)
64
+ ```
65
+
66
+ * **FILES_UPLOAD** (https://developers.google.com/drive/manage-uploads)
67
+
68
+ Supporting only: **simple** and **multipart** uploads for now.
69
+
70
+ **Simple Upload Example**
71
+
72
+ ```ruby
73
+ file_object = File.open("/tmp/awesome.pdf")
74
+ args = {:uploadType => 'media'}
75
+ client.files_upload(file_object, args)
76
+ ```
77
+
78
+ **Multipart Upload Example**
79
+
80
+ ```ruby
81
+ file_object = File.open("/tmp/awesome.pdf")
82
+ args = {:uploadType => 'multipart', :body_object => {:title => "A thesis about how awesome I am", :description => "Ok! It needs!" }}
83
+ client.files_upload(file_object, args)
84
+ ```
85
+
86
+ * **FILES_PATCH** (https://developers.google.com/drive/v2/reference/files/patch)
87
+
88
+ ```ruby
89
+ body = {:title => "A thesis about how awesome I am", :description => "Ok! It needs!" }
90
+ optional_params = { :convert => true, :ocr => true }
91
+ client.files_patch(file_id, body, optional_params)
92
+ ```
93
+
94
+ * **FILES_COPY** (https://developers.google.com/drive/v2/reference/files/copy)
95
+
96
+ ```ruby
97
+ body = {:title => "A thesis about how awesome I am (copy)", :description => "Ok! It needs!" }
98
+ optional_params = { :convert => true, :ocr => true }
99
+ client.files_copy(file_id, body, optional_params)
100
+ ```
101
+
102
+ * **FILES_DELETE** (https://developers.google.com/drive/v2/reference/files/delete)
103
+
104
+ ```ruby
105
+ client.files_delete(file_id)
106
+ ```
107
+
108
+ * **FILES_LIST** (https://developers.google.com/drive/v2/reference/files/list)
109
+
110
+ The most important part of this method is the search parameters and you can find more at https://developers.google.com/drive/search-parameters
111
+
112
+ ```ruby
113
+ optional_params = {:maxResults => 10, :q => "title = 'awesome'"}
114
+ client.files_list(optional_params)
115
+ ```
116
+
117
+ * **FILES_TOUCH** (https://developers.google.com/drive/v2/reference/files/touch)
118
+
119
+ ```ruby
120
+ client.files_touch(file_id)
121
+ ```
122
+
123
+ * **FILES_TRASH** (https://developers.google.com/drive/v2/reference/files/trash)
124
+
125
+ ```ruby
126
+ client.files_trash(file_id)
127
+ ```
128
+
129
+ * **FILES_UNTRASH** (https://developers.google.com/drive/v2/reference/files/untrash)
130
+
131
+ ```ruby
132
+ client.files_untrash(file_id)
133
+ ```
134
+
135
+ * **FILES_WATCH** (https://developers.google.com/drive/v2/reference/files/watch)
136
+
137
+ ```ruby
138
+ client.files_watch(file_id)
139
+ ```
140
+
141
+ ## Todo's
142
+
143
+ * Implement authenticantion flow
144
+ * Implementing more methods
145
+ * Improve test suite
146
+
147
+ ## Contributing
148
+
149
+ 1. Fork it ( http://github.com/guivinicius/simple_google_drive/fork )
150
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
151
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
152
+ 4. Push to the branch (`git push origin my-new-feature`)
153
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,131 @@
1
+ module SimpleGoogleDrive
2
+
3
+ class Client < SessionBase
4
+
5
+ attr_accessor :access_token
6
+
7
+ def initialize(oauth2_access_token)
8
+
9
+ if oauth2_access_token.is_a?(String)
10
+ @access_token = oauth2_access_token
11
+ else
12
+ raise ArgumentError, "oauth2_access_token doesn't have a valid type"
13
+ end
14
+
15
+ end
16
+
17
+ public
18
+
19
+ def about
20
+ url = build_url("/about")
21
+ request = build_request(url)
22
+ response = send_request(url, request)
23
+
24
+ parse_response(response)
25
+ end
26
+
27
+ def files_get(file_id, params = nil)
28
+ url = build_url("/files/#{file_id}", params)
29
+ request = build_request(url)
30
+ response = send_request(url, request)
31
+
32
+ parse_response(response)
33
+ end
34
+
35
+ def files_insert(body = {}, params = nil)
36
+ url = build_url("/files", params)
37
+ request = build_request(url, 'post', body.to_json)
38
+ response = send_request(url, request)
39
+
40
+ parse_response(response)
41
+ end
42
+
43
+ def files_upload(file_object, args = {})
44
+ raise ArgumentError, "Invalid upload type. Choose between media, multipart or resumable." if args[:uploadType].nil?
45
+
46
+ case args[:uploadType].to_s
47
+ when 'media'
48
+ body = file_object
49
+ content_type = MIME::Types.type_for(file_object.path).first.to_s
50
+ when 'multipart'
51
+ body = build_multipart_body(file_object, args[:body_object])
52
+ content_type = "multipart/related;boundary=simple_google_drive_boundary"
53
+ when 'resumable'
54
+ body = build_resumable_body(file_object, args[:body_object])
55
+ content_type = ""
56
+ end
57
+
58
+ url = build_url("/files", args[:parameters], true)
59
+ request = build_request(url, 'post', body, content_type)
60
+ response = send_request(url, request)
61
+
62
+ parse_response(response)
63
+ end
64
+
65
+ def files_patch(file_id, body = nil, params = nil)
66
+ url = build_url("/files/#{file_id}", params)
67
+ request = build_request(url, 'patch', body)
68
+ response = send_request(url, request)
69
+
70
+ parse_response(response)
71
+ end
72
+
73
+ def files_copy(file_id, body = nil, params = nil)
74
+ url = build_url("/files/#{file_id}/copy", params)
75
+ request = build_request(url, 'post', body)
76
+ response = send_request(url, request)
77
+
78
+ parse_response(response)
79
+ end
80
+
81
+ def files_delete(file_id)
82
+ url = build_url("/files/#{file_id}")
83
+ request = build_request(url, 'delete')
84
+ response = send_request(url, request)
85
+
86
+ parse_response(response)
87
+ end
88
+
89
+ def files_list(params = nil)
90
+ url = build_url("/files", params)
91
+ request = build_request(url)
92
+ response = send_request(url, request)
93
+
94
+ parse_response(response)
95
+ end
96
+
97
+ def files_touch(file_id)
98
+ url = build_url("/files/#{file_id}/touch")
99
+ request = build_request(url, 'post')
100
+ response = send_request(url, request)
101
+
102
+ parse_response(response)
103
+ end
104
+
105
+ def files_trash(file_id)
106
+ url = build_url("/files/#{file_id}/trash")
107
+ request = build_request(url, 'post')
108
+ response = send_request(url, request)
109
+
110
+ parse_response(response)
111
+ end
112
+
113
+ def files_untrash(file_id)
114
+ url = build_url("/files/#{file_id}/untrash")
115
+ request = build_request(url, 'post')
116
+ response = send_request(url, request)
117
+
118
+ parse_response(response)
119
+ end
120
+
121
+ def files_watch(file_id, body = nil)
122
+ url = build_url("/files/#{file_id}/watch")
123
+ request = build_request(url, 'post', body.to_json)
124
+ response = send_request(url, request)
125
+
126
+ parse_response(response)
127
+ end
128
+
129
+ end
130
+
131
+ end
@@ -0,0 +1,114 @@
1
+ module SimpleGoogleDrive
2
+
3
+ class SessionBase
4
+
5
+ private
6
+
7
+ def build_url(path, params = nil, upload = false)
8
+ url = URI.parse("#{ upload ? API_UPLOAD_URL : API_BASE_URL }#{path}")
9
+ url.query = URI.encode_www_form(params) if !params.nil?
10
+
11
+ return url
12
+ end
13
+
14
+ def build_request(url, method = 'get', body = nil, content_type = nil)
15
+
16
+ default_headers = {'User-Agent' => "Ruby/SimpleGoogleDrive/#{SimpleGoogleDrive::VERSION}", 'Authorization' => "Bearer #{@access_token}"}
17
+
18
+ case method
19
+ when 'get'
20
+ req = Net::HTTP::Get.new(url, default_headers)
21
+ when 'patch'
22
+ req = Net::HTTP::Patch.new(url, default_headers)
23
+ when 'post'
24
+ req = Net::HTTP::Post.new(url, default_headers)
25
+ when 'delete'
26
+ req = Net::HTTP::Delete.new(url, default_headers)
27
+ end
28
+
29
+ if !body.nil?
30
+ if body.is_a?(Hash)
31
+ req.set_form_data(body)
32
+ elsif body.respond_to?(:read)
33
+ if body.respond_to?(:length)
34
+ req["Content-Length"] = body.length.to_s
35
+ elsif body.respond_to?(:stat) && body.stat.respond_to?(:size)
36
+ req["Content-Length"] = body.stat.size.to_s
37
+ else
38
+ raise ArgumentError, "Don't know how to handle 'body' (responds to 'read' but not to 'length' or 'stat.size')."
39
+ end
40
+ req.body_stream = body
41
+ req["Content-Type"]= content_type
42
+ else
43
+ s = body.to_s
44
+ req["Content-Length"] = s.length
45
+ req["Content-Type"] = content_type
46
+ req.body = s
47
+ end
48
+
49
+ end
50
+
51
+ return req
52
+ end
53
+
54
+ def send_request(url, request)
55
+
56
+ http = Net::HTTP.new(url.host, url.port)
57
+ http.use_ssl = true
58
+
59
+ begin
60
+ response = http.request(request)
61
+ rescue Exception => e
62
+ raise "Something wrong with the http response: #{e}"
63
+ end
64
+
65
+ end
66
+
67
+ def parse_response(response)
68
+ return "" if response.body.nil?
69
+
70
+ if response.kind_of?(Net::HTTPServerError)
71
+ raise "Google Drive Server Error: #{response} - #{response.body}"
72
+ elsif response.kind_of?(Net::HTTPUnauthorized)
73
+ raise "User is not authenticated."
74
+ elsif not response.kind_of?(Net::HTTPSuccess)
75
+ begin
76
+ d = JSON.parse(response.body)
77
+ rescue
78
+ raise "Server Error: response=#{response}"
79
+ end
80
+ end
81
+
82
+ begin
83
+ JSON.parse(response.body)
84
+ rescue JSON::ParserError
85
+ raise "Unable to parse JSON response: #{response.body}"
86
+ end
87
+
88
+ end
89
+
90
+ def build_multipart_body(file_object, body_object)
91
+ content_type = MIME::Types.type_for(file_object.path).first.to_s
92
+
93
+ body = <<-eos
94
+ --simple_google_drive_boundary
95
+ Content-Type: application/json; charset=UTF-8
96
+
97
+ #{body_object.to_json}
98
+
99
+ --simple_google_drive_boundary
100
+ Content-Type: #{content_type}
101
+
102
+ #{file_object.read}
103
+
104
+ --simple_google_drive_boundary--
105
+ eos
106
+ end
107
+
108
+ def build_resumable_body(file_object, body_object)
109
+
110
+ end
111
+
112
+ end
113
+
114
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleGoogleDrive
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'mime/types'
5
+
6
+ require 'simple_google_drive/version'
7
+ require 'simple_google_drive/session_base'
8
+ require 'simple_google_drive/client'
9
+
10
+ module SimpleGoogleDrive
11
+
12
+ API_HOST = "www.googleapis.com"
13
+ API_VERSION = "2"
14
+ API_UPLOAD_URL = "https://#{API_HOST}/upload/drive/v#{API_VERSION}"
15
+ API_BASE_URL = "https://#{API_HOST}/drive/v#{API_VERSION}"
16
+
17
+ def self.new(oauth2_access_token)
18
+ Client.new(oauth2_access_token)
19
+ end
20
+
21
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_google_drive/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_google_drive"
8
+ spec.version = SimpleGoogleDrive::VERSION
9
+ spec.authors = ["Guilherme Vinicius Moreira"]
10
+ spec.email = ["gui.vinicius@gmail.com"]
11
+ spec.summary = "A simple interface for Google Drive API"
12
+ spec.description = "A simple interface for Google Drive API"
13
+ spec.homepage = "https://github.com/guivinicius/simple_google_drive"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,230 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleGoogleDrive::Client do
4
+
5
+ let(:oauth2_access_token) { "1/fFBGRNJru1FQd44AzqT3Zg" }
6
+ let(:client) { SimpleGoogleDrive.new(oauth2_access_token) }
7
+ let(:headers) {
8
+ {
9
+ "Accept" => "*/*",
10
+ "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
11
+ "Authorization"=>"Bearer #{oauth2_access_token}",
12
+ "Host" => "www.googleapis.com",
13
+ "User-Agent" => "Ruby/SimpleGoogleDrive/#{SimpleGoogleDrive::VERSION}"
14
+ }
15
+ }
16
+
17
+ describe "#about" do
18
+
19
+ it "returns the user information" do
20
+ stub_request(:get, "#{SimpleGoogleDrive::API_BASE_URL}/about")
21
+ .with(:headers => headers)
22
+ .to_return(:status => 200, :body => '{"kind": "drive#about"}')
23
+
24
+ expect(client.about).to eq(JSON.parse('{"kind": "drive#about"}'))
25
+ end
26
+
27
+ end
28
+
29
+ describe "#files" do
30
+
31
+ let(:file_id) { 159 }
32
+
33
+ describe "#get" do
34
+ it "returns a file's metadata by ID" do
35
+ stub_request(:get, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}")
36
+ .with(:headers => headers)
37
+ .to_return(:status => 200, :body => '{"kind": "drive#files"}')
38
+
39
+ expect(client.files_get(file_id)).to eq(JSON.parse('{"kind": "drive#files"}'))
40
+ end
41
+
42
+ it "returns a file's metadata by ID with updateViewedDate param" do
43
+ stub_request(:get, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}")
44
+ .with(:query => {:updateViewedDate => "true"}, :headers => headers)
45
+ .to_return(:status => 200, :body => '{"kind": "drive#files"}')
46
+
47
+ expect(client.files_get(file_id, :updateViewedDate => true)).to eq(JSON.parse('{"kind": "drive#files"}'))
48
+ end
49
+
50
+ end
51
+
52
+ describe "#insert" do
53
+
54
+ it "Insert a new file and return it's metadata." do
55
+
56
+ request_body = '{"title":"New file from insert","description":"Blank file!"}'
57
+ response_body = '{"kind": "drive#files", "title": "New file from insert", "description": "Blank file!"}'
58
+
59
+ body = {:title => "New file from insert", :description => "Blank file!"}
60
+ params = { :convert => "true" }
61
+
62
+ stub_request(:post, "#{SimpleGoogleDrive::API_BASE_URL}/files")
63
+ .with(:query => params, :body => request_body, :headers => headers)
64
+ .to_return(:status => 200, :body => response_body)
65
+
66
+ expect(client.files_insert(body, params)).to eq(JSON.parse(response_body))
67
+
68
+ end
69
+
70
+ end
71
+
72
+ describe "#upload" do
73
+
74
+ let (:file_path) { File.expand_path("spec/support/example.txt") }
75
+ let (:file_obj) { File.open(file_path) }
76
+
77
+ it "returns it's metadata using 'simple' method" do
78
+
79
+ response_body = '{"kind": "drive#files", "title": "example.txt"}'
80
+ params = { :uploadType => "media", :parameters => { :convert => true} }
81
+
82
+ stub_request(:post, "#{SimpleGoogleDrive::API_UPLOAD_URL}/files")
83
+ .with(:query => {:convert => 'true'}, :body => /.+/, :headers => headers.merge({'Content-Type' => 'text/plain'}))
84
+ .to_return(:status => 200, :body => response_body)
85
+
86
+ expect(client.files_upload(file_obj, params)).to eq(JSON.parse(response_body))
87
+
88
+ end
89
+
90
+ it "returns it's metadata using 'multipart' method" do
91
+ params = { :uploadType => "multipart", :parameters => { :convert => true }, :body_object => { :title => "example2.txt", :description => "something" } }
92
+
93
+ request_body = <<-eos
94
+ --simple_google_drive_boundary
95
+ Content-Type: application/json; charset=UTF-8
96
+
97
+ #{params[:body_object].to_json}
98
+
99
+ --simple_google_drive_boundary
100
+ Content-Type: text/plain
101
+
102
+ #{file_obj.read}
103
+
104
+ --simple_google_drive_boundary--
105
+ eos
106
+
107
+ response_body = '{"kind": "drive#files", "title": "example2.txt", "description": "something"}'
108
+
109
+ stub_request(:post, "#{SimpleGoogleDrive::API_UPLOAD_URL}/files")
110
+ .with(:query => {:convert => 'true'}, :body => request_body, :headers => headers.merge({'Content-Type' => 'multipart/related;boundary=simple_google_drive_boundary'}))
111
+ .to_return(:status => 200, :body => response_body)
112
+
113
+ expect(client.files_upload(File.open(file_path), params)).to eq(JSON.parse(response_body))
114
+
115
+ end
116
+
117
+ end
118
+
119
+ describe "#patch" do
120
+
121
+ it "Updates file metadata and return it" do
122
+ response_body = '{"kind": "drive#files", "title": "new title"}'
123
+
124
+ stub_request(:patch, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}").with(:body => {:title => 'new title'}, :headers => headers)
125
+ .to_return(:status => 200, :body => response_body)
126
+
127
+ expect(client.files_patch(file_id, {:title => 'new title'})).to eq(JSON.parse(response_body))
128
+ end
129
+
130
+ end
131
+
132
+ describe "#update" do
133
+
134
+ end
135
+
136
+ describe "#copy" do
137
+ it "Copies the origin file and return the copy metadata" do
138
+
139
+ response_body = '{"kind": "drive#files"}'
140
+
141
+ stub_request(:post, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}/copy").with(:headers => headers)
142
+ .to_return(:status => 200, :body => response_body)
143
+
144
+ expect(client.files_copy(file_id)).to eq(JSON.parse(response_body))
145
+ end
146
+ end
147
+
148
+ describe "#delete" do
149
+ it "Permanently deletes a file by ID." do
150
+
151
+ stub_request(:delete, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}").with(:headers => headers)
152
+ .to_return(:status => 204)
153
+
154
+ expect(client.files_delete(file_id)).to eq("")
155
+ end
156
+ end
157
+
158
+ describe "#list" do
159
+
160
+ it "Lists the user's files" do
161
+
162
+ response_body = '{"kind": "drive#fileList", "items":"[]"}'
163
+
164
+ stub_request(:get, "#{SimpleGoogleDrive::API_BASE_URL}/files").with(:headers => headers)
165
+ .to_return(:status => 200, :body => response_body)
166
+
167
+ expect(client.files_list).to eq(JSON.parse(response_body))
168
+ end
169
+
170
+ end
171
+
172
+ describe "#touch" do
173
+
174
+ it "Set the file's updated time to the current server time." do
175
+
176
+ response_body = '{"kind": "drive#files"}'
177
+
178
+ stub_request(:post, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}/touch").with(:headers => headers)
179
+ .to_return(:status => 200, :body => response_body)
180
+
181
+ expect(client.files_touch(file_id)).to eq(JSON.parse(response_body))
182
+ end
183
+
184
+ end
185
+
186
+ describe "#trash" do
187
+
188
+ it "Moves a file to the trash and return files metadata." do
189
+
190
+ response_body = '{"kind": "drive#files"}'
191
+
192
+ stub_request(:post, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}/trash").with(:headers => headers)
193
+ .to_return(:status => 200, :body => response_body)
194
+
195
+ expect(client.files_trash(file_id)).to eq(JSON.parse(response_body))
196
+ end
197
+
198
+ end
199
+
200
+ describe "#untrash" do
201
+ it "Restores a file from the trash and return file metadata." do
202
+
203
+ response_body = '{"kind": "drive#files"}'
204
+
205
+ stub_request(:post, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}/untrash").with(:headers => headers)
206
+ .to_return(:status => 200, :body => response_body)
207
+
208
+ expect(client.files_untrash(file_id)).to eq(JSON.parse(response_body))
209
+ end
210
+ end
211
+
212
+ describe "#watch" do
213
+
214
+ it "Start watching for changes to a file and return a api#channel metadata." do
215
+
216
+ response_body = '{"kind": "api#channel"}'
217
+ request_body = '{"id":"1","token":"123123","type":"web_hook","address":"192.168.0.1","params":{"ttl":"60000"}}'
218
+ params = { :id => "1", :token => "123123", :type => "web_hook", :address => "192.168.0.1", :params => {:ttl => "60000"} }
219
+
220
+ stub_request(:post, "#{SimpleGoogleDrive::API_BASE_URL}/files/#{file_id}/watch").with(:body => request_body, :headers => headers)
221
+ .to_return(:status => 200, :body => response_body)
222
+
223
+ expect(client.files_watch(file_id, params)).to eq(JSON.parse(response_body))
224
+ end
225
+
226
+ end
227
+
228
+ end
229
+
230
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleGoogleDrive do
4
+
5
+ let(:oauth2_access_token) { "1/fFBGRNJru1FQd44AzqT3Zg" }
6
+
7
+ it "returns a new client instance" do
8
+ expect(SimpleGoogleDrive.new(oauth2_access_token)).to be_instance_of(SimpleGoogleDrive::Client)
9
+ end
10
+
11
+ end
@@ -0,0 +1,16 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'simple_google_drive'
5
+ require 'webmock/rspec'
6
+
7
+ # Allowing codeclimate connections
8
+ WebMock.disable_net_connect!(:allow => "codeclimate.com")
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ config.order = 'random'
16
+ end
@@ -0,0 +1,15 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
2
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
3
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
4
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
5
+ cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
6
+ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
7
+
8
+ Do you preffer Dropbox ?
9
+
10
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
11
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
12
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
13
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
14
+ cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
15
+ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_google_drive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Guilherme Vinicius Moreira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple interface for Google Drive API
42
+ email:
43
+ - gui.vinicius@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/simple_google_drive.rb
56
+ - lib/simple_google_drive/client.rb
57
+ - lib/simple_google_drive/session_base.rb
58
+ - lib/simple_google_drive/version.rb
59
+ - simple_google_drive.gemspec
60
+ - spec/lib/simple_google_drive/client_spec.rb
61
+ - spec/lib/simple_google_drive_spec.rb
62
+ - spec/spec_helper.rb
63
+ - spec/support/example.txt
64
+ homepage: https://github.com/guivinicius/simple_google_drive
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.2.0
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A simple interface for Google Drive API
88
+ test_files:
89
+ - spec/lib/simple_google_drive/client_spec.rb
90
+ - spec/lib/simple_google_drive_spec.rb
91
+ - spec/spec_helper.rb
92
+ - spec/support/example.txt