Пример #1
0
 private ServiceArtist(IRequest req)
 {
     req.BaseUrl("http://ws.audioscrobbler.com/2.0/");
     req.AddParameter("format", "json");
     req.AddParameter("api_key", LastFmAPI.API_KEY);
     webao = new WebaoArtist(req);
 }
Пример #2
0
        public static object Build(Type interfaceWebao, IRequest req)
        {
            var typeInformation  = TypeInfoCache.Get(interfaceWebao);
            var baseUrl          = typeInformation.GetClassAttributesByName("BaseUrl");
            var parametersByName = typeInformation.GetClassAttributesByName("AddParameter");

            if (baseUrl[0] is BaseUrlAttribute baseUrlAttribute)
            {
                req.BaseUrl(baseUrlAttribute.host);
            }

            foreach (var param in parametersByName)
            {
                if (param is AddParameterAttribute parameterAttribute)
                {
                    req.AddParameter(parameterAttribute.name, parameterAttribute.val);
                }
            }


            var typeMethods       = interfaceWebao.GetMethods();
            var methodInformation = typeMethods.Select(BuilderHelper.ProcessMethod).ToList();

            return(BuildTask(interfaceWebao, req, methodInformation));
        }
Пример #3
0
        public void ApplyParameters(IRequest req)
        {
            req.AddParameter("client_id", _audienceId);
            req.AddParameter("client_secret", _audienceSecret);
            req.AddParameter("grant_type", GrantType);

            var dict = new Dictionary <string, object>();

            AddPostData(dict);

            if (dict.Count > 0)
            {
                foreach (var kvp in dict)
                {
                    req.AddParameter(kvp.Key, kvp.Value);
                }
            }
        }
Пример #4
0
 public object Build(IRequest request)
 {
     request.BaseUrl(BaseUrl);
     foreach (var parameter in ParameterAttributes)
     {
         request.AddParameter(parameter.name, parameter.val);
     }
     return(WebaoGenericBuilder.BuildTask(typeof(T), request, MethodInformations));
 }
Пример #5
0
        public static AbstractAccessObject Build(Type webao, IRequest req)
        {
            AddParameterAttribute[] parameters = (AddParameterAttribute[])webao.GetCustomAttributes(typeof(AddParameterAttribute), true);
            foreach (AddParameterAttribute param in parameters)
            {
                req.AddParameter(param.name, param.val);
            }

            BaseUrlAttribute baseURL = (BaseUrlAttribute)webao.GetCustomAttribute(typeof(BaseUrlAttribute), true);

            req.BaseUrl(baseURL.host);


            return((AbstractAccessObject)Activator.CreateInstance(webao, req));
        }
Пример #6
0
        public static AbstractAccessObject Build(Type webao, IRequest req)
        {
            var typeInformation  = TypeInfoCache.Get(webao);
            var baseUrl          = typeInformation.GetClassAttributesByName("BaseUrl");
            var parametersByName = typeInformation.GetClassAttributesByName("AddParameter");

            if (baseUrl[0] is BaseUrlAttribute baseUrlAttribute)
            {
                req.BaseUrl(baseUrlAttribute.host);
            }

            foreach (var param in parametersByName)
            {
                if (param is AddParameterAttribute parameterAttribute)
                {
                    req.AddParameter(parameterAttribute.name, parameterAttribute.val);
                }
            }
            return((AbstractAccessObject)Activator.CreateInstance(webao, req));
        }
Пример #7
0
        public static object Build(Type interfaceWebao, IRequest req)
        {
            var typeInformation  = TypeInfoCache.Get(interfaceWebao);
            var baseUrl          = typeInformation.GetClassAttributesByName("BaseUrl");
            var parametersByName = typeInformation.GetClassAttributesByName("AddParameter");

            if (baseUrl[0] is BaseUrlAttribute baseUrlAttribute)
            {
                req.BaseUrl(baseUrlAttribute.host);
            }

            foreach (var param in parametersByName)
            {
                if (param is AddParameterAttribute parameterAttribute)
                {
                    req.AddParameter(parameterAttribute.name, parameterAttribute.val);
                }
            }

            builderHelper.SetModuleBuilder(interfaceWebao.Name.Remove(0, 1));
            builderHelper.SetTypeBuilder(interfaceWebao);
            emitter.EmitConstructor(builderHelper.TypeBuilder, builderHelper.GetBaseCtor());

            var methods = interfaceWebao.GetMethods();

            foreach (var method in methods)
            {
                var info = builderHelper.ProcessMethod(method);
                emitter.EmitMethod(builderHelper.TypeBuilder, info);
            }

            var type = builderHelper.TypeBuilder.CreateType();

            builderHelper.Save();
            return(Activator.CreateInstance(type, req));
        }
Пример #8
0
 /// <summary>
 /// add a URL param (?name=value), uses a default encoder
 /// </summary>
 /// <param name="name">the name</param>
 /// <param name="value">value</param>
 public static void AddParameter(this IRequest request, string name, string value)
 {
     request.AddParameter(new Parameter {
         Name = name, Value = value
     });
 }