intouch-gdata4ruby 0.1.5 → 0.1.5.1
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/lib/gdata4ruby.rb +1 -0
- data/lib/gdata4ruby/oauth_service.rb +88 -0
- metadata +2 -1
data/lib/gdata4ruby.rb
CHANGED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Author:: David Pitman (ui-design@vestaldesign.com )
|
2
|
+
# Copyright:: Copyright (C) 2010 David Pitman
|
3
|
+
# License:: LGPL v2.1
|
4
|
+
#--
|
5
|
+
# Licensed under the Lesser General Public License (GPL), Version 2.1 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.gnu.org/licenses/lgpl-2.1.txt
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
#
|
15
|
+
# Feel free to use and update, but be sure to contribute your
|
16
|
+
# code back to the project and attribute as required by the license.
|
17
|
+
#++
|
18
|
+
require 'gdata4ruby/base'
|
19
|
+
|
20
|
+
module GData4Ruby
|
21
|
+
#The service class is the main handler for all direct interactions with the
|
22
|
+
#Google Data API.
|
23
|
+
|
24
|
+
class OAuthService < Base
|
25
|
+
#Convenience attribute contains the currently OAuth access token
|
26
|
+
attr_reader :access_token
|
27
|
+
|
28
|
+
#Accepts an optional attributes hash for initialization values, most likely :gdata_version
|
29
|
+
def initialize(attributes = {})
|
30
|
+
super(attributes)
|
31
|
+
attributes.each do |key, value|
|
32
|
+
if self.respond_to?("#{key}=")
|
33
|
+
self.send("#{key}=", value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# The method is a generic hash to allow subclasses to easily receive args for their own type of authentication
|
39
|
+
# In this case, we're using an OAuth AccessToken - http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html
|
40
|
+
def authenticate(options = {})
|
41
|
+
@access_token = options[:access_token]
|
42
|
+
end
|
43
|
+
|
44
|
+
def reauthenticate(options = {})
|
45
|
+
@access_token ||= options[:access_token]
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def authenticated?
|
50
|
+
return (@access_token != nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def do_request(request)
|
56
|
+
log("Sending request\nHeader: #{request.headers.inspect.to_s}\nContent: #{request.content.to_s}\n")
|
57
|
+
set_protocol!(request)
|
58
|
+
ret = case request.type
|
59
|
+
when :get
|
60
|
+
@access_token.get(request.url.to_s, {}, request.headers)
|
61
|
+
when :post
|
62
|
+
@access_token.post(request.url.to_s, request.content, request.headers)
|
63
|
+
when :put
|
64
|
+
@access_token.put(request.url.to_s, request.content, request.headers)
|
65
|
+
when :delete
|
66
|
+
@access_token.delete(request.url.to_s, {}, request.headers)
|
67
|
+
end
|
68
|
+
|
69
|
+
if not ret.success?
|
70
|
+
log("invalid response received: "+ret.status)
|
71
|
+
raise HTTPRequestFailed, ret.body
|
72
|
+
end
|
73
|
+
log("20x response received\nResponse: \n"+ret.body)
|
74
|
+
return ret
|
75
|
+
end
|
76
|
+
|
77
|
+
# Not used in OAuth implementation...
|
78
|
+
def get_http_object(location)
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
|
82
|
+
# Not used in OAuth implementation...
|
83
|
+
def add_auth_header(request)
|
84
|
+
return nil
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: intouch-gdata4ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.5
|
5
|
+
version: 0.1.5.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mike Reich
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/gdata4ruby.rb
|
38
38
|
- lib/gdata4ruby/base.rb
|
39
39
|
- lib/gdata4ruby/service.rb
|
40
|
+
- lib/gdata4ruby/oauth_service.rb
|
40
41
|
- lib/gdata4ruby/request.rb
|
41
42
|
- lib/gdata4ruby/gdata_object.rb
|
42
43
|
- lib/gdata4ruby/utils/utils.rb
|