001package com.plivo.api.models.message; 002 003import com.plivo.api.models.base.ListResponse; 004import com.plivo.api.models.base.Lister; 005import com.plivo.api.util.PropertyFilter; 006 007import com.plivo.api.exceptions.PlivoRestException; 008import java.io.IOException; 009 010import java.lang.reflect.Field; 011 012import java.util.Date; 013import retrofit2.Call; 014import retrofit2.Response; 015 016/** 017 * Pending list request that can be executed by calling list(); 018 */ 019public class MessageLister extends Lister<Message> { 020 021 private String subaccount = null; 022 private MessageDirection messageDirection = null; 023 private PropertyFilter<Date> messageTime = null; 024 private MessageState messageState = null; 025 private Long errorCode = null; 026 private String powerpackID = null; 027 private String tendlcCampaignID = null; 028 private String tendlcRegistrationStatus = null; 029 private String destinationCountryIso2 = null; 030 private MessageType messageType = null; 031 private String conversationID = null; 032 private String conversationOrigin = null; 033 034 public String subaccount() { 035 return this.subaccount; 036 } 037 038 public MessageDirection messageDirection() { 039 return this.messageDirection; 040 } 041 042 public PropertyFilter<Date> messageTime() { 043 return this.messageTime; 044 } 045 046 public MessageState messageState() { 047 return this.messageState; 048 } 049 050 public Long errorCode() { 051 return this.errorCode; 052 } 053 054 public String powerpackID() { 055 return this.powerpackID; 056 } 057 058 public String tendlcCampaignID() { 059 return this.tendlcCampaignID; 060 } 061 062 public String tendlcRegistrationStatus() { 063 return this.tendlcRegistrationStatus; 064 } 065 066 public String destinationCountryIso2() { 067 return this.destinationCountryIso2; 068 } 069 070 public MessageType messageType() { 071 return this.messageType; 072 } 073 074 public String conversationID() { 075 return this.conversationID; 076 } 077 078 public String conversationOrigin() { 079 return this.conversationOrigin; 080 } 081 082 public MessageLister subaccount(final String subaccount) { 083 this.subaccount = subaccount; 084 return this; 085 } 086 087 public MessageLister messageDirection( 088 final MessageDirection messageDirection) { 089 this.messageDirection = messageDirection; 090 return this; 091 } 092 093 public MessageLister messageTime(final PropertyFilter<Date> messageTime) { 094 this.messageTime = messageTime; 095 return this; 096 } 097 098 public MessageLister messageState(final MessageState messageState) { 099 this.messageState = messageState; 100 return this; 101 } 102 103 public MessageLister errorCode(final Long errorCode) { 104 this.errorCode = errorCode; 105 return this; 106 } 107 108 public MessageLister tendlcCampaignID(final String tendlcCampaignID) { 109 this.tendlcCampaignID = tendlcCampaignID; 110 return this; 111 } 112 113 public MessageLister tendlcRegistrationStatus(final String tendlcRegistrationStatus) { 114 this.tendlcRegistrationStatus = tendlcRegistrationStatus; 115 return this; 116 } 117 118 public MessageLister destinationCountryIso2(final String destinationCountryIso2) { 119 this.destinationCountryIso2 = destinationCountryIso2; 120 return this; 121 } 122 123 public MessageLister powerpackID(final String powerpackID) { 124 this.powerpackID = powerpackID; 125 return this; 126 } 127 128 public MessageLister messageType(final MessageType messageType) { 129 this.messageType = messageType; 130 return this; 131 } 132 133 public MessageLister conversationID(final String conversationID) { 134 this.conversationID = conversationID; 135 return this; 136 } 137 138 public MessageLister conversationOrigin(final String conversationOrigin) { 139 this.conversationOrigin = conversationOrigin; 140 return this; 141 } 142 143 @Override 144 /** 145 * Actually list instances of the resource. 146 */ 147 public ListResponse<Message> list() throws IOException, PlivoRestException { 148 validate(); 149 Response<ListResponse<Message>> response = obtainCall().execute(); 150 151 handleResponse(response); 152 153 try 154 { 155 Field meta = response.body().getClass().getDeclaredField("meta"); 156 meta.setAccessible(true); 157 meta.set(response.body(), new MessageMeta(response.body().getMeta())); 158 } 159 catch(Exception e) 160 { 161 e.printStackTrace(); 162 } 163 164 return response.body(); 165 } 166 167 @Override 168 protected Call<ListResponse<Message>> obtainCall() { 169 return client().getApiService().messageList(client().getAuthId(), toMap()); 170 } 171}