package com.github.scribejava.apis.examples;

import com.github.scribejava.apis.YahooApi20;
import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.model.*;
import com.github.scribejava.core.oauth.OAuth20Service;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;

/**
 * Flow as documented at https://developer.yahoo.com/oauth2/guide/flows_authcode
 * <ol>
 *     <li>Create an application at https://developer.yahoo.com/apps/create/</li>
 *     <li>Make sure the application has the API permission where your protected resource resides (Profiles, Fantasy Sports, etc)</li>
 * 	   <li>get Client ID and Client Secret after registering your app</li>
 * </ol>
 */
public class Yahoo20Example {

	// Update PROTECTED_RESOURCE_URL to a secure URL only you could reach = your profile, or private fantasy sports
    private static final String PROTECTED_RESOURCE_URL
            = "https://baseball.fantasysports.yahoo.com/b1/ ADD TEAM HERE!!!!";

    private Yahoo20Example() {
    }

    public static void main(String... args) throws IOException, InterruptedException, ExecutionException {

    	// Add your personal information here
    	final String clientId = "ADD CLIENT ID HERE!!!!";
        final String clientSecret = "ADD SECRET HERE!!!!";

        final OAuth20Service service = new ServiceBuilder(clientId)
                .apiSecret(clientSecret)
                .callback("oob")
                .build(YahooApi20.instance());
        final Scanner in = new Scanner(System.in);

        System.out.println("=== Yahoo's OAuth Workflow ===");
        System.out.println();

        // Obtain the Request Token
        System.out.println("Fetching the Request Token...");
        System.out.println("Got the Request Token!");
        System.out.println();

        System.out.println("Now go and authorize ScribeJava here:");
        System.out.println(service.getAuthorizationUrl());
        System.out.println("And paste the verifier here");
        System.out.print(">>");
        final String oauthVerifier = in.nextLine();
        System.out.println();

        // Trade the Request Token and Verfier for the Access Token
        System.out.println("Trading the Request Token for an Access Token...");
        final OAuth2AccessToken accessToken = service.getAccessToken(oauthVerifier);
        System.out.println("Got the Access Token!");
        System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
        System.out.println();

        // Now let's go and ask for a protected resource!
        System.out.println("Now we're going to access a protected resource...");
        final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
        service.signRequest(accessToken, request);
        final Response response = service.execute(request);
        System.out.println("Got it! Lets see what we found...");
        System.out.println();
        System.out.println(response.getCode());
        System.out.println(response.getBody());

        System.out.println();
        System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");

    }
}

@@ -183,17 +183,183 @@
 e.model.
-*
+OAuth2AccessToken;%0Aimport com.github.scribejava.core.model.OAuthRequest;%0Aimport com.github.scribejava.core.model.Response;%0Aimport com.github.scribejava.core.model.Verb
 ;%0Aimport
@@ -603,28 +603,24 @@
 e%0A * %3Col%3E%0A *
-    
  %3Cli%3ECreate 
@@ -685,20 +685,16 @@
 %3C/li%3E%0A *
-    
  %3Cli%3EMak
@@ -700,20 +700,16 @@
 ke sure 
-the 
 applicat
@@ -720,16 +720,8 @@
 has 
-the API 
 perm
@@ -731,28 +731,14 @@
 ion 
-where your protected
+to API
  res
@@ -747,16 +747,8 @@
 rce 
-resides 
 (Pro
@@ -786,12 +786,8 @@
 %3E%0A *
- %09  
  %3Cli
@@ -895,17 +895,20 @@
 mple %7B%0A%0A
-%09
+    
 // Updat
@@ -1292,22 +1292,24 @@
 ption %7B%0A
-%0A
+    
     
-%09
 // Add y
@@ -1346,9 +1346,12 @@
     
-%09
+    
 fina
@@ -3361,9 +3361,8 @@
 %0A    %7D%0A%7D
-%0A

fix formatting issues identified by CI.