chocolate_rain 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +1 -0
  4. data/chocolate_rain.gemspec +26 -0
  5. data/generators/youtube_model/USAGE +3 -0
  6. data/generators/youtube_model/templates/config.yml +6 -0
  7. data/generators/youtube_model/templates/model.rb +17 -0
  8. data/generators/youtube_model/templates/unit_test.rb +7 -0
  9. data/generators/youtube_model/youtube_model_generator.rb +15 -0
  10. data/lib/.DS_Store +0 -0
  11. data/lib/chocolate_rain.rb +5 -0
  12. data/lib/chocolate_rain/version.rb +3 -0
  13. data/lib/gdata/auth/authsub.rb +161 -0
  14. data/lib/gdata/auth/clientlogin.rb +102 -0
  15. data/lib/gdata/client.rb +84 -0
  16. data/lib/gdata/client/apps.rb +27 -0
  17. data/lib/gdata/client/base.rb +182 -0
  18. data/lib/gdata/client/blogger.rb +28 -0
  19. data/lib/gdata/client/booksearch.rb +28 -0
  20. data/lib/gdata/client/calendar.rb +58 -0
  21. data/lib/gdata/client/contacts.rb +28 -0
  22. data/lib/gdata/client/doclist.rb +28 -0
  23. data/lib/gdata/client/finance.rb +28 -0
  24. data/lib/gdata/client/gbase.rb +28 -0
  25. data/lib/gdata/client/gmail.rb +28 -0
  26. data/lib/gdata/client/health.rb +28 -0
  27. data/lib/gdata/client/notebook.rb +28 -0
  28. data/lib/gdata/client/photos.rb +29 -0
  29. data/lib/gdata/client/spreadsheets.rb +28 -0
  30. data/lib/gdata/client/webmaster_tools.rb +28 -0
  31. data/lib/gdata/client/youtube.rb +47 -0
  32. data/lib/gdata/g_data.rb +22 -0
  33. data/lib/gdata/http.rb +18 -0
  34. data/lib/gdata/http/default_service.rb +82 -0
  35. data/lib/gdata/http/mime_body.rb +95 -0
  36. data/lib/gdata/http/request.rb +74 -0
  37. data/lib/gdata/http/response.rb +44 -0
  38. data/lib/youtube_helpers.rb +58 -0
  39. data/lib/youtube_model.rb +341 -0
  40. metadata +84 -0
@@ -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 GMail Atom Feed.
19
+ class GMail < Base
20
+
21
+ def initialize(options = {})
22
+ options[:clientlogin_service] ||= 'mail'
23
+ options[:authsub_scope] ||= 'https://mail.google.com/mail/feed/atom/'
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 Health API.
19
+ class Health < Base
20
+
21
+ def initialize(options = {})
22
+ options[:clientlogin_service] ||= 'health'
23
+ options[:authsub_scope] ||= 'https://www.google.com/health/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 Notebook Data API.
19
+ class Notebook < Base
20
+
21
+ def initialize(options = {})
22
+ options[:clientlogin_service] ||= 'notebook'
23
+ options[:authsub_scope] ||= 'http://www.google.com/notebook/feeds/'
24
+ super(options)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
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 Picasa Web Albums API.
19
+ class Photos < Base
20
+
21
+ def initialize(options = {})
22
+ options[:clientlogin_service] ||= 'lh2'
23
+ options[:authsub_scope] ||= 'http://picasaweb.google.com/data/'
24
+ options[:version] ||= '1'
25
+ super(options)
26
+ end
27
+ end
28
+ end
29
+ 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 Spreadsheets API.
19
+ class Spreadsheets < Base
20
+
21
+ def initialize(options = {})
22
+ options[:clientlogin_service] ||= 'wise'
23
+ options[:authsub_scope] ||= 'http://spreadsheets.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 Webmaster Tools API.
19
+ class WebmasterTools < Base
20
+
21
+ def initialize(options = {})
22
+ options[:clientlogin_service] ||= 'sitemaps'
23
+ options[:authsub_scope] ||= 'http://www.google.com/webmasters/tools/feeds/'
24
+ super(options)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
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 YouTube API. Sets some
19
+ # YouTube-specific options.
20
+ class YouTube < Base
21
+
22
+ # The YouTube developer key being used.
23
+ attr_accessor :developer_key
24
+ # The YouTube ClientID being used.
25
+ attr_accessor :client_id
26
+
27
+ def initialize(options = {})
28
+ options[:clientlogin_service] ||= 'youtube'
29
+ options[:clientlogin_url] ||= 'https://www.google.com/youtube/accounts/ClientLogin'
30
+ options[:authsub_scope] ||= 'http://gdata.youtube.com'
31
+ options[:version] ||= '2'
32
+ super(options)
33
+ end
34
+
35
+ # Custom prepare_headers to include the developer key and clientID
36
+ def prepare_headers
37
+ if @client_id
38
+ @headers['X-GData-Client'] = @client_id
39
+ end
40
+ if @developer_key
41
+ @headers['X-GData-Key'] = "key=#{@developer_key}"
42
+ end
43
+ super
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,22 @@
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
+ require 'gdata/auth/clientlogin'
16
+ require 'gdata/auth/authsub'
17
+
18
+ module GData
19
+ module Auth
20
+ SOURCE_LIB_STRING = 'GoogleDataRubyUtil-'
21
+ end
22
+ end
data/lib/gdata/http.rb ADDED
@@ -0,0 +1,18 @@
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
+ require 'gdata/http/default_service'
16
+ require 'gdata/http/mime_body'
17
+ require 'gdata/http/request'
18
+ require 'gdata/http/response'
@@ -0,0 +1,82 @@
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
+ require 'net/http'
16
+ require 'net/https'
17
+ require 'uri'
18
+
19
+ module GData
20
+ module HTTP
21
+
22
+ # This is the default implementation of the HTTP layer that uses
23
+ # Net::HTTP. You could roll your own if you have different requirements
24
+ # or cannot use Net::HTTP for some reason.
25
+ class DefaultService
26
+
27
+ # Take a GData::HTTP::Request, execute the request, and return a
28
+ # GData::HTTP::Response object.
29
+ def make_request(request)
30
+ url = URI.parse(request.url)
31
+ http = Net::HTTP.new(url.host, url.port)
32
+ http.use_ssl = (url.scheme == 'https')
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
+
35
+ case request.method
36
+ when :get
37
+ req = Net::HTTP::Get.new(url.request_uri)
38
+ when :put
39
+ req = Net::HTTP::Put.new(url.request_uri)
40
+ when :post
41
+ req = Net::HTTP::Post.new(url.request_uri)
42
+ when :delete
43
+ req = Net::HTTP::Delete.new(url.request_uri)
44
+ else
45
+ raise ArgumentError, "Unsupported HTTP method specified."
46
+ end
47
+
48
+ case request.body
49
+ when String
50
+ req.body = request.body
51
+ when Hash
52
+ req.set_form_data(request.body)
53
+ when File
54
+ req.body_stream = request.body
55
+ request.chunked = true
56
+ when GData::HTTP::MimeBody
57
+ req.body_stream = request.body
58
+ request.chunked = true
59
+ else
60
+ req.body = request.body.to_s
61
+ end
62
+
63
+ request.headers.each do |key, value|
64
+ req[key] = value
65
+ end
66
+
67
+ request.calculate_length!
68
+
69
+ res = http.request(req)
70
+
71
+ response = Response.new
72
+ response.body = res.body
73
+ response.headers = Hash.new
74
+ res.each do |key, value|
75
+ response.headers[key] = value
76
+ end
77
+ response.status_code = res.code.to_i
78
+ return response
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,95 @@
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
+
16
+ module GData
17
+ module HTTP
18
+
19
+ # Class acts as a virtual file handle to a MIME multipart message body
20
+ class MimeBody
21
+
22
+ # The MIME boundary being used.
23
+ attr_reader :boundary
24
+
25
+ # All fields are required, the entry should be a string and is assumed
26
+ # to be XML.
27
+ def initialize(entry, file, file_mime_type)
28
+ @boundary = "END_OF_PART_#{rand(64000)}"
29
+ entry = wrap_entry(entry, file_mime_type)
30
+ closing_boundary = MimeBodyString.new("\r\n--#{@boundary}--")
31
+ @parts = [entry, file, closing_boundary]
32
+ @current_part = 0
33
+ end
34
+
35
+ # Implement read so that this class can be treated as a stream.
36
+ def read(bytes_requested)
37
+ if @current_part >= @parts.length
38
+ return false
39
+ end
40
+
41
+ buffer = @parts[@current_part].read(bytes_requested)
42
+
43
+ until buffer.length == bytes_requested
44
+ @current_part += 1
45
+ next_buffer = self.read(bytes_requested - buffer.length)
46
+ break if not next_buffer
47
+ buffer += next_buffer
48
+ end
49
+
50
+ return buffer
51
+ end
52
+
53
+ # Returns the content type of the message including boundary.
54
+ def content_type
55
+ return "multipart/related; boundary=\"#{@boundary}\""
56
+ end
57
+
58
+ private
59
+
60
+ # Sandwiches the entry body into a MIME message
61
+ def wrap_entry(entry, file_mime_type)
62
+ wrapped_entry = "--#{@boundary}\r\n"
63
+ wrapped_entry += "Content-Type: application/atom+xml\r\n\r\n"
64
+ wrapped_entry += entry
65
+ wrapped_entry += "--#{@boundary}\r\n"
66
+ wrapped_entry += "Content-Type: #{file_mime_type}\r\n\r\n"
67
+ return MimeBodyString.new(wrapped_entry)
68
+ end
69
+
70
+ end
71
+
72
+ # Class makes a string into a stream-like object
73
+ class MimeBodyString
74
+
75
+ def initialize(source_string)
76
+ @string = source_string
77
+ @bytes_read = 0
78
+ end
79
+
80
+ # Implement read so that this class can be treated as a stream.
81
+ def read(bytes_requested)
82
+ if @bytes_read == @string.length
83
+ return false
84
+ elsif bytes_requested > @string.length - @bytes_read
85
+ bytes_requested = @string.length - @bytes_read
86
+ end
87
+
88
+ buffer = @string[@bytes_read, bytes_requested]
89
+ @bytes_read += bytes_requested
90
+
91
+ return buffer
92
+ end
93
+ end
94
+ end
95
+ end