C# implementation of the Otohits API (http://docs.otohitsapi.apiary.io).
You can use the Otohits.API.TestConsole project to play with the API.
Add your API Key/Secret in the App.Config
file:
<appSettings>
<add key="Otohits:API:Key" value="yourApiKey"/>
<add key="Otohits:API:Secret" value="yourSecret"/>
</appSettings>
Launch the Console App and... That's it! You should get your account info.
Set your credentials once to make all further requests
OtohitsRequest.SetCredentials("yourApiKey", "yourSecret");
var user = new OtohitsRequest().GetUserInfo();
Most of the services are directly mapped into OtohitsRequest
, but if you need to make a specific request, you can use Get
, Post
, Put
and Delete
methods.
Both can retrieve either a JSON string or a POCO object (JSON deserialize).
Basic Get
, Post
, Put
and Delete
methods also have Async() methods.
You can use the POCO object if available
var user = new OtohitsRequest().Get<ApiResponse<User>>("/me");
Or just get back the JSON string if needed:
string userResponse = new OtohitsRequest().Get("/me");
All the response coming from the API return an object with the status (success), the data (data...) and errors if any.
public class ApiResponse
{
public bool IsSuccess { get; set; }
public List<ApiError> Errors { get; set; }
}
public class ApiResponse<T>
{
public bool IsSuccess { get; set; }
public T Data { get; set; }
public List<ApiError> Errors { get; set; }
}
KISS :)