Sunday, September 15, 2013

OAuth continued

I ran into another small problem: I was trying to do a POST request to get access to the API using the access token. This is a GET. I wasted about an hour.

After you get everything back, I needed to have everything stored into my application.
My question was how to redirect the user to the appropriate location.

Here's how you do it

Usually, the method that receives the Rest call says
@Produces("application/xml")
or
@Produces("application/pdf")
@Produces("text/plain")

turns out, you can do 
@Produces("text/html")
(for more on producible MIME types, see this)

Then, when your response is served to the client, it tells the browser to interpret it as an html. This is pretty neat! You can include a script tag inside the response and do a location.href = '/location_here'

I realized that this is just like saving the file with a .html extension. Neat!
So, we get a little lesson about how browsers read files.

That's about it! Everything seems pretty clear to me now. It's just a bunch of mop up work.

Google OAuth 2

Well, this is the thing I've been trying to avoid for awhile.
I finally got it figured out (mostly)

I've found that the documentation is really annoying, since it's trying to sell you the APIs when you're just looking for simple authentication and authorization. (Incidentally, I'm only using OAuth for authentication, and I'm authorizing on my own). The pages are each written nicely, but the links are a mess.

I've found the following two links to be most useful:
Overview
Playground

Of course, Google also gives you some "help" by providing example java clients (or your preferred fill in the blank back end service)

Turns out the first step to getting the access code is stupid. You just put a link with the right queryparams and Google pulls through that part for you, giving you the auth code as a get query parameter in the redirect uri. The next part was the annoying part for me.

Since I have a restful web service, I needed to do another post request with the auth code that Google gave me and send my client id and secret back to Google. I bootlegged a vanilla java post request thing from the web and muscled through it. It uses HttpsUrlRequest or something.

Be sure that your parameters are correct here, Google likes to throw 400s when you misbehave.
Two examples:

  1. you try to post twice. It'll only work if you get it right on the first try. If you mess up, you have to re-authorize.
  2. if you mess up the redirect uri. I'm dumb.
Finally, you get the access_token.

You do another call with that to get the info. This call is easy (finally).

You celebrate, as you've gotten the info from Google that you need. Now everything is handed back to your application.

More to come! As I figure the rest out.

Saturday, August 24, 2013

ST2.2.1 bug with the New Chrome 29.0.1547.57

The new Chrome 29.0.1547.57 doesn't handle the default css from ST2.2.1.

The fix can be found below
here

Thursday, August 22, 2013

ST2 screws you! (rhyme intended)

For some reason, when I had

store: 'Storename',

as a config, it kept on messing up, saying
[WARN][Ext.dataview.List#applyStore] The specified Store cannot be found

Turns out, you need to use

store : { xclass : 'SenchaTest.store.Storename'},


Also, you need to use a UUID identification strategy in your model:
        identifier: {
            type: 'uuid'
        },


Again, ST 2 screws you!

Monday, July 29, 2013

JS Compilation

So you have lots of options,

  • YUI,
  • Closure,
  • UglifyJS.


Since I'm a noob at javascript minification, I've been using the default Sencha CMD yui compressor to minify my scripts. Apparently I think Sencha hacked up the compressor to be Sencha framework aware or something (so claims Sencha themselves).

When I tried using Sencha CMD to compress one of my all-classes.js scripts, it threw some js errors when I deployed.

I then tried to use Google Closure compiler online at http://closure-compiler.appspot.com/home
but it told me my file was too large. I guess I could download closure to run on my local machine, but I didn't feel like learning how to use closure at the moment.

Then I remembered earlier in the morning I crossed the site http://www.freeformatter.com/ which had a butt load of formatters and, whoop dee doo, a js compressor. They said it was also yui based, and had no effect anywhatsoever on your code.

I gave it a shot by linking my url.
Bingo!
No size limitations, no problems, and it worked during deployment. Better yet, it compressed my file just as well as the Sencha one did, so I'm not sure where Sencha went wrong.

In any case, go to http://www.freeformatter.com/javascript-minifier.html#ad-output. It's awesome!

Sunday, July 28, 2013

sencha cmd findings

1. Trailing commas are crap. Remove them from your js laziness habits.
2. Do not use Ext.create(myclass) ?! For some reason, it gets angry at me.


3. If for some reason, sencha cmd v3.1.2.342 does not include your controllers when you compile to all-classes (and you happen to go crazy) here is the solution! (which I finally found, after a full day's worth of fiddling about)

http://www.sencha.com/forum/showthread.php?264130-sencha-compile-does-not-resolve-controller-dependencies

Yes, Sencha is trying to screw us all! You have to include which SDK you are using, because apparently sencha cmd works differently for different sdks. Yes, shoot me now, but that's how it works.

So, I'm running the command

sencha -sdk ../../ext compile -classpath=../../ext/src,. page -yui -in index.html -out build/index.html

Horrid!

Monday, July 22, 2013

Ext grid reconfigure function

This is what everyone was dreaming for in terms of reusing their grids!

You can pass in a new store and new column definitions. Awesome!