Tag Archives: damn_u_technology.

Service accounts with Ruby and the google api client

  1. Goto https://code.google.com/apis/console
  2. Create a new project
  3. Under services, select Google Analytics
  4. Goto API Access of a new project
  5. generate a new oAuth credential, selecting “service account”.
  6. Download your p12 cert file

 

In Google analytics, use the service account email address and assign it as a new administrator to the desired GA profile.

On ALL servers destined to use the service account to GA, install and syncronized with ntp.  If your even 500ms off, you’re going to have a bad time with “Grant_invalid” messages.

In a testbed project, make 2 files: Gemfile & testbed1.rb ( you’re going to create a lot of these testbed files on your own ).

Gemfile

source "http://rubygems.org"
gem 'google-api-client'
gem 'pry'

testbed1.rb

require 'pry'
require 'rubygems'
require 'google/api_client'

keyFile = "SOME_KEY_GOES_HERE-privatekey.p12"

cID = "YOUR_SOOPA_SECRET_SA"

scope = 'https://www.googleapis.com/auth/analytics.readonly'
email = 'YOUR_EMAIL_GOES_HERE@developer.gserviceaccount.com'


#Normally it would be bad to put the passphrase here, but aftet talking to several dozen devs, everyone's pass phrase is not a secret
key = Google::APIClient::PKCS12.load_key(keyFile, "notasecret")

asserter = Google::APIClient::JWTAsserter.new(
   email,
   scope,
   key)

puts asserter.authorize()

binding.pry

If all goes well, the JWTAsserter instance will get a valid token and no exceptions/errors will be thrown. If you’ve followed all of the steps listed earlier and things are still breaking, troubleshooting paths are: Verify your machine time is correct, verify your service account email address is bound to google analytics, and lastly you might need to wait until Google platform catches up with the changes. For myself, it took 9 hours until my account finally authenticated through. Google has potentially a million or more servers organized into cells, the fact that they seem to cooperate well doesn’t mean they’re perfectly in sync at all times.

Otherwise if all else fails, I recommend stalking this guy Nick https://groups.google.com/d/msg/google-analytics-data-export-api/maa_fyjD2cM/sT8tDDh0wNsJ – It seems like he’s a Google employee on the service account dev/implementation team and generally stuff gets fixed if he says it’s getting fixed.

As I run into any more troubles, I will update and add more notes.

PrototypeJS, a fond memory

Four-five years ago there was a crossroad that in reflection I screwed up on. I was so sure that PrototypeJS was the right library to invest in, it made working with multi-browser javascript a breeze & had a plethora of fantastically useful helper functions. Now, present day, its been almost three years of non-stop jQuery and I’m kind of fine with that. Though a mere shadow of the power that is ExtJS, jQuery UI is a semi-decent library for widgets and asthetics, jQuery itself does what I need, and I don’t get looks of WTF when I mention I’m using jQuery over Prototype at the local developer meetups.

What’s in a title?

With my latest contract, I will be celebrating almost seven years ( 6 continuous years ) as a senior consultant.  I’m comfortable with that title for some very simple reasons:  I started my first business ( onsite tech. support ) when I was 13 then got bought out by a larger firm and became a junior partner at 16.  Then after moving from Florida to Philadelphia ( trust me, official records say Philadelphia is a city but it’s really a state of it’s own ) I started college and multiple companies.  I know the cardinal rule of business, which is to provide less for more but appear to be providing more for less ) regardless of domain.

As a consultant, your technical know how usually plays second fiddle to finding ways for your client’s to be profitable and self-sustaining.  Not to say that you can be technically inept but I’ve worked with a few consultants that were/are.  It doesn’t really matter what the most elegant choice is sometimes if its going to take to long to ensure your client keeps the initiative in their business domain.  That really sucks, but its the truth.

That said, both my clients and my consultancy agencies I’ve worked for have thrown all sorts of crazy titles at me.  Chief engineer, chief sys. admin, architect, senior engineer, lead engineer, software developer, etc.  I’ve been somewhat dumbfounded by the naming choices as the reality doesn’t always match the title.

During the interview for my recent client, when they asked what grade/title I felt I was at I told them I was a competent software engineer with full stack experience.  It would have been quicker to just say “I’m the mother fucking man” but I refuse to do that because all it takes is one little estoric piece of knowledge I don’t know about to blow that card house down.  Somehow we got into a monologue where I explained my opinion on titles:

Apprentice

What’s the difference between a POST & GET based form?   I don’t know how to setup a development workstation.   Of course I know SOAP but why do we have to use all this XML?  Why do I need to use a quicksort when this works? ( emergent bubble sort ).

I don’t know what you’re saying.

Journeymen

Caching is stupid, it gets in the way.  Why should we use that open source framework when we can write our own?  Documentation sucks and we don’t have enough time to implement unit-testing!  Yo dawg, I herd you like patterns so I put a singleton factory in your observer so that I can command pattern inject your dependancies…. uhm no, I’ve got no idea how to fix that bug, let me get back to you in a couple days ( turns out to be an entire week).   But we’re going to need all this extra complexity because I’m bored and figured will need it someday soon.

I don’t know how to implement that and won’t tell you that until I’ve fucked things all to hell.

Craftsmen

I think I can get that done in the needed timeframe.  I hate this language/framework/database but will bear down and get this done while looking for opportunities to make things better.  I refactored feature X to use a factory pattern and will make notes to try and reinforce that change elsewhere.  I’m hesistent to add more complexity here and realize this will be a problem in the future so I’m going to add a quick unit-test to ensure integrity.

Here is how I would implement that, what do you think?

Master

No I won’t/can’t implement that right now until we get the core features down.  Why don’t you like technology X,Y,Z and how can we compromise?  I appreciate your input and will take that into consideration.  Hey boss, check out what minion 12 accomplished, I think he/she/it has a bright future.   It’s unacceptable to modify the system tier framework to resolve your issue, asking the framework mailing list/group for advice/criticism and if they accept it then submit a path.

I will delivery these features in this time frame and if I can’t I will tell you why and a better target date.

Summary

I’ve been writing software since I was 7 or 8, I’ve made a couple million dollars in revenue writing software over a decade or two, and my clients have made several more million using that software.  I’ve worked with people with decades of “experience” but no practical knowledge and inversely people with literally a year or two of experience but are masters at their trade.  I remember working with a Ruby on Rails developer a couple years back who was a goddamn bad ass combat developer knocking out reliable code and pulling epic 90 hours weeks..he learned to program the year prior.  The conclusion is that I think titles are a bit of crap.  Sticking around long enough with a company and you’ll end up being the lead/chief/senior company minion by default.  OR have enough clients you half-assed through and you can claim the title of senior… but neither is an indicator of competence.