gdata 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -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
@@ -19,19 +19,16 @@ module GData
19
19
  # YouTube-specific options.
20
20
  class YouTube < Base
21
21
 
22
- DEFAULT_OPTIONS = {
23
- :version => '2',
24
- :clientlogin_url => 'https://www.google.com/youtube/accounts/ClientLogin',
25
- :clientlogin_service => 'youtube',
26
- :authsub_scope => 'http://gdata.youtube.com' }
27
-
28
22
  # The YouTube developer key being used.
29
23
  attr_accessor :developer_key
30
24
  # The YouTube ClientID being used.
31
25
  attr_accessor :client_id
32
26
 
33
27
  def initialize(options = {})
34
- options = DEFAULT_OPTIONS.merge(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'
35
32
  super(options)
36
33
  end
37
34
 
@@ -13,5 +13,6 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require 'gdata/http/default_service'
16
+ require 'gdata/http/mime_body'
16
17
  require 'gdata/http/request'
17
18
  require 'gdata/http/response'
@@ -37,25 +37,43 @@ module GData
37
37
  req = Net::HTTP::Get.new(url.request_uri)
38
38
  when :put
39
39
  req = Net::HTTP::Put.new(url.request_uri)
40
- request.calculate_length!
41
40
  when :post
42
41
  req = Net::HTTP::Post.new(url.request_uri)
43
- request.calculate_length!
44
42
  when :delete
45
43
  req = Net::HTTP::Delete.new(url.request_uri)
46
44
  else
47
45
  raise ArgumentError, "Unsupported HTTP method specified."
48
46
  end
49
47
 
50
- req.body = request.body
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
+
51
63
  request.headers.each do |key, value|
52
64
  req[key] = value
53
65
  end
66
+
67
+ request.calculate_length!
68
+
54
69
  res = http.request(req)
55
70
 
56
71
  response = Response.new
57
72
  response.body = res.body
58
- response.headers = res.header.to_hash
73
+ response.headers = Hash.new
74
+ res.each do |key, value|
75
+ response.headers[key] = value
76
+ end
59
77
  response.status_code = res.code.to_i
60
78
  return response
61
79
  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