/// <summary> /// Gets the IDs of jobs belonging to a given group. For jobs to belong /// to a group, they must have been submitted together, with the same /// source and target languages and with a requirement of same /// translator. /// </summary> /// <param name="jobIds">The group ID</param> /// <returns>Task yielding list of job IDs</returns> public async Task <TimestampedReadOnlyCollection <int> > GetJobGroup( int groupId ) { var uri = UriPartJobsGroup + groupId; var json = await _client.GetJsonAsync <JObject>(uri, true); if (json == null) { throw new Exception( Resources.ServiceDidNotReturnExpectedValue); } var created = json.DateValueStrict("ctime"); var jobs = json["jobs"] as JArray; var ids = new List <int>(); if (jobs != null) { foreach (JObject obj in jobs) { ids.Add(obj.IntValueStrict("job_id")); } } return(new TimestampedReadOnlyCollection <int>(created, ids)); }
/// <summary> /// Gets information about a submitted job /// </summary> /// <param name="jobId">The job ID</param> /// <param name="includeMachineTranslation"> /// If a machine translated preview should be provided if a human- /// made one is not yet avaible. /// </param> /// <returns>Task yielding job data</returns> public async Task <SubmittedJob> Get(int jobId, bool includeMachineTranslation) { var uri = UriPartJob + jobId; var data = new Dictionary <string, string>(); data["pre_mt"] = Convert.ToInt32(includeMachineTranslation).ToString(); var obj = await _client.GetJsonAsync <JObject>(uri, data, true); return(new SubmittedJob(obj["job"] as JObject)); }
/// <summary> /// Gets information about an order, its constituent jobs /// and their statuses /// </summary> /// <param name="orderId">The order ID</param> /// <returns>Task yielding order information</returns> public async Task <Order> Get(int orderId) { var obj = await _client.GetJsonAsync <JObject>( UriPartOrder + orderId, true); if (obj == null) { throw new Exception( Resources.ServiceDidNotReturnExpectedValue); } return(new Order(obj.Value <JObject>("order"))); }
internal static async Task <JsonT> GetJsonPropertyAsync <JsonT>( this IGengoClient client, string propName, String uriPart, bool authenticated ) where JsonT : JToken { var data = await client.GetJsonAsync <JObject>(uriPart, authenticated); if (data == null) { throw new Exception( "Remote service did not return object."); } var result = data[propName] as JsonT; if (result == null) { throw new Exception( "Object returned by remote service did not have property " + propName + " of type " + typeof(JsonT).Name); } return(result); }
/// <summary> /// Gets the languages currently supported by Gengo /// </summary> /// <returns>Task yielding array of languages</returns> public async Task <Language[]> GetLanguages() { var json = await _client.GetJsonAsync <JArray>(UriPartLanguages, false); return(json.Values <JObject>().Select(e => new Language(e)).ToArray()); }
/// <summary> /// Gets the account balance /// </summary> /// <returns>Current credits and currency</returns> public async Task <AccountBalance> GetBalance() { var json = await _client.GetJsonAsync <JObject>(UriPartBalance, true); return(new AccountBalance(json)); }
/// <summary> /// Gets all glossaries belonging to the authenticated user /// </summary> /// <returns>Task yielding glossaries</returns> public async Task <Glossary[]> GetAll() { var arr = await _client.GetJsonAsync <JArray>(UriPartGlossary, true); return(arr.Values <JObject>().Select(obj => new Glossary(obj)).ToArray()); }