Skip to content

Commit

Permalink
modified to allow adding subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
James Stuart committed May 21, 2010
1 parent 54bd447 commit a80ecd3
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 313 deletions.
20 changes: 10 additions & 10 deletions lib/config/calendar.yml
Expand Up @@ -18,7 +18,7 @@
:retrieve_acls_for_calendar:
:method: :get
:path: ":feed_basic:/:calendar:/acl/full"
:format: GoogleAppsApi::CalendarEntity
:format: GoogleAppsApi::CalendarAcl
:feed: true
:retrieve_calendars_for_user:
:method: :get
Expand All @@ -34,25 +34,25 @@
:method: :post
:path: ":feed_basic:/:username:/allcalendars/full"
:format: GoogleAppsApi::CalendarEntity
:delete_calendar_from_user:
:remove_calendar_from_user:
:method: :delete
:path: ":feed_basic:/:username:/allcalendars/full/:calendar:"
:format: :text
:create_calendar_acl_for_user:
:create_calendar_acl:
:method: :post
:path: ":feed_basic:/:calendar:/acl/full"
:format: GoogleAppsApi::CalendarEntity
:format: GoogleAppsApi::CalendarAcl
:retrieve_calendar_acl_for_user:
:method: :get
:path: ":feed_basic:/:calendar:/acl/full/:scope_type:%3a:scope_id:"
:format: GoogleAppsApi::CalendarAclEntity
:remove_calendar_acl_for_user:
:format: GoogleAppsApi::CalendarAcl
:remove_calendar_acl:
:method: :delete
:path: ":feed_basic:/:calendar:/acl/full/user%3a:username:"
:path: ":feed_basic:/:calendar:/acl/full/:scope:"
:format: :text
:update_calendar_acl_for_user:
:set_calendar_acl:
:method: :put
:path: ":feed_basic:/:calendar:/acl/full/user%3a:username:"
:format: :text
:path: ":feed_basic:/:calendar:/acl/full/:scope:"
:format: GoogleAppsApi::CalendarAcl


33 changes: 19 additions & 14 deletions lib/google_apps_api/base_api.rb
Expand Up @@ -63,18 +63,17 @@ def request(action, *args)

response = http_request(method, path, options[:body], options[:headers])

if options[:debug]
puts response.body.content
puts "\n\n"
end

if format == :text
puts response.body.content if options[:debug]
return response.body.content
else
begin
xml = Nokogiri::XML(response.body.content) { |c| c.strict.noent}

test_errors(xml)
puts xml.to_s if options[:debug]


if format == :xml || !is_feed
format.kind_of?(Class) ? format.new(:xml => xml) : xml
else
Expand All @@ -92,6 +91,8 @@ def request(action, *args)


rescue Nokogiri::XML::SyntaxError => e
puts response.body.content if options[:debug]

error = GDataError.new()
error.code = "SyntaxError"
error.input = "path: #{path}"
Expand Down Expand Up @@ -169,7 +170,7 @@ def escapeXML(text)


class Entity
VALID_ENTITY_TYPES = [:user, :calendar]
VALID_ENTITY_TYPES = [:user, :calendar, :domain]

attr_reader :kind, :id, :domain
def initialize(*args)
Expand All @@ -179,7 +180,7 @@ def initialize(*args)
@id = options.delete(:id)
@domain = options.delete(:domain)

if (kind = options.keys.detect { |k| VALID_ENTITY_TYPES.include?(k)})
if (kind = options.keys.detect { |k| VALID_ENTITY_TYPES.include?(k.to_sym)})
@kind = kind.to_s

value = CGI::unescape(options[kind])
Expand All @@ -192,24 +193,28 @@ def initialize(*args)
end


raise(ArgumentError, "Kind and Id and Domain must be specified") unless @kind && @id && @domain
raise(ArgumentError, "Kind and Id must be specified") unless @kind && @id
end

def full_id
@id + "@" + @domain
@id + (@domain.nil? ? "" : "@" + @domain)
end

def full_id_escaped
CGI::escape(full_id)
end


def <=>(other)
[kind, id, domain] <=> [other.kind, other.id, other.domain]

def qualified_id
@kind + ":" + full_id
end

def qualified_id_escaped
CGI::escape(qualified_id)
end


def ==(other)
(self <=> other) == 0
other.kind_of?(Entity) && @kind == other.kind && @id == other.id && @domain == other.domain
end
end

Expand Down

0 comments on commit a80ecd3

Please sign in to comment.