Creating and implementing the TwitterWebService interface

In this section, we will create the ITwitterWebService class, which will essentially contain various instance methods that will be used by our TwitterWebService class. The advantage of creating an ITwitterWebService class is that it's much easier to add additional class instance methods that will be used by other classes that utilize this interface.

Let's start by creating the ITwitterWebService interface for our TrackMyWalks app by performing the following steps:

  1. Right-click on the Services folder, and choose Add | New File... from the pop-up menu, as you did in the section entitled Creating and implementing the LocationService interface within Chapter 7, Adding Location-based Features Within Your App.
  1. Then, choose the Empty Interface option under the General section and enter ITwitterWebService for the name of the interface to be created, as shown in the following screenshot:

Creating the ITwitterWebService Interface
  1. Next, click on the New button to allow the wizard to proceed and create the new file, as shown in the preceding screenshot. Now that we have created our ITwitterWebService interface, we can proceed with implementing the required code for our class.
  2. Then, locate and open the ITwitterWebService.cs file, which is located within the Services folder, and ensure that it is displayed within the code editor. Then, enter the following code snippet:
    //
// ITwitterWebService.cs
// TwitterWebService Interface used by our TwitterWebService Class
//
// Created by Steven F. Daniel on 10/08/2018.
// Copyright © 2018 GENIESOFT STUDIOS. All rights reserved.
//
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Xamarin.Auth;

namespace TrackMyWalks.Services
{
public interface ITwitterService
{
// Instance method to get the user's Twitter Profile Details
Task<JObject> GetTwitterProfile(Account e);

// Instance method to post a Tweet message to the users Twitter Feed
Task<string> TweetMessage(string message, Account e);
}
}

Now, let's start by taking a look at what we covered in the preceding code snippet:

  1. We started by including references to the System.Threading.Tasks, Newtonsoft.Json.Linq, and Xamarin.Auth namespaces so that we can access the classes that are defined within these namespaces.
  2. Next, we declared a GetTwitterProfile instance method, which will be responsible for asynchronously retrieving the Twitter profile details for the logged-in user.
  3. Finally, we declared a TweetMessage instance method that will be responsible for asynchronously posting walk trail information to the logged-in Twitter user's feed.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.120.206