Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AllocationManager {
- String url = 'https://myapi.url';
- // Pass in the endpoint to be used using the string url
- @AuraEnabled
- public AllocationOutput getAllocationBreakdown() {
- String jsonstr = '{"returnSecurityDetails":"true","displayLevel":"1","portfolios":[{"portfolioName":"Portfolio A","cashBalance":5000,"holdings":[{"symbol":"IVV","holdingValue":50000},{"symbol":"IWM","holdingValue":25000},{"symbol":"VWO","holdingValue":10000},{"symbol":"AAPL","holdingValue":5000}]},{"portfolioName":"Portfolio B","cashBalance":5000,"holdings":[{"symbol":"VIG","holdingValue":50000},{"symbol":"VO","holdingValue":25000},{"symbol":"VB","holdingValue":10000},{"symbol":"EFA","holdingValue":5000}]}]}';
- AllocationInput obj = AllocationInput.parse(jsonstr);
- String allocInput = JSON.serialize(obj);
- //System.debug(allocInput);
- // Instantiate a new http object
- Http h = new Http();
- // Instantiate a new HTTP request, specify the method (POST) as well as the endpoint
- HttpRequest req = new HttpRequest();
- req.setHeader('Authorization', 'MY_CLIENT client_id=xxxxxx client_secret=xxxxxxxxxxxxxx');
- req.setHeader('Content-Type', 'application/json');
- req.setHeader('Accept','application/json');
- req.setEndpoint(url);
- req.setMethod('POST');
- req.setBody(allocInput);
- // Send the request, and return a response
- HttpResponse res = h.send(req);
- String allocOutput = res.getBody();
- //System.debug(allocOutput);
- AllocationOutput output = AllocationOutput.parse(allocOutput);
- return output;
- }
- }
- public class AllocationInput {
- public class Holdings {
- public String symbol;
- public Integer holdingValue;
- }
- public String returnSecurityDetails;
- public String displayLevel;
- public List<Portfolios> portfolios;
- public class Portfolios {
- public String portfolioName;
- public Integer cashBalance;
- public List<Holdings> holdings;
- }
- public static AllocationInput parse(String json) {
- return (AllocationInput) System.JSON.deserialize(json, AllocationInput.class);
- }
- }
- public class AllocationOutput {
- public class PortfolioStyles {
- public String styleID;
- public String styleName;
- public String styleAllocation;
- public String styleValue;
- }
- public String apiVersion;
- public String timestamp;
- public String tenantName;
- public List<Portfolios> portfolios;
- public String asOfDate;
- public class Portfolios {
- public String portfolioName;
- public String portfolioValue;
- public List<PortfolioStyles> portfolioStyles;
- public List<SecurityDetails> securityDetails;
- }
- public class SecurityDetails {
- public String securityId;
- public String symbol;
- public String name;
- public List<PortfolioStyles> securityStyles;
- }
- public static AllocationOutput parse(String json) {
- return (AllocationOutput) System.JSON.deserialize(json, AllocationOutput.class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement