예제 #1
0
        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);
        }
예제 #4
0
        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));
        }
예제 #6
0
        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);
 }
예제 #8
0
        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);
            }
        }
예제 #9
0
 internal GeoCalls(MeetupClientOptions options)
 {
     _options = options;
 }
예제 #10
0
 public GroupCalls(MeetupClientOptions options)
 {
     _options = options;
 }
예제 #11
0
        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));
        }
예제 #12
0
        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));
        }
예제 #13
0
 internal MetaCalls(MeetupClientOptions options)
 {
     _options = options;
 }
예제 #14
0
 public VenueCalls(MeetupClientOptions options)
 {
     _options = options;
 }
예제 #15
0
 public TopicCalls(MeetupClientOptions options)
 {
     _options = options;
 }
예제 #16
0
 public EventCalls(MeetupClientOptions options)
 {
     _options = options;
 }