WAK operations define everything about an HTTP call.  The information on how to structure the class comes from the API’s documentation.

Let’s take a look at one of Instagram’s endpoints.

Screen Shot 2015-07-02 at 8.06.04 AM

Let’s take a look at the URI:

https://api.instagram.com/v1/tags/{tag-name}/media/recent?access_token=ACCESS-TOKEN&count=100
Base URI Resource Path Query String
https://api.instagram.com/v1/
tags/{tag-name}/media/recent
?access_token=ACCESS-TOKEN&count=10
This is our entry point into Intagram’s version 1 API. Notice the {tag-name}.  This is a URI Template that must be replaced and resolved before making the request. Parameters as part of the URI.

From this information we can begin constructing our operation class.  Any operation class must inherit from hg.ApiWebKit.core.http.HttpOperation.


    
[HttpPath(null,"https://api.instagram.com/v1/tags/{$tag}/media/recent")]
    [HttpGET]
    public class InstagramRecentMediaForTag : hg.ApiWebKit.core.http.HttpOperation
    {
        [HttpUriSegment("tag")]
        public string Tag = "gaming";
        
        [HttpQueryString("count")]
        public int Count = 10;

        [HttpQueryString]
        public string access_token = "abc123";
    }

Notice that we are using C# attributes everywhere.  At runtime the URI in the [HttpPath] attribute will be expanded by using the values from the class fields and will look like this:

https://api.instagram.com/v1/tags/gaming/media/recent?access_token=abc123&count=10

Most attribute constructors in this example accept optional parameters and are really just key-value pairs.  By using the parameterless constructor you are defining the ‘Name’ to be the same as the field name, as seen in the ‘access_token’ field.

  • Name: the name of the parameter.  For example, the ‘Count’ field as is will evaluate to query string ‘count=10’.
  • Value: static value of the parameter.  Instead of using the value of the ‘Count’ field during evaluation, you can force it to use a static value.  This would look like [HttpQueryString("count", Value= "10")].
  • VariableName: name of the parameter resolved from settings in the Configuration class.
  • VariableValue: value of the parameter resolved from settings in the Configuration class.

Now we are ready to test our operation.  By adding Configuration.SetSetting ("log-VERBOSE", true); to the beginning of the Start method, you will see copious amounts of information in the Unity Console.

Screen Shot 2015-06-30 at 6.19.14 PM

 

If you have entered a valid access token you should see these entries in Unity’s Console breaking down the request and responses.

RequestScreen Shot 2015-07-02 at 9.39.11 AM

 

 

ResponseScreen Shot 2015-07-02 at 9.32.25 AM

 

The returned text is raw JSON and is pretty useless to us at this point.

Screen Shot 2015-07-02 at 9.35.07 AM

In the next post we will take a look on how to make this JSON data accessible to us in Unity.

Next: Modeling WAK Responses

Previous: How WAK Works

Related Articles

WAK: MQTT for IoT – Brief Documentation

Read about MQTT here. Setting up your scene: 1. Create a GameObject. 2. Add the following scripts: ConnectionBroker, DesktopClient, and…

WAK FAQ [1]

Here are answers to questions a potential user asked recently. Previous: OAuth2 in Unity

OAuth Overview in Unity

Below is one of the OAuth flows available in the WAK OAuth Token Interceptor asset. Next: WAK FAQ 1 Previous: Switching WAK…