fudok 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/fudok.rb +82 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b820cc9a19d9152226f7e3202df1e07e4744b6d9
|
4
|
+
data.tar.gz: f79063de17005b40834b77409d13f8fb1cea058f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93d86c19460e59fff99653b61b8a8551cf6190a330f791f7f6de64a60cfeae54111cbc3090e915af95dbfd980eabf4c5e451604ced78f941bc08fcb3eaa603e0
|
7
|
+
data.tar.gz: 6d61c3a395154bb7a41b596ec074a19ccae9d9bffe601b86a713d28b2654ab2bf32ccac91cc693e426c47d69b7f6fb02c640d1090d5d50fa4fbdf0bf51ca4a35
|
data/lib/fudok.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Fudok
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# Fudok client
|
7
|
+
# Author:: cchantep
|
8
|
+
class Client
|
9
|
+
|
10
|
+
# Merges values with specified the specified Fudok template.
|
11
|
+
# Arguments are the following.
|
12
|
+
#
|
13
|
+
# * token (string): Fudok application token
|
14
|
+
# * template (string): ID of Fudok template
|
15
|
+
# * values (hash): Map of one string value per area name
|
16
|
+
# * ssl (boolean): Whether should use SSL (true) or not (false)
|
17
|
+
def self.merge(token, template, values, ssl, &block)
|
18
|
+
http = self._prepared_http(ssl)
|
19
|
+
|
20
|
+
# Prepare parameters
|
21
|
+
params = {
|
22
|
+
"fudok_token" => token,
|
23
|
+
"fudok_template" => template
|
24
|
+
}
|
25
|
+
|
26
|
+
values.each {|key, value| params[key] = value}
|
27
|
+
|
28
|
+
# Prepare request to merge feature
|
29
|
+
req = Net::HTTP::Post.new("/api/merge")
|
30
|
+
req.set_form_data(params)
|
31
|
+
|
32
|
+
# Send request, process response (there save it as file)
|
33
|
+
http.request req do |response|
|
34
|
+
yield response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Authenticates as Fudok manager, and returns an admin token (string)
|
39
|
+
# (not an application token, used for features such as merge).
|
40
|
+
# Arguments are the following.
|
41
|
+
#
|
42
|
+
# * email (string): Fudok user email (username)
|
43
|
+
# * password (string): Password of specified user (clear text)
|
44
|
+
# * ssl (boolean): Whether should use SSL (true; recommanded) or not (false)
|
45
|
+
def self.auth(email, password, ssl)
|
46
|
+
http = self._prepared_http(ssl)
|
47
|
+
|
48
|
+
# Prepare parameters
|
49
|
+
params = { "email" => email, "password" => password }
|
50
|
+
|
51
|
+
# Prepare request to merge feature
|
52
|
+
req = Net::HTTP::Post.new("/api/auth")
|
53
|
+
req.set_form_data(params)
|
54
|
+
|
55
|
+
res = http.request(req).body
|
56
|
+
obj = JSON.parse(res)
|
57
|
+
|
58
|
+
return obj["token"]
|
59
|
+
end
|
60
|
+
|
61
|
+
# (For internal use) Returns a prepared HTTP client.
|
62
|
+
# * ssl (boolean): Whether should use SSL (true) or not (false)
|
63
|
+
def self._prepared_http(ssl)
|
64
|
+
if ssl == true
|
65
|
+
require 'openssl'
|
66
|
+
end
|
67
|
+
|
68
|
+
scheme = (ssl == true) ? "https" : "http"
|
69
|
+
|
70
|
+
# Prepare HTTP client for Fudok API
|
71
|
+
uri = URI.parse(scheme + "://go.fudok.com/api/merge")
|
72
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
73
|
+
|
74
|
+
if ssl == true
|
75
|
+
http.use_ssl = true
|
76
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
77
|
+
end
|
78
|
+
|
79
|
+
return http
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fudok
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cchantep
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Client API for Fudok PDF templating
|
14
|
+
email: contact@fudok.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/fudok.rb
|
20
|
+
homepage: https://github.com/cchantep/fudok-ruby
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.14
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Fudok
|
44
|
+
test_files: []
|