|
9 | 9 | import io.getstream.core.LookupKind; |
10 | 10 | import io.getstream.core.Region; |
11 | 11 | import io.getstream.core.models.*; |
12 | | -import io.getstream.core.options.ActivityMarker; |
13 | | -import io.getstream.core.options.EnrichmentFlags; |
14 | | -import io.getstream.core.options.Filter; |
15 | | -import io.getstream.core.options.Pagination; |
| 12 | +import io.getstream.core.options.*; |
16 | 13 |
|
| 14 | +import java.io.File; |
| 15 | +import java.net.URL; |
17 | 16 | import java.time.LocalDateTime; |
18 | 17 | import java.util.Date; |
19 | 18 | import java.util.List; |
|
22 | 21 | import static io.getstream.core.utils.Enrichment.createCollectionReference; |
23 | 22 | import static io.getstream.core.utils.Enrichment.createUserReference; |
24 | 23 |
|
25 | | -//TODO: move this to an appropriate place |
26 | 24 | class Example { |
27 | 25 | private static final String apiKey = "gp6e8sxxzud6"; |
28 | 26 | private static final String secret = "7j7exnksc4nxy399fdxvjqyqsqdahax3nfgtp27pumpc7sfm9um688pzpxjpjbf2"; |
@@ -528,9 +526,103 @@ public static void main(String[] args) throws Exception { |
528 | 526 |
|
529 | 527 | /* -------------------------------------------------------- */ |
530 | 528 |
|
531 | | - client.user("123").update(new Data("") |
532 | | - .set("name", "John Doe") |
| 529 | + client.user("123").update(new Data() |
| 530 | + .set("name", "Jane Doe") |
533 | 531 | .set("occupation", "Software Engineer") |
534 | | - .set("gender", "male")); |
| 532 | + .set("gender", "female")); |
| 533 | + |
| 534 | + /* -------------------------------------------------------- */ |
| 535 | + |
| 536 | + // Read the personalization feed for a given user |
| 537 | + client.personalization().get("personalized_feed", new ImmutableMap.Builder<String, Object>() |
| 538 | + .put("user_id", 123) |
| 539 | + .put("feed_slug", "timeline") |
| 540 | + .build()); |
| 541 | + |
| 542 | + // Our data science team will typically tell you which endpoint to use |
| 543 | + client.personalization().get("discovery_feed", new ImmutableMap.Builder<String, Object>() |
| 544 | + .put("user_id", 123) |
| 545 | + .put("source_feed_slug", "timeline") |
| 546 | + .put("target_feed_slug", "user") |
| 547 | + .build()); |
| 548 | + |
| 549 | + /* -------------------------------------------------------- */ |
| 550 | + |
| 551 | + client.analytics().trackEngagement(Engagement.builder() |
| 552 | + .feedID("user:thierry") |
| 553 | + .content(new Content("message:34349698") |
| 554 | + .set("verb", "share") |
| 555 | + .set("actor", ImmutableMap.of("1", "user1"))) |
| 556 | + .boost(2) |
| 557 | + .location("profile_page") |
| 558 | + .position(3) |
| 559 | + .build()); |
| 560 | + |
| 561 | + /* -------------------------------------------------------- */ |
| 562 | + |
| 563 | + client.analytics().trackImpression(Impression.builder() |
| 564 | + .contentList(new Content("tweet:34349698") |
| 565 | + .set("verb", "share") |
| 566 | + .set("actor", ImmutableMap.of("1", "user1")), |
| 567 | + new Content("tweet:34349699"), |
| 568 | + new Content("tweet:34349700")) |
| 569 | + .feedID("flat:tommaso") |
| 570 | + .location("android-app") |
| 571 | + .build()); |
| 572 | + |
| 573 | + /* -------------------------------------------------------- */ |
| 574 | + |
| 575 | + // the URL to direct to |
| 576 | + URL targetURL = new URL("http://mysite.com/detail"); |
| 577 | + |
| 578 | + // track the impressions and a click |
| 579 | + List<Impression> impressions = Lists.newArrayList(Impression.builder() |
| 580 | + .contentList(new Content("tweet:1"), |
| 581 | + new Content("tweet:2"), |
| 582 | + new Content("tweet:3")) |
| 583 | + .userData(new UserData("tommaso", null)) |
| 584 | + .location("email") |
| 585 | + .feedID("user:global") |
| 586 | + .build()); |
| 587 | + List<Engagement> engagements = Lists.newArrayList(Engagement.builder() |
| 588 | + .content(new Content("tweet:2")) |
| 589 | + .label("click") |
| 590 | + .position(1) |
| 591 | + .userData(new UserData("tommaso", null)) |
| 592 | + .location("email") |
| 593 | + .feedID("user:global") |
| 594 | + .build()); |
| 595 | + |
| 596 | + // when the user opens the tracking URL in their browser gets redirected to the target URL |
| 597 | + // the events are added to our analytics platform |
| 598 | + URL trackingURL = client.analytics().createRedirectURL(targetURL, impressions, engagements); |
| 599 | + |
| 600 | + /* -------------------------------------------------------- */ |
| 601 | + |
| 602 | + File image = new File("..."); |
| 603 | + URL imageURL = client.images().upload(image).join(); |
| 604 | + |
| 605 | + File file = new File("..."); |
| 606 | + URL fileURL = client.files().upload(file).join(); |
| 607 | + |
| 608 | + /* -------------------------------------------------------- */ |
| 609 | + |
| 610 | + // deleting an image using the url returned by the APIs |
| 611 | + client.images().delete(imageURL); |
| 612 | + |
| 613 | + // deleting a file using the url returned by the APIs |
| 614 | + client.files().delete(fileURL); |
| 615 | + |
| 616 | + /* -------------------------------------------------------- */ |
| 617 | + |
| 618 | + // create a 50x50 thumbnail and crop from center |
| 619 | + client.images().process(imageURL, new Resize(50, 50, Resize.Type.CROP)); |
| 620 | + |
| 621 | + // create a 50x50 thumbnail using clipping (keeps aspect ratio) |
| 622 | + client.images().process(imageURL, new Resize(50, 50, Resize.Type.CLIP)); |
| 623 | + |
| 624 | + /* -------------------------------------------------------- */ |
| 625 | + |
| 626 | + OGData urlPreview = client.openGraph(new URL("http://www.imdb.com/title/tt0117500/")).join(); |
535 | 627 | } |
536 | 628 | } |
0 commit comments