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

Bynder / bynder-java-sdk / 7089197049

04 Dec 2023 04:00PM UTC coverage: 38.731% (-0.1%) from 38.837%
7089197049

push

github

ahongbynder
API-1822 get derivatives for portal

0 of 7 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

708 of 1828 relevant lines covered (38.73%)

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

32
public class MediaSample {
×
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
         */
39
        Properties appProperties = Utils.loadConfig("app");
×
40

41
        // Initialize BynderClient with OAuth
42
        OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), new URI(appProperties.getProperty("REDIRECT_URI")));
×
43
        BynderClient client = BynderClient.Builder.create(
×
44
                new Configuration.Builder(new URL(appProperties.getProperty("BASE_URL")))
×
45
                        .setOAuthSettings(oAuthSettings)
×
46
                        .setHttpConnectionSettings(new HttpConnectionSettings()).build());
×
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
52
        OAuthService oauthService = client.getOAuthService();
×
53
        URL authorizationUrl = oauthService.getAuthorizationUrl("state example", scopes);
×
54

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

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

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

68
        // Initialize asset service
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
80
        MediaQuery mediaQuery =  new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
×
81
        List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
×
82
        if (mediaList != null && !mediaList.isEmpty()) {
×
83
            for (Media media : mediaList) {
×
NEW
84
                LOG.info("Media ID: " + media.getId());
×
NEW
85
                LOG.info("Media Name: " + media.getName());
×
UNCOV
86
            }
×
87
        }
88

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

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

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

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

124
        // remove media
125
        String mediaToRemove = appProperties.getProperty("MEDIA_ID_FOR_REMOVAL");
×
126
        MediaDeleteQuery mediaDeleteQuery = new MediaDeleteQuery(mediaToRemove);
×
127
        LOG.info("Removing media id: " + mediaToRemove);
×
128
        assetService.deleteMedia(mediaDeleteQuery).blockingSingle();
×
129
    }
×
130
}
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