class Applidok::Client
Applidok
client
- Author
-
cchantep
Public Class Methods
(For internal use) Returns a prepared HTTP client.
-
ssl (boolean): Whether should use SSL (true) or not (false)
# File lib/applidok.rb, line 63 def self._prepared_http(ssl) if ssl == true require 'openssl' end scheme = (ssl == true) ? "https" : "http" # Prepare HTTP client for Applidok API uri = URI.parse(scheme + "://go.applidok.com/api/merge") http = Net::HTTP.new(uri.host, uri.port) if ssl == true http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end return http end
Authenticates as Applidok
manager, and returns an admin token (string) (not an application token, used for features such as merge). Arguments are the following.
-
email (string):
Applidok
user email (username) -
password (string): Password of specified user (clear text)
-
ssl (boolean): Whether should use SSL (true; recommanded) or not (false)
# File lib/applidok.rb, line 45 def self.auth(email, password, ssl) http = self._prepared_http(ssl) # Prepare parameters params = { "email" => email, "password" => password } # Prepare request to merge feature req = Net::HTTP::Post.new("/api/auth") req.set_form_data(params) res = http.request(req).body obj = JSON.parse(res) return obj["token"] end
Merges values with specified the specified Applidok
template. Arguments are the following.
-
token (string):
Applidok
application token -
template (string): ID of
Applidok
template -
values (hash): Map of one string value per area name
-
ssl (boolean): Whether should use SSL (true) or not (false)
# File lib/applidok.rb, line 17 def self.merge(token, template, values, ssl, &block) http = self._prepared_http(ssl) # Prepare parameters params = { "applidok_token" => token, "applidok_template" => template } values.each {|key, value| params[key] = value} # Prepare request to merge feature req = Net::HTTP::Post.new("/api/merge") req.set_form_data(params) # Send request, process response (there save it as file) http.request req do |response| yield response end end