Skip to content

Instantly share code, notes, and snippets.

@bessey
Last active August 29, 2015 14:05
Show Gist options
  • Save bessey/789b0ac89e520cf44cbd to your computer and use it in GitHub Desktop.
Save bessey/789b0ac89e520cf44cbd to your computer and use it in GitHub Desktop.
My ideal v3 directory client.
##### In my app
class Account < DirectoryClient::Base
def self.specific_convenient_scope_method
where(blah: "blah").order(:bloo)
end
end
Account.all
# Handles OAuth authentication and reauthentication on timeout
# Introspects class name to work out api endpoint (/api/v3/accounts)
#### In client
class DirectoryClient::Base
# OAuth handling
# Ransack compatibile methods
end
# In short, the client is skinny and, like the API v3 BaseController, implements a generic class that has
# all the non unique functionality of every API endpoint baked in. It is then up to the dev to extend
# or include that class in their actual endpoint specific classes.
# Best of both worlds. Client isn't updated every time theres a new endpoint, but abstract away authentication
# into the bowels of the client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment