Google Apps Provisioning の使用法注意:このドキュメントでは、英語版のリビジョン 22742 の更新内容をスキップしています。 Google Apps はドメイン管理者向けのサービスで、Google の提供する メールやカレンダー、Docs & Spreadsheets などをユーザに使用させることができます。 Provisioning API は、 これらのサービスをプログラム上から設定するためのインターフェイスです。 特に、この API を使用すると ユーザアカウントやニックネーム、グループ、メーリングリストなどの追加、取得、 更新、削除ができるようになります。 このライブラリは Provisioning API バージョン 2.0 を実装しています。 Provisioning API であなたのアカウントにアクセスできるようにするには、 Google Apps コントロールパネル上で手動で有効にする必要があります。 この機能を利用できるのは、特定の種別のアカウントだけに限られます。 Google Apps Provisioning API の使用法や API にアクセスできるようにするための方法については » Provisioning API V2.0 Reference を参照ください。
現在のドメインの設定Provisioning API を使用するには、 すべてのリクエスト URI で対象のドメインを指定する必要があります。 開発を楽に進めるために、この情報は Gapps サービスクラスとクエリクラスの両方で保持するようにしています。 サービスクラスへのドメインの設定リクエスト対象のドメインをサービスクラスに設定するには、 setDomain() をコールするか、 あるいはサービスクラスのインスタンスの作成時に指定します。 たとえば次のようになります。
クエリクラスへのドメインの設定リクエスト対象のドメインをクエリクラスに設定する方法は、 サービスクラスの場合と同じです。 setDomain() をコールするか、 あるいはクエリの作成時に指定します。 たとえば次のようになります。
サービスクラスのファクトリメソッドでクエリを作成する際は、 サービスクラスが自動的にクエリクラスのドメインを設定します。 したがってこの場合は、 コンストラクタの引数でドメインを指定する必要がなくなります。
ユーザの操作Google Apps がホストするドメイン上のユーザアカウントは、 Zend_Gdata_Gapps_UserEntry のインスタンスで表されます。 このクラスを使用すると、 アカウント名やユーザ名、パスワード、アクセス権限、 そして容量制限などすべての情報にアクセスできるようになります。 ユーザアカウントの作成ユーザアカウントを作成するには、 createUser() メソッドを使用します。
あるいは UserEntry のインスタンスから作成することもできます。 作成したインスタンスに対してユーザ名や姓、名、パスワードを設定し、 サービスオブジェクトの insertUser() をコールすることでそのエントリをサーバにアップロードします。
ユーザのパスワードは、通常はプレーンテキストで指定しなければなりません。 login->passwordHashFunction を 'SHA-1' に設定した場合は、パスワードを SHA-1 ダイジェスト形式で指定することもできます。 ユーザアカウントの取得各ユーザアカウントを取得するには retrieveUser() メソッドをコールします。 ユーザが見つからない場合は NULL が返されます。
もうひとつの方法は、まず Zend_Gdata_Gapps_UserQuery のインスタンスを作成して username プロパティを (取得したいユーザのユーザ名に) 設定し、サービスオブジェクトの getUserEntry() をコールするものです。
指定したユーザが発見できない場合は ServiceException がスローされ、エラーコード Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST を返します。ServiceExceptions については エラー処理 を参照ください。 ドメイン内のすべてのユーザの取得ドメイン内のすべてのユーザを取得するには、 retrieveAllUsers() メソッドをコールします。
これは Zend_Gdata_Gapps_UserFeed オブジェクトを作成します。 このオブジェクトは、ドメイン上の各ユーザの情報を保持しています。 あるいは、何もオプションを指定せずに getUserFeed() をコールする方法もあります。 大きなドメインでは、このフィードが サーバ側で複数ページに分割される可能性があることに注意しましょう。 ページ分割についての詳細は 複数ページのフィードの扱い方 を参照ください。
ユーザアカウントの更新ユーザアカウントを更新するいちばん簡単な方法は、 まず先ほどの方法でユーザを取得し、 必要な箇所を変更し、最後にそのユーザの save() をコールするというものです。 これにより、変更内容がサーバに反映されます。
ユーザのパスワードのリセットユーザのパスワードをリセットして新しい値を設定するには、 login->password プロパティを変更します。
現在のパスワードをこの方式で取得することはできません。 セキュリティ上の理由により、Provisioning API では現在のパスワードを取得できないようになっているからです。 ユーザに強制的にパスワードを変更させる次にログインしたときに強制的にパスワードを変更させるようにするには、 login->changePasswordAtNextLogin を TRUE に設定します。
同様に、強制しないようにするなら login->changePasswordAtNextLogin を FALSE に設定します。 ユーザアカウントの凍結ユーザのログインを制限したいがアカウント自体は残しておきたいという場合は、 そのアカウントを凍結します。 アカウントを凍結したり凍結を解除したりするには suspendUser() メソッドおよび restoreUser() メソッドを使用します。
あるいは、UserEntry のプロパティ login->suspended を TRUE に設定します。
アクセス制限を解除するには、同様に login->suspended を FALSE に設定します。 管理者権限の付与ユーザに対してドメインの管理者権限を付与するには、プロパティ login->admin を TRUE に設定します。
だいたい予想はつくでしょうが、 login->admin プロパティを FALSE に設定すれば管理者権限を剥奪できます。 ユーザアカウントの削除ユーザアカウントを削除するには、単純に UserEntry の delete() をコールするだけです。
そのアカウントの UserEntry オブジェクトが手元にないのなら、 deleteUser() メソッドを使用します。
ニックネームの操作ニックネームは、既存のユーザのメールアドレスのエイリアスとなります。 ニックネームには、name と owner のふたつのプロパティがあります。 あるニックネームあてに送信されたメールは、 そのニックネームの持ち主であるユーザに転送されます。 ニックネームは Zend_Gdata_Gapps_NicknameEntry のインスタンスで表されます。 ニックネームの作成ニックネームを作成するには createNickname() メソッドをコールします。
あるいは NicknameEntry のインスタンスから作成することもできます。 作成したインスタンスに対して名前と所有者を設定し、 サービスオブジェクトの insertNickname() をコールすることでそのエントリをサーバにアップロードします。
ニックネームの取得ニックネームを取得するには retrieveNickname() メソッドをコールします。 ユーザが見つからない場合は NULL が返されます。
もうひとつの方法は、まず Zend_Gdata_Gapps_NicknameQuery のインスタンスを作成して nickname プロパティを (取得したいニックネームに) 設定し、サービスオブジェクトの getNicknameEntry() をコールするものです。
ユーザの場合と同様、指定したニックネームが発見できない場合は ServiceException がスローされ、エラーコード Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST を返します。ServiceExceptions については エラー処理 を参照ください。 あるユーザのすべてのニックネームの取得指定したユーザのすべてのニックネームを取得するには、 retrieveNicknames() メソッドをコールします。
これは Zend_Gdata_Gapps_NicknameFeed オブジェクトを作成します。 このオブジェクトは、指定したユーザのニックネームに関する情報を保持します。 あるいは、新しい Zend_Gdata_Gapps_NicknameQuery を作成して username プロパティをそのユーザに設定し、 サービスオブジェクトの getNicknameFeed() をコールすることもできます。
ドメイン内のすべてのニックネームの取得フィード内のすべてのニックネームを取得するには、 retrieveAllNicknames() メソッドをコールします。
これは Zend_Gdata_Gapps_NicknameFeed オブジェクトを作成します。 このオブジェクトは、ドメイン上の各ニックネームの情報を保持しています。 あるいは、サービスオブジェクトの getNicknameFeed() を引数なしでコールする方法もあります。
ニックネームの削除ニックネームを削除するには、単純に NicknameEntry の delete() をコールするだけです。
そのニックネームの NicknameEntry オブジェクトが手元にないのなら、 deleteNickname() メソッドを使用します。
Interacting with groupsGoogle Groups allows people to post messages like an email list. Google is depreciating the Email List API. Google Groups provides some neat features like nested groups and group owners. If you want to start a new email lst, it is advisable to use Google Groups instead. Google's Email List is not compatible with Google Groups. So if you create an email list, it will not show up as a group. The opposite is true as well. Each group on a domain is represented as an instance of Zend_Gdata_Gapps_GroupEntry. グループを作成createGroup() という便利なメソッドを呼び出すと、 グループが作成できます。
Groups can also be created by instantiating GroupEntry, providing a group id and name for the group, then calling insertGroup() on a service object to upload the entry to the server.
Retrieving an individual groupTo retrieve an individual group, call the retrieveGroup() convenience method:
This will create a Zend_Gdata_Gapps_GroupEntry object which holds the properties about the group. Alternatively, create a new Zend_Gdata_Gapps_GroupQuery, set its groupId property to the desired group id, and submit the query by calling getGroupEntry() on a service object.
Retrieving all groups in a domainTo retrieve all groups in a domain, call the convenience method retrieveAllGroups().
This will create a Zend_Gdata_Gapps_GroupFeed object which holds each group on the domain. Alternatively, call getGroupFeed() on a service object with no arguments.
グループを削除グループを削除するには、deleteGroup() という便利なメソッドを呼び出します。
グループを更新updateGroup() という便利なメソッドを呼び出すと、 グループが更新できます。
The first parameter is required. The second, third and fourth parameter, representing the group name, group descscription, and email permission, respectively are optional. Setting any of these optional parameters to null will not update that item. Retrieving all groups to which a person is a memberTo retrieve all groups to which a particular person is a member, call the retrieveGroups() convenience method:
This will create a Zend_Gdata_Gapps_GroupFeed object which holds each group associated with the specified member. Alternatively, create a new Zend_Gdata_Gapps_GroupQuery, set its member property to the desired email address, and submit the query by calling getGroupFeed() on a service object.
Interacting with group membersEach member subscribed to a group is represented by an instance of Zend_Gdata_Gapps_MemberEntry. Through this class, individual recipients can be added and removed from groups. Adding a member to a groupTo add a member to a group, simply call the addMemberToGroup() convenience method:
Check to see if member belongs to groupTo check to see if member belongs to group, simply call the isMember() convenience method:
The method returns a boolean value. If the member belongs to the group specified, the method returns true, else it returns false. Removing a member from a groupTo remove a member from a group, call the removeMemberFromGroup() convenience method:
Retrieving the list of members to a groupThe convenience method retrieveAllMembers() can be used to retrieve the list of members of a group:
Alternatively, construct a new MemberQuery, set its groupId property to match the desired group id, and call getMemberFeed() on a service object.
This will create a Zend_Gdata_Gapps_MemberFeed object which holds each member for the selected group. Interacting with group ownersEach owner associated with a group is represented by an instance of Zend_Gdata_Gapps_OwnerEntry. Through this class, individual owners can be added and removed from groups. Adding an owner to a groupTo add an owner to a group, simply call the addOwnerToGroup() convenience method:
Retrieving the list of the owner of a groupThe convenience method retrieveGroupOwners() can be used to retrieve the list of the owners of a group:
Alternatively, construct a new OwnerQuery, set its groupId property to match the desired group id, and call getOwnerFeed() on a service object.
This will create a Zend_Gdata_Gapps_OwnerFeed object which holds each member for the selected group. Check to see if an email is the owner of a groupTo check to see if an email is the owner of a group, simply call the isOwner() convenience method:
The method returns a boolean value. If the email is the owner of the group specified, the method returns true, else it returns false. Removing an owner from a groupTo remove an owner from a group, call the removeOwnerFromGroup() convenience method:
メーリングリストの操作メーリングリストは、複数のユーザのメールアドレスを ひとつのメールアドレスに対応させるものです。 このドメインのメンバー以外であっても、 メーリングリストに参加できます。 ドメイン上のメーリングリストの情報は、 Zend_Gdata_Gapps_EmailListEntry のインスタンスとして表されます。 メーリングリストの作成メーリングリストを作成するには createEmailList() メソッドを使用します。
あるいは EmailListEntry のインスタンスから作成することもできます。 作成したインスタンスに対してメーリングリストの名前を設定し、 サービスオブジェクトの insertEmailList() をコールすることでそのエントリをサーバにアップロードします。
あるアカウントが購読しているすべてのメーリングリストの取得特定の参加者が購読しているすべてのメーリングリストを取得するには retrieveEmailLists() メソッドをコールします。
これは Zend_Gdata_Gapps_EmailListFeed オブジェクトを作成します。 このオブジェクトは、指定した参加者に関連するメーリングリストの情報を保持します。 あるいは、新しい Zend_Gdata_Gapps_EmailListQuery を作成して recipient プロパティをそのメールアドレスに設定し、 サービスオブジェクトの getEmailListFeed() をコールすることもできます。
ドメイン内のすべてのメーリングリストの取得ドメイン内のすべてのメーリングリストを取得するには retrieveAllEmailLists() メソッドをコールします。
これは Zend_Gdata_Gapps_EmailListFeed オブジェクトを作成します。 このオブジェクトは、ドメイン上の各メーリングリストに関する情報を保持します。 あるいは、サービスオブジェクトの getEmailListFeed() を引数なしでコールする方法もあります。
メーリングリストの削除メーリングリストを削除するには deleteEmailList() メソッドをコールします。
メーリングリストの参加者の操作メーリングリストの各参加者は、 Zend_Gdata_Gapps_EmailListRecipient のインスタンスとして表されます。 このクラスを使用すると、メーリングリストにメンバーを追加したり、 そこからメンバーを削除したりできます。 メーリングリストへの参加者の追加メーリングリストにメンバーを追加するには addRecipientToEmailList() メソッドをコールします。
メーリングリストの参加者一覧の取得retrieveAllRecipients() メソッドを使用すると、メーリングリストの参加者一覧を取得できます。
あるいは、新しい EmailListRecipientQuery を作成して emailListName プロパティをそのメーリングリストに設定し、 サービスオブジェクトの getEmailListRecipientFeed() をコールすることもできます。
これは Zend_Gdata_Gapps_EmailListRecipientFeed オブジェクトを作成します。 このオブジェクトは、指定したメーリングリストの各参加者に関する情報を保持します。 ある参加者のメーリングリストからの削除メーリングリストからメンバーを削除するには removeRecipientFromEmailList() メソッドをコールします。
エラー処理Zend_Gdata が標準でスローする例外に加えて、 Provisioning API によるリクエストでは Zend_Gdata_Gapps_ServiceException がスローされる可能性があります。これらの例外は、 API 固有のエラーが原因でリクエストが失敗したことを表します。 ServiceException のインスタンスには、 ひとつあるいは複数の Error オブジェクトが含まれます。 これらのオブジェクトにはエラーコードとエラーの原因、そして (オプションで) その例外を引き起こした入力が含まれます。 エラーコードの完全な一覧は、Zend Framework API ドキュメントで Zend_Gdata_Gapps_Error の部分を参照ください。 さらに、正式なエラーの一覧は » Google Apps Provisioning API V2.0 Reference: Appendix D で見ることができます。 ServiceException に含まれるすべてのエラーの一覧は getErrors() で配列として取得できますが、 特定のエラーが発生したのかどうかだけを知りたいこともあります。 そのような場合には hasError() をコールします。 以下の例は、 リクエストしたリソースが存在しなかった場合を検出し、 適切に処理するものです。
|
|