Search in sources :

Example 16 with Company

use of com.google.cloud.talent.v4.Company in project googleads-java-lib by googleads.

the class AdManagerAxisSoapIntegrationTest method testGoldenSoap_oauth2_offlineCredentials.

/**
 * Tests making a Axis Ad Manager API call with OfflineCredentials.
 */
@Test
public void testGoldenSoap_oauth2_offlineCredentials() throws Exception {
    testHttpServer.setMockResponseBodies(Lists.newArrayList(AuthResponseProvider.getTestOAuthResponse("TEST_ACCESS_TOKEN_1", 1L, "newRefreshToken1"), AuthResponseProvider.getTestOAuthResponse("TEST_ACCESS_TOKEN_2", 3600L, "newRefreshToken2"), SoapResponseXmlProvider.getTestSoapResponse(API_VERSION)));
    OfflineCredentials offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.AD_MANAGER).withTokenUrlServer(testHttpServer.getServerUrl()).fromFile(AdManagerAxisSoapIntegrationTest.class.getResource("props/ads-test.properties")).build();
    Credential credential = offlineCredentials.generateCredential();
    assertTrue(testHttpServer.getLastRequestBody().contains("grant_type=refresh_token"));
    assertTrue(testHttpServer.getLastRequestBody().contains("refresh_token=refreshToken"));
    assertTrue(testHttpServer.getLastRequestBody().contains("client_id=clientId"));
    assertTrue(testHttpServer.getLastRequestBody().contains("client_secret=clientSecret"));
    // Make sure the old token expires - the session builder should issue a request
    // for another access token.
    Thread.sleep(1000);
    assertEquals("TEST_ACCESS_TOKEN_1", credential.getAccessToken());
    AdManagerSession session = new AdManagerSession.Builder().withApplicationName("TEST_APP").withOAuth2Credential(credential).withEndpoint(testHttpServer.getServerUrl()).withNetworkCode("TEST_NETWORK_CODE").build();
    CompanyServiceInterface companyService = new AdManagerServices().get(session, CompanyServiceInterface.class);
    Company[] companies = companyService.createCompanies(new Company[] { new Company() });
    assertEquals(1234L, companies[0].getId().longValue());
    Diff diff = DiffBuilder.compare(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION)).withTest(testHttpServer.getLastRequestBody()).checkForSimilar().build();
    assertFalse(diff.hasDifferences());
    assertFalse("Did not request compression but request was compressed", testHttpServer.wasLastRequestBodyCompressed());
    assertEquals("newRefreshToken2", credential.getRefreshToken());
    assertEquals("Bearer TEST_ACCESS_TOKEN_2", testHttpServer.getLastAuthorizationHttpHeader());
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202205.CompanyServiceInterface) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) Credential(com.google.api.client.auth.oauth2.Credential) Company(com.google.api.ads.admanager.axis.v202205.Company) Diff(org.xmlunit.diff.Diff) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) DiffBuilder(org.xmlunit.builder.DiffBuilder) AdManagerSession(com.google.api.ads.admanager.lib.client.AdManagerSession) AdManagerServices(com.google.api.ads.admanager.axis.factory.AdManagerServices) Test(org.junit.Test) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)

Example 17 with Company

use of com.google.cloud.talent.v4.Company in project googleads-java-lib by googleads.

the class CreateCompanies method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the CompanyService.
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create an advertiser.
    Company advertiser = new Company();
    advertiser.setName("Advertiser #" + new Random().nextInt(Integer.MAX_VALUE));
    advertiser.setType(CompanyType.ADVERTISER);
    // Create an agency.
    Company agency = new Company();
    agency.setName("Agency #" + new Random().nextInt(Integer.MAX_VALUE));
    agency.setType(CompanyType.AGENCY);
    // Create the companies on the server.
    Company[] companies = companyService.createCompanies(new Company[] { advertiser, agency });
    for (Company createdCompany : companies) {
        System.out.printf("A company with ID %d, name '%s', and type '%s' was created.%n", createdCompany.getId(), createdCompany.getName(), createdCompany.getType());
    }
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202111.Company) Random(java.util.Random)

Example 18 with Company

use of com.google.cloud.talent.v4.Company in project googleads-java-lib by googleads.

the class GetAdvertisers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create a statement to select companies.
    StatementBuilder statementBuilder = new StatementBuilder().where("type = :type").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("type", CompanyType.ADVERTISER.toString());
    // Retrieve a small amount of companies at a time, paging through
    // until all companies have been retrieved.
    int totalResultSetSize = 0;
    do {
        CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each company.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Company company : page.getResults()) {
                System.out.printf("%d) Company with ID %d, name '%s', and type '%s' was found.%n", i++, company.getId(), company.getName(), company.getType());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202111.Company) CompanyPage(com.google.api.ads.admanager.axis.v202111.CompanyPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)

Example 19 with Company

use of com.google.cloud.talent.v4.Company in project java-docs-samples by GoogleCloudPlatform.

the class JobSearchListCompanies method listCompanies.

// List Companies.
public static void listCompanies(String projectId, String tenantId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
        TenantName parent = TenantName.of(projectId, tenantId);
        ListCompaniesRequest request = ListCompaniesRequest.newBuilder().setParent(parent.toString()).build();
        for (Company responseItem : companyServiceClient.listCompanies(request).iterateAll()) {
            System.out.format("Company Name: %s%n", responseItem.getName());
            System.out.format("Display Name: %s%n", responseItem.getDisplayName());
            System.out.format("External ID: %s%n", responseItem.getExternalId());
        }
    }
}
Also used : ListCompaniesRequest(com.google.cloud.talent.v4beta1.ListCompaniesRequest) CompanyServiceClient(com.google.cloud.talent.v4beta1.CompanyServiceClient) Company(com.google.cloud.talent.v4beta1.Company) TenantName(com.google.cloud.talent.v4beta1.TenantName)

Example 20 with Company

use of com.google.cloud.talent.v4.Company in project googleads-java-lib by googleads.

the class GetAdvertisers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create a statement to select companies.
    StatementBuilder statementBuilder = new StatementBuilder().where("type = :type").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("type", CompanyType.ADVERTISER.toString());
    // Retrieve a small amount of companies at a time, paging through
    // until all companies have been retrieved.
    int totalResultSetSize = 0;
    do {
        CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each company.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Company company : page.getResults()) {
                System.out.printf("%d) Company with ID %d, name '%s', and type '%s' was found.%n", i++, company.getId(), company.getName(), company.getType());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202108.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202108.Company) CompanyPage(com.google.api.ads.admanager.axis.v202108.CompanyPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)

Aggregations

Test (org.junit.Test)13 Company (com.google.cloud.talent.v4beta1.Company)10 Company (com.google.api.ads.admanager.axis.v202205.Company)7 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202205.CompanyServiceInterface)7 AdManagerSession (com.google.api.ads.admanager.lib.client.AdManagerSession)6 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)6 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)6 CompanyServiceClient (com.google.cloud.talent.v4beta1.CompanyServiceClient)6 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)5 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)5 Company (com.google.api.ads.admanager.axis.v202108.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202108.CompanyServiceInterface)4 Company (com.google.api.ads.admanager.axis.v202111.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface)4 Company (com.google.api.ads.admanager.axis.v202202.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202202.CompanyServiceInterface)4 CompanyServiceClient (com.google.cloud.talent.v4.CompanyServiceClient)4 Random (java.util.Random)4 Diff (org.xmlunit.diff.Diff)4 AdManagerServices (com.google.api.ads.admanager.axis.factory.AdManagerServices)3