Esempio n. 1
0
        public virtual IEnumerable<ofWorker> List(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var workers = Requestor.Get<List<ofWorker>>(Urls.Workers, requestOptions);
            return workers;
        }
Esempio n. 2
0
        public virtual IEnumerable<ofTeam> List(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);
            var response = Requestor.Get<List<ofTeam>>(Urls.Teams, requestOptions);

            return response;
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        public virtual IEnumerable <ofTask> List(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);
            var tasks = Requestor.Get <List <ofTask> >(Urls.Tasks, requestOptions);

            return(tasks);
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
        public virtual IEnumerable <ofTeam> List(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);
            var response = Requestor.Get <List <ofTeam> >(Urls.Teams, requestOptions);

            return(response);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public virtual IEnumerable<ofTask> List(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);
            var tasks = Requestor.Get<List<ofTask>>(Urls.Tasks, requestOptions);

            return tasks;
        }
Esempio n. 11
0
        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;
        }
Esempio n. 12
0
        public virtual ofOrganization Get(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var org = Requestor.Get <ofOrganization>(Urls.Organization, requestOptions);

            return(org);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        public virtual IEnumerable <ofWorker> List(ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            var workers = Requestor.Get <List <ofWorker> >(Urls.Workers, requestOptions);

            return(workers);
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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;
        }
Esempio n. 24
0
        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;
        }
Esempio n. 25
0
        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;
        }
Esempio n. 26
0
        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));
        }
Esempio n. 27
0
        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;
        }
Esempio n. 28
0
        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;
        }
Esempio n. 29
0
        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);
        }
Esempio n. 30
0
        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);
        }
Esempio n. 31
0
        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);
        }
Esempio n. 32
0
        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);
            }
        }
Esempio n. 33
0
        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);
        }
Esempio n. 34
0
        protected ofRequestOptions SetupRequestOptions(ofRequestOptions requestOptions)
        {
            if (requestOptions == null)
            {
                requestOptions = new ofRequestOptions();
            }

            if (!String.IsNullOrEmpty(ApiKey))
            {
                requestOptions.ApiKey = ApiKey;
            }

            return(requestOptions);
        }
Esempio n. 35
0
        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;
        }
Esempio n. 36
0
        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);
            }
        }
Esempio n. 37
0
        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;
        }
Esempio n. 38
0
        public virtual ofTeam Get(string id, ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            return Requestor.Get<ofTeam>(string.Format("{0}/{1}", Urls.Teams, id), requestOptions);
        }
Esempio n. 39
0
        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);
        }
Esempio n. 40
0
        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);
        }
Esempio n. 41
0
        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));
        }
Esempio n. 42
0
        public virtual ofTeam Get(string id, ofRequestOptions requestOptions = null)
        {
            requestOptions = SetupRequestOptions(requestOptions);

            return(Requestor.Get <ofTeam>(string.Format("{0}/{1}", Urls.Teams, id), requestOptions));
        }
Esempio n. 43
0
        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);
        }
Esempio n. 44
0
        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);
        }
Esempio n. 45
0
        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));
        }