gaah 0.2.1 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51fc7e203dd89db1eab8f6486aa75d6121fc258d
4
- data.tar.gz: 83cf55fae1d9245147dac00355969df1f5ddcc9f
3
+ metadata.gz: 287f7c3f2ca94996a1b786c6f788501a62748855
4
+ data.tar.gz: af476cf2943ef05c0ffb67557a5d89b587dc2448
5
5
  SHA512:
6
- metadata.gz: a0cd242d54a99df822ca368def835cec6c517c6265c8a744dda4e262f6973536121ed0d98fb213f0bb2b81a14af6bb371da375e590d9100d850da09da1729c07
7
- data.tar.gz: e0a61ff4fc1e974e922826d206a2c13ca5672eba797a185cd30fedd90ea70a7c4a610a748a15902e8e3be5d1b0b3a3b8ee1bf49c7c8499e3d2426b64f1d0ca22
6
+ metadata.gz: e7b2c3134ce2238b372e867746789c528fadb6e3ef56daa5a13502ec46762d94e0570f7f69384bb67f688b383821c5c6eca69e642bb0ac4fb0697d37f8680ac0
7
+ data.tar.gz: 8a83de8aa155bdcc60d0bef93cbf65674feabe262c0b85493d71a17f76e33643180a2287054c9dcf35cc568dcd4933ee50349b87dc0ddcc7827d144886c63997
@@ -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
@@ -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
- event = JSON.load(json)
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
- event = JSON.load(json)
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
@@ -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, @attendees, @transparency, @visibility]
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, @attendees, @transparency, @visibility = array
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
@@ -1,6 +1,24 @@
1
1
  module Gaah
2
- class HTTPForbidden < Exception;end
3
- class HTTPUnauthorized < Exception;end
4
- class HTTPBadRequest < Exception;end
5
- class UnknownHTTPException < Exception;end
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
@@ -1,3 +1,3 @@
1
1
  module Gaah
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
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.2.1
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: