Recently started to make an API based on REST Using a little Polymorphism - i.e. the same name with different parameter types:
Samples:
public Eloqua.API.Models.Contact GetContact(string email)
{ /* gets the first contact with this email */
List<Eloqua.API.Models.Contact> cg = SearchContacts(email, 1, 1);
Eloqua.API.Models.Contact c = cg.FirstOrDefault<Eloqua.API.Models.Contact>();
return c;
}
public Eloqua.API.Models.Contact GetContact(int id)
{ /* gets the first contact with this id */
Eloqua.API.Models.Contact c = SearchContacts(id.ToString(), 1, 1).FirstOrDefault<Eloqua.API.Models.Contact>();
return c;
}
public List<Eloqua.API.Models.Contact> SearchContacts(string searchTerm, int page, int pageSize)
{
RestRequest request = new RestRequest(Method.GET)
{
RequestFormat = DataFormat.Json,
Resource = string.Format("/data/contacts?search={0}&page={1}&count={2}&depth=complete&sort=firstName&dir=asc", EncodeString(searchTerm),
page, pageSize)
};
IRestResponse<RequestObjectList<Eloqua.API.Models.Contact>> response = _client.Execute<RequestObjectList<Eloqua.API.Models.Contact>>(request);
List<Eloqua.API.Models.Contact> contacts = response.Data.elements;
return contacts;
}