chocolate_rain 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/chocolate_rain.gemspec +26 -0
- data/generators/youtube_model/USAGE +3 -0
- data/generators/youtube_model/templates/config.yml +6 -0
- data/generators/youtube_model/templates/model.rb +17 -0
- data/generators/youtube_model/templates/unit_test.rb +7 -0
- data/generators/youtube_model/youtube_model_generator.rb +15 -0
- data/lib/.DS_Store +0 -0
- data/lib/chocolate_rain.rb +5 -0
- data/lib/chocolate_rain/version.rb +3 -0
- data/lib/gdata/auth/authsub.rb +161 -0
- data/lib/gdata/auth/clientlogin.rb +102 -0
- data/lib/gdata/client.rb +84 -0
- data/lib/gdata/client/apps.rb +27 -0
- data/lib/gdata/client/base.rb +182 -0
- data/lib/gdata/client/blogger.rb +28 -0
- data/lib/gdata/client/booksearch.rb +28 -0
- data/lib/gdata/client/calendar.rb +58 -0
- data/lib/gdata/client/contacts.rb +28 -0
- data/lib/gdata/client/doclist.rb +28 -0
- data/lib/gdata/client/finance.rb +28 -0
- data/lib/gdata/client/gbase.rb +28 -0
- data/lib/gdata/client/gmail.rb +28 -0
- data/lib/gdata/client/health.rb +28 -0
- data/lib/gdata/client/notebook.rb +28 -0
- data/lib/gdata/client/photos.rb +29 -0
- data/lib/gdata/client/spreadsheets.rb +28 -0
- data/lib/gdata/client/webmaster_tools.rb +28 -0
- data/lib/gdata/client/youtube.rb +47 -0
- data/lib/gdata/g_data.rb +22 -0
- data/lib/gdata/http.rb +18 -0
- data/lib/gdata/http/default_service.rb +82 -0
- data/lib/gdata/http/mime_body.rb +95 -0
- data/lib/gdata/http/request.rb +74 -0
- data/lib/gdata/http/response.rb +44 -0
- data/lib/youtube_helpers.rb +58 -0
- data/lib/youtube_model.rb +341 -0
- metadata +84 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Apps Provisioning API.
|
19
|
+
class Apps < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'apps'
|
23
|
+
super(options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# A client object used to interact with different Google Data APIs.
|
19
|
+
class Base
|
20
|
+
|
21
|
+
# A subclass of GData::Auth that handles authentication signing.
|
22
|
+
attr_accessor :auth_handler
|
23
|
+
# A subclass of GData::HTTP that handles making HTTP requests.
|
24
|
+
attr_accessor :http_service
|
25
|
+
# Headers to include in every request.
|
26
|
+
attr_accessor :headers
|
27
|
+
# The API version being used.
|
28
|
+
attr_accessor :version
|
29
|
+
# The default URL for ClientLogin.
|
30
|
+
attr_accessor :clientlogin_url
|
31
|
+
# A default service name for ClientLogin (overriden by subclasses).
|
32
|
+
attr_accessor :clientlogin_service
|
33
|
+
# The broadest AuthSub scope for working with an API.
|
34
|
+
# This is overriden by the service-specific subclasses.
|
35
|
+
attr_accessor :authsub_scope
|
36
|
+
# A short string identifying the current application.
|
37
|
+
attr_accessor :source
|
38
|
+
|
39
|
+
def initialize(options = {})
|
40
|
+
options.each do |key, value|
|
41
|
+
self.send("#{key}=", value)
|
42
|
+
end
|
43
|
+
|
44
|
+
@headers ||= {}
|
45
|
+
@http_service ||= GData::HTTP::DefaultService
|
46
|
+
@version ||= '2'
|
47
|
+
@source ||= 'AnonymousApp'
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sends an HTTP request with the given file as a stream
|
51
|
+
def make_file_request(method, url, file_path, mime_type, entry = nil)
|
52
|
+
if not File.readable?(file_path)
|
53
|
+
raise ArgumentError, "File #{file_path} is not readable."
|
54
|
+
end
|
55
|
+
file = File.open(file_path, 'rb')
|
56
|
+
@headers['Slug'] = File.basename(file_path)
|
57
|
+
if entry
|
58
|
+
@headers['MIME-Version'] = '1.0'
|
59
|
+
body = GData::HTTP::MimeBody.new(entry, file, mime_type)
|
60
|
+
@headers['Content-Type'] = body.content_type
|
61
|
+
response = self.make_request(method, url, body)
|
62
|
+
else
|
63
|
+
@headers['Content-Type'] = mime_type
|
64
|
+
response = self.make_request(method, url, file)
|
65
|
+
end
|
66
|
+
file.close
|
67
|
+
return response
|
68
|
+
end
|
69
|
+
|
70
|
+
# Sends an HTTP request and return the response.
|
71
|
+
def make_request(method, url, body = '')
|
72
|
+
headers = self.prepare_headers
|
73
|
+
request = GData::HTTP::Request.new(url, :headers => headers,
|
74
|
+
:method => method, :body => body)
|
75
|
+
|
76
|
+
if @auth_handler and @auth_handler.respond_to?(:sign_request!)
|
77
|
+
@auth_handler.sign_request!(request)
|
78
|
+
end
|
79
|
+
|
80
|
+
service = http_service.new
|
81
|
+
response = service.make_request(request)
|
82
|
+
|
83
|
+
case response.status_code
|
84
|
+
when 200, 201, 302
|
85
|
+
#Do nothing, it's a success.
|
86
|
+
when 401, 403
|
87
|
+
raise AuthorizationError.new(response)
|
88
|
+
when 400
|
89
|
+
raise BadRequestError, response.body
|
90
|
+
when 409
|
91
|
+
raise VersionConflictError.new(response)
|
92
|
+
when 500
|
93
|
+
raise ServerError.new(response)
|
94
|
+
else
|
95
|
+
raise UnknownError.new(response)
|
96
|
+
end
|
97
|
+
|
98
|
+
return response
|
99
|
+
end
|
100
|
+
|
101
|
+
# Performs an HTTP GET against the API.
|
102
|
+
def get(url)
|
103
|
+
return self.make_request(:get, url)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Performs an HTTP PUT against the API.
|
107
|
+
def put(url, body)
|
108
|
+
return self.make_request(:put, url, body)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Performs an HTTP PUT with the given file
|
112
|
+
def put_file(url, file_path, mime_type, entry = nil)
|
113
|
+
return self.make_file_request(:put, url, file_path, mime_type, entry)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Performs an HTTP POST against the API.
|
117
|
+
def post(url, body)
|
118
|
+
return self.make_request(:post, url, body)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Performs an HTTP POST with the given file
|
122
|
+
def post_file(url, file_path, mime_type, entry = nil)
|
123
|
+
return self.make_file_request(:post, url, file_path, mime_type, entry)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Performs an HTTP DELETE against the API.
|
127
|
+
def delete(url)
|
128
|
+
return self.make_request(:delete, url)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Constructs some necessary headers for every request.
|
132
|
+
def prepare_headers
|
133
|
+
headers = @headers
|
134
|
+
headers['GData-Version'] = @version
|
135
|
+
headers['User-Agent'] = GData::Auth::SOURCE_LIB_STRING + @source
|
136
|
+
# by default we assume we are sending Atom entries
|
137
|
+
if not headers.has_key?('Content-Type')
|
138
|
+
headers['Content-Type'] = 'application/atom+xml'
|
139
|
+
end
|
140
|
+
return headers
|
141
|
+
end
|
142
|
+
|
143
|
+
# Performs ClientLogin for the service. See GData::Auth::ClientLogin
|
144
|
+
# for details.
|
145
|
+
def clientlogin(username, password, captcha_token = nil,
|
146
|
+
captcha_answer = nil, service = nil, account_type = nil)
|
147
|
+
if service.nil?
|
148
|
+
service = @clientlogin_service
|
149
|
+
end
|
150
|
+
options = { :account_type => account_type }
|
151
|
+
self.auth_handler = GData::Auth::ClientLogin.new(service, options)
|
152
|
+
if @clientlogin_url
|
153
|
+
@auth_handler.auth_url = @clientlogin_url
|
154
|
+
end
|
155
|
+
source = GData::Auth::SOURCE_LIB_STRING + @source
|
156
|
+
@auth_handler.get_token(username, password, source, captcha_token, captcha_answer)
|
157
|
+
end
|
158
|
+
|
159
|
+
def authsub_url(next_url, secure = false, session = true, domain = nil,
|
160
|
+
scope = nil)
|
161
|
+
if scope.nil?
|
162
|
+
scope = @authsub_scope
|
163
|
+
end
|
164
|
+
GData::Auth::AuthSub.get_url(next_url, scope, secure, session, domain)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Sets an AuthSub token for the service.
|
168
|
+
def authsub_token=(token)
|
169
|
+
self.auth_handler = GData::Auth::AuthSub.new(token)
|
170
|
+
end
|
171
|
+
|
172
|
+
# Sets a private key to use with AuthSub requests.
|
173
|
+
def authsub_private_key=(key)
|
174
|
+
if @auth_handler.class == GData::Auth::AuthSub
|
175
|
+
@auth_handler.private_key = key
|
176
|
+
else
|
177
|
+
raise Error, "An AuthSub token must be set first."
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Blogger API.
|
19
|
+
class Blogger < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'blogger'
|
23
|
+
options[:authsub_scope] ||= 'http://www.blogger.com/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Book Search Data API.
|
19
|
+
class BookSearch < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'print'
|
23
|
+
options[:authsub_scope] ||= 'http://www.google.com/books/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Calendar Data API.
|
19
|
+
class Calendar < Base
|
20
|
+
|
21
|
+
# Holds on to a session cookie
|
22
|
+
attr_accessor :session_cookie
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
options[:clientlogin_service] ||= 'cl'
|
26
|
+
options[:authsub_scope] ||= 'http://www.google.com/calendar/feeds/'
|
27
|
+
super(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Overrides auth_handler= so if the authentication changes,
|
31
|
+
# the session cookie is cleared.
|
32
|
+
def auth_handler=(handler)
|
33
|
+
@session_cookie = nil
|
34
|
+
return super(handler)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Overrides make_request to handle 302 redirects with a session cookie.
|
38
|
+
def make_request(method, url, body = '', retries = 4)
|
39
|
+
response = super(method, url, body)
|
40
|
+
if response.status_code == 302 and retries > 0
|
41
|
+
@session_cookie = response.headers['set-cookie']
|
42
|
+
return self.make_request(method, url, body,
|
43
|
+
retries - 1)
|
44
|
+
else
|
45
|
+
return response
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Custom prepare_headers to include the session cookie if it exists
|
50
|
+
def prepare_headers
|
51
|
+
if @session_cookie
|
52
|
+
@headers['cookie'] = @session_cookie
|
53
|
+
end
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Contacts API.
|
19
|
+
class Contacts < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'cp'
|
23
|
+
options[:authsub_scope] ||= 'http://www.google.com/m8/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Documents List Data API.
|
19
|
+
class DocList < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'writely'
|
23
|
+
options[:authsub_scope] ||= 'http://docs.google.com/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Finance API.
|
19
|
+
class Finance < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'finance'
|
23
|
+
options[:authsub_scope] ||= 'http://finance.google.com/finance/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2008 Google Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module GData
|
16
|
+
module Client
|
17
|
+
|
18
|
+
# Client class to wrap working with the Google Base API.
|
19
|
+
class GBase < Base
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options[:clientlogin_service] ||= 'gbase'
|
23
|
+
options[:authsub_scope] ||= 'http://www.google.com/base/feeds/'
|
24
|
+
super(options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|