Esempio n. 1
0
        /// <summary>
        /// id, slug, etc
        /// </summary>
        internal static IEnumerable <T> AccessParameterReservedApiArray <T>(this TokensBase t, MethodType m, string uri, string reserved, IDictionary <string, object> parameters)
        {
            var r = parameters[reserved];

            parameters.Remove(reserved);
            return(t.AccessApiArray <T>(m, uri.Replace(string.Format("{{{0}}}", reserved), r.ToString()), parameters));
        }
Esempio n. 2
0
        internal static Task <T> AccessParameterReservedApiAsync <T>(this TokensBase t, MethodType m, string uri, string reserved, IEnumerable <KeyValuePair <string, object> > parameters, CancellationToken cancellationToken)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            var list = parameters.ToList();
            var kvp  = GetReservedParameter(list, reserved);

            list.Remove(kvp);
            return(t.AccessApiAsyncImpl <T>(m, uri.Replace(string.Format("{{{0}}}", reserved), kvp.Value.ToString()), list, cancellationToken, ""));
        }
Esempio n. 3
0
 /// <summary>
 /// Convert the json to a twitter object of the specified type.
 /// </summary>
 /// <remarks>
 /// This method is used internally in CoreTweet.
 /// You can use this method for debugging.
 /// </remarks>
 /// <param name='tokens'>
 /// OAuth tokens.
 /// </param>
 /// <param name='json'>
 /// The json message.
 /// </param>
 /// <typeparam name='T'>
 /// The type of a twitter object.
 /// </typeparam>
 /// <returns>
 /// The twitter object.
 /// </returns>
 static T ConvertBase <T>(TokensBase tokens, string json, string jsonPath)
 {
     try
     {
         var js = new JsonSerializer();
         var cr = new DefaultContractResolver();
         cr.DefaultMembersSearchFlags = cr.DefaultMembersSearchFlags | BindingFlags.NonPublic;
         js.ContractResolver          = cr;
         return(JToken.Parse(json).SelectToken(JsonPathPrefix + jsonPath).ToObject <T>(js));
     }
     catch (Exception ex)
     {
         throw new ParsingException("on a REST api, cannot parse the json", JToken.Parse(json).ToString(Formatting.Indented), ex);
     }
 }
Esempio n. 4
0
        internal static Task <T> AccessParameterReservedApiAsync <T>(this TokensBase t, MethodType m, string uri, IEnumerable <string> reserveds, IEnumerable <KeyValuePair <string, object> > parameters, CancellationToken cancellationToken)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            var list     = parameters.ToList();
            var replaced = reserveds.Select(reserved =>
            {
                var kvp = GetReservedParameter(list, reserved);
                list.Remove(kvp);
                return(kvp);
            }).Aggregate(uri, (acc, kvp) => acc.Replace(string.Format("{{{0}}}", kvp.Key), kvp.Value.ToString()));

            return(t.AccessApiAsyncImpl <T>(m, replaced, list, cancellationToken, ""));
        }
Esempio n. 5
0
 internal ApiProviderBase(TokensBase tokens)
 {
     Tokens = tokens;
 }
Esempio n. 6
0
 /// <summary>
 /// Convert the json to a twitter object of the specified type.
 /// </summary>
 /// <remarks>
 /// This method is used internally in CoreTweet.
 /// You can use this method for debugging.
 /// </remarks>
 /// <param name='tokens'>
 /// OAuth tokens.
 /// </param>
 /// <param name='json'>
 /// The json message.
 /// </param>
 /// <typeparam name='T'>
 /// The type of a twitter object.
 /// </typeparam>
 /// <returns>
 /// The twitter object.
 /// </returns>
 public static T Convert <T>(TokensBase tokens, string json, string jsonPath = "")
 {
     return(ConvertBase <T>(tokens, json, jsonPath));
 }
Esempio n. 7
0
 /// <summary>
 /// Convert the json to a twitter object of the specified type.
 /// This is used for APIs that return an array.
 /// </summary>
 /// <remarks>
 /// This method is used internally in CoreTweet.
 /// You can use this method for debugging.
 /// </remarks>
 /// <param name='tokens'>
 /// OAuth tokens.
 /// </param>
 /// <param name='json'>
 /// The json message.
 /// </param>
 /// <typeparam name='T'>
 /// The type of a twitter object.
 /// </typeparam>
 /// <returns>
 /// Twitter objects.
 /// </returns>
 public static IEnumerable <T> ConvertArray <T>(TokensBase tokens, string json, string jsonPath)
 {
     return(ConvertBase <IEnumerable <T> >(tokens, json, jsonPath));
 }