Package com.google.api.ads.adwords.awreporting.model.entities

Examples of com.google.api.ads.adwords.awreporting.model.entities.AuthMcc


        ReportWriterType.FileSystemWriter);

    MockitoAnnotations.initMocks(this);

    when(mockedAuthTokenPersister.getAuthToken(Mockito.anyString())).thenReturn(
        new AuthMcc("1", "AccountName", "TOKEN", "scope"));

    Mockito.doAnswer(new Answer<Void>() {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        return null;
View Full Code Here


  }
 
  @Test
  public void testGetAndRemoveWithListValues() {
    List<AuthMcc> authMccs = Lists.newArrayList();
    authMccs.add(new AuthMcc("1", "Name1", "Token", "OAuth"));
    authMccs.add(new AuthMcc("2", "Name2", "Token", "OAuth"));
    authMccs.add(new AuthMcc("3", "Name3", "Token", "OAuth"));

    reportEntitiesPersister.save(authMccs);

    List<AuthMcc> authMccsResult = reportEntitiesPersister.get(
        AuthMcc.class, AuthMcc.TOP_ACCOUNT_ID, Lists.newArrayList("1", "2", "3"));
View Full Code Here

      throws OAuthException {

    Credential credential = null;

    LOGGER.debug("Retrieving Auth Token from DB.");
    AuthMcc authMcc = this.getAuthTokenFromStorage(mccAccountId);
    String authToken = null;

    // Generate a new Auth Token if necessary
    if (authMcc == null || authMcc.getScope() == null
        || !authMcc.getScope().equals(scope) || force) {
      try {

        LOGGER.debug("Auth Token FORCED. Getting a new one.");
        credential = getNewOAuth2Credential();

      } catch (OAuthException e) {
        if (e.getMessage().contains("Connection reset")) {

          LOGGER.info("Connection reset when getting Auth Token, retrying...");
          credential = getNewOAuth2Credential();

        } else {
          LOGGER.error("Error Authenticating: " + e.getMessage());
          e.printStackTrace();
          throw e;
        }
      } finally {
        if (credential != null) {
         
          // Try to get the MCC Company Name and DescriptiveName
          String name = "";
          try {
            AdWordsSession adWordsSession = authenticate(null, mccAccountId, credential).build();
            CustomerDelegate customerDelegate = new CustomerDelegate(adWordsSession);         
            Customer customer = customerDelegate.getCustomer();
            name = customer.getCompanyName() + " (" + customer.getDescriptiveName() + ")";
          } catch (ValidationException e) {
            LOGGER.error("Error trying to get MCC Name " + e.getMessage());
          } catch (ApiException e) {
            LOGGER.error("Error trying to get MCC Name " + e.getMessage());
          }

          LOGGER.info("Saving Refresh Token to DB...");
          this.saveAuthTokenToStorage(mccAccountId, name, credential.getRefreshToken(), scope);
        }
      }
    } else {
      authToken = authMcc.getAuthToken();
      credential = buildOAuth2Credentials(authToken);
    }

    return credential;
  }
View Full Code Here

   * @param authToken the authentication token.
   * @param scope the OAuth2 scope.
   */
  private void saveAuthTokenToStorage(String mccAccountId, String topAccountName, String authToken, String scope) {
    LOGGER.debug("Persisting refresh token...");
    AuthMcc authMcc = new AuthMcc(mccAccountId, topAccountName, authToken, scope);
    this.authTokenPersister.persistAuthToken(authMcc);
    LOGGER.debug("... success.");
  }
View Full Code Here

   *            the MCC account ID.
   * @return the authentication token.
   */
  private AuthMcc getAuthTokenFromStorage(String mccAccountId) {

    AuthMcc authToken = this.authTokenPersister.getAuthToken(mccAccountId);
    if (authToken != null) {
      return authToken;
    }
    return null;
  }
View Full Code Here

   * Tests the persistence and retrieval of the token.
   */
  @Test
  public void testTokenPersistence() {

    AuthMcc authMcc = new AuthMcc("1234", "Name", "4321", "scope");
    this.authTokenPersister.persistAuthToken(authMcc);

    AuthMcc authToken = this.authTokenPersister.getAuthToken("1234");
    Assert.assertNotNull(authToken);
    Assert.assertEquals("4321", authToken.getAuthToken());

    authToken = this.authTokenPersister.getAuthToken("12345");
    Assert.assertNull(authToken);

    authMcc = new AuthMcc("1234", "Name", "54321", "scope");
    this.authTokenPersister.persistAuthToken(authMcc);

    authToken = this.authTokenPersister.getAuthToken("1234");
    Assert.assertNotNull(authToken);
    Assert.assertEquals("54321", authToken.getAuthToken());
  }
View Full Code Here

TOP

Related Classes of com.google.api.ads.adwords.awreporting.model.entities.AuthMcc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.