1
0
mirror of https://github.com/captn3m0/outliner.git synced 2024-09-28 13:22:53 +00:00
outliner/lib/outliner/client.rb

40 lines
1002 B
Ruby
Raw Normal View History

2019-07-24 14:06:18 +00:00
require 'httparty'
require 'json'
module Outliner
class Client
include HTTParty
def initialize(base_uri)
self.class.base_uri (base_uri + "/api")
@token = ENV['OUTLINE_TOKEN']
end
2019-08-12 13:26:52 +00:00
def find_or_create_collection(name)
collections = self.collections_list(limit: 100)['data']
collections.filter!{|c|c['name'] == name}
if collections.size >= 1
collections[0]['id']
else
self.collections_create(name: name, description: 'Imported Collection')['data']['id']
end
end
2019-07-24 14:06:18 +00:00
def method_missing(method_name, params = {})
method_name = '/' + method_name.to_s.sub('_', '.')
body = {token: @token}.merge(params).to_json
2019-08-12 13:26:52 +00:00
options = {
2019-07-24 14:06:18 +00:00
body: body,
headers: {
'Accept'=>'application/json',
'Content-Type': 'application/json',
'User-Agent': "Outliner/#{Outliner::VERSION}"
},
format: :json
}
self.class.post(method_name, options)
end
end
end