gaah 0.1.7.1 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/gaah/api_client.rb +17 -7
- data/lib/gaah/calendar/api.rb +60 -6
- data/lib/gaah/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDczNGU5ZjE4YTFkMWIzMWMwMDczM2ZkNjg3OTQ0ZmI3ZGNhMTQ3Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDEwMmM5NWY1MGQ1NWU0YWVlMzRhMDY0Y2E3Nzc5MGRlMWU5MWYxNw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDAwM2ZhMTE5ZDU5MmRmMmRjMjgyMTgzNzMyOTNlYjlkZmM4ZWJmNWZiZmE0
|
10
|
+
NjUyNjI5ZWE2NzdlOTdmYWFlOGIyY2EwOTlhYjdmYTRmODQ0ZDljMDYwYThi
|
11
|
+
YmUxZWY5NjdiNzQ2NjA3NGQ4MjJhNTlhODIzMWY5NmRiOWYyNTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjFiZjVmMjhmNjlkMDc4YzkzYzM4NjE0NTA1NWYzNGEwYzZlYzkwNDM1ODk0
|
14
|
+
MzZhMWYyMzVlZmNmZjIzYWVlMzg2MjdhNWExYjIyMjFhMWJhOWZiZWYyYzI1
|
15
|
+
Njc0Mzk5NDRiNTA4MzUxMDE1OGRlM2YxZTNjYTYxMGQ2YTI0ZmI=
|
data/lib/gaah/api_client.rb
CHANGED
@@ -24,22 +24,32 @@ module Gaah
|
|
24
24
|
@token = OAuth::AccessToken.new(oauth_consumer)
|
25
25
|
end
|
26
26
|
|
27
|
-
def get(base, query_params={})
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def get(base, query_params = {})
|
28
|
+
make_request(:get, base, query_params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def post(base, query_params = {}, body = {})
|
32
|
+
make_request(:post, base, query_params, body)
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
34
36
|
|
35
|
-
def make_request(method, url)
|
36
|
-
|
37
|
+
def make_request(method, url, params = {}, body = nil)
|
38
|
+
url = "#{url}?#{QueryParams.encode(params)}" if params.keys.length > 0
|
39
|
+
case method
|
40
|
+
when :get
|
41
|
+
response = @token.get(url, 'GData-Version' => '2.0')
|
42
|
+
when :post
|
43
|
+
response = @token.post(url, body.to_json, 'Content-Type' => 'application/json')
|
44
|
+
else
|
45
|
+
response = @token.request(method, url, 'GData-Version' => '2.0')
|
46
|
+
end
|
37
47
|
|
38
48
|
if response.is_a? Net::HTTPSuccess
|
39
49
|
response.body
|
40
50
|
elsif response.is_a? Net::HTTPFound
|
41
51
|
url = response['Location']
|
42
|
-
make_request(method, response['Location'])
|
52
|
+
make_request(method, response['Location'], params, body)
|
43
53
|
elsif response.is_a? Net::HTTPForbidden
|
44
54
|
raise Gaah::HTTPForbidden
|
45
55
|
elsif response.is_a? Net::HTTPUnauthorized
|
data/lib/gaah/calendar/api.rb
CHANGED
@@ -6,37 +6,91 @@ module Gaah
|
|
6
6
|
module Calendar
|
7
7
|
class Api
|
8
8
|
class << self
|
9
|
+
# API: Events#list
|
9
10
|
def events(xoauth_requestor_id, options)
|
10
11
|
url = build_api_url(options[:email])
|
11
|
-
params =
|
12
|
+
params = build_events_api_params(xoauth_requestor_id, options)
|
12
13
|
json = ApiClient.instance.get(url, params)
|
13
14
|
events = JSON.load(json)
|
14
15
|
Event.batch_create(events['items'])
|
15
16
|
end
|
16
17
|
|
18
|
+
# API: Events#insert
|
19
|
+
def create_event(xoauth_requestor_id, options)
|
20
|
+
url = build_api_url(options.delete(:email))
|
21
|
+
params = { xoauth_requestor_id: xoauth_requestor_id }
|
22
|
+
body = build_create_api_body(options)
|
23
|
+
json = ApiClient.instance.post(url, params, body)
|
24
|
+
event = JSON.load(json)
|
25
|
+
end
|
26
|
+
|
27
|
+
# API: Events#get
|
28
|
+
def event(xoauth_requestor_id, options)
|
29
|
+
base = build_api_url(options.delete(:email))
|
30
|
+
id = options.delete(:event_id)
|
31
|
+
url = "#{base}/#{id}"
|
32
|
+
params = { xoauth_requestor_id: xoauth_requestor_id }
|
33
|
+
json = ApiClient.instance.get(url, params)
|
34
|
+
event = JSON.load(json)
|
35
|
+
end
|
36
|
+
|
17
37
|
private
|
18
38
|
|
19
39
|
def build_api_url(email)
|
20
40
|
API_URL.sub('CAL_ID', email || 'default')
|
21
41
|
end
|
22
42
|
|
23
|
-
def
|
43
|
+
def build_events_api_params(xoauth_requestor_id, options)
|
24
44
|
api_params = {
|
25
45
|
xoauth_requestor_id: xoauth_requestor_id,
|
26
46
|
alwaysIncludeEmail: true,
|
27
47
|
}
|
28
48
|
api_params[:orderBy] = options.delete(:order_by) || 'startTime'
|
29
49
|
api_params[:singleEvents] = options.delete(:single_events) || true
|
30
|
-
api_params[:timeMin] =
|
31
|
-
api_params[:timeMax] =
|
50
|
+
api_params[:timeMin] = dateify(options.delete(:time_min))
|
51
|
+
api_params[:timeMax] = dateify(options.delete(:time_max))
|
32
52
|
api_params
|
33
53
|
end
|
34
54
|
|
35
|
-
|
55
|
+
# required options (heh):
|
56
|
+
# email
|
57
|
+
# start_time
|
58
|
+
# end_time
|
59
|
+
#
|
60
|
+
# optional options:
|
61
|
+
# summary
|
62
|
+
# description
|
63
|
+
# participants
|
64
|
+
# resources
|
65
|
+
def build_create_api_body(options)
|
66
|
+
body = {}
|
67
|
+
|
68
|
+
start_time = { dateTime: options.delete(:start_time).xmlschema }
|
69
|
+
end_time = { dateTime: options.delete(:end_time ).xmlschema }
|
70
|
+
summary = options.delete(:summary)
|
71
|
+
description = options.delete(:description)
|
72
|
+
|
73
|
+
attendees =
|
74
|
+
attendeeify(options.delete(:participants), 'needsAction') +
|
75
|
+
attendeeify(options.delete(:resources), 'accepted')
|
76
|
+
|
77
|
+
body[:start] = start_time
|
78
|
+
body[:end] = end_time
|
79
|
+
body[:summary] = summary unless summary.nil?
|
80
|
+
body[:description] = description unless description.nil?
|
81
|
+
body[:attendees] = attendees unless attendees.empty?
|
82
|
+
body
|
83
|
+
end
|
84
|
+
|
85
|
+
def dateify(time)
|
36
86
|
time.nil? ? nil : DateTime.parse(time.strftime('%Y-%m-%dT17:00:00')).rfc3339
|
37
87
|
end
|
38
88
|
|
39
|
-
|
89
|
+
def attendeeify(emails, status)
|
90
|
+
return [] if emails.nil?
|
91
|
+
emails.map { |email| { email: email, responseStatus: status } }
|
92
|
+
end
|
93
|
+
|
40
94
|
API_URL = 'https://www.googleapis.com/calendar/v3/calendars/CAL_ID/events'
|
41
95
|
end
|
42
96
|
end
|
data/lib/gaah/version.rb
CHANGED