private static string BuildQueryString(Dictionary <string, string> qstring, MeetupClientOptions options) { if (qstring == null && options.AddedQueryString == null) { return(string.Empty); } var osb = new StringBuilder(); var added = AddTo(osb, qstring, true); added = AddTo(osb, options.AddedQueryString, added); return(osb.ToString()); }
public static MeetupClient WithApiToken(string token, MeetupClientOptions options = null) { if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentException("No token specified", nameof(token)); } options = SetupOptions(options, null); options.AddedQueryString.Add("sign", "true"); options.AddedQueryString.Add("key", token); options.Level = AuthLevel.ApiKey; return(new MeetupClient(options)); }
internal static MeetupClientOptions SetupOptions(MeetupClientOptions options, HttpClient client) { options = options ?? new MeetupClientOptions(); options.Client = client ?? options.Client ?? new HttpClient(); options.CustomSerializer = options.CustomSerializer ?? JsonSerializer.CreateDefault(); options.AddedQueryString = options.AddedQueryString ?? new Dictionary <string, string>(); if (options.Client.BaseAddress == null) { options.Client.BaseAddress = new Uri(MeetupApiBaseAddress, UriKind.Absolute); } return(options); }
internal static async Task <HttpResponseMessage> GetAsync( string requestUri, MeetupClientOptions options, MeetupRequest request = null) { var fullUri = $"{requestUri}{BuildQueryString(request?.AsDictionary(),options)}"; var message = new HttpRequestMessage(HttpMethod.Get, fullUri); AddContext(message, request); var response = await options.Client.SendAsync(message); return(response); }
public static MeetupClient WithOAuthToken(string token, MeetupClientOptions options = null) { if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentException("No token specified", nameof(token)); } var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); options = SetupOptions(options, client); options.Level = AuthLevel.OAuth2; return(new MeetupClient(options)); }
internal static async Task <HttpResponseMessage> PostAsync <TContent>( string requestUri, MeetupClientOptions options, TContent content) { var fullUri = $"{requestUri}{BuildQueryString(new Dictionary<string, string>(), options)}"; var message = new HttpRequestMessage(HttpMethod.Post, fullUri); var mem = new MemoryStream(); var writer = new JsonTextWriter(new StreamWriter(mem)); options.CustomSerializer.Serialize(writer, content); await writer.FlushAsync(); mem.Seek(0, SeekOrigin.Begin); message.Content = new StreamContent(mem); var response = await options.Client.SendAsync(message); return(response); }
public MeetupClient(MeetupClientOptions options) { Options = SetupOptions(options, null); }
public static async Task <MeetupResponse <T> > AsObject <T>(this HttpResponseMessage response, MeetupClientOptions options) { if (response.Content == null) { if (response.IsSuccessStatusCode) { return(default(MeetupResponse <T>)); } throw new MeetupException(response.StatusCode); } var stream = await response.Content.ReadAsStreamAsync(); using (var reader = new JsonTextReader(new StreamReader(stream))) { if (response.IsSuccessStatusCode) { var objectContent = options.CustomSerializer.Deserialize <T>(reader); return(new MeetupResponse <T>(response, objectContent)); } var errorContent = options.CustomSerializer.Deserialize <MeetupErrorContainer>(reader); throw new MeetupException(response.StatusCode, errorContent.Errors); } }
internal GeoCalls(MeetupClientOptions options) { _options = options; }
public GroupCalls(MeetupClientOptions options) { _options = options; }
internal static async Task <MeetupResponse <TResponse> > PostWithContentAsync <TContent, TResponse>(string requestUri, MeetupClientOptions options, TContent content) { var response = await PostAsync(requestUri, options, content); return(await response.AsObject <TResponse>(options)); }
internal static async Task <MeetupResponse <T> > GetWithRequestAsync <T>(string requestUri, MeetupClientOptions options, MeetupRequest request) { var response = await GetAsync(requestUri, options, request); return(await response.AsObject <T>(options)); }
internal MetaCalls(MeetupClientOptions options) { _options = options; }
public VenueCalls(MeetupClientOptions options) { _options = options; }
public TopicCalls(MeetupClientOptions options) { _options = options; }
public EventCalls(MeetupClientOptions options) { _options = options; }