-
-
Save givemelove/115f93ba5942f4b73ce60059f072805a to your computer and use it in GitHub Desktop.
Watch Dox API
This file contains hidden or 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
gem 'json', '= 1.1.3' | |
require 'json' | |
module Watchdox | |
class API | |
BASE_URL = "https://api.watchdox.com" | |
API_VERSION = "1.0" | |
attr_accessor :ssid | |
def login(user, password) | |
payload = {'password' => password}.to_json | |
url = build_url 'session', user.split('@').reverse.join('/') | |
response = RestClient.post url, payload, headers | |
self.ssid = response.headers[:x_wdox_ssid] | |
end | |
def documents | |
RestClient.post build_url("documents"), {:owner => true}.to_json, headers | |
end | |
def set_permissions(user, document) | |
doc = Watchdox::Config::DOCUMENTS[document] | |
guid = JSON.parse(guids(doc[:url]))["guids"] | |
payload = {:recipients => [{:user => user, :permission => {:view => "true", :print => "true", :download => "true", :exprationDate => doc[:expires].call.strftime('%Y-%m-%d') }}], | |
:isSendEmail => true, | |
:documents => guid, | |
:whoCanView => "RECEIVER_ONLY"}.to_json | |
url = build_url 'permission', 'add' | |
RestClient.post url, payload, headers | |
end | |
def guids(urls) | |
RestClient.post build_url("document"), {:urls => urls}.to_json, headers | |
end | |
private | |
def headers | |
h = { :x_wdox_version => API_VERSION, :content_type => :json } | |
h[:x_wdox_ssid] = @ssid if @ssid | |
h | |
end | |
def build_url(*parts) | |
File.join BASE_URL, *parts | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment