Exemplo n.º 1
0
 public Request(ServResources serverResources)
 {
     this.servRes = serverResources;
 }
Exemplo n.º 2
0
        private static void ConnectToApi(object sender, DoWorkEventArgs e) {
            /* Initiate connection to API */ {
                // You could add this into another thread
                // to have a animation while the application is connecting
                // etc.
                splash.SetText("Creating Object!");

                // Setup our sided api
                var serverAPIURL = "http://callumcarmicheal.com/LCAPI/"; // LINK TO WHERE YOU UPLOADED AND SETUP THE PHP SCRIPT
                apiRequest = new Request(servResources = new ServResources(serverAPIURL));

                // Get a new GUID for our API Access
                var guidReqResponse = apiRequest.getNewGUID();

                // Print our information from the guidReqResponse
                splash.SetText("Requesting a Authorization GUID and URL");
                var apiSetupResponse = apiRequest.SetupAPIRequest(false); // When using our own checking method, we just check to see if its "RETURN"

                // Check if our state == return (We will handle our own checking of the token)
                if (apiSetupResponse.getState() != ResponseState.RETURN) {
                    splash.SetText("Unexpected Response (" + apiSetupResponse.getState().ToString() + "): " + apiSetupResponse.getMessage());
                }

                // Get our token state
                GUID_Status guidStatus;
                splash.SetText("Waiting for user to accept POPUP");

                while (true) {
                    // Now we play the waiting game!
                    //splash.SetText("State: " + state.ToString() + "\n");

                    // Check our GUID State
                    guidStatus = apiRequest.getGUIDState();

                    if (guidStatus == GUID_Status.STATE_ID_VALID) {
                        splash.SetText("Server recieved token.");
                        break;
                    }

                    // Wait 0.5 seconds before checking
                    // for a token! NOTE: since this is a splashscreen
                    // we dont need to do Application.DoEvents to redraw
                    // the form since it is static.
                    Thread.Sleep(500);
                }


                splash.SetText("Requesting Token");

                apiAccess = new APIAccess(apiRequest);
                var apiToken = apiAccess.getBearerCode();

                if (apiToken.Error) {
                    // TODO: Handle Error
                }

                splash.SetText("Creating extra objects");
                oAuthCreds = new oAuthAuth(apiToken.Token);
                apiEngine  = new Engine(oAuthCreds);


                splash.SetText("Done.");
            }
        }
Exemplo n.º 3
0
 public  Request(ServResources serverResources) { this.servRes = serverResources; }