@@ -9,18 +9,35 @@ def initialize(connection)
9
9
end
10
10
11
11
def find ( calendar_token , url = nil , redirect_count = 0 )
12
- url ||= "/calendar/feeds/default/allcalendars/full/#{ calendar_token } ?alt=jsonc"
12
+ url ||= "https://www.google.com /calendar/feeds/default/allcalendars/full/#{ calendar_token } ?alt=jsonc"
13
13
response = @connection . get url , Client ::HEADERS
14
14
15
15
raise 'Redirection Loop' if redirect_count > 3
16
16
17
17
if success? response
18
- Response ::Calendar . new ( response , @connection )
18
+ item = JSON . parse ( response . body ) [ 'data' ]
19
+ Response ::Calendar . new ( item , @connection )
19
20
elsif redirect? response
20
21
find ( calendar_token , response [ 'location' ] , redirect_count += 1 )
21
22
end
22
23
end
23
24
25
+ def all ( url = nil , redirect_count = 0 )
26
+ url ||= "https://www.google.com/calendar/feeds/default/allcalendars/full?alt=jsonc"
27
+ response = @connection . get url , Client ::HEADERS
28
+
29
+ if success? response
30
+ # Response::Event.new(response, @connection, @calendar)
31
+ if items = JSON . parse ( response . body ) [ 'data' ] [ 'items' ]
32
+ items . map { |item | Response ::Calendar . new ( item , @connection , @calendar ) }
33
+ else
34
+ [ ]
35
+ end
36
+ elsif redirect? response
37
+ all ( response [ 'location' ] , redirect_count += 1 )
38
+ end
39
+ end
40
+
24
41
def create ( params = { } , url = nil , redirect_count = 0 )
25
42
url ||= '/calendar/feeds/default/owncalendars/full?alt=jsonc'
26
43
response = @connection . post url ,
@@ -34,7 +51,8 @@ def create(params = {}, url = nil, redirect_count = 0)
34
51
raise 'Redirection Loop' if redirect_count > 3
35
52
36
53
if success? response
37
- Response ::Calendar . new ( response , @connection )
54
+ item = JSON . parse ( response . body ) [ 'data' ]
55
+ Response ::Calendar . new ( item , @connection )
38
56
elsif redirect? ( response )
39
57
create ( params , response [ 'location' ] , redirect_count += 1 )
40
58
end
0 commit comments