public async Task<bool> CompletePasswordResetAsync(string email, string newPassword, string code, string answer) { if (email == null) { throw new ArgumentNullException("email"); } if (newPassword == null) { throw new ArgumentNullException("newPassword"); } if (code != null && answer != null) { throw new ArgumentException("You must specify either code or answer parameters but not both.", "answer"); } var address = baseAddress.WithResource("password").WithParameter("login", true); PasswordRequest data = new PasswordRequest { email = email, new_password = newPassword, code = code, security_answer = answer }; string content = contentSerializer.Serialize(data); IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders, content); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); bool success = contentSerializer.Deserialize<PasswordResponse>(response.Body).success ?? false; if (success) { Session session = await GetSessionAsync(); baseHeaders.AddOrUpdate(HttpHeaders.DreamFactorySessionTokenHeader, session.session_id); } return success; }
public async Task<bool> RegisterAsync(Register register, bool login = false) { if (register == null) { throw new ArgumentNullException("register"); } var address = baseAddress.WithResource("register"); if (login) { address = address.WithParameter("login", true); } string content = contentSerializer.Serialize(register); IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders, content); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var success = new { success = false }; success = contentSerializer.Deserialize(response.Body, success); if (success.success && login) { Session session = await GetSessionAsync(); baseHeaders.AddOrUpdate(HttpHeaders.DreamFactorySessionTokenHeader, session.session_id); } return success.success; }
public async Task<FileResponse> CreateFileAsync(string container, string filepath, string content, bool checkExists = true) { if (container == null) { throw new ArgumentNullException("container"); } if (filepath == null) { throw new ArgumentNullException("filepath"); } if (content == null) { throw new ArgumentNullException("content"); } IHttpAddress address = baseAddress.WithResource( container, filepath).WithParameter("check_exist", checkExists); IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders.Exclude(HttpHeaders.ContentTypeHeader), content); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var data = new { file = new List<FileResponse>() }; return contentSerializer.Deserialize(response.Body, data).file.First(); }
public async Task<Session> GetSessionAsync() { var address = baseAddress.WithResource("session"); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return contentSerializer.Deserialize<Session>(response.Body); }
/// <inheritdoc /> public async Task<IEnumerable<Service>> GetServicesAsync() { IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), BaseHeaders); IHttpResponse response = await HttpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, ContentSerializer); var services = new { service = new List<Service>() }; return ContentSerializer.Deserialize(response.Body, services).service; }
public async Task<IEnumerable<TableInfo>> GetAccessComponentsAsync() { IHttpRequest request = new HttpRequest(HttpMethod.Get, baseAddress.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var resource = new { resource = new List<TableInfo>() }; return contentSerializer.Deserialize(response.Body, resource).resource; }
public async Task<ConfigResponse> SetConfigAsync(ConfigRequest config) { IHttpAddress address = baseAddress.WithResource("config"); string body = contentSerializer.Serialize(config); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders, body); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return contentSerializer.Deserialize<ConfigResponse>(response.Body); }
public async Task<IEnumerable<ContainerInfo>> GetAccessComponentsAsync() { IHttpAddress address = baseAddress.WithParameter("include_properties", true); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var data = new { container = new List<ContainerInfo>() }; return contentSerializer.Deserialize(response.Body, data).container; }
public async Task<bool> LogoutAsync() { var address = baseAddress.WithResource("session"); IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); baseHeaders.Delete(HttpHeaders.DreamFactorySessionTokenHeader); var logout = new { success = false }; return contentSerializer.Deserialize(response.Body, logout).success; }
public async Task<byte[]> DownloadApplicationSdkAsync(int applicationId) { IHttpAddress address = baseAddress .WithResource("app", applicationId.ToString(CultureInfo.InvariantCulture)) .WithParameter("sdk", true); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return response.RawBody; }
public async Task<IEnumerable<ScriptResponse>> GetScriptsAsync(bool includeUserScripts) { IHttpAddress address = baseAddress.WithResource("script") .WithParameter("include_script_body", true) .WithParameter("include_user_scripts", includeUserScripts); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var scripts = new { resource = new List<ScriptResponse>() }; return contentSerializer.Deserialize(response.Body, scripts).resource; }
public async Task<IEnumerable<EventCacheResponse>> GetEventsAsync(bool allEvents) { IHttpAddress address = baseAddress.WithResource("event").WithParameter("as_cached", false); if (allEvents) { address = address.WithParameter("all_events", true); } IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var records = new { record = new List<EventCacheResponse>() }; return contentSerializer.Deserialize(response.Body, records).record; }
public async Task UnregisterEventsAsync(params EventRequest[] requests) { if (requests == null || requests.Length < 1) { throw new ArgumentException("At least one parameter must be specificed", "requests"); } IHttpAddress address = baseAddress.WithResource("event"); var records = new { record = new List<EventRequest>(requests) }; string body = contentSerializer.Serialize(records); IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders, body); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); }
public async Task<byte[]> GetBinaryFileAsync(string filepath) { if (filepath == null) { throw new ArgumentNullException("filepath"); } IHttpAddress address = base.BaseAddress.WithResource(filepath); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), base.BaseHeaders.Include(HttpHeaders.AcceptHeader, OctetStream)); IHttpResponse response = await base.HttpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, base.ContentSerializer); return response.RawBody; }
public async Task RunAsync(IRestContext context) { /* * Get random bytes as hex string from random.org */ const string url = "https://www.random.org/cgi-bin/randbyte?nbytes=16&format=h"; IHttpRequest request = new HttpRequest(HttpMethod.Get, url, new HttpHeaders()); IHttpFacade httpFacade = new UnirestHttpFacade(); Console.WriteLine("Sending GET request: {0}", url); IHttpResponse response = await httpFacade.RequestAsync(request); Console.WriteLine("Response CODE = {0}, BODY = {1}", response.Code, response.Body.Trim()); }
public async Task DeleteScriptAsync(string scriptId) { if (scriptId == null) { throw new ArgumentNullException("scriptId"); } IHttpAddress address = baseAddress .WithResource("script", scriptId) .WithParameter("is_user_script", true); IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); }
public async Task<byte[]> DownloadApplicationPackageAsync(int applicationId, bool includeFiles, bool includeServices, bool includeSchema) { IHttpAddress address = baseAddress .WithResource("app", applicationId.ToString(CultureInfo.InvariantCulture)) .WithParameter("pkg", true) .WithParameter("include_files", includeFiles) .WithParameter("include_services", includeServices) .WithParameter("include_schema", includeSchema); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return response.RawBody; }
public async Task<int> SendEmailAsync(EmailRequest emailRequest) { if (emailRequest == null) { throw new ArgumentNullException("emailRequest"); } string content = contentSerializer.Serialize(emailRequest); IHttpRequest request = new HttpRequest(HttpMethod.Post, baseAddress.Build(), baseHeaders, content); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var emailsSent = new { count = 0 }; return contentSerializer.Deserialize(response.Body, emailsSent).count; }
public async Task<PasswordResponse> RequestPasswordResetAsync(string email) { if (email == null) { throw new ArgumentNullException("email"); } var address = baseAddress.WithResource("password").WithParameter("reset", true); PasswordRequest data = new PasswordRequest { email = email }; string content = contentSerializer.Serialize(data); IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders, content); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return contentSerializer.Deserialize<PasswordResponse>(response.Body); }
public Task<FileResponse> ReplaceFileContentsAsync(string filepath, string contents) { if (filepath == null) { throw new ArgumentNullException("filepath"); } if (contents == null) { throw new ArgumentNullException("contents"); } IHttpAddress address = base.BaseAddress.WithResource(filepath); IHttpRequest request = new HttpRequest(HttpMethod.Put, address.Build(), base.BaseHeaders.Exclude(HttpHeaders.ContentTypeHeader), contents); return base.ExecuteRequest<FileResponse>(request); }
public async Task<bool> UpdateProfileAsync(ProfileRequest profileRequest) { if (profileRequest == null) { throw new ArgumentNullException("profileRequest"); } var address = baseAddress.WithResource("profile"); string content = contentSerializer.Serialize(profileRequest); IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders, content); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var success = new { success = false }; return contentSerializer.Deserialize(response.Body, success).success; }
public async Task<bool> DeleteTableAsync(string tableName) { if (tableName == null) { throw new ArgumentNullException("tableName"); } IHttpAddress address = baseAddress.WithResource( "_schema", tableName); IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var success = new { success = false }; success = contentSerializer.Deserialize(response.Body, success); return success.success; }
private async Task DeleteRecordsAsync(string resource, bool setDeleteStorage, params int[] ids) { if (ids == null || ids.Length < 1) { throw new ArgumentException("At least one application ID must be specificed", "ids"); } string list = string.Join(",", ids); IHttpAddress address = baseAddress.WithResource(resource).WithParameter("ids", list); if (setDeleteStorage) { address = address.WithParameter("delete_storage", true); } IHttpRequest request = new HttpRequest(HttpMethod.Delete, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); }
public async Task DeleteContainersAsync(params string[] containers) { if (containers == null) { throw new ArgumentNullException("containers"); } if (containers.Length < 1) { throw new ArgumentException("At least one container name must be provided", "containers"); } var data = new { container = containers.Select(x => new { name = x, path = x }) }; string body = contentSerializer.Serialize(data); IHttpRequest request = new HttpRequest(HttpMethod.Delete, baseAddress.Build(), baseHeaders, body); request.SetTunnelingWith(HttpMethod.Post); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); }
public async Task<FolderResponse> GetFolderAsync(string container, string path, ListingFlags flags) { if (container == null) { throw new ArgumentNullException("container"); } if (path == null) { throw new ArgumentNullException("path"); } IHttpAddress address = baseAddress.WithResource( container, path, string.Empty); address = AddListingParameters(address, flags); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return contentSerializer.Deserialize<FolderResponse>(response.Body); }
public async Task<byte[]> DownloadFolderAsync(string container, string path) { if (container == null) { throw new ArgumentNullException("container"); } if (path == null) { throw new ArgumentNullException("path"); } IHttpAddress address = baseAddress.WithResource( container, path, string.Empty) .WithParameter("zip", true); IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return response.RawBody; }
public async Task CreateContainersAsync(bool checkExists, params string[] containers) { if (containers == null) { throw new ArgumentNullException("containers"); } if (containers.Length < 1) { throw new ArgumentException("At least one container name must be provided", "containers"); } IHttpAddress address = baseAddress.WithParameter("check_exist", checkExists); var data = new { container = containers.Select(x => new ContainerInfo { name = x, path = x }) }; string body = contentSerializer.Serialize(data); IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders, body); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); }
public async Task<Session> LoginAsync(string applicationName, string email, string password, int duration) { if (applicationName == null) { throw new ArgumentNullException("applicationName"); } if (email == null) { throw new ArgumentNullException("email"); } if (password == null) { throw new ArgumentNullException("password"); } if (duration < 0) { throw new ArgumentOutOfRangeException("duration"); } var address = baseAddress.WithResource("session"); baseHeaders.AddOrUpdate(HttpHeaders.DreamFactoryApplicationHeader, applicationName); Login login = new Login { email = email, password = password, duration = duration }; string loginContent = contentSerializer.Serialize(login); IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders, loginContent); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); Session session = contentSerializer.Deserialize<Session>(response.Body); baseHeaders.AddOrUpdate(HttpHeaders.DreamFactorySessionTokenHeader, session.session_id); return session; }
public async Task<ScriptResponse> WriteScriptAsync(string id, string body) { if (id == null) { throw new ArgumentNullException("id"); } if (body == null) { throw new ArgumentNullException("body"); } IHttpAddress address = baseAddress .WithResource("script", id) .WithParameter("is_user_script", true); IHttpRequest request = new HttpRequest(HttpMethod.Put, address.Build(), baseHeaders.Exclude(HttpHeaders.ContentTypeHeader), body); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); return contentSerializer.Deserialize<ScriptResponse>(response.Body); }
public async Task<IEnumerable<string>> GetTableNamesAsync(bool includeSchemas, bool refresh = false) { IHttpAddress address = baseAddress.WithParameter("names_only", true); if (includeSchemas) { address = address.WithParameter("include_schemas", true); } if (refresh) { address = address.WithParameter("refresh", true); } IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders); IHttpResponse response = await httpFacade.RequestAsync(request); HttpUtils.ThrowOnBadStatus(response, contentSerializer); var resource = new { resource = new List<string>() }; return contentSerializer.Deserialize(response.Body, resource).resource; }