Class: GoogleAppsApi::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/google_apps_api/base_api.rb

Direct Known Subclasses

CalendarEntity, ContactEntity, UserEntity

Constant Summary collapse

VALID_ENTITY_TYPES =
[:user, :calendar, :domain, :contact]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Entity

Returns a new instance of Entity.

Raises:

  • (ArgumentError)


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/google_apps_api/base_api.rb', line 177

def initialize(*args)
  options = args.extract_options!

  @kind = options.delete(:kind)
  @id = options.delete(:id)
  @domain = options.delete(:domain)

  if (kind = options.keys.detect { |k| VALID_ENTITY_TYPES.include?(k.to_sym)})
    @kind = kind.to_s
  
    value = CGI::unescape(options[kind])
    
    if value.include?("@")
      @id, @domain = value.split("@",2)
    else
      @id = value
    end
  end
  

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

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



176
177
178
# File 'lib/google_apps_api/base_api.rb', line 176

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



176
177
178
# File 'lib/google_apps_api/base_api.rb', line 176

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



176
177
178
# File 'lib/google_apps_api/base_api.rb', line 176

def kind
  @kind
end

Instance Method Details

#==(other) ⇒ Object



221
222
223
# File 'lib/google_apps_api/base_api.rb', line 221

def ==(other)
  other.kind_of?(Entity) && @kind == other.kind && @id == other.id && @domain == other.domain
end

#full_idObject



204
205
206
# File 'lib/google_apps_api/base_api.rb', line 204

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

#full_id_escapedObject



208
209
210
# File 'lib/google_apps_api/base_api.rb', line 208

def full_id_escaped
  CGI::escape(full_id)
end

#id_escapedObject



200
201
202
# File 'lib/google_apps_api/base_api.rb', line 200

def id_escaped
  CGI::escape(@id)
end

#qualified_idObject



212
213
214
# File 'lib/google_apps_api/base_api.rb', line 212

def qualified_id
  @kind + ":" + full_id
end

#qualified_id_escapedObject



216
217
218
# File 'lib/google_apps_api/base_api.rb', line 216

def qualified_id_escaped
  CGI::escape(qualified_id)
end