googlebase.pp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. { Base Google REST classes
  2. Copyright (C) 2015 Michael Van Canneyt [email protected]
  3. This library is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Library General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or (at your
  6. option) any later version with the following modification:
  7. As a special exception, the copyright holders of this library give you
  8. permission to link this library with independent modules to produce an
  9. executable, regardless of the license terms of these independent modules,and
  10. to copy and distribute the resulting executable under terms of your choice,
  11. provided that you also meet, for each linked independent module, the terms
  12. and conditions of the license of that module. An independent module is a
  13. module which is not derived from or based on this library. If you modify
  14. this library, you may extend this exception to your version of the library,
  15. but you are not obligated to do so. If you do not wish to do so, delete this
  16. exception statement from your version.
  17. This program is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  20. for more details.
  21. You should have received a copy of the GNU Library General Public License
  22. along with this library; if not, write to the Free Software Foundation,
  23. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. }
  25. unit googlebase;
  26. {$mode objfpc}{$H+}
  27. { $DEFINE DEBUGBASEOBJMEMLEAK}
  28. interface
  29. uses
  30. typinfo, Classes, SysUtils, restbase;
  31. Type
  32. EGoogleAPI = Class(ERestAPI);
  33. Type
  34. { TGoogleBaseObject }
  35. TGoogleBaseObject = CLass(TBaseObject)
  36. Class Function AllowAdditionalProperties: Boolean; override;
  37. end;
  38. TGoogleBaseObjectClass = Class of TGoogleBaseObject;
  39. TGoogleObjectArray = Array of TGoogleBaseObject;
  40. { TGoogleBaseObjectList }
  41. TGoogleBaseObjectList = Class(TBaseObjectList)
  42. private
  43. function GetO(Aindex : Integer): TGoogleBaseObject;
  44. procedure SetO(Aindex : Integer; AValue: TGoogleBaseObject);
  45. Protected
  46. Class Function ObjectClass : TBaseObjectClass; Override;
  47. Public
  48. Function AddGoogleObject(Const AKind : String) : TGoogleBaseObject; virtual;
  49. Property GoogleObjects [Aindex : Integer] : TGoogleBaseObject Read GetO Write SetO; default;
  50. end;
  51. Function GoogleFactory : TObjectFactory;
  52. implementation
  53. Function GoogleFactory : TObjectFactory;
  54. begin
  55. Result:=RestFactory;
  56. end;
  57. { TGoogleBaseObject }
  58. Class Function TGoogleBaseObject.AllowAdditionalProperties: Boolean;
  59. begin
  60. // We override this, so people don't get caught whenn google inadvertently adds properties.
  61. // (see e.g. 30174)
  62. Result:=True;
  63. end;
  64. { TGoogleBaseObjectList }
  65. function TGoogleBaseObjectList.GetO(Aindex: Integer): TGoogleBaseObject;
  66. begin
  67. Result:=TGoogleBaseObject(Inherited GetO(AIndex))
  68. end;
  69. procedure TGoogleBaseObjectList.SetO(Aindex: Integer; AValue: TGoogleBaseObject
  70. );
  71. begin
  72. Inherited SetO(AIndex,AValue);
  73. end;
  74. class function TGoogleBaseObjectList.ObjectClass: TBaseObjectClass;
  75. begin
  76. Result:=TGoogleBaseObject;
  77. end;
  78. function TGoogleBaseObjectList.AddGoogleObject(const AKind: String
  79. ): TGoogleBaseObject;
  80. begin
  81. Result:=AddObject(AKind) as TGoogleBaseObject;
  82. end;
  83. end.