public async Task <JObject> GetUserProfileAsync() { Credentials credentials = await Credentials.FromSessionAsync(Request.Cookies, Response.Cookies); if (credentials == null) { return(null); } // the API SDK UserProfileApi userApi = new UserProfileApi(); userApi.Configuration.AccessToken = credentials.TokenInternal; // get the user profile dynamic userProfile = await userApi.GetUserProfileAsync(); // prepare a response with name & picture dynamic response = new JObject(); response.name = string.Format("{0} {1}", userProfile.firstName, userProfile.lastName); response.picture = userProfile.profileImages.sizeX40; return(response); }
public async Task <IRestResponse> GetIssueTypesAsync(string containerId) { Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); RestClient client = new RestClient(BASE_URL); RestRequest request = new RestRequest("/issues/v1/containers/{container_id}/ng-issue-types?include=subtypes", RestSharp.Method.GET); request.AddParameter("container_id", containerId, ParameterType.UrlSegment); request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal); request.AddHeader("Content-Type", "application/vnd.api+json"); return(await client.ExecuteTaskAsync(request)); }
public async Task <IRestResponse> GetIssuesAsync(string containerId, string resource, string filterType, string filterValue) { Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); RestClient client = new RestClient(BASE_URL); RestRequest request = new RestRequest("/issues/v1/containers/{container_id}/{resource}?filter[{filterType}]={filterValue}", RestSharp.Method.GET); request.AddParameter("container_id", containerId, ParameterType.UrlSegment); request.AddParameter("filterType", filterType, ParameterType.UrlSegment); request.AddParameter("filterValue", filterValue, ParameterType.UrlSegment); request.AddParameter("resource", resource, ParameterType.UrlSegment); request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal); return(await client.ExecuteTaskAsync(request)); }
public async Task <IRestResponse> PostIssuesAsync(string containerId, string resource, JObject data) { Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); RestClient client = new RestClient(BASE_URL); RestRequest request = new RestRequest("/issues/v1/containers/{container_id}/{resource}", RestSharp.Method.POST); request.AddParameter("container_id", containerId, ParameterType.UrlSegment); request.AddParameter("resource", resource, ParameterType.UrlSegment); request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal); request.AddHeader("Content-Type", "application/vnd.api+json"); request.AddParameter("text/json", Newtonsoft.Json.JsonConvert.SerializeObject(data), ParameterType.RequestBody); return(await client.ExecuteTaskAsync(request)); }
public async Task <AccessToken> GetPublicTokenAsync() { Credentials credentials = await Credentials.FromSessionAsync(Request.Cookies, Response.Cookies); if (credentials == null) { base.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return(new AccessToken()); } // return the public (viewables:read) access token return(new AccessToken() { access_token = credentials.TokenPublic, expires_in = (int)credentials.ExpiresAt.Subtract(DateTime.Now).TotalSeconds }); }
public async Task <dynamic> GetContainerAsync(string href) { string[] idParams = href.Split('/'); string projectId = idParams[idParams.Length - 1]; string hubId = idParams[idParams.Length - 3]; Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); ProjectsApi projectsApi = new ProjectsApi(); projectsApi.Configuration.AccessToken = credentials.TokenInternal; var project = await projectsApi.GetProjectAsync(hubId, projectId); var issues = project.data.relationships.issues.data; if (issues.type != "issueContainerId") { return(null); } return(new { ContainerId = issues["id"], HubId = hubId }); }