public virtual IEnumerable<ofWorker> List(ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var workers = Requestor.Get<List<ofWorker>>(Urls.Workers, requestOptions); return workers; }
public virtual IEnumerable<ofTeam> List(ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var response = Requestor.Get<List<ofTeam>>(Urls.Teams, requestOptions); return response; }
public virtual ofWorker Get(string workerId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var worker = Requestor.Get<ofWorker>(string.Format("{0}/{1}", Urls.Workers, workerId), requestOptions); return worker; }
public virtual IEnumerable <ofTask> List(ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var tasks = Requestor.Get <List <ofTask> >(Urls.Tasks, requestOptions); return(tasks); }
public virtual ofRecipient Get(string recipientId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var recipient = Requestor.Get<ofRecipient>(string.Format("{0}/{1}", Urls.Recipients, recipientId), requestOptions); return recipient; }
public virtual ofRecipient FindByPhone(string recipientPhone, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var recipient = Requestor.Get<ofRecipient>(string.Format("{0}/phone/{1}", Urls.Recipients, HttpUtility.UrlEncode(recipientPhone)), requestOptions); return recipient; }
public virtual ofTask Get(string taskId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var task = Requestor.Get<ofTask>(string.Format("{0}/{1}", Urls.Tasks, taskId), requestOptions); return task; }
public virtual IEnumerable <ofTeam> List(ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var response = Requestor.Get <List <ofTeam> >(Urls.Teams, requestOptions); return(response); }
public static ofTask CreateWithDestinationAndWorker(this ofTaskService taskService, ofTaskCreateOptions taskCreateOptions, string address, string workerID, ofRecipientsCreateOptions recipientCreateOptions = null, ofRequestOptions requestOptions = null) { ofDestinationCreateOptions destinationCreateOptions = new ofDestinationCreateOptions { Address = new ofAddress { Unparsed = address } }; ofDestinationService destinationService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofDestinationService() : new ofDestinationService(taskService.ApiKey); ofDestination destination = destinationService.Create(destinationCreateOptions, requestOptions); taskCreateOptions.DestinationId = destination.Id; if (recipientCreateOptions != null) { ofRecipientService recipientService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofRecipientService() : new ofRecipientService(taskService.ApiKey); var recipient = recipientService.Create(recipientCreateOptions, requestOptions); taskCreateOptions.Recipients = new List<string> { recipient.Id }; } var task = taskService.Create(taskCreateOptions, requestOptions); ofWorkerService workerService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofWorkerService() : new ofWorkerService(taskService.ApiKey); ofWorkerUpdateOptions workerUpdateOptions = new ofWorkerUpdateOptions{ Tasks = new List<string>{ task.Id} }; workerService.Update(workerID, workerUpdateOptions, requestOptions); return taskService.Get(task.Id, requestOptions); }
public virtual IEnumerable<ofTask> List(ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var tasks = Requestor.Get<List<ofTask>>(Urls.Tasks, requestOptions); return tasks; }
public virtual ofDestination Get(string destinationId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var destination = Requestor.Get<ofDestination>(string.Format("{0}/{1}", Urls.Destinations, destinationId), requestOptions); return destination; }
public virtual ofOrganization Get(ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var org = Requestor.Get <ofOrganization>(Urls.Organization, requestOptions); return(org); }
public virtual ofTask Get(string taskId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var task = Requestor.Get <ofTask>(string.Format("{0}/{1}", Urls.Tasks, taskId), requestOptions); return(task); }
public virtual ofDestination Get(string destinationId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var destination = Requestor.Get <ofDestination>(string.Format("{0}/{1}", Urls.Destinations, destinationId), requestOptions); return(destination); }
public ofTask Update(string taskId, ofTaskCreateOptions options, ofRequestOptions requestOptions) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(options, new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); return Requestor.Put<ofTask>(string.Format("{0}/{1}", Urls.Tasks, taskId), requestOptions, postData); }
public virtual void Delete(string workerId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var url = string.Format("{0}/{1}", Urls.Workers, workerId); Requestor.Delete(url, requestOptions); }
public virtual ofRecipient Get(string recipientId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var recipient = Requestor.Get <ofRecipient>(string.Format("{0}/{1}", Urls.Recipients, recipientId), requestOptions); return(recipient); }
public virtual ofRecipient FindByName(string recipientName, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var recipient = Requestor.Get <ofRecipient>(string.Format("{0}/name/{1}", Urls.Recipients, HttpUtility.UrlEncode(recipientName)), requestOptions); return(recipient); }
public virtual ofWorker Get(string workerId, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var worker = Requestor.Get <ofWorker>(string.Format("{0}/{1}", Urls.Workers, workerId), requestOptions); return(worker); }
public virtual IEnumerable <ofWorker> List(ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var workers = Requestor.Get <List <ofWorker> >(Urls.Workers, requestOptions); return(workers); }
public ofRecipient Update(string recipientId, ofRecipientsCreateOptions options, ofRequestOptions requestOptions) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(options); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); return Requestor.Put<ofRecipient>(string.Format("{0}/{1}", Urls.Recipients, recipientId), requestOptions, postData); }
public virtual ofRecipient Create(ofRecipientsCreateOptions createOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(createOptions); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var recipient = Requestor.Post<ofRecipient>(Urls.Recipients, requestOptions, postData); return recipient; }
public virtual ofWorker Update(string workerId, ofWorkerUpdateOptions updateOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); string serilizedObj = JsonConvert.SerializeObject(updateOptions, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }).ToString(); var PostData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var worker = Requestor.Put<ofWorker>(string.Format("{0}/{1}", Urls.Workers, workerId), requestOptions, PostData); return worker; }
public virtual ofDestination Create(ofDestinationCreateOptions createOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); string serilizedObj = JsonConvert.SerializeObject(createOptions, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }).ToString(); var PostData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var destination = Requestor.Post<ofDestination>(Urls.Destinations, requestOptions, PostData); return destination; }
public ofTask Update(string taskId, ofTaskCreateOptions options, ofRequestOptions requestOptions) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(options, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); return(Requestor.Put <ofTask>(string.Format("{0}/{1}", Urls.Tasks, taskId), requestOptions, postData)); }
public virtual ofTask Create(ofTaskCreateOptions createOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(createOptions, new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var task = Requestor.Post<ofTask>(Urls.Tasks, requestOptions, postData); return task; }
public static ofTask CreatePickupAndDelivery(this ofTaskService taskService, ofTaskCreateOptions pickupTaskCreateOptions, ofTaskCreateOptions deliveryTaskCreateOptions, ofRequestOptions requestOptions = null) { pickupTaskCreateOptions.PickupTask = true; var pickupTask = taskService.Create(pickupTaskCreateOptions, requestOptions); deliveryTaskCreateOptions.Dependencies = new List<string> { pickupTask.Id }; var deliveryTask = taskService.Create(deliveryTaskCreateOptions, requestOptions); return deliveryTask; }
public virtual ofRecipient Create(ofRecipientsCreateOptions createOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(createOptions); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var recipient = Requestor.Post <ofRecipient>(Urls.Recipients, requestOptions, postData); return(recipient); }
internal static HttpClient GetHttpClient(ofRequestOptions requestOptions) { requestOptions.ApiKey = requestOptions.ApiKey ?? ofConfiguration.GetApiKey(); HttpClient client = new HttpClient(); var byteArray = Encoding.ASCII.GetBytes(requestOptions.ApiKey); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return(client); }
public virtual ofWorker Create(ofWorkerCreateOptions createOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); string serilizedObj = JsonConvert.SerializeObject(createOptions, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }).ToString(); var PostData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var worker = Requestor.Post <ofWorker>(Urls.Workers, requestOptions, PostData); return(worker); }
public static void Delete(string url, ofRequestOptions requestOptions) { var client = GetHttpClient(requestOptions); var responseMessage = client.DeleteAsync(url).Result; var responseString = responseMessage.Content.ReadAsStringAsync().Result; if (!responseMessage.IsSuccessStatusCode) { ofError err = JsonConvert.DeserializeObject <ofError>(responseString); throw new ofException(responseMessage.StatusCode, err); } }
public virtual ofTask Create(ofTaskCreateOptions createOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(createOptions, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var task = Requestor.Post <ofTask>(Urls.Tasks, requestOptions, postData); return(task); }
protected ofRequestOptions SetupRequestOptions(ofRequestOptions requestOptions) { if (requestOptions == null) { requestOptions = new ofRequestOptions(); } if (!String.IsNullOrEmpty(ApiKey)) { requestOptions.ApiKey = ApiKey; } return(requestOptions); }
public static ofWorker AssignToWorker(this ofTaskService taskService, string taskId, string workerId,bool assignTaskDependencies = true, ofRequestOptions requestOptions = null) { var workerService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofWorkerService() : new ofWorkerService(taskService.ApiKey); var tasksIds = new List<string>(); if (assignTaskDependencies == true) { var task = taskService.Get(taskId, requestOptions); tasksIds.AddRange(task.Dependencies); } tasksIds.Add(taskId); ofWorkerUpdateOptions updateoptions = new ofWorkerUpdateOptions { Tasks = tasksIds }; var worker = workerService.Update(workerId, updateoptions, requestOptions); return worker; }
public static T Put <T>(string url, ofRequestOptions requestOptions, StringContent content = null) { var client = GetHttpClient(requestOptions); var responseMessage = client.PutAsync(url, content).Result; var responseString = responseMessage.Content.ReadAsStringAsync().Result; if (responseMessage.IsSuccessStatusCode) { T obj = JsonConvert.DeserializeObject <T>(responseString); return(obj); } else { ofError err = JsonConvert.DeserializeObject <ofError>(responseString); throw new ofException(responseMessage.StatusCode, err); } }
public static ofRecipient FindOrCreate(this ofRecipientService recipientService, string phoneNumber, ofRecipientsCreateOptions createOptions, ofRequestOptions requestOptions = null) { ofRecipient recipient = new ofRecipient(); try { recipient = recipientService.FindByPhone(phoneNumber, requestOptions); } catch (ofException ex) { if (ex.Error.ErrorCode == "ResourceNotFound") { recipient = recipientService.Create(createOptions, requestOptions); return recipient; } throw ex; } return recipient; }
public virtual ofTeam Get(string id, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); return Requestor.Get<ofTeam>(string.Format("{0}/{1}", Urls.Teams, id), requestOptions); }
public static ofTask CreatePickupAndDelivery(this ofTaskService taskService, ofTaskCreateOptions pickupTaskCreateOptions, ofTaskCreateOptions deliveryTaskCreateOptions, ofRequestOptions requestOptions = null) { pickupTaskCreateOptions.PickupTask = true; var pickupTask = taskService.Create(pickupTaskCreateOptions, requestOptions); deliveryTaskCreateOptions.Dependencies = new List <string> { pickupTask.Id }; var deliveryTask = taskService.Create(deliveryTaskCreateOptions, requestOptions); return(deliveryTask); }
public static ofWorker AssignToWorker(this ofTaskService taskService, string taskId, string workerId, bool assignTaskDependencies = true, ofRequestOptions requestOptions = null) { var workerService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofWorkerService() : new ofWorkerService(taskService.ApiKey); var tasksIds = new List <string>(); if (assignTaskDependencies == true) { var task = taskService.Get(taskId, requestOptions); tasksIds.AddRange(task.Dependencies); } tasksIds.Add(taskId); ofWorkerUpdateOptions updateoptions = new ofWorkerUpdateOptions { Tasks = tasksIds }; var worker = workerService.Update(workerId, updateoptions, requestOptions); return(worker); }
public ofRecipient Update(string recipientId, ofRecipientsCreateOptions options, ofRequestOptions requestOptions) { requestOptions = SetupRequestOptions(requestOptions); var serilizedObj = JsonConvert.SerializeObject(options); var postData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); return(Requestor.Put <ofRecipient>(string.Format("{0}/{1}", Urls.Recipients, recipientId), requestOptions, postData)); }
public virtual ofTeam Get(string id, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); return(Requestor.Get <ofTeam>(string.Format("{0}/{1}", Urls.Teams, id), requestOptions)); }
public virtual ofWorker Update(string workerId, ofWorkerUpdateOptions updateOptions, ofRequestOptions requestOptions = null) { requestOptions = SetupRequestOptions(requestOptions); string serilizedObj = JsonConvert.SerializeObject(updateOptions, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }).ToString(); var PostData = new StringContent(serilizedObj, Encoding.UTF8, "application/json"); var worker = Requestor.Put <ofWorker>(string.Format("{0}/{1}", Urls.Workers, workerId), requestOptions, PostData); return(worker); }
public static ofRecipient FindOrCreate(this ofRecipientService recipientService, string phoneNumber, ofRecipientsCreateOptions createOptions, ofRequestOptions requestOptions = null) { ofRecipient recipient = new ofRecipient(); try { recipient = recipientService.FindByPhone(phoneNumber, requestOptions); } catch (ofException ex) { if (ex.Error.ErrorCode == "ResourceNotFound") { recipient = recipientService.Create(createOptions, requestOptions); return(recipient); } throw ex; } return(recipient); }
public static ofTask CreateWithDestinationAndWorker(this ofTaskService taskService, ofTaskCreateOptions taskCreateOptions, string address, string workerID, ofRecipientsCreateOptions recipientCreateOptions = null, ofRequestOptions requestOptions = null) { ofDestinationCreateOptions destinationCreateOptions = new ofDestinationCreateOptions { Address = new ofAddress { Unparsed = address } }; ofDestinationService destinationService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofDestinationService() : new ofDestinationService(taskService.ApiKey); ofDestination destination = destinationService.Create(destinationCreateOptions, requestOptions); taskCreateOptions.DestinationId = destination.Id; if (recipientCreateOptions != null) { ofRecipientService recipientService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofRecipientService() : new ofRecipientService(taskService.ApiKey); var recipient = recipientService.Create(recipientCreateOptions, requestOptions); taskCreateOptions.Recipients = new List <string> { recipient.Id }; } var task = taskService.Create(taskCreateOptions, requestOptions); ofWorkerService workerService = string.IsNullOrEmpty(taskService.ApiKey) ? new ofWorkerService() : new ofWorkerService(taskService.ApiKey); ofWorkerUpdateOptions workerUpdateOptions = new ofWorkerUpdateOptions { Tasks = new List <string> { task.Id } }; workerService.Update(workerID, workerUpdateOptions, requestOptions); return(taskService.Get(task.Id, requestOptions)); }