Created
January 30, 2016 19:46
-
-
Save laander/83cb7f5dde1f933173c7 to your computer and use it in GitHub Desktop.
Example integration with Timekit in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Global configs for "admin" user | |
TK_ADMIN_USER = 'my-email@gmail.com' | |
TK_ADMIN_TOKEN = '12345ABCD' | |
# Example usage: | |
# timekit = Timekit.new(TK_ADMIN_USER, TK_ADMIN_TOKEN) | |
# tk_user = timekit.create_user(account) | |
# someInternalUser.update(tk_token: tk_user.token) | |
class Timekit | |
include HTTParty | |
base_uri 'https://api.timekit.io' | |
headers 'Timekit-App' => 'your-app-name' | |
def initialize(user, password) | |
@auth = {username: user, password: password} | |
end | |
def create_user(account) | |
options = { | |
body: { | |
"email" => account.email, | |
"first_name" => account.first_name, | |
"last_name" => account.last_name, | |
"timezone" => "America/Los_Angeles" | |
}.to_json, | |
basic_auth: @auth, | |
} | |
self.class.post('/v2/users/', options) | |
end | |
def create_calendar(account) | |
options = { | |
body: { | |
name: "Appointments", | |
description: "Hold bookings for clients." | |
}.to_json, | |
basic_auth: @auth | |
} | |
self.class.post('/v2/calendars', options) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment