public GithubService(HttpClient http) { _http = http; _http.BaseAddress = new Uri("https://api.github.com"); _http.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("portfolio", "1.0")); _http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "API_KEY"); var productInformation = new Octokit.GraphQL.ProductHeaderValue("portfolio", "1.0"); _connection = new Connection(productInformation, "API_KEY"); }
private static async Task Main(string[] args) { // -- Common code start -- const string gitHubGraphQlEndpoint = "http://api.github.com/graphql"; string credentials; if (args.Length == 1) { credentials = args[0]; } else { Console.Write("Enter credentials (<username>:<password> or <personal access token>): "); credentials = Console.ReadLine(); } AuthenticationHeaderValue authorizationHeader; if (credentials.Contains(":")) { authorizationHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials))); } else { authorizationHeader = new AuthenticationHeaderValue("Bearer", credentials); } var query = @"query {{ viewer {{ login name }} }}"; // -- Common code end -- var productInformation = new Octokit.GraphQL.ProductHeaderValue("Hummingbird", "0.1.0"); var connection = new Connection(productInformation, credentials); var octokitQuery = new Query() .Viewer .Select(viewer => new { viewer.Login, viewer.Name }) .Compile(); var result = await connection.Run(octokitQuery); Console.WriteLine($"Hello {result.Name}!"); }
public GithubRepository(HttpClient http, IConfiguration configuration) { _http = http; _configuration = configuration; _http.BaseAddress = new Uri("https://api.github.com"); _http.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("portfolio", "1.0")); _http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", _configuration.GetSection("AuthKey:Github").Value); var productInformation = new Octokit.GraphQL.ProductHeaderValue("portfolio", "1.0"); _connection = new Connection(productInformation, _configuration.GetSection("AuthKey:Github").Value); }
/// <summary> /// Creates a new connection instance used to make requests of the GitHub GraphQL API. /// </summary> /// <remarks> /// See more information regarding User-Agent requirements here: https://developer.github.com/v3/#user-agent-required. /// </remarks> /// <param name="productInformation"> /// The name (and optionally version) of the product using this library, the name of your GitHub organization, or your GitHub username (in that order of preference). This is sent to the server as part of /// the user agent for analytics purposes, and used by GitHub to contact you if there are problems. /// </param> /// <param name="credentialStore">Provides credentials to the client when making requests.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="productInformation"/> or <paramref name="credentialStore"/> are <see langword="null"/>. /// </exception> public Connection(ProductHeaderValue productInformation, ICredentialStore credentialStore) : this(productInformation, GithubApiUri, credentialStore) { }
/// <summary> /// Creates a new connection instance used to make requests of the GitHub GraphQL API. /// </summary> /// <remarks> /// See more information regarding User-Agent requirements here: https://developer.github.com/v3/#user-agent-required. /// </remarks> /// <param name="productInformation"> /// The name (and optionally version) of the product using this library, the name of your GitHub organization, or your GitHub username (in that order of preference). This is sent to the server as part of /// the user agent for analytics purposes, and used by GitHub to contact you if there are problems. /// </param> /// <param name="uri"> /// The address to point this client to such as https://api.github.com or the URL to a GitHub Enterprise instance. /// </param> /// <param name="token">The token to use to authenticate with the GitHub GraphQL API.</param> /// <exception cref="ArgumentException"> /// <paramref name="uri"/> is not an absolute URI. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="productInformation"/> or <paramref name="uri"/> are <see langword="null"/>. /// </exception> public Connection(ProductHeaderValue productInformation, Uri uri, string token) : this(productInformation, uri, new InMemoryCredentialStore(token)) { }
/// <summary> /// Creates a new connection instance used to make requests of the GitHub GraphQL API. /// </summary> /// <remarks> /// See more information regarding User-Agent requirements here: https://developer.github.com/v3/#user-agent-required. /// </remarks> /// <param name="productInformation"> /// The name (and optionally version) of the product using this library, the name of your GitHub organization, or your GitHub username (in that order of preference). This is sent to the server as part of /// the user agent for analytics purposes, and used by GitHub to contact you if there are problems. /// </param> /// <param name="token">The token to use to authenticate with the GitHub GraphQL API.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="productInformation"/> is <see langword="null"/>. /// </exception> public Connection(ProductHeaderValue productInformation, string token) : this(productInformation, GithubApiUri, token) { }
/// <summary> /// Creates a new connection instance used to make requests of the GitHub GraphQL API. /// </summary> /// <remarks> /// See more information regarding User-Agent requirements here: https://developer.github.com/v3/#user-agent-required. /// </remarks> /// <param name="productInformation"> /// The name (and optionally version) of the product using this library, the name of your GitHub organization, or your GitHub username (in that order of preference). This is sent to the server as part of /// the user agent for analytics purposes, and used by GitHub to contact you if there are problems. /// </param> /// <param name="uri"> /// The address to point this client to such as https://api.github.com or the URL to a GitHub Enterprise instance. /// </param> /// <param name="credentialStore">Provides credentials to the client when making requests.</param> /// <exception cref="ArgumentException"> /// <paramref name="uri"/> is not an absolute URI. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="productInformation"/>, <paramref name="uri"/> or <paramref name="credentialStore"/> are <see langword="null"/>. /// </exception> public Connection(ProductHeaderValue productInformation, Uri uri, ICredentialStore credentialStore) : this(productInformation, uri, credentialStore, new HttpClient()) { }