コード例 #1
0
    public GitHubClient GetClient([NotNull] IDataContext context)
    {
      var boundSettings = mySettingsStore.BindToContextTransient(ContextRange.Smart((lt, _) => context));

      var proxy = myProxySettingsReader.GetProxySettings(boundSettings);
      var settings = boundSettings.GetKey<GitHubSettings>(SettingsOptimization.DoMeSlowly);

      var client = new GitHubClient { Proxy = proxy };
      if (!settings.IsAnonymous)
        client.Authenticator = new HttpBasicAuthenticator(settings.Username, settings.Password);

      return client;
    }
コード例 #2
0
 private string Publish(GitHubClient client, IDictionary<string, string> content)
 {
   var response = client.Execute<GitHub.Gist>(new RestRequest("/gists", Method.POST) {  RequestFormat = DataFormat.Json }
     .AddBody(new GitHub.Gist { IsPublic = true, Files = content.ToDictionary(_ => _.Key, _ => new GistFile { Content = _.Value }) }));
   if ((response.ResponseStatus == ResponseStatus.Error) || !response.StatusCode.InRange(HttpStatusCode.OK, HttpStatusCode.Ambiguous - 1))
   {
     Logger.LogMessage("Gist error: {0}", response.ErrorMessage ?? string.Format("{0:D} {1}", response.StatusCode, response.StatusDescription));
     return null;
   }
   return response.Data != null ? response.Data.HtmlUrl : null;
 }