/// <summary> /// Validate an uri for an button(instagram partner) /// <para> /// Note: Use <see cref="IBusinessProcessor.GetBusinessPartnersButtonsAsync" /> to get business buttons(instagram /// partner) list! /// </para> /// </summary> /// <param name="desirePartner"> /// Desire partner (Use <see cref="IBusinessProcessor.GetBusinessPartnersButtonsAsync" /> to /// get business buttons(instagram partner) list!) /// </param> /// <param name="uri">Uri to check (Must be related to desire partner!)</param> public async Task <IResult <bool> > ValidateUrlAsync(InstaBusinessPartner desirePartner, Uri uri) { InstaUserAuthValidator.Validate(userAuthValidate); try { if (desirePartner?.AppId == null) { return(Result.Fail <bool>("Desire partner cannot be null")); } if (uri == null) { return(Result.Fail <bool>("Uri cannot be null")); } var instaUri = InstaUriCreator.GetBusinessValidateUrlUri(); var data = new JObject { { "app_id", desirePartner.AppId }, { "_csrftoken", user.CsrfToken }, { "url", uri.ToString() }, { "_uid", user.LoggedInUser.Pk.ToString() }, { "_uuid", deviceInfo.DeviceGuid.ToString() } }; var request = httpHelper.GetSignedRequest(HttpMethod.Post, instaUri, deviceInfo, data); var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false); var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var obj = JsonConvert.DeserializeObject <InstaBusinessValidateUrl>(json); return(obj.IsValid ? Result.Success(true) : Result.Fail <bool>(obj.ErrorMessage)); } catch (HttpRequestException httpException) { logger?.LogError(httpException, "Error"); return(Result.Fail(httpException, default(bool), ResponseType.NetworkProblem)); } catch (Exception exception) { logger?.LogError(exception, "Error"); return(Result.Fail <bool>(exception)); } }
/// <summary> /// Add button to your business account /// </summary> /// <param name="businessPartner">Desire partner button (Use <see cref="IBusinessProcessor.GetBusinessPartnersButtonsAsync"/> to get business buttons(instagram partner) list!)</param> /// <param name="uri">Uri (related to Business partner button)</param> public async Task <IResult <InstaBusinessUser> > AddOrChangeBusinessButtonAsync(InstaBusinessPartner businessPartner, Uri uri) { UserAuthValidator.Validate(_userAuthValidate); try { if (businessPartner == null) { return(Result.Fail <InstaBusinessUser>("Business partner cannot be null")); } if (uri == null) { return(Result.Fail <InstaBusinessUser>("Uri related to business partner cannot be null")); } var validateUri = await ValidateUrlAsync(businessPartner, uri); if (!validateUri.Succeeded) { return(Result.Fail <InstaBusinessUser>(validateUri.Info.Message)); } var instaUri = UriCreator.GetUpdateBusinessInfoUri(); var data = new JObject { { "ix_url", uri.ToString() }, { "ix_app_id", businessPartner.AppId }, { "is_call_to_action_enabled", "1" }, { "_csrftoken", _user.CsrfToken }, { "_uid", _user.LoggedInUser.Pk.ToString() }, { "_uuid", _deviceInfo.DeviceGuid.ToString() } }; var request = _httpHelper.GetSignedRequest(HttpMethod.Post, instaUri, _deviceInfo, data); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaBusinessUser>(response, json)); } var obj = JsonConvert.DeserializeObject <InstaBusinessUserContainerResponse>(json); return(Result.Success(ConvertersFabric.Instance.GetBusinessUserConverter(obj).Convert())); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail <InstaBusinessUser>(exception)); } }