01 #!/usr/local/bin/perl -w 02 use strict; 03 use Thrift; 04 use Thrift::HttpClient; 05 use Thrift::BinaryProtocol; 06 07 use lib 'gen-perl'; 08 use EDAMUserStore::Constants; 09 use EDAMUserStore::UserStore; 10 use EDAMNoteStore::NoteStore; 11 use EDAMErrors::Types; 12 use EDAMTypes::Types; 13 14 my $username = "perlsnapshot"; 15 my $password = "*******"; 16 my $consumer_key = "perlsnapshot"; 17 my $consumer_secret = "****************"; 18 19 my( $message ) = @ARGV; 20 die "usage: $0 note" if !defined $message; 21 22 my $evernote_host = "evernote.com"; 23 my $user_store_uri = 24 "https://$evernote_host/edam/user"; 25 my $note_store_uri_base = 26 "https://$evernote_host/edam/note/"; 27 28 my $http_client = 29 Thrift::HttpClient->new($user_store_uri); 30 my $protocol = Thrift::BinaryProtocol->new( 31 $http_client); 32 33 my $client = 34 EDAMUserStore::UserStoreClient->new( 35 $protocol); 36 37 my $version_ok = 38 $client->checkVersion( "perlsnapshot", 39 EDAMUserStore::Constants::EDAM_VERSION_MAJOR, 40 EDAMUserStore::Constants::EDAM_VERSION_MINOR, 41 ); 42 43 if ( !$version_ok ) { 44 die "Version not ok"; 45 } 46 47 my $result = 48 $client->authenticate( $username, 49 $password, $consumer_key, 50 $consumer_secret ); 51 52 my $user = $result->user(); 53 54 my $note_store_uri = 55 $note_store_uri_base . $user->shardId(); 56 57 my $note_store_client = 58 Thrift::HttpClient->new($note_store_uri); 59 60 my $note_store_protocol = 61 Thrift::BinaryProtocol->new( 62 $note_store_client); 63 64 my $note_store = 65 EDAMNoteStore::NoteStoreClient->new( 66 $note_store_protocol); 67 68 my $notebooks = 69 $note_store->listNotebooks( 70 $result->authenticationToken() ); 71 72 my $inbox_guid; 73 74 for my $notebook (@$notebooks) { 75 if ( $notebook->name() eq "Inbox" ) { 76 $inbox_guid = $notebook->guid(); 77 last; 78 } 79 } 80 81 if ( !defined $inbox_guid ) { 82 die "No Inbox notebook found"; 83 } 84 85 my $note = EDAMTypes::Note->new(); 86 $note->title( $message ); 87 $note->content(); 88 89 my $created = 90 $note_store->createNote( 91 $result->authenticationToken(), $note ); 92 93 # move new note to "Inbox" 94 $note_store->copyNote( 95 $result->authenticationToken(), 96 $created->guid(), $inbox_guid );