@Override public NoteStoreClient execute() throws Exception { return clientFactory.createNoteStoreClient(); } });
public EvernoteTemplate(EvernoteService evernoteService, String accessToken) { this.evernoteService = evernoteService; this.evernoteAuth = new EvernoteAuth(evernoteService, accessToken); this.clientFactory = new ClientFactory(this.evernoteAuth); }
@Override public UserStoreClient execute() throws Exception { return clientFactory.createUserStoreClient(); } });
/** * Create a new Business NoteStore client. Each call to this method will * return a new NoteStore.Client instance. The returned client can be used for * any number of API calls, but is NOT thread safe. * * This method will check expiration time for the business authorization * token, this is a network request * * This method is synchronous * * @throws TException * @throws EDAMUserException * @throws EDAMSystemException * User is not part of a business */ public BusinessNoteStoreClient createBusinessNoteStoreClient() throws TException, EDAMUserException, EDAMSystemException { NoteStoreClient mainNoteStoreClient = createNoteStoreClient(); AuthenticationResult businessAuthResult = createUserStoreClient() .authenticateToBusiness(); NoteStoreClient linkedNoteStoreClient = createStoreClient( NoteStoreClient.class, businessAuthResult.getNoteStoreUrl(), businessAuthResult.getAuthenticationToken()); return new BusinessNoteStoreClient(mainNoteStoreClient, linkedNoteStoreClient, businessAuthResult); }
/** * Creates a LinkedNoteStoreClient from a {@link LinkedNotebook} synchronously * * @param linkedNotebook */ public LinkedNoteStoreClient createLinkedNoteStoreClient( LinkedNotebook linkedNotebook) throws EDAMUserException, EDAMSystemException, TException, EDAMNotFoundException { NoteStoreClient mainNoteStoreClient = createNoteStoreClient(); AuthenticationResult sharedAuth = mainNoteStoreClient .authenticateToSharedNotebook(linkedNotebook.getShareKey()); NoteStoreClient linkedNoteStoreClient = createStoreClient( NoteStoreClient.class, linkedNotebook.getNoteStoreUrl(), sharedAuth.getAuthenticationToken()); return new LinkedNoteStoreClient(mainNoteStoreClient, linkedNoteStoreClient, sharedAuth); }
public synchronized static NoteStoreClient getNoteStoreClient(MessageContext ctxt) throws TException, EDAMUserException, EDAMSystemException { Axis2MessageContext axis2mc = (Axis2MessageContext)ctxt; axis2mc.getAxis2MessageContext(); String devToken = (String)axis2mc.getAxis2MessageContext().getOperationContext().getProperty("evernote.devToken"); String noteStoreUrl = (String)axis2mc.getAxis2MessageContext().getOperationContext().getProperty("evernote.noteStoreUrl"); String devTokenType = (String)axis2mc.getAxis2MessageContext().getOperationContext().getProperty("evernote.devTokenType"); EvernoteAuth auth = null; if(devTokenType.equalsIgnoreCase("PRODUCTION")) { auth = new EvernoteAuth(EvernoteService.PRODUCTION, devToken); } else if(devTokenType.equalsIgnoreCase("YINXIANG")) { auth = new EvernoteAuth(EvernoteService.YINXIANG, devToken); } else if (devTokenType.equalsIgnoreCase("SANDBOX")){ auth = new EvernoteAuth(EvernoteService.SANDBOX, devToken); } if (auth != null) { auth.setNoteStoreUrl(noteStoreUrl); } ClientFactory factory = new ClientFactory(auth); return factory.createNoteStoreClient(); }
/** * Create a new NoteStore client. Each call to this method will return a new * NoteStore.Client instance. The returned client can be used for any number * of API calls, but is NOT thread safe. * * @throws TException * @throws EDAMSystemException * @throws EDAMUserException */ public NoteStoreClient createNoteStoreClient() throws EDAMUserException, EDAMSystemException, TException { String noteStoreUrl = this.evernoteAuth.getNoteStoreUrl(); if (noteStoreUrl == null) { noteStoreUrl = createUserStoreClient().getNoteStoreUrl(); this.evernoteAuth.setNoteStoreUrl(noteStoreUrl); } return createStoreClient(NoteStoreClient.class, noteStoreUrl, this.evernoteAuth.getToken()); }
/** * Create a new UserStore client. Each call to this method will return a new * UserStore.Client instance. The returned client can be used for any number * of API calls, but is NOT thread safe. * * @param url * to connect to * * @throws TTransportException * if an error occurs setting up the connection to the Evernote * service. * */ public UserStoreClient createUserStoreClient() throws TTransportException { String serviceUrl = this.evernoteAuth.getUserStoreUrl(); return createStoreClient(UserStoreClient.class, serviceUrl, this.evernoteAuth.getToken()); }
/** * @param clientClass * @param url * @param token * @return * @throws TTransportException */ <T> T createStoreClient(Class<T> clientClass, String url, String token) throws TTransportException { THttpClient transport = new THttpClient(url); transport.setCustomHeader(USER_AGENT_KEY, generateUserAgent()); if (customHeaders != null) { for (Map.Entry<String, String> header : customHeaders.entrySet()) { transport.setCustomHeader(header.getKey(), header.getValue()); } } TProtocol protocol = new TBinaryProtocol(transport); try { return clientClass.getDeclaredConstructor(TProtocol.class, TProtocol.class, String.class).newInstance(protocol, protocol, token); } catch (Throwable e) { throw new RuntimeException("Couldn't create " + clientClass.getName() + " due to the error.", e); } }
@Override public LinkedNoteStoreClient execute() throws Exception { return clientFactory.createLinkedNoteStoreClient(linkedNotebook); } });
@Override public BusinessNoteStoreClient execute() throws Exception { return clientFactory.createBusinessNoteStoreClient(); } });
/** * Create a new Business NoteStore client. Each call to this method will * return a new NoteStore.Client instance. The returned client can be used for * any number of API calls, but is NOT thread safe. * * This method will check expiration time for the business authorization * token, this is a network request * * This method is synchronous * * @throws TException * @throws EDAMUserException * @throws EDAMSystemException * User is not part of a business */ public BusinessNoteStoreClient createBusinessNoteStoreClient() throws TException, EDAMUserException, EDAMSystemException { NoteStoreClient mainNoteStoreClient = createNoteStoreClient(); AuthenticationResult businessAuthResult = createUserStoreClient() .authenticateToBusiness(); NoteStoreClient linkedNoteStoreClient = createStoreClient( NoteStoreClient.class, businessAuthResult.getNoteStoreUrl(), businessAuthResult.getAuthenticationToken()); return new BusinessNoteStoreClient(mainNoteStoreClient, linkedNoteStoreClient, businessAuthResult); }
/** * Creates a LinkedNoteStoreClient from a {@link LinkedNotebook} synchronously * * @param linkedNotebook */ public LinkedNoteStoreClient createLinkedNoteStoreClient( LinkedNotebook linkedNotebook) throws EDAMUserException, EDAMSystemException, TException, EDAMNotFoundException { NoteStoreClient mainNoteStoreClient = createNoteStoreClient(); AuthenticationResult sharedAuth = mainNoteStoreClient .authenticateToSharedNotebook(linkedNotebook.getShareKey()); NoteStoreClient linkedNoteStoreClient = createStoreClient( NoteStoreClient.class, linkedNotebook.getNoteStoreUrl(), sharedAuth.getAuthenticationToken()); return new LinkedNoteStoreClient(mainNoteStoreClient, linkedNoteStoreClient, sharedAuth); }
/** * Create a new NoteStore client. Each call to this method will return a new * NoteStore.Client instance. The returned client can be used for any number * of API calls, but is NOT thread safe. * * @throws TException * @throws EDAMSystemException * @throws EDAMUserException */ public NoteStoreClient createNoteStoreClient() throws EDAMUserException, EDAMSystemException, TException { String noteStoreUrl = this.evernoteAuth.getNoteStoreUrl(); if (noteStoreUrl == null) { noteStoreUrl = createUserStoreClient().getNoteStoreUrl(); this.evernoteAuth.setNoteStoreUrl(noteStoreUrl); } return createStoreClient(NoteStoreClient.class, noteStoreUrl, this.evernoteAuth.getToken()); }
/** * Create a new UserStore client. Each call to this method will return a new * UserStore.Client instance. The returned client can be used for any number * of API calls, but is NOT thread safe. * * @param url * to connect to * * @throws TTransportException * if an error occurs setting up the connection to the Evernote * service. * */ public UserStoreClient createUserStoreClient() throws TTransportException { String serviceUrl = this.evernoteAuth.getUserStoreUrl(); return createStoreClient(UserStoreClient.class, serviceUrl, this.evernoteAuth.getToken()); }
/** * @param clientClass * @param url * @param token * @return * @throws TTransportException */ <T> T createStoreClient(Class<T> clientClass, String url, String token) throws TTransportException { THttpClient transport = new THttpClient(url); transport.setCustomHeader(USER_AGENT_KEY, generateUserAgent()); if (customHeaders != null) { for (Map.Entry<String, String> header : customHeaders.entrySet()) { transport.setCustomHeader(header.getKey(), header.getValue()); } } TProtocol protocol = new TBinaryProtocol(transport); try { return clientClass.getDeclaredConstructor(TProtocol.class, TProtocol.class, String.class).newInstance(protocol, protocol, token); } catch (Throwable e) { throw new RuntimeException("Couldn't create " + clientClass.getName() + " due to the error.", e); } }
public EvernoteTemplate(EvernoteService evernoteService, EvernoteOAuthToken accessToken) { int userId = 0; try { userId = Integer.parseInt(accessToken.getEdamUserId()); } catch (NumberFormatException e) { } this.evernoteAuth = new EvernoteAuth(evernoteService, accessToken.getValue(), accessToken.getEdamNoteStoreUrl(), accessToken.getEdamWebApiUrlPrefix(), userId); this.evernoteService = evernoteService; this.clientFactory = new ClientFactory(this.evernoteAuth); }