gaah 0.1.6 → 0.1.7

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
- ZDhkOTRiM2I1Njk1N2IwODg1ZjA4NTIwYWE4ODhiMDQyMjE5NDA2MA==
4
+ OWViNTAxOWIxMzM5ZDFhMzJmZWNkYWQ5YjhkZjQwMGQ4N2E1ODJhMw==
5
5
  data.tar.gz: !binary |-
6
- ZmE0ZTNjZGZiMTE0Y2JiNDVjOTVkOTI0ZDEzMDdiYTBmMTQyNjJiYg==
6
+ OTUxNThlOTM3ZjYzM2YxYzc5ZjliMTY4ODEzMTYyYmFiZDAxYjA5MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZmE3OTIyNjU5MmRiY2VlMWZmN2YyMGQ1YWM4ZjkyMDg3ZTc5ZDAzODA3YmEz
10
- YmFjNDRlNWM2MjU1MDI2OWVjNGQxNDRhODQyMGY1N2MwN2I5YWJiZjcwZjU4
11
- ZDZiNjdmOGNkYjhmZGE3M2JlMjUxYzhmMzgxYzEzM2M4NTYxZTc=
9
+ MzI0Yzc1ZjMwMGJhOTA5ODY3MTRiM2U3Yjc5YTRhNmQ2NTUxZmE3OTkzODMw
10
+ OWRjM2M0NGQ2NzI2NWVkNGNhZGExZDZmNTc5OGQ3Zjg5NjI0ZjcwNDFhZWY4
11
+ YjBiYWFmZmI4NDNjNmFiNzZhYTYxOWUxNWJmNDZlYTA0NzgyYjk=
12
12
  data.tar.gz: !binary |-
13
- NDc4OGU4MjA1MWM0ODM1MmUyOGE4NDdhZThmMzAzYzVlZDI4NGIwNGMzOTA4
14
- YjMyNzNlZWM2NWQ2YTcxYmVlZWE0MmFiMjdkZjJhMGUyZDlkNjBlNTM5YjFk
15
- YjFlODEyZGM3YjQzYmQ4NmQxODMyY2RlMGVlZGUwY2VjMmE0Mjk=
13
+ ZTExYjUyMDNjNmUxNmY2ODU4ZGI4NzU0MjExOTUyNTFlNTUyOTJhY2Q2OTkx
14
+ Mzg1Yzg1YjhjYmYwMGExNDUzMmMyYjUwMjJkNWZkOTJhODg5YTc0MzdhMGJj
15
+ NjcxYzk5YzQ0NGNhZmI0OWE4OGUxMmU1NDBmMjIwMjIwYzRlZmU=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gaah (0.1.5)
4
+ gaah (0.1.7)
5
5
  nokogiri (~> 1.5)
6
6
  oauth (~> 0.4)
7
7
  oauth2 (~> 0.9)
@@ -3,7 +3,11 @@ module Gaah
3
3
  attr_reader :id
4
4
 
5
5
  def self.batch_create(xml)
6
- (xml/:entry).map(&method(:new))
6
+ if xml.is_a? Array
7
+ xml.map(&method(:new))
8
+ else
9
+ (xml/:entry).map(&method(:new))
10
+ end
7
11
  end
8
12
 
9
13
  def ==(other)
@@ -12,6 +16,10 @@ module Gaah
12
16
 
13
17
  private
14
18
 
19
+ def store_json(json)
20
+ @json = json.is_a?(String) ? JSON.load(json) : json
21
+ end
22
+
15
23
  def store_xml(xml)
16
24
  @xml = xml.is_a?(String) ? Nokogiri::XML(xml) : xml
17
25
  end
@@ -9,15 +9,15 @@ module Gaah
9
9
  def events(xoauth_requestor_id, options)
10
10
  url = build_api_url(options[:email])
11
11
  params = build_api_params(xoauth_requestor_id, options)
12
- xml = ApiClient.instance.get(url, params)
13
- events = Nokogiri::XML(xml)/:entry
14
- Event.batch_create(events)
12
+ json = ApiClient.instance.get(url, params)
13
+ events = JSON.load(json)
14
+ Event.batch_create(events['items'])
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def build_api_url(email)
20
- API_URL.sub('EMAIL', email || 'default')
20
+ API_URL.sub('CAL_ID', email || 'default')
21
21
  end
22
22
 
23
23
  def build_api_params(xoauth_requestor_id, options)
@@ -34,7 +34,8 @@ module Gaah
34
34
  time.nil? ? nil : time.strftime('%Y-%m-%dT17:00:00')
35
35
  end
36
36
 
37
- API_URL = 'https://www.google.com/calendar/feeds/EMAIL/private/full'
37
+ #API_URL = 'https://www.google.com/calendar/feeds/EMAIL/private/full'
38
+ API_URL = 'https://www.googleapis.com/calendar/v3/calendars/CAL_ID/events'
38
39
  end
39
40
  end
40
41
  end
@@ -1,65 +1,68 @@
1
1
  module Gaah
2
2
  module Calendar
3
3
  class Event < Gaah::ApiModel
4
- attr_reader :published, :updated, :title, :content, :status, :who, :when, :where, :author, :transparency, :visibility
4
+ attr_reader :updated, :summary, :description, :attendees, :when, :location, :creator, :transparency, :visibility
5
5
 
6
- def initialize(xml)
7
- store_xml(xml)
6
+ def initialize(json)
7
+ store_json(json)
8
8
 
9
- @id = inner_text(:id)
10
- @published = Time.parse(inner_text(:published))
11
- @updated = Time.parse(inner_text(:updated))
12
- @title = inner_text(:title)
13
- @content = inner_text(:content)
14
- @status = tag_value('gd|eventStatus')
15
- @where = attr_value('gd|where', 'valueString')
16
- @author = Who.new((@xml/:author).first)
9
+ @id = json['id']
10
+ @updated = Time.parse(json['updated'])
11
+ @summary = json['summary'].to_s
12
+ @description = json['description'].to_s
13
+ @location = json['location'].to_s
14
+ @creator = Who.new(json['creator']) if json['creator']
17
15
  @when = parse_when
18
- @who = parse_who
19
- @transparency = tag_value('gd|transparency')
20
- @visibility = tag_value('gd|visibility')
16
+ @attendees = parse_attendees
17
+ @transparency = json['transparency'].to_s
18
+ @visibility = json['visibility'] || 'default'
21
19
  end
22
20
 
23
21
  def to_json(*args)
24
22
  {
25
23
  id: @id,
26
- published: @published,
27
24
  updated: @updated,
28
- title: @title,
29
- content: @content,
30
- status: @status,
31
- where: @where,
32
- author: @author,
25
+ summary: @summary,
26
+ description: @description,
27
+ location: @location,
28
+ creator: @creator,
33
29
  when: @when,
34
- who: @who,
30
+ attendees: @attendees,
35
31
  transparency: @transparency,
36
32
  visibility: @visibility,
37
33
  }.to_json
38
34
  end
39
35
 
36
+ # V2 -> V3
37
+ def author; creator; end
38
+ def content; description; end
39
+ def title; summary; end
40
+ def where; location; end
41
+ def who; attendees; end
42
+
40
43
  def marshal_dump
41
- [@id, @published, @updated, @title, @content, @status, @where, @author, @when, @who, @transparency, @visibility]
44
+ [@id, nil, @updated, @summary, @description, @location, @creator, @when, @attendees, @transparency, @visibility]
42
45
  end
43
46
 
44
47
  def marshal_load(array)
45
- @id, @published, @updated, @title, @content, @status, @where, @author, @when, @who, @transparency, @visibility = array
48
+ @id, _, @updated, @summary, @description, @location, @creator, @when, @attendees, @transparency, @visibility = array
46
49
  end
47
50
 
48
51
  private
49
52
 
50
- def store_xml(xml)
53
+ def store_json(json)
51
54
  super
52
- unless @xml.attr('gd:kind') == "calendar#event"
53
- puts "Possible invalid event xml - gd:kind is #{ @xml.attr('gd:kind') }"
55
+ unless @json['kind'] == "calendar#event"
56
+ puts "Possible invalid event json - kind is #{ @json['kind'] }"
54
57
  end
55
58
  end
56
59
 
57
60
  def parse_when
58
- When.new(attr_value('> gd|when', 'startTime'), attr_value('> gd|when', 'endTime'))
61
+ When.new(@json['start'], @json['end'])
59
62
  end
60
63
 
61
- def parse_who
62
- (@xml/'gd|who').map {|attendee| Who.new(attendee) }
64
+ def parse_attendees
65
+ (@json['attendees'] || []).map {|attendee| Who.new(attendee) }
63
66
  end
64
67
  end
65
68
  end
@@ -3,8 +3,13 @@ module Gaah
3
3
  class When
4
4
  attr_accessor :start_time, :end_time
5
5
  def initialize(start_time, end_time)
6
- @start_time = Time.parse(start_time)
7
- @end_time = Time.parse(end_time)
6
+ if start_time.is_a? Hash
7
+ @start_time = Time.parse(start_time.values.first)
8
+ @end_time = Time.parse(end_time.values.first)
9
+ else
10
+ @start_time = Time.parse(start_time)
11
+ @end_time = Time.parse(end_time)
12
+ end
8
13
  end
9
14
 
10
15
  def to_json(*args)
@@ -1,27 +1,10 @@
1
1
  module Gaah
2
2
  module Calendar
3
3
  class Who
4
- attr_reader :name, :email, :aliases
5
- def initialize(xml)
6
- @aliases = []
7
-
8
- case xml.name
9
- when 'author'
10
- @name = (xml/:name).inner_text
11
- @email = (xml/:email).inner_text
12
- when 'who'
13
- @name = xml.attr(:valueString)
14
- @email = xml.attr(:email)
15
- when 'entry'
16
- @name = (xml/:title).inner_text
17
- (xml/'gd|email').each do |gd_email|
18
- email = gd_email.attr('address')
19
- @aliases << email
20
- @email = email if gd_email.attr('primary') == 'true'
21
- end
22
- else
23
- raise "Invalid person record #{xml.name}"
24
- end
4
+ attr_reader :name, :email
5
+ def initialize(json)
6
+ @name = json['displayName'].to_s
7
+ @email = json['email'].to_s
25
8
  end
26
9
 
27
10
  def catch_all_user?
@@ -30,9 +13,8 @@ module Gaah
30
13
 
31
14
  def to_json(*args)
32
15
  {
33
- name: name,
34
- email: email,
35
- aliases: aliases,
16
+ name: name,
17
+ email: email,
36
18
  }.to_json
37
19
  end
38
20
 
@@ -14,7 +14,7 @@ module Gaah
14
14
  url = "https://apps-apis.google.com/a/feeds/calendar/resource/2.0/#{Gaah.domain}"
15
15
  xml = ApiClient.instance.get(url)
16
16
  parsed = Nokogiri::XML(xml)
17
-
17
+
18
18
  current_list = Resource.batch_create(parsed/:entry)
19
19
  next_link = (parsed/'link[rel=next]').first
20
20
 
@@ -1,3 +1,3 @@
1
1
  module Gaah
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -0,0 +1,135 @@
1
+ {
2
+ "kind": "calendar#events",
3
+ "etag": "\"foo\"",
4
+ "summary": "_me",
5
+ "updated": "2013-08-26T22:16:43.629Z",
6
+ "timeZone": "America/Los_Angeles",
7
+ "accessRole": "owner",
8
+ "defaultReminders": [{
9
+ "method": "popup",
10
+ "minutes": 10
11
+ }],
12
+ "items": [{
13
+ "kind": "calendar#event",
14
+ "etag": "\"bar1\"",
15
+ "id": "one",
16
+ "status": "confirmed",
17
+ "htmlLink": "https://www.google.com/calendar/event?eid=one",
18
+ "created": "2012-12-05T23:51:16.000Z",
19
+ "updated": "2012-12-13T22:00:00Z",
20
+ "summary": "Holiday Dinner",
21
+ "description": "Holiday party time!",
22
+ "location": "Prospect, 300 Spear St, San Francisco, CA 94105",
23
+ "creator": {
24
+ "email": "alice@example.com",
25
+ "displayName": "Alice McAlice"
26
+ },
27
+ "organizer": {
28
+ "email": "bob@example.com",
29
+ "displayName": "Bob O'Bob"
30
+ },
31
+ "start": {
32
+ "dateTime": "2012-12-14T18:30:00-08:00"
33
+ },
34
+ "end": {
35
+ "dateTime": "2012-12-14T21:30:00-08:00"
36
+ },
37
+ "iCalUID": "foo@google.com",
38
+ "visibility": "private",
39
+ "sequence": 0,
40
+ "attendees": [{
41
+ "email": "bob@example.com",
42
+ "displayName": "Bob-Bob O'Bob",
43
+ "responseStatus": "needsAction"
44
+ }, {
45
+ "email": "alice@example.com",
46
+ "displayName": "Alice McAlice",
47
+ "organizer": true,
48
+ "self": true,
49
+ "responseStatus": "accepted"
50
+ }, {
51
+ "email": "chris@example.com",
52
+ "displayName": "Chris Christiansen",
53
+ "responseStatus": "accepted"
54
+ }],
55
+ "reminders": {
56
+ "useDefault": true
57
+ }
58
+ }, {
59
+ "kind": "calendar#event",
60
+ "etag": "\"bar2\"",
61
+ "id": "dos",
62
+ "status": "confirmed",
63
+ "htmlLink": "https://www.google.com/calendar/event?eid=two",
64
+ "created": "2012-12-18T16:34:06.000Z",
65
+ "updated": "2012-12-19T19:49:46.817Z",
66
+ "summary": "Meet for WeWork Walkthrough",
67
+ "location": "795 Folsom",
68
+ "creator": {
69
+ "email": "david@notexample.com"
70
+ },
71
+ "organizer": {
72
+ "email": "david@notexample.com"
73
+ },
74
+ "start": {
75
+ "dateTime": "2012-12-19T10:15:00-08:00"
76
+ },
77
+ "end": {
78
+ "dateTime": "2012-12-19T11:15:00-08:00"
79
+ },
80
+ "iCalUID": "bar@google.com",
81
+ "sequence": 0,
82
+ "transparency": "transparent",
83
+ "attendees": [{
84
+ "email": "bob@example.com",
85
+ "responseStatus": "accepted"
86
+ }, {
87
+ "email": "alice@example.com",
88
+ "displayName": "Alice McAlice",
89
+ "self": true,
90
+ "responseStatus": "declined"
91
+ }],
92
+ "reminders": {
93
+ "useDefault": true
94
+ }
95
+ }, {
96
+ "kind": "calendar#event",
97
+ "etag": "\"baz\"",
98
+ "id": "three",
99
+ "status": "confirmed",
100
+ "htmlLink": "https://www.google.com/calendar/event?eid=three",
101
+ "created": "2013-02-11T19:42:44.000Z",
102
+ "updated": "2013-02-12T00:55:43.590Z",
103
+ "summary": "Weekly Sync",
104
+ "creator": {
105
+ "email": "alice@example.com",
106
+ "displayName": "Alice McAlice"
107
+ },
108
+ "organizer": {
109
+ "email": "alice@example.com",
110
+ "displayName": "Alice McAlice"
111
+ },
112
+ "start": {
113
+ "dateTime": "2013-02-11T17:00:00-08:00"
114
+ },
115
+ "end": {
116
+ "dateTime": "2013-02-11T17:30:00-08:00"
117
+ },
118
+ "iCalUID": "tres@google.com",
119
+ "sequence": 0,
120
+ "attendees": [{
121
+ "email": "alice@example.com",
122
+ "displayName": "Alice McAlice",
123
+ "organizer": true,
124
+ "responseStatus": "accepted"
125
+ }, {
126
+ "email": "bob@example.com",
127
+ "displayName": "Bob McBob",
128
+ "self": true,
129
+ "responseStatus": "needsAction"
130
+ }],
131
+ "reminders": {
132
+ "useDefault": true
133
+ }
134
+ }]
135
+ }
@@ -3,97 +3,90 @@ include Gaah::Calendar
3
3
 
4
4
  describe Event do
5
5
  let(:xml) { fixture('calendar.xml') }
6
- let(:events) { Nokogiri::XML(xml)/:entry }
6
+ let(:json) { fixture('calendar.json') }
7
+ #let(:events) { Nokogiri::XML(xml)/:entry }
8
+ let(:events) { JSON.load(json)['items'] }
7
9
  let(:event) { Event.new(events.first) }
8
10
 
9
11
  describe '#initialize' do
12
+ subject { event }
10
13
  it 'parses ID' do
11
- event.id.should == 'http://www.google.com/calendar/feeds/bobert%40example.com/events/n9ommrehhjm5dc6q89ofkm3f8g'
12
- end
13
-
14
- it 'parses published time' do
15
- event.published.should == Time.parse('2013-03-25T16:49:48.000Z')
14
+ subject.id.should == 'one'
16
15
  end
17
16
 
18
17
  it 'parses updated time' do
19
- event.updated.should == Time.parse('2013-03-25T17:03:10.000Z')
18
+ subject.updated.should == Time.parse('2012-12-13 22:00:00 UTC')
20
19
  end
21
20
 
22
- it 'parses title' do
23
- event.title.should == 'MomCorp'
21
+ it 'parses summary' do
22
+ subject.summary.should == 'Holiday Dinner'
24
23
  end
25
24
 
26
- it 'parses content' do
27
- event.content.should == ''
25
+ it 'parses description' do
26
+ subject.description.should == 'Holiday party time!'
28
27
  end
29
28
 
30
- it 'parses status' do
31
- event.status.should == 'confirmed'
32
- end
29
+ describe :attendees do
30
+ let(:subject) { event.attendees }
33
31
 
34
- describe :who do
35
- let(:who) { event.who }
32
+ it 'parses all attendees' do
33
+ subject.length.should == 3
34
+ end
36
35
 
37
- it 'parses who' do
38
- who.length.should == 2
39
- who.first.should be_an_instance_of(Gaah::Calendar::Who)
36
+ it 'parses Who object' do
37
+ subject.first.should be_an_instance_of(Gaah::Calendar::Who)
40
38
  end
41
39
 
42
40
  it 'parses name' do
43
- who.first.name.should == 'Bobert Jones'
41
+ subject.first.name.should == "Bob-Bob O'Bob"
44
42
  end
45
43
 
46
44
  it 'parses email' do
47
- who.first.email.should == 'bobert@example.com'
45
+ subject.first.email.should == 'bob@example.com'
48
46
  end
49
47
  end
50
48
 
51
49
  describe :when do
52
- let(:_when) { event.when }
50
+ let(:subject) { event.when }
53
51
 
54
- it 'parses when' do
55
- _when.should be_an_instance_of(When)
56
- end
52
+ it { should be_an_instance_of(When) }
57
53
 
58
54
  it 'parses start_time' do
59
- _when.start_time.should == Time.parse('2013-04-01 10:00:00 -0700')
55
+ subject.start_time.should == Time.parse('2012-12-14 18:30:00 -0800')
60
56
  end
61
57
 
62
58
  it 'parses end_time' do
63
- _when.end_time.should == Time.parse('2013-04-01 11:00:00 -0700')
59
+ subject.end_time.should == Time.parse('2012-12-14 21:30:00 -0800')
64
60
  end
65
61
  end
66
62
 
67
- it 'parses where' do
68
- event.where.should == ''
63
+ it 'parses location' do
64
+ subject.location.should == "Prospect, 300 Spear St, San Francisco, CA 94105"
69
65
  end
70
66
 
71
67
  describe :author do
72
68
  let(:author) { event.author }
73
69
 
74
70
  it 'parses email' do
75
- author.email.should == "bobert@example.com"
71
+ author.email.should == "alice@example.com"
76
72
  end
77
73
 
78
74
  it 'parses name' do
79
- author.name.should == "Bobert Jones"
75
+ author.name.should == "Alice McAlice"
80
76
  end
81
77
  end
82
78
 
83
79
  it 'parses transparency' do
84
- event.transparency.should == 'opaque'
80
+ subject.transparency.should == ''
85
81
  end
86
82
 
87
83
  it 'parses visibility' do
88
- event.visibility.should == 'default'
84
+ subject.visibility.should == 'private'
89
85
  end
90
86
  end
91
87
 
92
88
  describe '.batch_create' do
93
- let(:processed_events) { Event.batch_create(events) }
94
-
95
- it 'parses events' do
96
- processed_events.count.should == 10
97
- end
89
+ let(:subject) { Event.batch_create(events) }
90
+ it { subject.count.should == 3 }
98
91
  end
99
92
  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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hwan-Joon Choi
@@ -107,6 +107,7 @@ files:
107
107
  - lib/gaah/resource/api.rb
108
108
  - lib/gaah/resource/resource.rb
109
109
  - lib/gaah/version.rb
110
+ - spec/fixtures/calendar.json
110
111
  - spec/fixtures/calendar.xml
111
112
  - spec/fixtures/provisioning.xml
112
113
  - spec/models/event_spec.rb
@@ -137,6 +138,7 @@ signing_key:
137
138
  specification_version: 4
138
139
  summary: Limited API Wrapper for Google Apps API.
139
140
  test_files:
141
+ - spec/fixtures/calendar.json
140
142
  - spec/fixtures/calendar.xml
141
143
  - spec/fixtures/provisioning.xml
142
144
  - spec/models/event_spec.rb