本文整理汇总了C#中RestSharp.Parameter类的典型用法代码示例。如果您正苦于以下问题:C# Parameter类的具体用法?C# Parameter怎么用?C# Parameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parameter类属于RestSharp命名空间,在下文中一共展示了Parameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddParameter
public void AddParameter(string name, string value)
{
Parameter parm = new RestSharp.Parameter();
parm.Name = name;
parm.Value = value;
parameters.Add(parm);
}
示例2: Resolve
public SpreedlyStatus Resolve(Parameter statusHeader)
{
if (statusHeader == null)
throw new ArgumentNullException("statusHeader");
return ResolveStatusCode(GetStatusCodeString(statusHeader.Value.ToString()));
}
示例3: RetornaUsuario
public Usuario RetornaUsuario(string id)
{
Usuario u;
Parameter at = new Parameter();
Parameter at1 = new Parameter();
List<Parameter> param = new List<Parameter>();
//Alimentando parametros
//at1.Name = "access_token";
//at1.Value = m.AccessToken;
at.Name = "user_id";
at.Value = id;
param.Add(at);
//param.Add(at1);
RestResponse resp = (RestResponse)m.Get("/users/" + id);
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
var a = new JsonSerializerSettings();
u = JsonConvert.DeserializeObject<Usuario>(resp.Content);
return u;
}
else
{
throw new Exception("Falha ao tentar recuperar a Usuario");
}
}
示例4: BeforeGetUserInfo
/// <summary>
/// Called just before issuing request to third-party service when everything is ready.
/// Allows to add extra parameters to request or do any other needed preparations.
/// </summary>
protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
{
// Source document
// http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=12878032
args.Request.AddParameter("application_key", _configuration.ClientPublic);
args.Request.AddParameter("method", "users.getCurrentUser");
// workaround for current design, oauth_token is always present in URL, so we need emulate it for correct request signing
var fakeParam = new Parameter() { Name = "oauth_token", Value = AccessToken };
args.Request.AddParameter(fakeParam);
// Signing.
// Call API methods using access_token instead of session_key parameter
// Calculate every request signature parameter sig using a little bit different way described in
// http://dev.odnoklassniki.ru/wiki/display/ok/Authentication+and+Authorization
// sig = md5( request_params_composed_string+ md5(access_token + application_secret_key) )
// Don't include access_token into request_params_composed_string
string signature = string.Concat(args.Request.Parameters.OrderBy(x => x.Name).Select(x => string.Format("{0}={1}", x.Name, x.Value)).ToList());
signature = (signature + (AccessToken + _configuration.ClientSecret).GetMd5Hash()).GetMd5Hash();
// Removing fake param to prevent dups
args.Request.Parameters.Remove(fakeParam);
args.Request.AddParameter("access_token", AccessToken);
args.Request.AddParameter("sig", signature);
}
示例5: Parse
/// <summary>
/// Parses the specified header and returns a collection of warning headers discovered and parsed.
/// </summary>
/// <param name="header">The header to parse.</param>
/// <returns>A collection of warning headers that were discovered in the header and parsed.</returns>
public static IEnumerable<HttpWarning> Parse(Parameter header)
{
if (header != null && header.Value != null)
{
foreach (Match match in regex.Matches(header.Value.ToString()))
{
yield return HttpWarning.Parse(match.Value);
}
}
}
示例6: AddDefaultParameter
/// <summary>
/// Add a parameter to use on every request made with this client instance
/// </summary>
/// <param name="restClient">The IRestClient instance</param>
/// <param name="p">Parameter to add</param>
/// <returns></returns>
public static void AddDefaultParameter(this IRestClient restClient, Parameter p)
{
if (p.Type == ParameterType.RequestBody)
{
throw new NotSupportedException(
"Cannot set request body from default headers. Use Request.AddBody() instead.");
}
restClient.DefaultParameters.Add(p);
}
示例7: HandleErrors
public void HandleErrors ()
{
Meli.ApiUrl = "http://localhost:3000";
Meli m = new Meli (123456, "client secret", "invalid token");
var p = new Parameter ();
p.Name = "access_token";
p.Value = m.AccessToken;
var ps = new List<Parameter> ();
ps.Add (p);
var response = m.Get ("/users/me", ps);
Assert.AreEqual (HttpStatusCode.Forbidden, response.StatusCode);
}
示例8: GetContacts
public IEnumerable<CrmContact> GetContacts(long responsibleUserId)
{
var contacts = new List<CrmContact>();
for (var offset = 0;; offset += _crmConfig.LimitRows ?? 500)
{
_crmConfig.LimitOffset = offset;
var parameterResponsibleUserId = new Parameter {Name = "responsible_user_id", Value = responsibleUserId, Type = ParameterType.QueryString};
var contactsList = AmoMethod.Get<CrmContactResponse>(_crmConfig, parameterResponsibleUserId);
if (contactsList == null)
break;
contacts.AddRange(contactsList.Response.Contacts);
}
return contacts;
}
示例9: GetContacts
public IEnumerable<CrmContact> GetContacts(string query)
{
var contacts = new List<CrmContact>();
for (var offset = 0;; offset += _crmConfig.LimitRows ?? 500)
{
_crmConfig.LimitOffset = offset;
var parameterQuery = new Parameter {Name = "query", Value = query, Type = ParameterType.QueryString};
var contactsList = AmoMethod.Get<CrmGetContactResponse>(_crmConfig, parameterQuery);
if (contactsList == null)
break;
contacts.AddRange(contactsList.Response.Contacts);
}
return contacts;
}
示例10: ToSingleParameter
/// <summary>
/// Parameterizes this <see cref="ShopifyOrderFilterOptions"/> class, with special handling for <see cref="Ids"/>.
/// </summary>
/// <param name="propName">The name of the property. Will match the property's <see cref="JsonPropertyAttribute"/> name —
/// rather than the real property name — where applicable. Use <paramref name="property"/>.Name to get the real name.</param>
/// <param name="value">The property's value.</param>
/// <param name="property">The property itself.</param>
/// <param name="type">The type of parameter to create.</param>
/// <returns>The new parameter.</returns>
public override Parameter ToSingleParameter(string propName, object value, PropertyInfo property, ParameterType type)
{
if (propName == "ids" || propName == "Ids")
{
//RestSharp does not automatically convert arrays into querystring params.
var param = new Parameter()
{
Name = propName,
Type = type,
Value = string.Join(",", value as IEnumerable<long> )
};
return param;
}
return base.ToSingleParameter(propName, value, property, type);
}
示例11: GetWithRefreshToken
public void GetWithRefreshToken ()
{
Meli.ApiUrl = "http://localhost:3000";
Meli m = new Meli (123456, "client secret", "expired token", "valid refresh token");
var p = new Parameter ();
p.Name = "access_token";
p.Value = m.AccessToken;
var ps = new List<Parameter> ();
ps.Add (p);
var response = m.Get ("/users/me", ps);
Assert.AreEqual (HttpStatusCode.OK, response.StatusCode);
Assert.IsNotNullOrEmpty (response.Content);
}
示例12: ResponderPergunta
public void ResponderPergunta(decimal idQuestion, string texto)
{
try
{
Parameter at = new Parameter();
List<Parameter> param = new List<Parameter>();
//Alimentando parametros
at.Name = "access_token";
at.Value = m.AccessToken;
param.Add(at);
m.Post("/answers", param, new { question_id = idQuestion, text = texto });
}
catch (Exception ex)
{
throw new Exception("Erro na rotina ResponderPergunta", ex);
}
}
示例13: RetornarOrdens
public ListOrder RetornarOrdens(Usuario u, Int32 ofset)
{
ListOrder o;
Parameter at = new Parameter();
Parameter seller = new Parameter();
Parameter offset = new Parameter();
List<Parameter> param = new List<Parameter>();
//Alimentando parametros
at.Name = "access_token";
at.Value = m.AccessToken;
seller.Name = "seller";
seller.Value = u.id;
offset.Name = "offset";
offset.Value = ofset;
//Adicionando na lista
param.Add(seller);
param.Add(at);
param.Add(offset);
RestResponse resp = (RestResponse)m.Get("/orders/search", param);
//offset
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
var a = new JsonSerializerSettings();
o = JsonConvert.DeserializeObject<ListOrder>(resp.Content);
return o;
}
else
{
throw new Exception("Falha ao tentar recuperar a lista de ordens");
}
}
示例14: RetonarQuestion
public Question RetonarQuestion(string resource)
{
try
{
Question q;
Parameter at = new Parameter();
List<Parameter> param = new List<Parameter>();
//Alimentando parametros
at.Name = "access_token";
at.Value = m.AccessToken;
param.Add(at);
RestResponse resp = (RestResponse)m.Get(resource, param);
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
var a = new JsonSerializerSettings();
q = JsonConvert.DeserializeObject<Question>(resp.Content);
FinalizaML(m.AccessToken, m.RefreshToken);
return q;
}
else
{
throw new Exception(string.Format("Falha ao tentar recuperar a pergunta {0} resp.StatusCode = {1} {0} resource = {2} {0}", Environment.NewLine, resp.StatusCode, resource));
}
}
catch (Exception ex)
{
throw new Exception("Erro na rotina RetonarQuestion.", ex);
}
}
示例15: RetornaOrder
public Order RetornaOrder(string codigo)
{
try
{
Order q;
Parameter at = new Parameter();
List<Parameter> param = new List<Parameter>();
//Alimentando parametros
at.Name = "access_token";
at.Value = m.AccessToken;
//Adicionando na lista
param.Add(at);
RestResponse resp = (RestResponse)m.Get(codigo, param);
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
var a = new JsonSerializerSettings();
q = JsonConvert.DeserializeObject<Order>(resp.Content);
FinalizaML(m.AccessToken, m.RefreshToken);
return q;
}
else
{
throw new Exception(String.Format("Ordem não encontrada. {0} codigo: {1} {0}",Environment.NewLine, codigo));
}
}
catch (Exception ex)
{
throw new Exception(String.Format("Erro na rotina RetornaOrder: {0} codigo: {1} {0}", Environment.NewLine, codigo), ex);
}
}