• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Bynder / bynder-java-sdk / 7116807269

06 Dec 2023 03:41PM UTC coverage: 38.562%. First build
7116807269

Pull #114

github

ahongbynder
API-1822 add System.exit(0) to terminate processes
Pull Request #114: API-1822 [BE] [SDK] Implement Sample Files for JAVA-SDK Functionality Testing

0 of 351 new or added lines in 8 files covered. (0.0%)

708 of 1836 relevant lines covered (38.56%)

0.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/bynder/sdk/sample/MediaSample.java
1
package com.bynder.sdk.sample;
2

3
import com.bynder.sdk.configuration.Configuration;
4
import com.bynder.sdk.configuration.HttpConnectionSettings;
5
import com.bynder.sdk.configuration.OAuthSettings;
6
import com.bynder.sdk.model.Derivative;
7
import com.bynder.sdk.model.DownloadUrl;
8
import com.bynder.sdk.model.Media;
9
import com.bynder.sdk.model.MediaType;
10

11
import com.bynder.sdk.query.*;
12

13
import com.bynder.sdk.service.BynderClient;
14
import com.bynder.sdk.service.asset.AssetService;
15
import com.bynder.sdk.service.oauth.OAuthService;
16
import com.bynder.sdk.util.Utils;
17

18
import java.awt.*;
19
import java.io.IOException;
20
import java.net.URI;
21
import java.net.URISyntaxException;
22
import java.net.URL;
23

24
import java.util.Arrays;
25
import java.util.List;
26
import java.util.Properties;
27
import java.util.Scanner;
28

29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

NEW
32
public class MediaSample {
×
NEW
33
    private static final Logger LOG = LoggerFactory.getLogger(MediaSample.class);
×
34

35
    public static void main(final String[] args) throws URISyntaxException, IOException {
36
        /**
37
         * Loads app.properties file under src/main/resources
38
         */
NEW
39
        Properties appProperties = Utils.loadConfig("app");
×
40

41
        // Initialize BynderClient with OAuth
NEW
42
        OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
×
NEW
43
        BynderClient client = BynderClient.Builder.create(
×
NEW
44
                new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
×
NEW
45
                        .setOAuthSettings(oAuthSettings)
×
NEW
46
                        .setHttpConnectionSettings(new HttpConnectionSettings()).build());
×
NEW
47
        List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
×
48
                "asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
49
                "meta.assetbank:write", "meta.workflow:read");
50

51
        // Initialize OAuthService
NEW
52
        OAuthService oauthService = client.getOAuthService();
×
NEW
53
        URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);
×
54

55
        // Open browser with authorization URL
NEW
56
        Desktop desktop = Desktop.getDesktop();
×
NEW
57
        desktop.browse(authorizationUrl.toURI());
×
58

59
        // Ask for the code returned in the redirect URI
NEW
60
        System.out.println("Insert the code: ");
×
NEW
61
        Scanner scanner = new Scanner(System.in);
×
NEW
62
        String code = scanner.nextLine();
×
NEW
63
        scanner.close();
×
64

65
        // Get the access token
NEW
66
        oauthService.getAccessToken(code, scopes).blockingSingle();
×
67

68
        // Initialize asset service
NEW
69
        AssetService assetService = client.getAssetService();
×
70

71
        // get derivatives
NEW
72
        List<Derivative> derivatives = client.getDerivatives().blockingSingle().body();
×
NEW
73
        if (derivatives != null && !derivatives.isEmpty()) {
×
NEW
74
            for (Derivative derivative : derivatives) {
×
NEW
75
                LOG.info("Derivative Prefix: " + derivative.getPrefix());
×
NEW
76
            }
×
77
        }
78

79
        // Call the API to request for media assets
NEW
80
        MediaQuery mediaQuery =  new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
×
NEW
81
        List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
×
NEW
82
        if (mediaList != null && !mediaList.isEmpty()) {
×
NEW
83
            for (Media media : mediaList) {
×
NEW
84
                LOG.info("Media ID: " + media.getId());
×
NEW
85
                LOG.info("Media Name: " + media.getName());
×
NEW
86
            }
×
87
        }
88

89
        // get media info for single asset
NEW
90
        String mediaIdInfo = appProperties.getProperty("MEDIA_ID_FOR_INFO");
×
NEW
91
        MediaInfoQuery mediaInfoQuery = new MediaInfoQuery(mediaIdInfo);
×
NEW
92
        Media foundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
×
NEW
93
        if (foundMedia != null) {
×
NEW
94
            LOG.info("get media info result: ");
×
NEW
95
            LOG.info("Media ID: " + foundMedia.getId());
×
NEW
96
            LOG.info("Media Name: " + foundMedia.getName());
×
NEW
97
            LOG.info("Media Brand ID: " + foundMedia.getBrandId());
×
98
        }
99

100
        // get media download url
NEW
101
        MediaDownloadQuery mediaDownloadQuery = new MediaDownloadQuery(mediaIdInfo);
×
NEW
102
        DownloadUrl mediaDownloadUrl = assetService.getMediaDownloadUrl(mediaDownloadQuery).blockingSingle().body();
×
NEW
103
        if (mediaDownloadUrl != null) {
×
NEW
104
            LOG.info("Media S3 File: " + mediaDownloadUrl.getS3File().getFile());
×
NEW
105
            LOG.info("Media S3 URI: " + mediaDownloadUrl.getS3File().toURI());
×
106
        }
107

108
        // modify name of asset
NEW
109
        String mediaIdForRename = appProperties.getProperty("MEDIA_ID_FOR_RENAME");
×
NEW
110
        MediaModifyQuery modifyQuery = new MediaModifyQuery(mediaIdForRename)
×
NEW
111
                .setName("New Name Updated")
×
NEW
112
                .setDescription("Test Updated Description");
×
NEW
113
        assetService.modifyMedia(modifyQuery).blockingSingle();
×
114

NEW
115
        MediaInfoQuery mediaInfoQueryRename = new MediaInfoQuery(mediaIdForRename);
×
NEW
116
        Media updatedFoundMedia = assetService.getMediaInfo(mediaInfoQueryRename).blockingSingle().body();
×
NEW
117
        if (updatedFoundMedia != null) {
×
NEW
118
            LOG.info("get updated media info result: ");
×
NEW
119
            LOG.info(updatedFoundMedia.getId());
×
NEW
120
            LOG.info(updatedFoundMedia.getName());
×
NEW
121
            LOG.info(updatedFoundMedia.getDescription());
×
122
        }
123

124
        // remove media
NEW
125
        String mediaToRemove = appProperties.getProperty("MEDIA_ID_FOR_REMOVAL");
×
NEW
126
        MediaDeleteQuery mediaDeleteQuery = new MediaDeleteQuery(mediaToRemove);
×
NEW
127
        LOG.info("Removing media id: " + mediaToRemove);
×
NEW
128
        assetService.deleteMedia(mediaDeleteQuery).blockingSingle();
×
NEW
129
        System.exit(0);
×
NEW
130
    }
×
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc