001package com.box.sdk; 002 003import com.eclipsesource.json.JsonObject; 004import com.eclipsesource.json.JsonValue; 005import java.net.MalformedURLException; 006import java.net.URL; 007import java.text.ParseException; 008import java.util.Date; 009 010/** 011 * Represents an individual recent item. 012 * 013 * <p>Unless otherwise noted, the methods in this class can throw an unchecked {@link BoxAPIException} (unchecked 014 * meaning that the compiler won't force you to handle it) if an error occurs. If you wish to implement custom error 015 * handling for errors related to the Box REST API, you should capture this exception explicitly.* 016 */ 017public class BoxRecentItem extends BoxJSONObject { 018 private String type; 019 private String interactionType; 020 private BoxItem.Info item; 021 private Date interactedAt; 022 private URL interactionSharedLink; 023 private BoxAPIConnection api; 024 025 /** 026 * Construct a BoxRecentItem. 027 * 028 * @param jsonObject the parsed JSON object. 029 * @param api the API connection to be used to fetch interacted item 030 */ 031 public BoxRecentItem(JsonObject jsonObject, BoxAPIConnection api) { 032 super(jsonObject); 033 this.api = api; 034 } 035 036 @Override 037 protected void parseJSONMember(JsonObject.Member member) { 038 super.parseJSONMember(member); 039 040 String memberName = member.getName(); 041 JsonValue value = member.getValue(); 042 try { 043 if (memberName.equals("type")) { 044 this.type = value.asString(); 045 } else if (memberName.equals("interaction_type")) { 046 this.interactionType = value.asString(); 047 } else if (memberName.equals("item")) { 048 String id = value.asObject().get("id").asString(); 049 this.item = new BoxFile(this.api, id).new Info(value.asObject()); 050 } else if (memberName.equals("interacted_at")) { 051 this.interactedAt = BoxDateFormat.parse(value.asString()); 052 } else if (memberName.equals("interaction_shared_link")) { 053 this.interactionSharedLink = new URL(value.asString()); 054 } 055 } catch (ParseException e) { 056 assert false : "A ParseException indicates a bug in the SDK."; 057 } catch (MalformedURLException e) { 058 assert false : "A ParseException indicates a bug in the SDK."; 059 } 060 } 061 062 /** 063 * Get item type. 064 * 065 * @return type of item 066 */ 067 public String getType() { 068 return this.type; 069 } 070 071 /** 072 * Get interaction type. 073 * 074 * @return interaction type 075 */ 076 public String getInteractionType() { 077 return this.interactionType; 078 } 079 080 /** 081 * Get the item which was interacted with. 082 * 083 * @return box item 084 */ 085 public BoxItem.Info getItem() { 086 return this.item; 087 } 088 089 /** 090 * Get the interaction date. 091 * 092 * @return interaction date 093 */ 094 public Date getInteractedAt() { 095 return this.interactedAt; 096 } 097 098 /** 099 * Get the shared link, if the item was accessed through a shared link. 100 * 101 * @return shared link 102 */ 103 public URL getInteractionSharedLink() { 104 return this.interactionSharedLink; 105 } 106 107}