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

Bynder / bynder-java-sdk / 7064590536

01 Dec 2023 07:59PM UTC coverage: 38.837% (-0.1%) from 38.965%
7064590536

push

github

ahongbynder
API-1822 add media removal, add README, add null checks for collections

0 of 14 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

708 of 1823 relevant lines covered (38.84%)

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.DownloadUrl;
7
import com.bynder.sdk.model.Media;
8
import com.bynder.sdk.model.MediaType;
9

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

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

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

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

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

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

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

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

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

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

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

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

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

70
        // Call the API to request for media assets
71
        MediaQuery mediaQuery =  new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
×
72
        List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
×
73
        if (mediaList != null && !mediaList.isEmpty()) {
×
74
            for (Media media : mediaList) {
×
75
                LOG.info(media.getId());
×
76
                LOG.info(media.getName());
×
77
            }
×
78
        }
79

80
        // get media info for single asset
81
        String mediaIdInfo = appProperties.getProperty("MEDIA_ID_FOR_INFO");
×
82
        MediaInfoQuery mediaInfoQuery = new MediaInfoQuery(mediaIdInfo);
×
83
        Media foundMedia = assetService.getMediaInfo(mediaInfoQuery).blockingSingle().body();
×
84
        if (foundMedia != null) {
×
85
            LOG.info("get media info result: ");
×
86
            LOG.info("Media ID: " + foundMedia.getId());
×
87
            LOG.info("Media Name: " + foundMedia.getName());
×
88
            LOG.info("Media Brand ID: " + foundMedia.getBrandId());
×
89
        }
90

91
        // get media download url
92
        MediaDownloadQuery mediaDownloadQuery = new MediaDownloadQuery(mediaIdInfo);
×
93
        DownloadUrl mediaDownloadUrl = assetService.getMediaDownloadUrl(mediaDownloadQuery).blockingSingle().body();
×
94
        if (mediaDownloadUrl != null) {
×
95
            LOG.info("Media S3 File: " + mediaDownloadUrl.getS3File().getFile());
×
96
            LOG.info("Media S3 URI: " + mediaDownloadUrl.getS3File().toURI());
×
97
        }
98

99
        // modify name of asset
100
        String mediaIdForRename = appProperties.getProperty("MEDIA_ID_FOR_RENAME");
×
101
        MediaModifyQuery modifyQuery = new MediaModifyQuery(mediaIdForRename)
×
102
                .setName("New Name Updated")
×
103
                .setDescription("Test Updated Description");
×
104
        assetService.modifyMedia(modifyQuery).blockingSingle();
×
105

106
        MediaInfoQuery mediaInfoQueryRename = new MediaInfoQuery(mediaIdForRename);
×
107
        Media updatedFoundMedia = assetService.getMediaInfo(mediaInfoQueryRename).blockingSingle().body();
×
108
        if (updatedFoundMedia != null) {
×
109
            LOG.info("get updated media info result: ");
×
110
            LOG.info(updatedFoundMedia.getId());
×
111
            LOG.info(updatedFoundMedia.getName());
×
112
            LOG.info(updatedFoundMedia.getDescription());
×
113
        }
114

115
        // remove media
NEW
116
        String mediaToRemove = appProperties.getProperty("MEDIA_ID_FOR_REMOVAL");
×
NEW
117
        MediaDeleteQuery mediaDeleteQuery = new MediaDeleteQuery(mediaToRemove);
×
NEW
118
        LOG.info("Removing media id: " + mediaToRemove);
×
NEW
119
        assetService.deleteMedia(mediaDeleteQuery).blockingSingle();
×
UNCOV
120
    }
×
121
}
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