gdata-jruby-client 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/base.rb CHANGED
@@ -7,6 +7,23 @@ Dir.glob("#{File.dirname(__FILE__)}/gdata/java/lib/*.jar").each do |j|
7
7
  end
8
8
 
9
9
  module GData
10
+ class AuthenticationError < Exception; end
11
+ class ServiceForbidden < Exception; end
12
+ class ResourceNotFound < Exception; end
13
+
14
+ def self.gdata_exception_for(e)
15
+ case e.message
16
+ when /AuthenticationException/
17
+ AuthenticationError.new(e.message)
18
+ when /ServiceForbiddenException/
19
+ ServiceForbidden.new(e.message)
20
+ when /ResourceNotFoundException/
21
+ ResourceNotFound.new(e.message)
22
+ else
23
+ e
24
+ end
25
+ end
26
+
10
27
  include_package 'com.google.gdata.data'
11
28
  include_package 'com.google.gdata.data.acl'
12
29
  include_package 'com.google.gdata.data.batch'
@@ -25,8 +25,7 @@ class Java::ComGoogleGdataClient::GoogleService
25
25
  options[:class].java_class)
26
26
  end
27
27
  rescue NativeException => e
28
- return nil if e.message =~ /NotFound/
29
- raise e
28
+ raise GData.gdata_exception_for(e)
30
29
  end
31
30
  end
32
31
 
@@ -45,8 +44,7 @@ class Java::ComGoogleGdataClient::GoogleService
45
44
  options[:class].java_class)
46
45
  end
47
46
  rescue NativeException => e
48
- return nil if e.message =~ /NotFound/
49
- raise e
47
+ raise GData.gdata_exception_for(e)
50
48
  end
51
49
  end
52
50
 
@@ -54,8 +52,9 @@ class Java::ComGoogleGdataClient::GoogleService
54
52
  raise "Feed URL is required" unless options[:url]
55
53
  raise "Entry is required" unless options[:entry]
56
54
  options[:url] = url_for(options[:url]) if options[:url]
57
-
58
55
  insert(options[:url], options[:entry])
56
+ rescue NativeException => e
57
+ raise GData.gdata_exception_for(e)
59
58
  end
60
59
 
61
60
  def delete_entry(options={})
@@ -71,6 +70,8 @@ class Java::ComGoogleGdataClient::GoogleService
71
70
  options[:url] = url_for(options[:url]) if options[:url]
72
71
 
73
72
  batch(options[:url], options[:feed])
73
+ rescue NativeException => e
74
+ raise GData.gdata_exception_for(e)
74
75
  end
75
76
 
76
77
  end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require File.dirname(__FILE__) + '/../lib/gdata_jruby_client'
3
+ require File.dirname(__FILE__) + '/google_keys.rb'
4
+
5
+ include GoogleHelpers
6
+
7
+ describe GData::GoogleService do
8
+ it "should able to raise the right exception" do
9
+ e = GData.gdata_exception_for(Exception.new("com.google.gdata.util.AuthenticationException: Token invalid - Invalid AuthSub token."))
10
+ e.should be_instance_of(GData::AuthenticationError)
11
+ end
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gdata-jruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Luk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-28 00:00:00 -08:00
12
+ date: 2010-02-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -131,5 +131,6 @@ test_files:
131
131
  - spec/google_contacts_service_spec.rb
132
132
  - spec/google_keys.rb
133
133
  - spec/google_oauth_parameters_spec.rb
134
+ - spec/google_service_spec.rb
134
135
  - spec/images/sergey.jpg
135
136
  - spec/images/sergey_out.jpg