NowDataSDK クラス: Android

  • リリースバージョン: Xanadu
  • 更新日 2024年08月01日
  • 所要時間:7分
  • NowDataSDK クラスは、NowGraphQLService、NowAttachmentService、NowTableService、NowAPIService などのさまざまな機能サービスの作成と初期化を可能にする関数を提供します。

    NowDataSDK - makeGraphQLService(instanceURL: URL)

    NowGraphQLService 機能のインスタンスを作成して初期化します。このサービスにより、ServiceNow インスタンスの GraphQL API にアクセスできます。

    ServiceNow GraphQL API の詳細については、「GraphQL API フレームワークを使用したレコードデータのクエリ」を参照してください。

    表 : 1. パラメーター
    名前 タイプ 説明
    インスタンス URL URL アクセスする ServiceNow インスタンスの URL。例 :「https://instance.servicenow.com」
    表 : 2. 返される内容
    タイプ Description (説明)
    結果<NowGraphQLService> Kotlin Result オブジェクトにラップされた NowGraphQLService オブジェクト。

    次のコード例は、この関数を呼び出す方法を示しています。

    private var nowGraphQLService: NowGraphQLService? = null
    
    /**
      * Create the NowGraphQLService once in the lifetime of the application, inside the Application class
      * or another manager class that will be injected into other classes via dagger/hilt.
      * NowGraphQLService should be created after initializing the NowSDK.
      */
    suspend fun getNowGraphQLService(): NowGraphQLService? {
      if (nowGraphQLService != null) return nowGraphQLService
    
      return NowDataSDK.makeGraphQLService(URL("https://instance-name.service-now.com")).getOrThrow()
        .also { this.nowGraphQLService = it }
    }

    NowDataSDK - makeNowAPIService(instanceURL: URL)

    NowAPIService サービスのインスタンスを作成して初期化します。このサービスを使用すると、 ServiceNow インスタンスによって公開されたパブリック REST API にアクセスできます。

    さらに、カスタムスクリプト済み REST API を ServiceNow インスタンス内で開発し、NowAPIService API を使用して Android アプリケーション内でそれらの API にアクセスすることもできます。ServiceNow REST API の詳細については、「Scripted REST APIs」を参照してください。

    表 : 3. パラメーター
    名前 タイプ 説明
    インスタンス URL URL アクセスする ServiceNow インスタンスの URL。例 :「https://instance.servicenow.com」
    表 : 4. 返される内容
    タイプ Description (説明)
    結果<NowAPIService> Kotlin Result オブジェクトにラップされた NowAPIService。

    次のコード例は、この関数を呼び出す方法を示しています。

    private var nowApiService: NowAPIService? = null
    
    /**
      * Create the NowAPIService once in the lifetime of the application inside the Application class
      * or another manager class that will be injected into other classes via dagger/hilt.
      * NowAPIService should be created after initializing the NowSDK
      */
    suspend fun getNowApiService(): NowAPIService? {
      if (nowApiService != null) return nowApiService
    
      return NowDataSDK.makeAPIService(URL("https://instance-name.service-now.com")).getOrThrow()
        .also { this.nowApiService = it }
    }

    NowDataSDK - makeNowAttachmentService(instanceURL: URL)

    NowAttachmentService 機能のインスタンスを作成して初期化します。

    このサービスを使用すると、 ServiceNow インスタンスから添付ファイルをアップロード、ダウンロード、および削除できます。添付ファイルをインスタンスにアップロードすると、 Android アプリケーションにダウンロードできる添付ファイルのメタデータが生成されます。

    ServiceNow添付ファイルの詳細については、「添付ファイル API」を参照してください。

    表 : 5. パラメーター
    名前 タイプ 説明
    インスタンス URL URL アクセスする ServiceNow インスタンスの URL。例 :「https://instance.servicenow.com」
    表 : 6. 返される内容
    タイプ Description (説明)
    結果<NowAttachmentService> Kotlin Result オブジェクトにラップされた NowAttachmentService オブジェクト。

    次のコード例は、このメソッドを呼び出す方法を示しています。

    private var nowAttachmentService: NowAttachmentService? = null
    
    /**
      * Create the NowAttachmentService once in the lifetime of the application inside the Application
      * class or another manager class that will be injected into other classes via dagger/hilt.
      * NowAttachmentService should be created after initializing the NowSDK.
      */
    suspend fun getNowAttachmentService(): NowAttachmentService? {
      if (nowAttachmentService != null) return nowAttachmentService
    
      return NowDataSDK.makeAttachmentService(URL("https://instance-name.service-now.com"))
        .getOrThrow()
        .also { this.nowAttachmentService = it }
    }

    NowDataSDK - makeTableService(instanceURL: URL)

    NowTableService 機能のインスタンスを作成して初期化します。

    このサービスを使用すると、ServiceNowインスタンス上の REST テーブル API にアクセスできます。REST テーブル API の詳細については、「 テーブル API」を参照してください。

    表 : 7. パラメーター
    名前 タイプ 説明
    インスタンス URL URL アクセスする ServiceNow インスタンスの URL。例 :「https://instance.servicenow.com」
    表 : 8. 返される内容
    タイプ Description (説明)
    結果<NowTableService> Kotlin Result オブジェクトにラップされた NowTableService オブジェクト。

    次のコード例は、この関数を呼び出す方法を示しています。

    private var nowTableService: NowTableService? = null
    
    /**
      * Create the NowTableService once in the lifetime of the application inside the Application
      * class or another manager class that will be injected into other classes via dagger/hilt.
      * NowTableService should be created after initializing the NowSDK.
      */
    suspend fun getNowTableService(): NowTableService? {
      if (nowTableService != null) return nowTableService
    
      return NowDataSDK.makeTableService(URL("https://instance-name.service-now.com")).getOrThrow()
        .also { this.nowTableService = it }
    }