applidok 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/applidok.rb +48 -16
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37be38906845a47ee4ad9da50935efb31e49e6db
4
- data.tar.gz: 0ff626405fc146790be20b79800061f53ba491c1
3
+ metadata.gz: 0fd3b7508955f81e67bd6b031d3a8cb795d935eb
4
+ data.tar.gz: f5908069a4cc80e7cfaaf31170f1340ae1dea13b
5
5
  SHA512:
6
- metadata.gz: 019ef816411aa907bc0c794c4525d9b4275c793f80595191cf0f2e381d805b0091a238da1ed0ba08fe5cf865e5dc15bf092de9df4b8bb0f4e0a29e04da0ec805
7
- data.tar.gz: 889df835e9140a49efb06a8dacde2316049aa1976c9b143673fff2d9140d4dea9524f8b7ab445a2451676a93ccf288892707af551e4ad7b980e462e880bb0d79
6
+ metadata.gz: 6c6ac44a8ae19c037cd69556addb7d41ad4a2d520a33e2610ebe685650eb4283fa840d0aae0b4eb4fb67d26d04b43e21355ab39294002582de6a00207ccb9fe4
7
+ data.tar.gz: d9159b65c0391ab288a7ea11c3ee091ec73d948bb8679a040c95b8149025b74e29bf638aaccd81b96a2be07318be40025028d0acf77f1908f43d2c869e7541c0
@@ -1,12 +1,13 @@
1
1
  module Applidok
2
2
  require 'net/http'
3
3
  require 'uri'
4
+ require 'json'
4
5
 
5
6
  # Applidok client
6
- # Author:: Applicius (mailto:contact@applidok.com)
7
+ # Author:: cchantep
7
8
  class Client
8
9
 
9
- # Merge values with specified the specified Applidok template.
10
+ # Merges values with specified the specified Applidok template.
10
11
  # Arguments are the following.
11
12
  #
12
13
  # * token (string): Applidok application token
@@ -14,21 +15,8 @@ module Applidok
14
15
  # * values (hash): Map of one string value per area name
15
16
  # * ssl (boolean): Whether should use SSL (true) or not (false)
16
17
  def self.merge(token, template, values, ssl, &block)
17
- if ssl == true
18
- require 'openssl'
19
- end
20
-
21
- proto = (ssl == true) ? "https" : "http"
18
+ http = self._prepared_http(ssl)
22
19
 
23
- # Prepare HTTP client for Applidok API
24
- uri = URI.parse(proto + "://go.applidok.com/api/merge")
25
- http = Net::HTTP.new(uri.host, uri.port)
26
-
27
- if ssl == true
28
- http.use_ssl = true
29
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
30
- end
31
-
32
20
  # Prepare parameters
33
21
  params = {
34
22
  "applidok_token" => token,
@@ -46,5 +34,49 @@ module Applidok
46
34
  yield response
47
35
  end
48
36
  end
37
+
38
+ # Authenticates as Applidok 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): Applidok 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 Applidok API
71
+ uri = URI.parse(scheme + "://go.applidok.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
49
81
  end
50
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: applidok
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
- - Applicius
7
+ - cchantep
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-24 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Client API for Applidok PDF templating
14
14
  email: contact@applidok.com
@@ -17,7 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/applidok.rb
20
- homepage: https://github.com/applicius/applidok-ruby
20
+ homepage: https://github.com/cchantep/applidok-ruby
21
21
  licenses:
22
22
  - MIT
23
23
  metadata: {}