001package com.plivo.examples; 002 003import com.plivo.api.Plivo; 004import com.plivo.api.PlivoClient; 005import com.plivo.api.exceptions.PlivoRestException; 006import com.plivo.api.models.account.Account; 007import com.plivo.api.models.account.AccountUpdateResponse; 008import com.plivo.api.models.account.Subaccount; 009import com.plivo.api.models.account.SubaccountCreateResponse; 010 011import java.io.IOException; 012 013public class Accounts { 014 private static final String authId = "MANTXXXXXXXXXXXXXXXX"; 015 private static final String authToken = "ZMANTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 016 private static PlivoClient client = new PlivoClient(authId, authToken); 017 018 public static void main(String[] args) { 019 Plivo.init(authId, authToken); 020// getAccountInfo(); 021// getAccountInfoBySettingClient(); 022// modifyAccount(); 023// modifyAccountBySettingClient(); 024 createSubAccount(); 025// createSubAccountBySettingClient(); 026 027 } 028 029 // trying to get account info without setting the client 030 private static void getAccountInfo() { 031 try { 032 Account response = Account.getter() 033 .get(); 034 System.out.println(response); 035 } catch (PlivoRestException | IOException e) { 036 e.printStackTrace(); 037 } 038 } 039 040 // trying to get account info by setting the client 041 private static void getAccountInfoBySettingClient() { 042 try { 043 Account response = Account.getter() 044 .client(client) 045 .get(); 046 System.out.println(response); 047 } catch (PlivoRestException | IOException e) { 048 e.printStackTrace(); 049 } 050 } 051 052 // update account 053 private static void modifyAccount() { 054 try { 055 AccountUpdateResponse response = Account.updater() 056 .address("Test Address") 057 .update(); 058 System.out.println(response); 059 } catch (PlivoRestException | IOException e) { 060 e.printStackTrace(); 061 } 062 } 063 064 // update account with different client settings 065 private static void modifyAccountBySettingClient() { 066 try { 067 AccountUpdateResponse response = Account.updater() 068 .city("Test city") 069 .client(client) 070 .update(); 071 System.out.println(response); 072 } catch (PlivoRestException | IOException e) { 073 e.printStackTrace(); 074 } 075 } 076 077 // create subaccount 078 private static void createSubAccount() { 079 try { 080 SubaccountCreateResponse subaccount = Subaccount.creator("Test") 081 .enabled(true) 082 .create(); 083 System.out.println(subaccount); 084 } catch (PlivoRestException | IOException e) { 085 e.printStackTrace(); 086 } 087 } 088 089 // create subaccount with different client settings 090 private static void createSubAccountBySettingClient() { 091 try { 092 SubaccountCreateResponse subaccount = Subaccount.creator("Test 2") 093 .enabled(true) 094 .client(client) 095 .create(); 096 System.out.println(subaccount); 097 } catch (PlivoRestException | IOException e) { 098 e.printStackTrace(); 099 } 100 } 101 102}