Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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}!");
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 /// <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)
 {
 }
Ejemplo n.º 5
0
 /// <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))
 {
 }
Ejemplo n.º 6
0
 /// <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)
 {
 }
Ejemplo n.º 7
0
 /// <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())
 {
 }