gaah 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gaah/api_client.rb +6 -0
- data/lib/gaah/calendar/api.rb +20 -2
- data/lib/gaah/calendar/event.rb +12 -3
- data/lib/gaah/exceptions.rb +22 -4
- data/lib/gaah/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 287f7c3f2ca94996a1b786c6f788501a62748855
|
4
|
+
data.tar.gz: af476cf2943ef05c0ffb67557a5d89b587dc2448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7b2c3134ce2238b372e867746789c528fadb6e3ef56daa5a13502ec46762d94e0570f7f69384bb67f688b383821c5c6eca69e642bb0ac4fb0697d37f8680ac0
|
7
|
+
data.tar.gz: 8a83de8aa155bdcc60d0bef93cbf65674feabe262c0b85493d71a17f76e33643180a2287054c9dcf35cc568dcd4933ee50349b87dc0ddcc7827d144886c63997
|
data/lib/gaah/api_client.rb
CHANGED
@@ -28,6 +28,10 @@ module Gaah
|
|
28
28
|
make_request(:get, base, query_params)
|
29
29
|
end
|
30
30
|
|
31
|
+
def delete(base, query_params = {})
|
32
|
+
make_request(:delete, base, query_params)
|
33
|
+
end
|
34
|
+
|
31
35
|
def post(base, query_params = {}, body = {})
|
32
36
|
make_request(:post, base, query_params, body)
|
33
37
|
end
|
@@ -39,6 +43,8 @@ module Gaah
|
|
39
43
|
case method
|
40
44
|
when :get
|
41
45
|
response = @token.get(url, 'GData-Version' => '2.0')
|
46
|
+
when :delete
|
47
|
+
response = @token.delete(url, 'GData-Version' => '2.0')
|
42
48
|
when :post
|
43
49
|
response = @token.post(url, body.to_json, 'Content-Type' => 'application/json')
|
44
50
|
else
|
data/lib/gaah/calendar/api.rb
CHANGED
@@ -21,7 +21,8 @@ module Gaah
|
|
21
21
|
params = { xoauth_requestor_id: xoauth_requestor_id }
|
22
22
|
body = build_create_api_body(options)
|
23
23
|
json = ApiClient.instance.post(url, params, body)
|
24
|
-
|
24
|
+
|
25
|
+
Gaah::Calendar::Event.new(JSON.load(json))
|
25
26
|
end
|
26
27
|
|
27
28
|
# API: Events#get
|
@@ -31,7 +32,24 @@ module Gaah
|
|
31
32
|
url = "#{base}/#{id}"
|
32
33
|
params = { xoauth_requestor_id: xoauth_requestor_id }
|
33
34
|
json = ApiClient.instance.get(url, params)
|
34
|
-
|
35
|
+
|
36
|
+
Gaah::Calendar::Event.new(JSON.load(json))
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_event(xoauth_requestor_id, options)
|
40
|
+
base = build_api_url(options.delete(:email))
|
41
|
+
id = options.delete(:event_id)
|
42
|
+
url = "#{base}/#{id}"
|
43
|
+
params = { xoauth_requestor_id: xoauth_requestor_id }
|
44
|
+
ApiClient.instance.delete(url, params)
|
45
|
+
{ success: true }
|
46
|
+
rescue Gaah::UnknownHTTPException => exception
|
47
|
+
case exception.message
|
48
|
+
when '404'
|
49
|
+
{ success: false, error: "Event was not found." }
|
50
|
+
when '410'
|
51
|
+
{ success: false, error: "Event is already canceled." }
|
52
|
+
end
|
35
53
|
end
|
36
54
|
|
37
55
|
private
|
data/lib/gaah/calendar/event.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Gaah
|
2
2
|
module Calendar
|
3
3
|
class Event < Gaah::ApiModel
|
4
|
-
attr_reader :updated, :summary, :description, :attendees, :when, :location, :creator, :transparency, :visibility
|
4
|
+
attr_reader :updated, :summary, :description, :attendees, :when, :location, :creator, :transparency, :visibility, :ical_uid, :organizer, :sequence, :status
|
5
5
|
|
6
6
|
def initialize(json)
|
7
7
|
store_json(json)
|
8
8
|
|
9
9
|
@id = json['id']
|
10
|
+
@ical_uid = json['iCalUID']
|
10
11
|
@updated = Time.parse(json['updated'])
|
11
12
|
@summary = json['summary'].to_s
|
12
13
|
@description = json['description'].to_s
|
@@ -16,6 +17,9 @@ module Gaah
|
|
16
17
|
@attendees = parse_attendees
|
17
18
|
@transparency = json['transparency'].to_s
|
18
19
|
@visibility = json['visibility'] || 'default'
|
20
|
+
@organizer = Who.new(json['organizer'])
|
21
|
+
@sequence = json['sequence']
|
22
|
+
@status = json['status']
|
19
23
|
end
|
20
24
|
|
21
25
|
def to_json(*args)
|
@@ -30,6 +34,7 @@ module Gaah
|
|
30
34
|
attendees: @attendees,
|
31
35
|
transparency: @transparency,
|
32
36
|
visibility: @visibility,
|
37
|
+
status: @status,
|
33
38
|
}.to_json
|
34
39
|
end
|
35
40
|
|
@@ -41,11 +46,15 @@ module Gaah
|
|
41
46
|
def who; attendees; end
|
42
47
|
|
43
48
|
def marshal_dump
|
44
|
-
[@id, nil, @updated, @summary, @description, @location, @creator, @when,
|
49
|
+
[@id, nil, @updated, @summary, @description, @location, @creator, @when,
|
50
|
+
@attendees, @transparency, @visibility, @ical_uid, @organizer,
|
51
|
+
@sequence, @status]
|
45
52
|
end
|
46
53
|
|
47
54
|
def marshal_load(array)
|
48
|
-
@id, _, @updated, @summary, @description, @location, @creator, @when,
|
55
|
+
@id, _, @updated, @summary, @description, @location, @creator, @when,
|
56
|
+
@attendees, @transparency, @visibility, @ical_uid, @organizer,
|
57
|
+
@sequence, @status = array
|
49
58
|
end
|
50
59
|
|
51
60
|
private
|
data/lib/gaah/exceptions.rb
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
module Gaah
|
2
|
-
class HTTPForbidden <
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class HTTPForbidden < StandardError
|
3
|
+
def initialize(msg = nil)
|
4
|
+
info = "You do not have the necessary permissions to perform this action on this domain"
|
5
|
+
super("#{info}#{msg.nil? ? '.' : ': '}#{msg}")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class HTTPUnauthorized < StandardError
|
10
|
+
def initialize(msg = nil)
|
11
|
+
info = "This domain or user does not support Google Apps"
|
12
|
+
super("#{info}#{msg.nil? ? '.' : ': '}#{msg}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class HTTPBadRequest < StandardError
|
17
|
+
def initialize(msg = nil)
|
18
|
+
info = "Unsupported action"
|
19
|
+
super("#{info}#{msg.nil? ? '.' : ': '}#{msg}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class UnknownHTTPException < StandardError;end
|
6
24
|
end
|
data/lib/gaah/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gaah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hwan-Joon Choi
|
@@ -145,3 +145,4 @@ test_files:
|
|
145
145
|
- spec/models/resource_spec.rb
|
146
146
|
- spec/models/user_spec.rb
|
147
147
|
- spec/spec_helper.rb
|
148
|
+
has_rdoc:
|