chdorner-gdocsapi-wrapper 0.0.1 → 0.0.2

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.
data/Manifest.txt CHANGED
@@ -1,11 +1,16 @@
1
+ gdocsapi-wrapper.gemspec
1
2
  History.txt
3
+ lib/gdocsapi-wrapper/auth/login.rb
4
+ lib/gdocsapi-wrapper/auth.rb
5
+ lib/gdocsapi-wrapper/base.rb
6
+ lib/gdocsapi-wrapper/client.rb
7
+ lib/gdocsapi-wrapper/http/request.rb
8
+ lib/gdocsapi-wrapper/http/response.rb
9
+ lib/gdocsapi-wrapper/http.rb
10
+ lib/gdocsapi-wrapper.rb
2
11
  Manifest.txt
3
12
  PostInstall.txt
4
- README.rdoc
5
13
  Rakefile
6
- lib/gdocsapi-wrapper.rb
7
- script/console
8
- script/destroy
9
- script/generate
14
+ README.rdoc
10
15
  test/test_gdocsapi-wrapper.rb
11
16
  test/test_helper.rb
data/README.rdoc CHANGED
@@ -9,7 +9,7 @@ A Ruby wrapper around the Google Documents List Data API
9
9
 
10
10
  == FEATURES/PROBLEMS:
11
11
 
12
- * FIX (list of features or problems)
12
+ * Add CaptchaError when logging in requires a Captcha
13
13
 
14
14
  == SYNOPSIS:
15
15
 
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{gdocsapi-wrapper}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Christof Dorner"]
9
+ s.date = %q{2009-08-10}
10
+ s.description = %q{A Ruby wrapper around the Google Documents List Data API}
11
+ s.email = ["christof@chdorner.com"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
13
+ s.files = ["gdocsapi-wrapper.gemspec", "History.txt", "lib/gdocsapi-wrapper/auth/login.rb", "lib/gdocsapi-wrapper/auth.rb", "lib/gdocsapi-wrapper/base.rb", "lib/gdocsapi-wrapper/client.rb", "lib/gdocsapi-wrapper/http/request.rb", "lib/gdocsapi-wrapper/http/response.rb", "lib/gdocsapi-wrapper/http.rb", "lib/gdocsapi-wrapper.rb", "Manifest.txt", "PostInstall.txt", "Rakefile", "README.rdoc", "test/test_gdocsapi-wrapper.rb", "test/test_helper.rb"]
14
+ s.homepage = %q{http://github.com/chdorner/gdocs-wrapper}
15
+ s.post_install_message = %q{PostInstall.txt}
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{gdocsapi-wrapper}
19
+ s.rubygems_version = %q{1.3.5}
20
+ s.summary = %q{A Ruby wrapper around the Google Documents List Data API}
21
+ s.test_files = ["test/test_gdocsapi-wrapper.rb", "test/test_helper.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
29
+ else
30
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
34
+ end
35
+ end
@@ -21,7 +21,12 @@
21
21
 
22
22
  $:.unshift(File.dirname(__FILE__)) unless
23
23
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
24
+
25
+ require 'gdocsapi-wrapper/base'
26
+ require 'gdocsapi-wrapper/http'
27
+ require 'gdocsapi-wrapper/auth'
28
+ require 'gdocsapi-wrapper/client'
24
29
 
25
- module GdocsapiWrapper
26
- VERSION = '0.0.1'
30
+ module GDocsAPIWrapper
31
+ VERSION = '0.0.2'
27
32
  end
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'gdocsapi-wrapper/auth/login'
23
+
24
+ module GDocsAPIWrapper
25
+ module Auth
26
+ SOURCE_PREFIX = 'GDOCSAPIWRAPPER-'
27
+ end
28
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module GDocsAPIWrapper
23
+ module Auth
24
+ class Login
25
+
26
+ attr_accessor :service
27
+ attr_accessor :account_type
28
+ attr_accessor :auth_url
29
+ attr_accessor :token
30
+
31
+ def initialize
32
+ @service = 'writely'
33
+ @acc_type = 'HOSTED_OR_GOOGLE'
34
+ @auth_url = 'https://www.google.com/accounts/ClientLogin'
35
+ end
36
+
37
+ def perform_login(username, password, source)
38
+ body = Hash.new
39
+ body['accountType'] = @acc_type
40
+ body['Email'] = username
41
+ body['Passwd'] = password
42
+ body['service'] = @service
43
+
44
+ request = GDocsAPIWrapper::HTTP::Request.new(@auth_url, :body => body, :method => :post)
45
+ response = request.send_request()
46
+
47
+ if response.status_code != 200
48
+ raise GDocsAPIWrapper::AuthorizationError.new(response)
49
+ end
50
+
51
+ @token = response.body[/Auth=(.*)/, 1]
52
+ return @token
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module GDocsAPIWrapper
23
+
24
+ # The basic error class for errors raised in the gdocsapi-wrapper
25
+ class Error < RuntimeError
26
+ end
27
+
28
+ # Base error class for errors raised by the GDocs API
29
+ class RequestError < Error
30
+ attr_accessor :response
31
+
32
+ def initialize(response)
33
+ @response = response
34
+ super "request error #{response.status_code}: #{response.body}"
35
+ end
36
+ end
37
+
38
+ class AuthorizationError < RequestError
39
+ end
40
+
41
+ end
@@ -0,0 +1,47 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module GDocsAPIWrapper
23
+ class Client
24
+
25
+ # Identifying the application which uses the GDocsAPIWrapper
26
+ attr_accessor :source
27
+ attr_accessor :login_handler
28
+
29
+ def initialize(options = {})
30
+ options.each do |key, value|
31
+ self.send("#{key}=", value)
32
+ end
33
+
34
+ @source ||= 'UndefinedApplication'
35
+ end
36
+
37
+ # Performs login on GDocsAPIWrapper:Auth
38
+ def login(username, password)
39
+ source = GDocsAPIWrapper::Auth::SOURCE_PREFIX + @source
40
+
41
+ @login_handler = GDocsAPIWrapper::Auth::Login.new
42
+ @login_handler.perform_login(username, password, source)
43
+
44
+ puts 'Token: ' + @login_handler.token
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'gdocsapi-wrapper/http/request'
23
+ require 'gdocsapi-wrapper/http/response'
@@ -0,0 +1,87 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'net/http'
23
+ require 'net/https'
24
+ require 'uri'
25
+
26
+ module GDocsAPIWrapper
27
+ module HTTP
28
+ class Request
29
+ attr_accessor :url
30
+ attr_accessor :body
31
+ attr_accessor :method
32
+
33
+ def initialize(url, options = {})
34
+ @url = url
35
+ options.each do |key, value|
36
+ self.send("#{key}=", value)
37
+ end
38
+
39
+ @method ||= :get
40
+ end
41
+
42
+ def send_request
43
+ uri = URI.parse(@url)
44
+ http = Net::HTTP.new(uri.host, uri.port)
45
+ http.use_ssl = (uri.scheme == 'https')
46
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
47
+
48
+ case @method
49
+ when :get
50
+ req = Net::HTTP::Get.new(uri.request_uri)
51
+ when :post
52
+ req = Net::HTTP::Post.new(uri.request_uri)
53
+ when :put
54
+ req = Net::HTTP::Put.new(uri.request_uri)
55
+ when :delete
56
+ req = Net::HTTP::Delete.new(uri.request_uri)
57
+ else
58
+ raise ArgumentError, 'Unsupported HTTP Method' + request.method
59
+ end
60
+
61
+ case @body
62
+ when String
63
+ req.body = @body
64
+ when Hash
65
+ req.set_form_data(@body)
66
+ when File
67
+ req.body_stream = @body
68
+ request.chunked = true
69
+ else
70
+ req.body = @body.to_s
71
+ end
72
+ #request.calculate_length!
73
+
74
+ res = http.request(req)
75
+
76
+ response = GDocsAPIWrapper::HTTP::Response.new
77
+ response.body = res.body
78
+ response.headers = Hash.new
79
+ res.each do |key, value|
80
+ response.headers[key] = value
81
+ end
82
+ response.status_code = res.code.to_i
83
+ return response
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,30 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module GDocsAPIWrapper
23
+ module HTTP
24
+ class Response
25
+ attr_accessor :status_code
26
+ attr_accessor :body
27
+ attr_accessor :headers
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chdorner-gdocsapi-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christof Dorner
@@ -34,15 +34,20 @@ extra_rdoc_files:
34
34
  - Manifest.txt
35
35
  - PostInstall.txt
36
36
  files:
37
+ - gdocsapi-wrapper.gemspec
37
38
  - History.txt
39
+ - lib/gdocsapi-wrapper/auth/login.rb
40
+ - lib/gdocsapi-wrapper/auth.rb
41
+ - lib/gdocsapi-wrapper/base.rb
42
+ - lib/gdocsapi-wrapper/client.rb
43
+ - lib/gdocsapi-wrapper/http/request.rb
44
+ - lib/gdocsapi-wrapper/http/response.rb
45
+ - lib/gdocsapi-wrapper/http.rb
46
+ - lib/gdocsapi-wrapper.rb
38
47
  - Manifest.txt
39
48
  - PostInstall.txt
40
- - README.rdoc
41
49
  - Rakefile
42
- - lib/gdocsapi-wrapper.rb
43
- - script/console
44
- - script/destroy
45
- - script/generate
50
+ - README.rdoc
46
51
  - test/test_gdocsapi-wrapper.rb
47
52
  - test/test_helper.rb
48
53
  has_rdoc: false
data/script/console DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # File: script/console
3
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
-
5
- libs = " -r irb/completion"
6
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/gdocsapi-wrapper.rb'}"
9
- puts "Loading gdocsapi-wrapper gem"
10
- exec "#{irb} #{libs} --simple-prompt"
data/script/destroy DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Generate.new.run(ARGV)