PS-Pushover – Send Pushover messages from Powershell

I’ve been playing around with IFTTT.com recently.  Both in an effort to get more organised and as an excuse to make the most out of my awesome new Pebble watch :-)

If you’ve never heard of IFTTT, go have a play now.  It’s a brilliant site, framework and application designed to plug together many many things.  You can use it to:
  • Send you a text message when it’s someone's birthday on Facebook
  • Update all your profile pictures across social media applications in one go
  • Email you the weather update when it’s raining
  • Fetch new entries to an RSS feed and send to Pocket for reading
  • Catalogue your starred emails in Evernote
You get the idea, take data from an event in one location and pipe to another.

One of those pipes is Pushover.  Pushover is a notification application you can install on your Android/iOS device.  It’s a very simple app that will display a feed of messages as they come in but can be restricted by quiet hours, message priority and (most importantly for me) forwards messages to your Pebble.

After registering on the site I spotted that they allow you to create your own applications for free with a monthly message allowance of 7500. So, let’s make use of it!

PS-Pushover


I’ve knocked up a Powershell module to do just that.  With PS-Pushover you can add Pushover functionality to anything you can do in Powershell.  That means tracking performance of a server, watching for new files, waiting for completion of downloads or jobs to finish etc are all able to send messages as and when needed.

Here’s a couple of example scripts:



And here’s the results:



PowerShell for Sitecore Item Web API

My colleague Adam Simmonds did a demo of the Sitecore Item Web API at work based on the code provided by Kern Herskind from a recent Sitecore User Group.  It was great to see a small, simple, yet powerful API available to mobile solutions and third-party services that could operate in a RESTful way.

The ability to drop into a solution with very minor configuration changes makes the API incredibly simple to apply to existing solutions (if the Sitecore version is supported of course).  It also follows Sitecore's principle design of pipelines and security; making it really easy to extend with custom functionality or handlers while also restricting requests at a user level using the security domain set for the website.  This means full control of security restrictions can be applied using the standard Sitecore security model and interface.

In short, it’s pretty damn awesome.

Now with added PowerShell


On Tuesday evening I knocked up a quick module to send requests to a site running the API.  Yesterday I cleaned it up, improved documentation, and packaged with a proper manifest.

I’m not entirely happy with the state of the code but it is now much more usable and in a better state to extend and (hopefully) be useful to others.  I'm still learning PowerShell and need to work out a coding style and development process that works for me.

Usage


The module implements a small handful of commands:
  • Add-SitecoreItem – Creates a new Sitecore item, optionally setting fields
  • Get-SitecoreItem – Gets one or more Sitecore items which match the context of the given parameters
  • Remove-SitecoreItem – Deletes one or more Sitecore items based on the context
  • Set-SitecoreItem – Updates the fields of one or more Sitecore items
There is an additional Invoke-SitecoreRequest method which is a special “bare bones” function  to allow extended control of the parameters passed to Sitecore.  All other functions act as wrappers to this function, providing validation and parameter restrictions where possible.

Aside from making it simple to perform CRUD actions with Sitecore  (think bulk uploads, change properties, quick reports etc) I hope to use this to perform some level of integration testing.

I'm currently spending a lot of time investigating (and improving!) build processes.  With the aim of making the transition of code from Dev -> Stage -> Live as seamless and robust as possible.  Increasing the robustness involves validating that packages and items have been deployed properly.  This looks like it may be a useful tool to perform validation of fields that have been updated.

Download and Install


All the information you need is available at the Github repo.

If you don't have the Sitecore Item Web API installed already you can download the API and documentation from Sitecore (You'll need an SDN login).

Examples


For demo purposes the account used here is an admin.  To restrict access, use Sitecore roles and the configuration options in the Sitecore Item Web API config include.
Getting an item

Adding an item

Setting an item

Removing an item

Further Work

  1. Tests - seriously, if I want to use this for testing and building I’m going to need a decent test suite to know things are working as expected.  This will also give me a chance to get to grips with Pester.
  2. Additional functions – RSA encryption and the ability to upload media are next on the list
  3. Pipelining – PowerShell functions are even more useful when you chain them together.  It would be great to run something like: Import-Csv input.csv | Add-SitecoreItem mydomain –user username –pass password | select –expand Items | select DisplayName,ID,Path,Version | Export-Csv output.csv (which would read a csv, create new items based on each row then output the new item details to another csv
  4. Code structure – I don’t like everything being one big file.  I’d like to break things into smaller chunks and related modules. 
  5. Session based access – It’s a bit tedious adding the domain, username and password to every request.  While requests are stateless a PowerShell session needn't be.  Something like: Start-SitecoreSession domain username password -encrypt –params @{ path = “/sitecore/content/home” } could set session level variables that can be used by methods.  This is extended to cater for parameters which could apply to every call (while overriding at a function level) and also be a good place to perform encryption duties.
  6. Aliases - For parameters as well as functions.  The breadth of parameters available to the functions make it tedious to type long form when you just want to type in the command line.
  7. Response formatting - I've done a small amount of work to normalise the formatting of the different responses the API provides.  However the response format of the Fields property is a little awkward.  It would be better if this was an array of fields rather then a hash with guid based keys.
Hopefully this little module will be of use to others.  If you've taken a look and have any suggestions or improvements (or bugs!) let me know ;-)

Gaming For 2013

I wrote early last year about the pile of games I had to work through – having bought a bunch in the January sales.  I managed to play a some, a few I never got to.
There’s no shopping spree for me this year.  I got three major games for Christmas that should have a play time of at least 30+ hours each.  I also already have a pile sitting at home from previous shopping excursions, notably during the time Game and Gamestation couldn't make their mind up on who was closing down...
Here’s a brief run down of what I managed to play from last years pile:
  • Child Of Eden  - Love this, but it’s complete filler.  Something to play when I only have a little time.  It’s Rez with shinier graphics but doesn’t pretend to be anything more.
  • Rage – For a fiver this gave me plenty of game play but it was mediocre at best.  Even on hard the game struggled to be anything more then a pretty Fallout-esque landscape with elements of Borderlands thrown in.  Something of a swansong for Id during their acquisition by Bethesda.
  • Dead Rising 2 – Not touched beyond five minutes, one bought for the missus.  I’ll get there at some point
  • Far Cry 2 – Not touched… somehow there always seemed to be something else to play!
  • Crysis 2 – Great, short, zero replay-ability for me.  I ran through the game on Super-Soldier after completing once and being fully levelled up made things rather simple.  The initial run through was a lot of fun and set things up for Crysis 3 quite well.  Which is definitely one to pick up. 
  • Metro 2033 – This was quite a surprise.  In some places it felt quite like Half-Life.  Others, the story line is engaging enough to keep you interested but often forgotten once in an action set-piece.  Generally there was nothing to place it above any other story driven FPS.  The sequel does look to be quite interesting though.
  • Ninety Nine Nights – This is one of those games I’ve wanted to play forever, yet again I’ve barely scratched it.
  • Dark Souls – Wow.  I played this for just a few hours but for some reason just haven’t found the time to dedicate to it.  This isn’t a game to take lightly, I really like long gaming sessions and this game deserves to have a few days off work to play!
  • Splinter Cell: Double Agent – This was everything you’d expect from the series and nothing more.  Worthy of attention if in the bargain basement, otherwise ignore.
  • Skyrim – I’m not going to write longwinded on this, there’s enough of that on the internet already.  It’s everything that you’d expect from the Elder Scrolls series and then some.  I reached level 53 and all achievements in 110 hours but the world is so expansive that it still feels like you can adventure off in one direction and not know what you will find.  The DLC is yet to be played.
  • Fable 2 – After two hours this just wasn’t working for me.  It felt slow and after playing Skyrim, a shade of what games on this scale can be.
  • Halo 3 – I had a lot of fun playing through Legendary with a mate, but single-player I’ve no care for.
  • Left For Dead – This has now become a party game only
  • Left For Dead 2 – as above
  • Star Wars: The Force Unleashed  - Still not restarted, still not traded as the missus wants to play!
By my count, that’s still 5 games from that pile to play.  Plus the following…(in no particular order)
  • Borderlands 2
  • Mass Effect 3
  • Assassins Creed 3 (now playing!)
  • Dead Island
  • Dead to Rights: Retribution
  • Duke Nukem
  • Brink
  • Deadly Premonition (on loan)
  • Just Cause
  • Goldeneye Reloaded
  • The Darkness 2
  • Inversion
  • Dodonpachi Resurrection (this will just be filler)
  • Darksiders 2 – Apocalpytic run through (I’ve completed once already)
  • Dead Space 3 (on pre-order)
I’ll undoubtedly buy and play other games not in this list already.  I’m looking to keep track of what I’ve played to see just how much time I’m really spending on the console.  It’s going to be a busy year!

What to do with old domains?

So, it seems I suffer from one of two problems.
  1. I am incapable of seeing a personal project through to the end
  2. I struggle to find the time to dedicate to personal projects
I sincerely hope it’s number two.

I own the domains scraptrack.net and sharpnote.net.  Both were bought as the title domains for planned projects.  I did actually manage to start Sharpnote – a simple .NET wrapper to the Simplenote API.  However my workload in my actual job increased and it took some time getting used to being that busy.  By the time I was back to having free time that I didn’t use to just relax, I was using Workflowy for all my lists/note tracking and my interest in Simplenote waned.

That said, I do hope to get back to using the domains for something.  For the time being, I just don’t know what.

In an effort to be a little more organised and possibly a little more forward-thinking I plan to write blog posts a lot more often.  2-4 a month would be great.  I’m not holding any promises to myself but instead of trying to write on something that is new and hoping to be heard I’m just going to write on something that interests me.

I’m no literary genius either so if the post is only a handful of words or paragraphs, that’s just fine.

Multipart Form Posting in Android

I'm chugging away making a native Android app for the rather splendid @stringfellow.  It's been quite the eye-opener in terms of Android fragmentation, the joys of returning to Java after a (very) long hiatus and the intricacies of the platform as a whole.  I fully intend to write-up a few posts on what I've done (and hope for feedback on how things can be improved) but the following was an unexpected pitfall I think is worth talking about now.

Naturally the wealth of apps on Android and other mobile devices require some kind of network interface for consumption of data and communicating details back to servers.  Android - being built with Java - allows you to use the org.apache.http.client.HttpClient which is great until you want to send an image/file or anything else in a multi-part form.

The version of HttpClient in Android (2.2 - not developing against other versions yet) does not have support for multi-part forms.  You could write content as separate entities/directly to the stream but that can soon get messy.

To make things simpler, grab the HttpClient (4.1.3) jar from Apache, drop into your Android project build path and do the following in your request/response handler: