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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTAxMjZhZWI1Njc0ZjY4ZmRlODJmYWQ2ZjllZGU0YTgzZDEyMTUwYQ==
4
+ NDczNGU5ZjE4YTFkMWIzMWMwMDczM2ZkNjg3OTQ0ZmI3ZGNhMTQ3Yg==
5
5
  data.tar.gz: !binary |-
6
- MDI4NzU2NTZkM2NjMTI4NWY0YTY4ZTNmZmRiNDA5Yjc1MzY0MWFlNQ==
6
+ MDEwMmM5NWY1MGQ1NWU0YWVlMzRhMDY0Y2E3Nzc5MGRlMWU5MWYxNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzUyMDQyY2IyNjI0YzYxNjA1ODE4NmEyNzlmYTczM2FjOTRjYjQ0ZjVlN2Ey
10
- YWUzYjU3YzUxYjc1NTg2YjNmZGUwZDA3NmMzYmU4NzlmN2NiNDc1NWIxZWFk
11
- ZmUzMjg5ZGY1MTczMzMyMDIyN2E5MjRkOTI1ZTI2MGRjYjI1YmI=
9
+ NDAwM2ZhMTE5ZDU5MmRmMmRjMjgyMTgzNzMyOTNlYjlkZmM4ZWJmNWZiZmE0
10
+ NjUyNjI5ZWE2NzdlOTdmYWFlOGIyY2EwOTlhYjdmYTRmODQ0ZDljMDYwYThi
11
+ YmUxZWY5NjdiNzQ2NjA3NGQ4MjJhNTlhODIzMWY5NmRiOWYyNTU=
12
12
  data.tar.gz: !binary |-
13
- MDQyYmY3Mzc4YzZkNDhlNzkzZWFiZTJiYjc0NDc1MWNhNmViYzMzYWJlZmU2
14
- MDY4YWJmMGE1MTY5YWUzMTdjYmUxMWZlZTI1ZGVkNzBlZWM4ZjVmYTcyZmIw
15
- ODY4YzJhMWFlMTM4ZGQyOTRlNmQ5MmViZWQ1NzI4OGM5NTRmZDI=
13
+ NjFiZjVmMjhmNjlkMDc4YzkzYzM4NjE0NTA1NWYzNGEwYzZlYzkwNDM1ODk0
14
+ MzZhMWYyMzVlZmNmZjIzYWVlMzg2MjdhNWExYjIyMjFhMWJhOWZiZWYyYzI1
15
+ Njc0Mzk5NDRiNTA4MzUxMDE1OGRlM2YxZTNjYTYxMGQ2YTI0ZmI=
@@ -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
- url = base
29
- url = "#{base}?#{QueryParams.encode(query_params)}" if query_params.keys.length > 0
30
- make_request(:get, url)
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
- response = @token.request(method, url, 'GData-Version' => '2.0')
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
@@ -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 = build_api_params(xoauth_requestor_id, options)
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 build_api_params(xoauth_requestor_id, options)
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] = stringify(options.delete(:time_min))
31
- api_params[:timeMax] = stringify(options.delete(:time_max))
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
- def stringify(time)
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
- #API_URL = 'https://www.google.com/calendar/feeds/EMAIL/private/full'
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
@@ -1,3 +1,3 @@
1
1
  module Gaah
2
- VERSION = "0.1.7.1"
2
+ VERSION = "0.1.8"
3
3
  end
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.1.7.1
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hwan-Joon Choi