GData 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ == 0.0.2 / 2007-04-06
2
+
3
+ * Finally get some of the simple stuff out there
4
+ * Blogger and Spreadsheet support
5
+ * Core GData::Base support
6
+
7
+ == 0.0.1 / 2007-02-13
8
+
9
+ * 1 major enhancement
10
+ * Birthday!
11
+
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/addenclosure
6
+ bin/bloggerfeed
7
+ bin/gspreadsheet
8
+ bin/removeenclosure
9
+ lib/gdata.rb
10
+ lib/gdata/base.rb
11
+ lib/gdata/blogger.rb
12
+ lib/gdata/spreadsheet.rb
13
+ test/test_gdata.rb
@@ -0,0 +1,65 @@
1
+ GDataRuby
2
+ by Dion Almaer
3
+ http://gdata-ruby.rubyforge.net
4
+
5
+ == DESCRIPTION:
6
+
7
+ Google GData APIs allow developers to build applications on top of the Google open APIs. This project aims to help with wrappers on top of GData, and higher level libraries on top of each API itself (e.g. Calendar, Spreadsheet, Blogger, etc).
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ To start out the API set isn't covered. The aim is to support the GData API itself, and then higher level classes for the various Google APIs.
12
+
13
+ Current support:
14
+
15
+ * Google Account Authentication: Handle Google ClientLogin API
16
+ * Google Spreadsheet Data API
17
+
18
+ Future support:
19
+
20
+ * Google Calendar API
21
+ * Google AdSense API
22
+ * Google AdWords API
23
+ * Google Base Data API
24
+ * Blogger Data API
25
+ * Google Code Search API
26
+ * Google Data APIs
27
+
28
+ == SYNOPSIS:
29
+
30
+ require_gem 'gdata-ruby'
31
+
32
+ % gspreadsheet 'sin(0.2)'
33
+
34
+ == REQUIREMENTS:
35
+
36
+ * gem
37
+
38
+ == INSTALL:
39
+
40
+ * sudo gem install
41
+
42
+ == LICENSE:
43
+
44
+ (The MIT License)
45
+
46
+ Copyright (c) 2007 FIX
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of this software and associated documentation files (the
50
+ 'Software'), to deal in the Software without restriction, including
51
+ without limitation the rights to use, copy, modify, merge, publish,
52
+ distribute, sublicense, and/or sell copies of the Software, and to
53
+ permit persons to whom the Software is furnished to do so, subject to
54
+ the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
61
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
62
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
63
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
64
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
65
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/gdata.rb'
6
+
7
+ Hoe.new('GData', GData::VERSION) do |p|
8
+ p.rubyforge_name = 'gdata-ruby'
9
+ p.summary = 'Google GData Ruby API'
10
+ p.author = 'Dion Almaer'
11
+ p.email = 'dion@almaer.com'
12
+
13
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
14
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
15
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
16
+
17
+ #p.executables = %w(addenclosure bloggerfeed gspreadsheet removeenclosure)
18
+ end
19
+
20
+ # vim: syntax=Ruby
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby -I../lib
2
+ # --------------------------------------------------------------------------
3
+ # addenclosure - adds a podcast friendly enclosure to a given blog post
4
+ # --------------------------------------------------------------------------
5
+
6
+ require 'gdata/blogger'
7
+
8
+ unless ENV['GDATA_USER'] and ENV['GDATA_PASS']
9
+ puts "$0 requires GDATA_USER and GDATA_PASS to be set"
10
+ exit
11
+ end
12
+
13
+ unless ARGV.length > 3
14
+ puts "Usage: addenclosure blogid entryid enclosureurl enclosurelength"
15
+ puts "Example: addenclosure 4808741160899251111 5004114743910076111 http://foo.com/mypodcast.mp3 21015178"
16
+ exit
17
+ end
18
+
19
+ blog_id, entry_id, enclosure_url, enclosure_length = ARGV
20
+
21
+ blogger = GData::Blogger.new(blog_id, entry_id)
22
+ blogger.authenticate(ENV['GDATA_USER'], ENV['GDATA_PASS'])
23
+
24
+ blogger.add_enclosure(enclosure_url, enclosure_length)
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby -I../lib
2
+ # --------------------------------------------------------------------------
3
+ # bloggerfeed - given a blog id, show the feed
4
+ # --------------------------------------------------------------------------
5
+
6
+ require 'gdata/blogger'
7
+
8
+ unless ENV['GDATA_USER'] and ENV['GDATA_PASS']
9
+ puts "$0 requires GDATA_USER and GDATA_PASS to be set"
10
+ exit
11
+ end
12
+
13
+ blog_id = ARGV.first or raise "#{$0}: need a blog id and an entry id (% addenclosure blogid entryid)"
14
+
15
+ blogger = GData::Blogger.new(blog_id)
16
+ blogger.authenticate(ENV['GDATA_USER'], ENV['GDATA_PASS'])
17
+
18
+ puts blogger.feed
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby -I../lib
2
+ # --------------------------------------------------------------------------
3
+ # gspreadsheet - given a formula, run it in google spreadsheets and show the result
4
+ # --------------------------------------------------------------------------
5
+
6
+ require 'gdata/spreadsheet'
7
+
8
+ unless ENV['GDATA_USER'] and ENV['GDATA_PASS']
9
+ puts "$0 requires GDATA_USER and GDATA_PASS to be set"
10
+ exit
11
+ end
12
+
13
+ formula = ARGV.first or 'sin(0.2)'
14
+
15
+ gs = GData::Spreadsheet.new('pSYwzniwpzSFfn0KFRg9oWA')
16
+ gs.authenticate(ENV['GDATA_USER'], ENV['GDATA_PASS'])
17
+ gs.add_to_cell formula
18
+ puts gs.evaluate_cell('A1')
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby -I../lib
2
+ # --------------------------------------------------------------------------
3
+ # removeenclosure - given a blog id and entry id, nuke the given enclosure
4
+ # --------------------------------------------------------------------------
5
+
6
+ require 'gdata/blogger'
7
+
8
+ unless ENV['GDATA_USER'] and ENV['GDATA_PASS']
9
+ puts "$0 requires GDATA_USER and GDATA_PASS to be set"
10
+ exit
11
+ end
12
+
13
+ blog_id = ARGV.first or raise "#{$0}: need a blog id and an entry id (% removeenclosure blogid entryid)"
14
+ entry_id = ARGV[1] or raise "#{$0}: need an entry id after the blog id (% removeenclosure blogid entryid)"
15
+
16
+ blogger = GData::Blogger.new(blog_id, entry_id)
17
+ blogger.authenticate(ENV['GDATA_USER'], ENV['GDATA_PASS'])
18
+ blogger.remove_enclosure
@@ -0,0 +1,3 @@
1
+ class GData
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,75 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'rubygems'
5
+ require 'hpricot'
6
+
7
+ #
8
+ # Make it east to use some of the convenience methods using https
9
+ #
10
+ module Net
11
+ class HTTPS < HTTP
12
+ def initialize(address, port = nil)
13
+ super(address, port)
14
+ self.use_ssl = true
15
+ end
16
+ end
17
+ end
18
+
19
+ module GData
20
+ GOOGLE_LOGIN_URL = URI.parse('https://www.google.com/accounts/ClientLogin')
21
+
22
+ class Base
23
+
24
+ attr_reader :service, :source, :url
25
+
26
+ def initialize(service, source, url)
27
+ @service = service
28
+ @source = source
29
+ @url = url
30
+ end
31
+
32
+ def authenticate(email, password)
33
+ $VERBOSE = nil
34
+ response = Net::HTTPS.post_form(GOOGLE_LOGIN_URL,
35
+ {'Email' => email,
36
+ 'Passwd' => password,
37
+ 'source' => source,
38
+ 'service' => service })
39
+
40
+ response.error! unless response.kind_of? Net::HTTPSuccess
41
+
42
+ @headers = {
43
+ 'Authorization' => "GoogleLogin auth=#{response.body.split(/=/).last}",
44
+ 'Content-Type' => 'application/atom+xml'
45
+ }
46
+ end
47
+
48
+ def request(path)
49
+ response, data = get(path)
50
+ data
51
+ end
52
+
53
+ def get(path)
54
+ response, data = http.get(path, @headers)
55
+ end
56
+
57
+ def post(path, entry)
58
+ http.post(path, entry, @headers)
59
+ end
60
+
61
+ def put(path, entry)
62
+ h = @headers
63
+ h['X-HTTP-Method-Override'] = 'PUT' # just to be nice, add the method override
64
+
65
+ http.put(path, entry, h)
66
+ end
67
+
68
+ def http
69
+ conn = Net::HTTP.new(url, 80)
70
+ #conn.set_debug_output $stderr
71
+ conn
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,51 @@
1
+ require 'gdata/base'
2
+
3
+ module GData
4
+
5
+ class Blogger < GData::Base
6
+
7
+ def initialize(blog_id, entry_id=nil)
8
+ @blog_id = blog_id
9
+ @entry_id = entry_id
10
+ super 'blogger', 'gdata-ruby', 'www.blogger.com'
11
+ end
12
+
13
+ def feed
14
+ request "/feeds/#{@blog_id}/posts/default"
15
+ end
16
+
17
+ def entry
18
+ @entry ||= Hpricot(request("/feeds/#{@blog_id}/posts/default/#{@entry_id}"))
19
+ end
20
+
21
+ def enclosure
22
+ entry.search('//link[@rel="enclosure"]')
23
+ end
24
+
25
+ def enclosure?
26
+ enclosure.any?
27
+ end
28
+
29
+ def add_enclosure(enclosure_url, enclosure_length)
30
+ raise "An enclosure has already been added to this entry" if enclosure?
31
+
32
+ entry.search('//entry').append(qq|<link rel="enclosure" type="audio/mpeg" title="MP3" href="#{enclosure_url}" length="#{enclosure_length}" />|)
33
+ save_entry
34
+ end
35
+
36
+ def remove_enclosure
37
+ if enclosure?
38
+ enclosure.remove
39
+ save_entry
40
+ end
41
+ end
42
+
43
+ def save_entry
44
+ path = "/feeds/#{@blog_id}/posts/default/#{@entry_id}"
45
+
46
+ put(path, entry.to_s)
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,39 @@
1
+ require 'gdata/base'
2
+
3
+ module GData
4
+
5
+ class Spreadsheet < GData::Base
6
+
7
+ def initialize(spreadsheet_id)
8
+ @spreadsheet_id = spreadsheet_id
9
+ super 'wise', 'gdata-ruby', 'spreadsheets.google.com'
10
+ end
11
+
12
+ def evaluate_cell(cell)
13
+ path = "/feeds/cells/#{@spreadsheet_id}/1/#{@headers ? "private" : "public"}/basic/#{cell}"
14
+
15
+ doc = Hpricot(request(path))
16
+ result = (doc/"content[@type='text']").inner_html
17
+ end
18
+
19
+ def save_entry(entry)
20
+ path = "/feeds/cells/#{@spreadsheet_id}/1/#{@headers ? 'private' : 'public'}/full"
21
+
22
+ post(path, entry)
23
+ end
24
+
25
+ def entry(formula, row=1, col=1)
26
+ <<XML
27
+ <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
28
+ <gs:cell row='#{row}' col='#{col}' inputValue='=#{formula}' />
29
+ </entry>
30
+ XML
31
+ end
32
+
33
+ def add_to_cell(formula)
34
+ save_entry(entry(formula))
35
+ end
36
+
37
+ end
38
+
39
+ end
File without changes
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: GData
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.2
7
+ date: 2007-04-06 00:00:00 -07:00
8
+ summary: Google GData Ruby API
9
+ require_paths:
10
+ - lib
11
+ email: dion@almaer.com
12
+ homepage: " by Dion Almaer"
13
+ rubyforge_project: gdata-ruby
14
+ description: "== FEATURES/PROBLEMS: To start out the API set isn't covered. The aim is to support the GData API itself, and then higher level classes for the various Google APIs. Current support: * Google Account Authentication: Handle Google ClientLogin API * Google Spreadsheet Data API Future support:"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Dion Almaer
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/addenclosure
37
+ - bin/bloggerfeed
38
+ - bin/gspreadsheet
39
+ - bin/removeenclosure
40
+ - lib/gdata.rb
41
+ - lib/gdata/base.rb
42
+ - lib/gdata/blogger.rb
43
+ - lib/gdata/spreadsheet.rb
44
+ - test/test_gdata.rb
45
+ test_files:
46
+ - test/test_gdata.rb
47
+ rdoc_options: []
48
+
49
+ extra_rdoc_files: []
50
+
51
+ executables:
52
+ - addenclosure
53
+ - bloggerfeed
54
+ - gspreadsheet
55
+ - removeenclosure
56
+ extensions: []
57
+
58
+ requirements: []
59
+
60
+ dependencies:
61
+ - !ruby/object:Gem::Dependency
62
+ name: hoe
63
+ version_requirement:
64
+ version_requirements: !ruby/object:Gem::Version::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.0
69
+ version: