├── README.md ├── android ├── contacts.js ├── calendar.js ├── messages.js └── alarm.js └── data-sources └── discogs.js /README.md: -------------------------------------------------------------------------------- 1 | # scripts 2 | -------------------------------------------------------------------------------- /android/contacts.js: -------------------------------------------------------------------------------- 1 | var AndroidContacts = { 2 | /** 3 | Create a contact 4 | @param {string} name - The contact name. 5 | @param {Arguments} options - Extra options 6 | You can specify extra contact options: 7 | {string} phone - The contact phone number. 8 | {string} email - The contact email address. 9 | {string} postal - The contact postal address. 10 | {string} company - The contact company. 11 | {string} jobTitle - The contact job title. 12 | {string} notes - The contact notes. 13 | 14 | @example 15 | AndroidContacts.create( entry().field("Full name") , 16 | {email:entry().field("Email"), notes:"from Memento"}); 17 | */ 18 | create: function(name, options) { 19 | i = intent("android.intent.action.INSERT"); 20 | i.mimeType("vnd.android.cursor.dir/contact"); 21 | i.extra("name", name); 22 | if (options !== undefined) { 23 | if (options.phone !== undefined) 24 | i.extra("phone" , options.phone); 25 | if (options.email !== undefined) 26 | i.extra("email" , options.email); 27 | if (options.postal !== undefined) 28 | i.extra("postal" , options.postal); 29 | if (options.company !== undefined) 30 | i.extra("company" , options.company); 31 | if (options.jobTitle !== undefined) 32 | i.extra("job_title" , options.jobTitle) 33 | if (options.notes !== undefined) 34 | i.extra("notes" , options.notes) 35 | } 36 | i.send(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /android/calendar.js: -------------------------------------------------------------------------------- 1 | var AndroidCalendar = { 2 | /** 3 | Add a calendar event 4 | @param {String} title - The event title 5 | @param {Arguments} options - Extra options 6 | You can then specify various event details using extra options: 7 | {String} desk - The event description 8 | {Date} begin - The start time of the event 9 | {Date} end - The end time of the event 10 | {bool} allDay - A boolean specifying whether this is an all-day event 11 | {String} location - The event location 12 | {Array} emails - Array of email addresses that specify the invitee 13 | 14 | @example 15 | AndroidCalendar.create( entry().field("Title") , {begin:new Date(), allDay:true}); 16 | */ 17 | create: function(title, options) { 18 | i = intent("android.intent.action.INSERT"); 19 | i.data("content://com.android.calendar/events"); 20 | i.extra("title", title); 21 | if (options !== undefined) { 22 | if (options.desc !== undefined) 23 | i.extra("description", options.desc); 24 | if (options.begin !== undefined) 25 | i.extraLong("beginTime", options.begin.getTime()); 26 | if (options.end !== undefined) 27 | i.extraLong("endTime", options.end.getTime()); 28 | if (options.location !== undefined) 29 | i.extra("eventLocation", options.location); 30 | if (options.allDay !== undefined) 31 | i.extraBool("allDay", options.allDay); 32 | if (options.emails != undefined) 33 | i.extra("android.intent.extra.EMAIL", options.emails.join()); 34 | } 35 | i.send(); 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /android/messages.js: -------------------------------------------------------------------------------- 1 | var AndroidMessages = { 2 | /** 3 | Compose an email with optional attachments 4 | @param {Array} email - A string array of all "To" recipient email addresses. 5 | @param {string} subject - A string with the email subject. 6 | @param {string} text - A string with the body of the email. 7 | @param {Array} attachments - Array of attachments. 8 | 9 | @example 10 | AndroidMessages.email( entry().field("Email") , "Subject" , 11 | "Hello , " + entry().field("Name") +"!\nPlease find attached!", entry().field("Photos") ); 12 | */ 13 | email: function(email, subject, text, attachments) { 14 | i = intent(attachments instanceof Array && attachments.length > 1 ? 15 | "android.intent.action.SEND_MULTIPLE" : "android.intent.action.SEND"); 16 | i.mimeType("message/rfc822"); 17 | i.extraArrayString("android.intent.extra.EMAIL", email); 18 | i.extra("android.intent.extra.SUBJECT", subject); 19 | i.extra("android.intent.extra.TEXT", text); 20 | if (attachments !== undefined) { 21 | if (attachments instanceof Array && attachments.length == 1) 22 | i.extraUri("android.intent.extra.STREAM", attachments[0]) 23 | else i.extraUri("android.intent.extra.STREAM", attachments) 24 | } 25 | i.send(); 26 | }, 27 | 28 | /** 29 | Compose an SMS message 30 | @param {string} - The phone number 31 | @param {text} - A string for the text message. 32 | 33 | @example 34 | AndroidMessages.sms("+1555102088" , entry().field("Status")); 35 | */ 36 | 37 | sms: function(phone , text) { 38 | i = intent("android.intent.action.SENDTO" ); 39 | i.data("smsto:"+phone); 40 | i.extra("sms_body", text); 41 | i.send(); 42 | } 43 | 44 | }; 45 | -------------------------------------------------------------------------------- /android/alarm.js: -------------------------------------------------------------------------------- 1 | var AndroidAlarm = { 2 | /** 3 | Create an alarm 4 | @param {number} hour - The hour for the alarm. 5 | @param {number} minutes - The minutes for the alarm. 6 | @param {string} message - A custom message to identify the alarm. 7 | @param {Arguments} options - Extra options 8 | You can specify extra alarm options: 9 | {Array} days - An Array including each week day on which this alarm should be repeated. Each day must be declared with an integer. 10 | {bool} vibrate - A boolean specifying whether to vibrate for this alarm. 11 | {bool} skipUI - A boolean specifying whether the responding app should skip its UI when setting the alarm. 12 | 13 | @example 14 | AndroidAlarm.create( 12 , 30 , "My alarm" , {days:[2,3], vibrate:true}); 15 | */ 16 | create: function(hour, minutes, message, options) { 17 | i = intent("android.intent.action.SET_ALARM"); 18 | i.extraInt("android.intent.extra.alarm.HOUR", hour); 19 | i.extraInt("android.intent.extra.alarm.MINUTES", minutes); 20 | if (message !== undefined) 21 | i.extra("android.intent.extra.alarm.MESSAGE", message); 22 | if (options !== undefined) { 23 | if (options.days !== undefined) 24 | i.extraArrayInt("android.intent.extra.alarm.DAYS", options.days); 25 | if (options.vibrate !== undefined) 26 | i.extraBool("android.intent.extra.alarm.VIBRATE", options.vibrate); 27 | if (options.skipUI !== undefined) 28 | i.extraBool("android.intent.extra.alarm.SKIP_UI", options.skipUI); 29 | } 30 | i.send(); 31 | }, 32 | 33 | /** 34 | Create a timer 35 | @param {number} length - The length of the timer in seconds. 36 | @param {string} message -A custom message to identify the timer. 37 | @param {bool} skipUI - A boolean specifying whether the responding app should skip its UI when setting the timer. 38 | 39 | @example 40 | AndroidAlarm.timer(30); 41 | */ 42 | timer: function(length, message, skipUI) { 43 | i = intent("android.intent.action.SET_TIMER"); 44 | i.extraInt("android.intent.extra.alarm.LENGTH", length); 45 | if (message !== undefined) 46 | i.extra("android.intent.extra.alarm.MESSAGE", message); 47 | if (skipUI !== undefined) 48 | i.extraBool("android.intent.extra.alarm.SKIP_UI", skipUI); 49 | i.send(); 50 | } 51 | 52 | }; 53 | -------------------------------------------------------------------------------- /data-sources/discogs.js: -------------------------------------------------------------------------------- 1 | /** 2 | The data source for obtaining information from discogs.com. 3 | @param {string} apiKey - Consumer key. 4 | @param {string} apiSecret - Consumer secret. 5 | @param {string} type - One of release, master, artist. 6 | Consumer key and Consumer secret can be obtained by this link : https://www.discogs.com/settings/developers 7 | More info about Discogs API see here: https://www.discogs.com/developers 8 | @example 9 | var discogs = new Discogs("Consumer key" ,"Consumer secret" , "release" ); 10 | var r = discogs.search(query); 11 | result( r , function(id) { return discogs.extra(id);}); 12 | */ 13 | function Discogs (apiKey , apiSecret, type) { 14 | this.apiKey = apiKey; 15 | this.apiSecret = apiSecret; 16 | this.type = type; 17 | } 18 | 19 | 20 | /** 21 | Issue a search query to Discogs database. 22 | @param {string} query - Search query. 23 | */ 24 | Discogs.prototype.search = function(query) { 25 | var result = http().get("https://api.discogs.com/database/search?q=" + encodeURIComponent(query) + "&key=" + this.apiKey + "&secret=" + this.apiSecret + "&type=" + this.type); 26 | var json = JSON.parse(result.body); 27 | return json.results; 28 | } 29 | 30 | /** 31 | Issue a search query to Discogs database. 32 | @param {string} code - Search barcodes. 33 | */ 34 | Discogs.prototype.barcode = function(code) { 35 | var result = http().get("https://api.discogs.com/database/search?barcode=" + encodeURIComponent(code) + "&key=" + this.apiKey + "&secret=" + this.apiSecret + "&type=" + this.type); 36 | var json = JSON.parse(result.body); 37 | return json.results; 38 | } 39 | 40 | /** 41 | @param {string} id - The resource identifier. 42 | */ 43 | Discogs.prototype.extra = function(id) { 44 | var resultJson = http().get("https://api.discogs.com/" + this.type + "s/" + id + "?key=" + this.apiKey + "&secret=" + this.apiSecret); 45 | var result = JSON.parse(resultJson.body); 46 | if (result.images !== undefined) 47 | result['images'] = result.images.map(function(e) { return e.uri; }).join(); 48 | if (result.videos !== undefined) 49 | result['videos'] = result.videos.map(function(e) { return e.uri; }).join(); 50 | if (result.artists !== undefined) 51 | result['artists'] = result.artists.map(function(e) { return e.name; }).join(); 52 | if (result.tracklist !== undefined) 53 | result['tracklist'] = result.tracklist.map(function(e) { return e.position + ". " + e.title + " " + e.duration; }).join("\n"); 54 | if (result.styles !== undefined) 55 | result['styles'] = result.styles.join(); 56 | if (result.genres !== undefined) 57 | result['genres'] = result.genres.join(); 58 | return result; 59 | } 60 | --------------------------------------------------------------------------------