 Good afternoon. Is everybody enjoying the conference so far? Having been here, after having seen the pictures, of Fort Mason, and now that I'm actually here, I'm pretty convinced that next week they're going to announce that OS-1010 is actually called Fort Mason, that's my prediction for next week. So I'm here to talk a little bit about Ruby Motion and connecting to the enterprise. But first off, you're probably wondering who the heck I am. So I'm Kevin Porman. Oh, hey, that's the wrong way. There we go. My name's Kevin Porman, and you can find me at Code Friar on Twitter and various other places. I currently work as an architect for CRM development at a company called West Monroe. I put some of my things. I know Mark Rickert and I have been following him for a while on his beer app tweets. Every once in a while, he does one of those. I'm a big fan of that. So that's a little bit about me. That's boring stuff. We're going to talk a little bit today about four things here. One, why enterprise software? Why you should care about it? Why you should be writing it or writing interfaces for it? And we're going to talk about the challenges. Some of them are pretty big, some of them are pretty small. But we can do it. We're going to talk about the tools that we have to connect to the enterprise. And then we're going to do an example. Now, my bread and butter is an everyday job is to be an architect for CRM development. And that's usually with Salesforce. So I'm going to use a Salesforce example, because that's my wheelhouse. So we're going to connect to Salesforce in an example, and we're going to see how all of this fits together. So why enterprise software? It was really great to set up with the Flappy Birds demo right before my talk. That was fantastic. When you go on the App Store, when you're thinking about apps and writing mobile apps, there are really two genres that pop out in my mind to start with. The first one is games. Everybody wants to write a game. And you asked before, but let's do it again. If you want to write a game, raise your hand. OK? Raise your hand if you've actually written a game. OK? Now, raise your hand if you have an email account. Raise your hand if you have more than five email accounts. That wasn't a large change right there. Right? When we talk about enterprise software, that's everything from email and email interfaces to big CRM systems or ERP systems. And if you're not in the enterprise software, I just use acronyms you've never heard of and don't have any idea what I'm talking about. I'm talking about customer relationship management systems and enterprise resource planning systems. And these are SAP Oracle, Salesforce, Microsoft Dynamics, lots of enterprise software vendors. And the problem with games or social products or social networks on the App Store is there's a whole lot of them and only a few of them really take off. Flappy Birds was a great social success, but it was a financial disaster. Not all of us are going to be as successful at writing a Flappy Birds clone or even something like it, but if we can write the next thing to go with an enterprise system and we can integrate with an enterprise system, we've now unlocked an app that thousands of users will want to use. Everyone uses email, not everyone even plays games. So we're gonna look here at a graph, I warn you, I'm not a big fan of corporate buzzwords or even graphs and charts and that sort of thing, but I do have one here for you. And I want you to really notice that of all of these lines, they all go at least slightly up and to the right. And what this is, this is from a Gartner IT spending forecast report. You've never read through one of these white papers they're not terribly exciting. But what they do is they have pretty graphs and reports telling the readers where money is going to be spent and they start at a given year, so 2013 is this column. And then they predict into the future where the money's gonna be spent. Now these are all enterprise software systems. They're broken down by type. You'll see that CRM is really growing. And the next one is enterprise resource planning. So there's a lot of money being spent in enterprise systems and we can have part of that. We can break into that ecosystem. There's over 278 billion, wow, in 2012 and that's going to keep expanding. So we're going to, as companies, we're gonna keep investing in such systems. And if you don't think, if you're wondering like who would use these? Even HipBite uses one of them. They use a low level one. They use JetBrains issue tracking system. And that's an enterprise level issue tracking system. So when we think about enterprise systems we're not talking about just thousands of people companies using. We're talking about everything from HipBite sized on up. So why enterprise software? I read this trism in a paper once and it said that all enterprise software stinks. If you ever get the great joy of dealing with enterprise CRM on a day to day basis, you will know that that's a greatly understated statement. The flip side of that, I found a big fan of Porsche in cars. Ferdinand Porsche wrote in his journal One Day and it was later publicized that design is not simply art, it is the elegance of function. And I've been thinking about that a lot and if enterprise software stinks, then I think it's also true and greatly understated that vendor supplied mobile enterprise software is even worse. So if you've used Salesforce before, raise your hand, we've got a few in here. If you've used Salesforce on your iPhone, raise your hand. All right, so not a whole lot here and until recently it's been pretty bad. It's been really bad and the features and the functionality have not really been there. But we have iPhone apps that we've seen here at this conference. There's one, Jukli and another one, Redidot, that I'm a big fan of that demonstrate that well-designed apps are totally possible and what they do is they provide us gorgeous artwork that is also functional and elegant for us to use. And in doing so, they can connect us to an enterprise system and provide a better workflow and a better UI for doing the same thing. This is our sweet spot, this is our niche, that we can write apps to follow to access that growing ecosystem of 200 and some odd billion being spent in enterprise software. So we have some challenges. I like to talk about REST APIs, but I realize that in enterprise software there's no such thing as a REST API. Whatever makes that vendor a leader in their class is also what's going to make their REST API completely unrest-like. So if it's big data, if it's identity management, whatever that is, it's going to break down somehow around that specialization. So we have REST-ish APIs and you'll find that a lot of enterprise software systems, especially those from north of here, tend to deal with a lot of SOAP APIs. Friends don't unfriend you, SOAP, just saying. Also, any protocol that is published and has the word simple in it, just leave it be, leave it be. Other issues that we're going to have to deal with when you're dealing with an enterprise system, everyone's going to be concerned about security, authentication, and if you're really lucky, they're going to use OAuth and if you're not lucky, well, one does not simply just integrate by flipping on a switch. And lastly, data integration, so data integrity, I mean. So if you are of the ability to read and write data from an enterprise system, what are you doing to make sure that you're not putting trashy data in the system or trusting trashy data coming out of the system? So we've got a few challenges ahead of us, not all of them are technical. Some of these are very user-oriented. And we find this in, this is a universal set of challenges. It doesn't matter if you're dealing with Atlassian and their HipChat API or Yammer and some of their APIs. We have some tools to use that we get to deal with. We get to deal with Cocoa Ponds and I'm going to talk about one here in just a bit called ZKSforce, guess what it does? Great name, tells you nothing. We get to use great gems like AFMotion. Again, it kind of tells you what it does, but most of our work for integrating, most of our tooling actually comes in the actual rakefile. RubyMotion's rakefile and project management system is actually really well tuned for integrating with enterprise software. So we're gonna use the rakefile to do most of our work. We're gonna use it for the heavy lifting, but we're also gonna incorporate some Cocoa Pods and we're going to use some gems here. One of the things that I always look for when I'm hiring a developer to work with here is to what degree they're willing or gung-ho about reinventing the wheel. I like reinventing the wheel as much as the next developer, but sometimes the wheel that you have in front of you is really well done. When you're dealing with integrations to these REST-ish APIs with their SDKs, so on and so forth, you're dealing less with inventing something new and understanding and doing it their way. Enterprise software systems, they make the assumption that if you're paying them the thousands or even millions of dollars for the system that you wanna play the way they think you should play. When you go to integrate with them, one of the key things is to learn their philosophy and to play their way. But we can do that largely with AFMotion with gems that allow us to basically build a REST client specific to an API. And we can do things like use ZKSforce, which is a SOAP library for dealing with Salesforce that comes in a Cocoa Pod version. And we can do all these things straight from the rake file. So when I wrote this app that I'm gonna demonstrate to you here about a year ago, the number one thing that Salesforce admins wanted that they wish they could do was reset a password. Can't make that up. So I wrote an app to reset passwords on the go from your mobile phone. And that's what we're gonna do. We're gonna reset some passwords like a boss and I'm gonna show you the code here in just a second. But a little background here, we're gonna use the Salesforce SDK. They've got a mobile iOS SDK that we're gonna use. And we're gonna load that in through the rake file. We're going to see all the fun stuff that does. And we're actually going to be able to reset passwords from our phone. So with that said, let me demo the app here. Now, when you're using their SDK, when I said one of the things they want you to do is play along in their philosophy. In this situation, the SDK actually overrides app delegate and has its own protocol for what an app delegate should be. So by doing playing their way, we also, out of the box, get them to handle authentication for us. We don't have to write any OAuth code. We just implement their protocol methods and we're done on app delegate. So let me input my password here. Nobody read it. Yes, it is quite hard to read. No, it's not a software demo until something goes wrong. Let's do this. Now along with using their SDK and filling in their protocol methods like they've asked us to, we also get this moment management system that they've developed for. So our application, it's gonna show the users and it's actually showing the users, it's got a little bit of a weird glitch going on there. But it pulls in all the users from our org or from our organization. And I've only got three. This is a demo org, so there's only three here. But if we go down to our remotion inspect user, I've got all my details and you can see here that I've got some controls on it. But most importantly, I've got this trigger password reset bit. And if I trigger the password reset, click okay. And this takes a little while on Salesforce's end. But it will eventually come back and ask us a very important question here. And this app fulfills all of the needs that a Salesforce administrator, of which there's one per org, by definition at least one per org, needs in an application that wasn't provided by Salesforce before. This app does one thing, resets passwords. It does it simply and easily. And it gives us everything we need for a mobile admin. You'll have to forgive me, I'm actually connected by tethering to my phone. So not only is it slow on their end, it's not terribly speedy to start with. Let's go back to our presentation here. So we've got an app, resets passwords. The rake file itself provides everything we need to harness this and hook it up. So I'm gonna demonstrate a little few lines here in the rake file as we go through it. They are specific for setting up this SDK, but they're an example of how you might set up a different SDK as well. The first thing that you'll notice is that pretty much every SDK I've ever run into uses some subset of standard frameworks. You just have to know which ones to include here. How do you know which ones you need? Well, if you're lucky, the documentation tells you. If you're not lucky, you just try to build the application until you've got all the frameworks in there. You'll be able to read from your error output. For the record, I am not lucky. This is the minimum needed for dealing with Salesforce. So we're gonna put them in there. And there's nothing very exciting in there. Now, the more exciting bit comes in in these next two sections here. The first part is this library section. And if we look at the libraries, there's two bits. There's two parts. There's the parts that are standard dilids that come from the system and are part of the Xcode and SDKs for iOS development. And then the rest of these are libraries that are provided by the SDK itself. These libraries, sometimes we just use out of the box. One of the tricky bits with integrating with an SDK is sometimes that SDK will provide you everything you need in the form of a ready-to-go library, a .a file. And sometimes you're gonna have to compile those or vendor them in order for RubyMotion to be able to grab the bridge support file if it's not provided. So these libraries, the open SSL libraries are provided and they work out of the box, they're fine. And these two down here, Libs, EqualCypher, and that's loaded, it's awesome. Those load just fine too. But sometimes we're gonna have to deal with naughty libraries, as I like to refer to them, and vendor a project. Now, some of these project libraries that come with the SDK, they're perfectly normal CocoaPod available libraries. But if they're provided with the SDK as a specific version, there's likely a reason that the SDK provides that particular set of source files or headers or version for that. In this case, I've discovered that ResKit, the very common thing that I can pull in via CocoaPod, has actually been highly modified by Salesforce and their SDK. I have to use their version. Yes, exactly. So when you vendor a project, you're telling RubyMotion to go build this sub-project and pull it in, build the library, et cetera. Now, the static means I've got a .a file. I just wanted to generate the bridge support files from the header directory. I need to do that if I'm calling a method within that library and there's no bridge support file. This is what generates it. I learned that the hard way with, I think it was like tech support ticket 63 or something like that. So whoever answered that one, awesome. Sometimes, specifically, we have to do these four big, big projects like the Salesforce native SDK. This is the main library provided. And if you ever are in the situation where you need to modify their SDK, you might find yourself in a situation where you have to modify the source, build it using their own build script, their own build tool to generate that .a file and then incorporate it this way. In the Salesforce case, this is fun. In the Salesforce case, in order to make a password reset call, it's part of their public API, but it's never been put into their iOS SDK. I had to go in and edit the objective C source, add that to it, compile it using their ant script, generate not one, but 63 .a files, find the right one and its headers and pull them into the right folder. These are all things that are doable, but they can take time. I point this out mostly, because if you're in the situation where you're trying to write down a budget for a project or you're trying to figure out how much time it's going to take for a project, these are the things that'll kill you. I'm gonna show you, there's a big wall of soulless code coming, forgive me. I talked about earlier how we had to deal with the SDKs protocol methods in the app delegate. I point this out, because there's a really neat trick that Jamon and the promotion team sort of glossed over yesterday, and that is you don't have to part and parcel use that gem. I'm using promotion with this highly modified app delegate. I'm not using promotion app delegate class. I'm actually using the protocol methods, et cetera, that Salesforce wants me to use, but there's this one little bit in my app delegate and that whole wall of code there that actually boots me into promotion. I'm gonna pass off a home screen, a promotion screen, directly into my root view controller as my navigation controller, and doing so you can basically adopt any SDK that has a weird app delegate, do what they want you to do and then boot it into promotion, quick and easy. That right there is worth the price of admission to just about anything. Now, when you get into, you've got your app compiling. That was a big moment for me when I got this app compiling. I then needed to actually make calls to the API, and this is where they have to provide you some documentation or some form of example code, and this is how I actually get to call one of the methods to grab data from Salesforce. I've got the SFRest API, and it's only going to give me a shared instance. They want a singleton of the API instance, and I'm gonna call the method perform socle query. The rest of this is boilerplate and a couple of callbacks. I wanna point out one thing that just blew my mind when I learned it, is this bit down here, complete block method, and then a symbol sort result. I'm gonna directly read this because this is a tongue twister. Method is a fun method that invokes the named method as a lambda. Say that 10 times fast, what a prize. Basically what this does is it allows you to keep your code nice and clean, and instead of defining lambdas in line here, you can just call it through the method, method, which is fun, because it calls a named method, and hand it off as a lambda. That's brilliant, it just blew my mind when I found that out. And this is a very common pattern when you're dealing with SDKs or APIs that are gonna grab data and pull it back. So I pointed out, have fun with it. I had to learn how to read the Objective C source. At the time I didn't know any Objective C. To this day I know this much Objective C. To figure out how to use this. There's no documentation for it, there's just basically, here's some example code. So the key to understanding how to use the API, the SDKs that are given to you, when you're trying to incorporate this kind of thing, is to look at the source code and figure out how to convert it to Ruby. That can be kind of tedious, or you can install this great sublime text plugin called Objective C to Ruby Motion, and that turns this Objective C code into this. You can literally highlight, invoke it, be done with it, it's not perfect, but it'll get you 98% of the way there. This particular code was converted, and then I immediately turned around and replaced root VC with homescreen.new. So I demoed a little app there, there's probably plenty of questions here. I'm gonna try and answer them if you've got them. Feel free to heckle, not your marks are great.