public SocialRequest(SLServiceKind kind, string method, Uri url, IDictionary <string, string> parametrs, Account account)
                : base(method, url, parametrs, account)
            {
                var m = SLRequestMethod.Get;

                switch (method.ToLowerInvariant())
                {
                case "get":
                    m = SLRequestMethod.Get;
                    break;

                case "post":
                    m = SLRequestMethod.Post;
                    break;

                case "delete":
                    m = SLRequestMethod.Delete;
                    break;

                default:
                    throw new NotSupportedException("Social framework does not support the HTTP method '" + method + "'");
                }

                request = SLRequest.Create(kind, m, new NSUrl(url.AbsoluteUri), new NSMutableDictionary());
                UpdateParameters(request);

                Account = account;
            }
        private string parseFacebookUserIdFromSettings(ACAccount account)
        {
            SLRequest sl = SLRequest.Create(SLServiceKind.Facebook, SLRequestMethod.Get, new NSUrl("https://graph.facebook.com/me"), null);

            sl.Account = account;

            AutoResetEvent completedEvent = new AutoResetEvent(false);
            var            id             = string.Empty;

            sl.PerformRequest((data, response, error) =>
            {
                if (error == null)
                {
                    NSError parseError;
                    NSDictionary jsonDict = (NSDictionary)NSJsonSerialization.Deserialize(data, 0, out parseError);
                    if (jsonDict != null)
                    {
                        NSObject obj = jsonDict.ValueForKey(new NSString("id"));
                        id           = obj?.ToString();
                    }
                }

                completedEvent.Set();
            });

            completedEvent.WaitOne();
            return(id);
        }
            void UpdateParameters(SLRequest request)
            {
                if (Parameters == null)
                {
                    return;
                }

                foreach (var p in Parameters)
                {
                    request.Parameters.SetValueForKey(new NSString(p.Value), new NSString(p.Key));
                }
            }
        public async Task <List <TweetInfo> > SearchAsync(string term, int count)
        {
            await LoadAccountAsync();

            Debug.WriteLine($"Searching for '{term}'");

            if (account == null)
            {
                throw new Exception("Couldn't open Twitter account!");
            }
            if (term == null)
            {
                throw new Exception("Null search term!");
            }

            // create the Twitter search request
            var requestUrl = new NSUrl($"https://api.twitter.com/1.1/search/tweets.json?count={count}&q={Uri.EscapeUriString(term)}");
            var request    = SLRequest.Create(SLServiceKind.Twitter, SLRequestMethod.Get, requestUrl, new NSDictionary());

            request.Account = account;
            var preparedRequest = request.GetPreparedUrlRequest();

            if (preparedRequest == null)
            {
                throw new Exception("Couldn't construct request!");
            }

            var taskRequest = await NSUrlSession.SharedSession.CreateDataTaskAsync(preparedRequest);

            var statusCode = ((NSHttpUrlResponse)taskRequest.Response).StatusCode;

            if (statusCode != 200)
            {
                throw new Exception($"HTTP Code {statusCode}");
            }

            var parsedResponse = ParseResponse(taskRequest.Data);

            if (parsedResponse == null)
            {
                throw new Exception("Failed to parse response!");
            }

            Debug.WriteLine("Search completed!");

            return(parsedResponse);
        }
Beispiel #5
0
        private void _Request(string url, SLRequestMethod method, Dictionary <object, object> parameters, Action <object, NSHTTPURLResponse, NSError> callback)
        {
            _service.RequestAccessToAccounts(_accountType, _options, delegate(bool granted, NSError error) {
                CoreXT.RunOnMainThread(delegate() {
                    if (granted)
                    {
                        var account = _service.FindAccounts(_accountType)[0] as ACAccount;
                        var request = SLRequest.Request(
                            _serviceType,
                            method,
                            new NSURL(url),
                            parameters);
                        request.account = account;
//						Debug.Log("prepared url: " + request.PreparedURLRequest().URL().AbsoluteString() + "\n" + Json.Serialize(request.PreparedURLRequest().AllHTTPHeaderFields())
//						          + "\n" + request.PreparedURLRequest().HTTPBody().ToByteArray().ToStraightString());

                        request.PerformRequest(delegate(NSData responseData, NSHTTPURLResponse urlResponse, NSError error2) {
                            object obj   = null;
                            var response = Encoding.UTF8.GetString(responseData.ToByteArray());
                            try {
                                obj = Json.Deserialize(response);
                            } catch (Exception) {
                                obj = response;
                            }
                            callback(obj, urlResponse, error2);
                            callback = null;
                        });

                        parameters = null;
                        account    = null;
                        request    = null;
                    }
                    else
                    {
                        callback(null, null, error);
                        parameters = null;
                        callback   = null;
                    }
                });
            });
        }
Beispiel #6
0
        partial void RequestFacebookTimeline_TouchUpInside(UIButton sender)
        {
            // Initialize request
            var parameters = new NSDictionary();
            var url        = new NSUrl("https://graph.facebook.com/283148898401104");
            var request    = SLRequest.Create(SLServiceKind.Facebook, SLRequestMethod.Get, url, parameters);

            // Request data
            request.Account = FacebookAccount;
            request.PerformRequest((data, response, error) => {
                // Was there an error?
                if (error == null)
                {
                    // Was the request successful?
                    if (response.StatusCode == 200)
                    {
                        // Yes, display it
                        InvokeOnMainThread(() => {
                            Results.Text = data.ToString();
                        });
                    }
                    else
                    {
                        // No, display error
                        InvokeOnMainThread(() => {
                            Results.Text = $"Error: {response.StatusCode}";
                        });
                    }
                }
                else
                {
                    // No, display error
                    InvokeOnMainThread(() => {
                        Results.Text = $"Error: {error}";
                    });
                }
            });
        }
Beispiel #7
0
        partial void RequestTwitterTimeline_TouchUpInside(UIButton sender)
        {
            // Initialize request
            var parameters = new NSDictionary();
            var url        = new NSUrl("https://api.twitter.com/1.1/statuses/user_timeline.json?count=10");
            var request    = SLRequest.Create(SLServiceKind.Twitter, SLRequestMethod.Get, url, parameters);

            // Request data
            request.Account = TwitterAccount;
            request.PerformRequest((data, response, error) => {
                // Was there an error?
                if (error == null)
                {
                    // Was the request successful?
                    if (response.StatusCode == 200)
                    {
                        // Yes, display it
                        InvokeOnMainThread(() => {
                            Results.Text = data.ToString();
                        });
                    }
                    else
                    {
                        // No, display error
                        InvokeOnMainThread(() => {
                            Results.Text = $"Error: {response.StatusCode}";
                        });
                    }
                }
                else
                {
                    // No, display error
                    InvokeOnMainThread(() => {
                        Results.Text = $"Error: {error}";
                    });
                }
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            twitterButton.TouchUpInside += delegate {
                if (SLComposeViewController.IsAvailable(SLServiceKind.Twitter))
                {
                    slComposer = SLComposeViewController.FromService(SLServiceType.Twitter);

                    slComposer.SetInitialText("test");
                    slComposer.AddImage(UIImage.FromFile("monkey.png"));

                    slComposer.CompletionHandler += (result) => {
                        InvokeOnMainThread(() => {
                            DismissViewController(true, null);
                            resultsTextView.Text = result.ToString();
                        });
                    };

                    PresentViewController(slComposer, true, null);
                }
                else
                {
                    resultsTextView.Text = "Twitter Account not added";
                }
            };

            facebookButton.TouchUpInside += delegate {
                if (SLComposeViewController.IsAvailable(SLServiceKind.Facebook))
                {
                    slComposer = SLComposeViewController.FromService(SLServiceType.Facebook);

                    slComposer.SetInitialText("test2");
                    slComposer.AddImage(UIImage.FromFile("monkey.png"));
                    slComposer.AddUrl(new NSUrl("http://xamarin.com"));

                    slComposer.CompletionHandler += (result) => {
                        InvokeOnMainThread(() => {
                            DismissViewController(true, null);
                            resultsTextView.Text = result.ToString();
                        });
                    };

                    PresentViewController(slComposer, true, null);
                }
                else
                {
                    resultsTextView.Text = "Facebook Account not added";
                }
            };

            twitterRequestButton.TouchUpInside += delegate {
                if (SLComposeViewController.IsAvailable(SLServiceKind.Twitter))
                {
                    var parameters = new NSDictionary();
                    var request    = SLRequest.Create(SLServiceKind.Twitter,
                                                      SLRequestMethod.Get,
                                                      new NSUrl("http://api.twitter.com/1/statuses/public_timeline.json"),
                                                      parameters);

                    request.PerformRequest((data, response, error) => {
                        if (response.StatusCode == 200)
                        {
                            InvokeOnMainThread(() => {
                                resultsTextView.Text = data.ToString();
                            });
                        }
                        else
                        {
                            InvokeOnMainThread(() => {
                                resultsTextView.Text = "Error: " + response.StatusCode.ToString();
                            });
                        }
                    });
                }
                else
                {
                    resultsTextView.Text = "Twitter Account not added";
                }
            };

            facebookRequestButton.TouchUpInside += delegate {
                if (SLComposeViewController.IsAvailable(SLServiceKind.Facebook))
                {
                    var parameters = new NSDictionary();
                    var request    = SLRequest.Create(SLServiceKind.Facebook,
                                                      SLRequestMethod.Get,
                                                      new NSUrl("https://graph.facebook.com/283148898401104"),
                                                      parameters);

                    request.PerformRequest((data, response, error) => {
                        if (response.StatusCode == 200)
                        {
                            InvokeOnMainThread(() => {
                                resultsTextView.Text = data.ToString();
                            });
                        }
                        else
                        {
                            InvokeOnMainThread(() => {
                                resultsTextView.Text = "Error: " + response.StatusCode.ToString();
                            });
                        }
                    });
                }
                else
                {
                    resultsTextView.Text = "Facebook Account not added";
                }
            };
        }
Beispiel #9
0
    public double GetFreightRate(string shipperFirstName, string shipperlastName, string shipperAddressline1, string shipperCity, string shipperState, string shipperPostalCode, string shipperCountry, string shipperPhone,
                                 string shipToFirstName, string shipTolastName, string shipToAddressline1, string shipToCity, string shipToState, string shipToPostalCode, string shipToCountry, string shipToPhone,
                                 string carrierType, string packageWeight)
    {
        SLRequest slReq    = new SLRequest();
        Request   oRequest = new Request();

        string[] carriers = { carrierType }; //define a valid carrier
        oRequest.CarriersToActOn = carriers;
        oRequest.ShipTransaction = new ShipTransaction();
        Shipment oShipment = new Shipment();

        oRequest.ShipTransaction.Shipment = oShipment;
        ShipperAddress oShipperAddress = new ShipperAddress();

        oShipperAddress.Address = new Address();
        SLXmlAttribute slXmlShipFirstName = new SLXmlAttribute();

        slXmlShipFirstName.Value          = shipperFirstName;
        oShipperAddress.Address.FirstName = slXmlShipFirstName;

        SLXmlAttribute slXmlShipLastName = new SLXmlAttribute();

        slXmlShipLastName.Value          = shipperlastName;
        oShipperAddress.Address.LastName = slXmlShipLastName;

        SLXmlAttribute slXmlShipAddress1 = new SLXmlAttribute();

        slXmlShipAddress1.Value          = shipperAddressline1;
        oShipperAddress.Address.Address1 = slXmlShipAddress1;

        SLXmlAttribute slXmlShipShipCity = new SLXmlAttribute();

        slXmlShipShipCity.Value      = shipperCity;
        oShipperAddress.Address.City = slXmlShipShipCity;

        SLXmlAttribute slXmlShipState = new SLXmlAttribute();

        slXmlShipState.Value          = shipperState;
        oShipperAddress.Address.State = slXmlShipState;

        SLXmlAttribute slXmlShipPostCode = new SLXmlAttribute();

        slXmlShipPostCode.Value            = shipperPostalCode;
        oShipperAddress.Address.PostalCode = slXmlShipPostCode;

        SLXmlAttribute slXmlShipCountry = new SLXmlAttribute();

        slXmlShipCountry.Value          = shipperCountry;
        oShipperAddress.Address.Country = slXmlShipCountry;

        SLXmlAttribute slXmlShipPhone = new SLXmlAttribute();

        slXmlShipPhone.Value          = shipperPhone;
        oShipperAddress.Address.Phone = slXmlShipPhone;

        oRequest.ShipTransaction.Shipment.ShipperAddress = oShipperAddress;
        DeliveryAddress oDeliveryAddress = new DeliveryAddress();

        oDeliveryAddress.Address = new Address();

        SLXmlAttribute slXmlDeliverFirstName = new SLXmlAttribute();

        slXmlDeliverFirstName.Value        = shipToFirstName;
        oDeliveryAddress.Address.FirstName = slXmlDeliverFirstName;

        SLXmlAttribute slXmlDeliverLastName = new SLXmlAttribute();

        slXmlDeliverLastName.Value        = shipTolastName;
        oDeliveryAddress.Address.LastName = slXmlDeliverLastName;

        SLXmlAttribute slXmlDeliverAddres1 = new SLXmlAttribute();

        slXmlDeliverAddres1.Value         = shipToAddressline1;
        oDeliveryAddress.Address.Address1 = slXmlDeliverAddres1;

        SLXmlAttribute slXmlDeliverCity = new SLXmlAttribute();

        slXmlDeliverCity.Value        = shipToCity;
        oDeliveryAddress.Address.City = slXmlDeliverCity;

        SLXmlAttribute slXmlDeliverState = new SLXmlAttribute();

        slXmlDeliverState.Value        = shipToState;
        oDeliveryAddress.Address.State = slXmlDeliverState;

        SLXmlAttribute slXmlDeliverPostalCode = new SLXmlAttribute();

        slXmlDeliverPostalCode.Value        = shipToPostalCode;
        oDeliveryAddress.Address.PostalCode = slXmlDeliverPostalCode;

        SLXmlAttribute slXmlDeliverCountry = new SLXmlAttribute();

        slXmlDeliverCountry.Value        = shipToCountry;
        oDeliveryAddress.Address.Country = slXmlDeliverCountry;

        SLXmlAttribute slXmlDeliverPhone = new SLXmlAttribute();

        slXmlDeliverPhone.Value        = shipToPhone;
        oDeliveryAddress.Address.Phone = slXmlDeliverPhone;
        oRequest.ShipTransaction.Shipment.DeliveryAddress = oDeliveryAddress;

        oRequest.Settings = new Settings();

        Package        oPkg         = new Package();
        SLXmlAttribute slXmlPackage = new SLXmlAttribute();

        slXmlPackage.Value       = packageWeight;
        oPkg.PackageActualWeight = slXmlPackage;
        Package[] oPkgArr = new Package[] { oPkg };
        oRequest.ShipTransaction.Shipment.Package = oPkgArr;
        slReq.Request = oRequest;
        SLResponse slResp = null;

        try
        {
            ShippingLiveService srvc = new ShippingLiveService();
            slResp = srvc.RateShipment(slReq);
            if (slResp.ResultList != null)
            {
                return(slResp.ResultList[0].TotalCharge);
            }

            return(0);
        }
        catch (Exception ex)
        {
            return(0);
            //exception handling here
        }
    }
Beispiel #10
0
    public bool GetFreightAddressEval(string shipperAddressline1, string shipperCity, string shipperState, string shipperPostalCode,
                                      string shipToAddressline1, string shipToCity, string shipToState, string shipToPostalCode)
    {
        SLRequest slReq    = new SLRequest();
        Request   oRequest = new Request();

        //string[] carriers = { carrierType }; //define a valid carrier
        //oRequest.CarriersToActOn = carriers;
        oRequest.ShipTransaction = new ShipTransaction();
        Shipment oShipment = new Shipment();

        oRequest.ShipTransaction.Shipment = oShipment;
        ShipperAddress oShipperAddress = new ShipperAddress();

        oShipperAddress.Address = new Address();
        SLXmlAttribute slXmlShipFirstName = new SLXmlAttribute();

        slXmlShipFirstName.Value          = "";
        oShipperAddress.Address.FirstName = slXmlShipFirstName;

        SLXmlAttribute slXmlShipLastName = new SLXmlAttribute();

        slXmlShipLastName.Value          = "";
        oShipperAddress.Address.LastName = slXmlShipLastName;

        SLXmlAttribute slXmlShipAddress1 = new SLXmlAttribute();

        slXmlShipAddress1.Value          = shipperAddressline1;
        oShipperAddress.Address.Address1 = slXmlShipAddress1;

        SLXmlAttribute slXmlShipShipCity = new SLXmlAttribute();

        slXmlShipShipCity.Value      = shipperCity;
        oShipperAddress.Address.City = slXmlShipShipCity;

        SLXmlAttribute slXmlShipState = new SLXmlAttribute();

        slXmlShipState.Value          = shipperState;
        oShipperAddress.Address.State = slXmlShipState;

        SLXmlAttribute slXmlShipPostCode = new SLXmlAttribute();

        slXmlShipPostCode.Value            = shipperPostalCode;
        oShipperAddress.Address.PostalCode = slXmlShipPostCode;

        SLXmlAttribute slXmlShipCountry = new SLXmlAttribute();

        slXmlShipCountry.Value          = "";
        oShipperAddress.Address.Country = slXmlShipCountry;

        SLXmlAttribute slXmlShipPhone = new SLXmlAttribute();

        slXmlShipPhone.Value          = "";
        oShipperAddress.Address.Phone = slXmlShipPhone;

        oRequest.ShipTransaction.Shipment.ShipperAddress = oShipperAddress;
        DeliveryAddress oDeliveryAddress = new DeliveryAddress();

        oDeliveryAddress.Address = new Address();

        SLXmlAttribute slXmlDeliverFirstName = new SLXmlAttribute();

        slXmlDeliverFirstName.Value        = "";
        oDeliveryAddress.Address.FirstName = slXmlDeliverFirstName;

        SLXmlAttribute slXmlDeliverLastName = new SLXmlAttribute();

        slXmlDeliverLastName.Value        = "";
        oDeliveryAddress.Address.LastName = slXmlDeliverLastName;

        SLXmlAttribute slXmlDeliverAddres1 = new SLXmlAttribute();

        slXmlDeliverAddres1.Value         = shipToAddressline1;
        oDeliveryAddress.Address.Address1 = slXmlDeliverAddres1;

        SLXmlAttribute slXmlDeliverCity = new SLXmlAttribute();

        slXmlDeliverCity.Value        = shipToCity;
        oDeliveryAddress.Address.City = slXmlDeliverCity;

        SLXmlAttribute slXmlDeliverState = new SLXmlAttribute();

        slXmlDeliverState.Value        = shipToState;
        oDeliveryAddress.Address.State = slXmlDeliverState;

        SLXmlAttribute slXmlDeliverPostalCode = new SLXmlAttribute();

        slXmlDeliverPostalCode.Value        = shipToPostalCode;
        oDeliveryAddress.Address.PostalCode = slXmlDeliverPostalCode;

        SLXmlAttribute slXmlDeliverCountry = new SLXmlAttribute();

        slXmlDeliverCountry.Value        = "";
        oDeliveryAddress.Address.Country = slXmlDeliverCountry;

        SLXmlAttribute slXmlDeliverPhone = new SLXmlAttribute();

        slXmlDeliverPhone.Value        = "";
        oDeliveryAddress.Address.Phone = slXmlDeliverPhone;
        oRequest.ShipTransaction.Shipment.DeliveryAddress = oDeliveryAddress;

        Package        oPkg         = new Package();
        SLXmlAttribute slXmlPackage = new SLXmlAttribute();

        slXmlPackage.Value       = "2";
        oPkg.PackageActualWeight = slXmlPackage;
        Package[] oPkgArr = new Package[] { oPkg };
        oRequest.ShipTransaction.Shipment.Package = oPkgArr;
        slReq.Request = oRequest;
        SLResponse slResp = null;

        try
        {
            bool addResult, addResSpec;
            ShippingLiveService srvc = new ShippingLiveService();
            srvc.ValidateAddress(slReq, out addResult, out addResSpec);
            string a = "xyz";
            //  slResp = srvc.RateShipment(slReq);
            //if (slResp.ResultList != null)
            //{
            //    return slResp.ResultList[0].TotalCharge;
            //}


            return(addResult);
        }
        catch (Exception ex)
        {
            return(false);
            //exception handling here
        }
    }
Beispiel #11
0
			void UpdateParameters (SLRequest request)
			{
				if (Parameters == null)
					return;

				foreach (var p in Parameters) {
					request.Parameters.SetValueForKey (new NSString (p.Value), new NSString (p.Key));
				}
			}
Beispiel #12
0
			public SocialRequest (SLServiceKind kind, string method, Uri url, IDictionary<string, string> parametrs, Account account)
				: base (method, url, parametrs, account)
			{
				var m = SLRequestMethod.Get;
				switch (method.ToLowerInvariant()) {
					case "get":
					m = SLRequestMethod.Get;
					break;
					case "post":
					m = SLRequestMethod.Post;
					break;
					case "delete":
					m = SLRequestMethod.Delete;
					break;
					default:
					throw new NotSupportedException ("Social framework does not support the HTTP method '" + method + "'");
				}

				request = SLRequest.Create (kind, m, new NSUrl (url.AbsoluteUri), new NSMutableDictionary ());
				UpdateParameters (request);

				Account = account;
			}