class Fudok::Client
Fudok
client
- Author
-
cchantep
Public Class Methods
_prepared_http(ssl)
click to toggle source
(For internal use) Returns a prepared HTTP client.
-
ssl (boolean): Whether should use SSL (true) or not (false)
# File lib/fudok.rb, line 63 def self._prepared_http(ssl) if ssl == true require 'openssl' end scheme = (ssl == true) ? "https" : "http" # Prepare HTTP client for Fudok API uri = URI.parse(scheme + "://go.fudok.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
auth(email, password, ssl)
click to toggle source
Authenticates as Fudok
manager, and returns an admin token (string) (not an application token, used for features such as merge). Arguments are the following.
-
email (string):
Fudok
user email (username) -
password (string): Password of specified user (clear text)
-
ssl (boolean): Whether should use SSL (true; recommanded) or not (false)
# File lib/fudok.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
merge(token, template, values, ssl) { |response| ... }
click to toggle source
Merges values with specified the specified Fudok
template. Arguments are the following.
-
token (string):
Fudok
application token -
template (string): ID of
Fudok
template -
values (hash): Map of one string value per area name
-
ssl (boolean): Whether should use SSL (true) or not (false)
# File lib/fudok.rb, line 17 def self.merge(token, template, values, ssl, &block) http = self._prepared_http(ssl) # Prepare parameters params = { "fudok_token" => token, "fudok_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