/snooze

Get off the ground with RESTful API into a python API

Primary LanguagePythonMIT LicenseMIT

Note

The notes are for us to show what needs to be done to the code, but it allows you to get excited about the possibilities that are coming

Use

The first step in using any RESTful api is knowing the base site that it is attached to. To add the base site you will need to uses the constructor of Snooze. A base site for github would look like this.

snooze = Snooze('github.com')

Make sure you do not add the http:// or https:// onto the domain. If you want to make it secure just set the secure argument to True. Also if you add the slash to the end of the domain that is ok, we can take it off for you :)

For every slash and command after the base url ("/something") in a restful api you will use a dot and a attribute call for that command (".something").

However you do not have to use that attribute call. You can override that attribute name to be anything you like. An example git hub api could look both ways

github RESTful API:
  http://github.com/api/v2/json/user/show/knobe

snooze api: 
  snooze.api.v2.json.user.show.knobe # great and fast for hard coding
  or
  snooze.api.v2.json.user.show.username['knobe'] # makes it easier to accept user input

Now that you have the url in api you can send the url generated by the api by performing a call on the object your created. By default it sends a post request.

snooze.api.v2.json.user.show.username['knobe'](_method_ = 'get') # sends a get request

You can also specify arguments to be sent in a request. For example lets say your trying to change your email address.

github RESTful API:
  http://github.com/api/v2/json/user/show/knobe
        with post value of:
            values[email]='new@email.address

snooze.api.v2.json.user.show.knobe('post', values={'email':'snooze@sleep.com'}) 

Note: This has not been tested

Authenticating a user for github is pretty easy, and the api currently supports it. This is because it is a post variable you need to set and that is it.

For other API's they require inserting things into the the header, which is not implmented yet.

< HOW TO CREATE USER AUTHENTICATION TO INPUT INTO THE HEADER >

Acknowledgments

Mike Verdone and his twitter api, because without his api the idea would not have made it out of my mind.