xolphin-api 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +28 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +169 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/examples/_credentials.rb +8 -0
  13. data/examples/certificate_cancel.rb +6 -0
  14. data/examples/certificate_reissue.rb +25 -0
  15. data/examples/certificate_renew.rb +22 -0
  16. data/examples/get_notes.rb +9 -0
  17. data/examples/request_create_ee.rb +29 -0
  18. data/examples/request_validation_call.rb +5 -0
  19. data/examples/requests_get.rb +7 -0
  20. data/examples/send_csa_email.rb +5 -0
  21. data/examples/send_note.rb +6 -0
  22. data/lib/xolphin/api.rb +32 -0
  23. data/lib/xolphin/api/certificate_requests/certificate_reissue.rb +47 -0
  24. data/lib/xolphin/api/certificate_requests/certificate_renew.rb +51 -0
  25. data/lib/xolphin/api/certificate_requests/create_certificate_request.rb +52 -0
  26. data/lib/xolphin/api/certificate_requests/create_ee_request.rb +33 -0
  27. data/lib/xolphin/api/client.rb +21 -0
  28. data/lib/xolphin/api/dcv_type.rb +9 -0
  29. data/lib/xolphin/api/endpoint/certificate.rb +59 -0
  30. data/lib/xolphin/api/endpoint/request.rb +86 -0
  31. data/lib/xolphin/api/endpoint/support.rb +47 -0
  32. data/lib/xolphin/api/format_type.rb +12 -0
  33. data/lib/xolphin/api/http.rb +67 -0
  34. data/lib/xolphin/api/product_type.rb +9 -0
  35. data/lib/xolphin/api/responses/base.rb +43 -0
  36. data/lib/xolphin/api/responses/certificate.rb +53 -0
  37. data/lib/xolphin/api/responses/certificates.rb +25 -0
  38. data/lib/xolphin/api/responses/csr_data.rb +43 -0
  39. data/lib/xolphin/api/responses/note.rb +37 -0
  40. data/lib/xolphin/api/responses/notes.rb +24 -0
  41. data/lib/xolphin/api/responses/product.rb +53 -0
  42. data/lib/xolphin/api/responses/product_price.rb +27 -0
  43. data/lib/xolphin/api/responses/products.rb +25 -0
  44. data/lib/xolphin/api/responses/request.rb +119 -0
  45. data/lib/xolphin/api/responses/request_ee.rb +29 -0
  46. data/lib/xolphin/api/responses/request_validation.rb +37 -0
  47. data/lib/xolphin/api/responses/request_validation_domain.rb +35 -0
  48. data/lib/xolphin/api/responses/requests.rb +25 -0
  49. data/lib/xolphin/api/version.rb +5 -0
  50. data/xolphin-api-0.1.0.gem +0 -0
  51. data/xolphin-api.gemspec +26 -0
  52. metadata +136 -0
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+
3
+ module Xolphin
4
+ module Api
5
+ module CertificateRequests
6
+ class ReissueCertificateRequest
7
+ attr_accessor :csr, :dcv_type, :subject_alternative_names, :dcv
8
+ attr_accessor :company, :department, :address, :zipcode, :city, :kvk, :reference
9
+ attr_accessor :approver_first_name, :approver_last_name, :approver_email, :approver_phone
10
+
11
+ def initialize(csr, dcv_type)
12
+ @csr = csr
13
+ @dcv_type = dcv_type
14
+ end
15
+
16
+ def to_param
17
+ result = {
18
+ "csr" => @csr,
19
+ "dcvType" => @dcv_type
20
+ }
21
+
22
+ result.merge!({
23
+ "company" => @company,
24
+ "department" => @department,
25
+ "address" => @address,
26
+ "zipcode" => @zipcode,
27
+ "city" => @city,
28
+ "kvk" => @kvk,
29
+ "reference" => @reference,
30
+ "approverFirstName" => @approver_first_name,
31
+ "approverLastName" => @approver_last_name,
32
+ "approverEmail" => @approver_email,
33
+ "approverPhone" => @approver_phone
34
+ }.reject { |_key, value| value.nil? })
35
+
36
+ if @subject_alternative_names
37
+ result["subjectAlternativeNames"] = @subject_alternative_names.join(",")
38
+ end
39
+
40
+ result["dcv"] = JSON.dump(@dcv) if @dcv
41
+
42
+ result
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+
3
+ module Xolphin
4
+ module Api
5
+ module CertificateRequests
6
+ class RenewCertificateRequest
7
+ attr_accessor :product, :years, :csr, :dcv_type, :subject_alternative_names, :dcv
8
+ attr_accessor :company, :department, :address, :zipcode, :city, :kvk, :reference
9
+ attr_accessor :approver_first_name, :approver_last_name, :approver_email, :approver_phone
10
+
11
+ def initialize(product, years, csr, dcv_type)
12
+ @product = product
13
+ @years = years
14
+ @csr = csr
15
+ @dcv_type = dcv_type
16
+ end
17
+
18
+ def to_param
19
+ result = {
20
+ "product" => @product,
21
+ "years" => @years,
22
+ "csr" => @csr,
23
+ "dcvType" => @dcv_type
24
+ }
25
+
26
+ result.merge!({
27
+ "company" => @company,
28
+ "department" => @department,
29
+ "address" => @address,
30
+ "zipcode" => @zipcode,
31
+ "city" => @city,
32
+ "kvk" => @kvk,
33
+ "reference" => @reference,
34
+ "approverFirstName" => @approver_first_name,
35
+ "approverLastName" => @approver_last_name,
36
+ "approverEmail" => @approver_email,
37
+ "approverPhone" => @approver_phone
38
+ }.reject { |_key, value| value.nil? })
39
+
40
+ if @subject_alternative_names
41
+ result["subjectAlternativeNames"] = @subject_alternative_names.join(",")
42
+ end
43
+
44
+ result["dcv"] = JSON.dump(@dcv) if @dcv
45
+
46
+ result
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ require 'json'
2
+
3
+ module Xolphin
4
+ module Api
5
+ module CertificateRequests
6
+ class CreateCertificateRequest
7
+ attr_accessor :product, :years, :csr, :dcv_type, :subject_alternative_names, :dcv, :language
8
+ attr_accessor :company, :department, :address, :zipcode, :city, :kvk, :reference
9
+ attr_accessor :approver_first_name, :approver_last_name, :approver_email, :approver_phone
10
+
11
+ def initialize(product, years, csr, dcv_type)
12
+ @product = product
13
+ @years = years
14
+ @csr = csr
15
+ @dcv_type = dcv_type
16
+ end
17
+
18
+ def to_param
19
+ result = {
20
+ "product" => @product,
21
+ "years" => @years,
22
+ "csr" => @csr,
23
+ "dcvType" => @dcv_type
24
+ }
25
+
26
+ result.merge!({
27
+ "company" => @company,
28
+ "department" => @department,
29
+ "address" => @address,
30
+ "zipcode" => @zipcode,
31
+ "city" => @city,
32
+ "kvk" => @kvk,
33
+ "reference" => @reference,
34
+ "approverFirstName" => @approver_first_name,
35
+ "approverLastName" => @approver_last_name,
36
+ "approverEmail" => @approver_email,
37
+ "approverPhone" => @approver_phone,
38
+ "language" => @language
39
+ }.reject { |_key, value| value.nil? })
40
+
41
+ if @subject_alternative_names
42
+ result["subjectAlternativeNames"] = @subject_alternative_names.join(",")
43
+ end
44
+
45
+ result["dcv"] = JSON.dump(@dcv) if @dcv
46
+
47
+ result
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+
3
+ module Xolphin
4
+ module Api
5
+ module CertificateRequests
6
+ class CreateEERequest
7
+ attr_accessor :csr, :dcv_type, :subject_alternative_names, :validate
8
+ attr_accessor :approver_first_name, :approver_last_name, :approver_email, :approver_phone
9
+
10
+ def to_param
11
+ result = {
12
+ "csr" => @csr,
13
+ "dcvType" => @dcv_type,
14
+ "approverFirstName" => @approver_first_name,
15
+ "approverLastName" => @approver_last_name,
16
+ "approverEmail" => @approver_email,
17
+ "approverPhone" => @approver_phone,
18
+ }
19
+
20
+ if @validate
21
+ result['validate'] = true;
22
+ end
23
+
24
+ if @subject_alternative_names
25
+ result["subjectAlternativeNames"] = @subject_alternative_names.join(",")
26
+ end
27
+
28
+ result
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Xolphin
2
+ module Api
3
+ class Client
4
+ def initialize(username, password, test = false)
5
+ @http = Xolphin::Api::Http.new(username, password, test: test)
6
+ end
7
+
8
+ def request
9
+ Xolphin::Api::Endpoint::Request.new(@http)
10
+ end
11
+
12
+ def certificate
13
+ Xolphin::Api::Endpoint::Certificate.new(@http)
14
+ end
15
+
16
+ def support
17
+ Xolphin::Api::Endpoint::Support.new(@http)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Xolphin
2
+ module Api
3
+ module DcvType
4
+ EMAIL = "EMAIL"
5
+ FILE = "FILE"
6
+ DNS = "DNS"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,59 @@
1
+ module Xolphin
2
+ module Api
3
+ module Endpoint
4
+ class Certificate
5
+ def initialize(http)
6
+ @http = http
7
+ end
8
+
9
+ def all
10
+ certificates = []
11
+
12
+ result = @http.get("/certificates", page: 1)
13
+ response = Xolphin::Api::Responses::Certificates.new(result)
14
+
15
+ unless response.error?
16
+ certificates = response.certificates
17
+ while response.page < response.pages
18
+ result = @http.get("/certificates", page: response.page + 1)
19
+ response = Xolphin::Api::Responses::Certificates.new(result)
20
+ break if response.error?
21
+
22
+ certificates += response.certificates
23
+ end
24
+ end
25
+
26
+ certificates
27
+ end
28
+
29
+ def get(id)
30
+ result = @http.get("/certificates/#{id}")
31
+
32
+ Xolphin::Api::Responses::Certificate.new(result)
33
+ end
34
+
35
+ def download(id, format = Xolphin::Api::FormatType::CRT)
36
+ @http.download("/certificates/#{id}/download", format: format)
37
+ end
38
+
39
+ def reissue(id, request)
40
+ result = @http.post("/certificates/#{id}/reissue", request.to_param)
41
+ response = Xolphin::Api::Responses::Requests.new(result)
42
+ end
43
+
44
+ def renew(id, request)
45
+ result = @http.post("/certificates/#{id}/renew", request.to_param)
46
+ response = Xolphin::Api::Responses::Requests.new(result)
47
+ end
48
+
49
+ def cancel(id, reason, revoke = nil)
50
+ revoke ||= false
51
+ @http.post("/certificates/#{id}/cancel", [
52
+ 'reason' => reason,
53
+ 'revoke' => revoke
54
+ ])
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,86 @@
1
+ require 'time'
2
+
3
+ module Xolphin
4
+ module Api
5
+ module Endpoint
6
+ class Request
7
+ def initialize(http)
8
+ @http = http
9
+ end
10
+
11
+ def all
12
+ requests = []
13
+
14
+ result = @http.get("/requests", page: 1)
15
+ response = Xolphin::Api::Responses::Requests.new(result)
16
+
17
+ unless response.error?
18
+ requests = response.requests
19
+ while response.page < response.pages
20
+ result = @http.get("/requests", page: response.page + 1)
21
+ response = Xolphin::Api::Responses::Requests.new(result)
22
+ break if response.error?
23
+
24
+ requests += response.requests
25
+ end
26
+ end
27
+
28
+ requests
29
+ end
30
+
31
+ def get(id)
32
+ result = @http.get("/requests/#{id}")
33
+
34
+ Xolphin::Api::Responses::Request.new(result)
35
+ end
36
+
37
+ def create(product, years, csr, dcv_type)
38
+ Xolphin::Api::CertificateRequests::CreateCertificateRequest.new(product, years, csr, dcv_type)
39
+ end
40
+
41
+ def send(request)
42
+ result = @http.post("/requests", request.to_param)
43
+
44
+ Xolphin::Api::Responses::Request.new(result)
45
+ end
46
+
47
+ def createEE()
48
+ Xolphin::Api::CertificateRequests::CreateEERequest.new()
49
+ end
50
+
51
+ def sendEE(request)
52
+ result = @http.post("/requests/ee", request.to_param)
53
+
54
+ Xolphin::Api::Responses::RequestEE.new(result)
55
+ end
56
+
57
+ def sendNote(id, note)
58
+ @http.post("/requests/#{id}/notes",{'message' => note})
59
+ end
60
+
61
+ def getNotes(id)
62
+ result = @http.get("/requests/#{id}/notes")
63
+
64
+ Xolphin::Api::Responses::Notes.new(result)
65
+ end
66
+
67
+ def sendComodoSAEmail(id, to, language = nil)
68
+ @http.post("requests/#{id}/sa",{'sa_email' => to, 'language' => language})
69
+ end
70
+
71
+ def upload(id, document, description = nil)
72
+ @http.post("requests/#{id}/upload-document",{'document' => document, 'description' => description})
73
+ end
74
+
75
+ def scheduleValidationCall(id, date_time)
76
+ t = Time.parse(date_time)
77
+ @http.post("requests/#{id}/schedule-validation-call",{'date' => t.strftime("%Y-%m-%d"), 'time' => t.strftime("%H:%M")})
78
+ end
79
+
80
+ def retryDCV(id, domain, dcv_type, email = nil)
81
+ @http.post("requests/#{id}/retry-dcv",{"domain" => domain, "dcvType" => dcv_type, "email" => email})
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,47 @@
1
+ module Xolphin
2
+ module Api
3
+ module Endpoint
4
+ class Support
5
+ def initialize(http)
6
+ @http = http
7
+ end
8
+
9
+ def products
10
+ products = []
11
+
12
+ result = @http.get("/products", page: 1)
13
+ response = Xolphin::Api::Responses::Products.new(result)
14
+
15
+ unless response.error?
16
+ products = response.products
17
+ while response.page < response.pages
18
+ result = @http.get("/products", page: response.page + 1)
19
+ response = Xolphin::Api::Responses::Products.new(result)
20
+ break if response.error?
21
+
22
+ products += response.products
23
+ end
24
+ end
25
+
26
+ products
27
+ end
28
+
29
+ def product(id)
30
+ result = @http.get("/products/#{id}")
31
+
32
+ Xolphin::Api::Responses::Product.new(result)
33
+ end
34
+
35
+ def decode_csr(csr)
36
+ result = @http.post("/decode-csr", csr: csr)
37
+
38
+ Xolphin::Api::Responses::CsrData.new(result)
39
+ end
40
+
41
+ def approver_email_addresses(domain)
42
+ @http.get("/approver-email-addresses", domain: domain)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ module Xolphin
2
+ module Api
3
+ module FormatType
4
+ CSR = "CSR"
5
+ CRT = "CRT"
6
+ ZIP = "ZIP"
7
+ PKCS7 = "PKCS7"
8
+ CA = "CA"
9
+ CA_BUNDLE = "CA_BUNDLE"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,67 @@
1
+ require 'cgi'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module Xolphin
7
+ module Api
8
+ class Http
9
+ LIVE_URL = "https://api.xolphin.com/v1/".freeze
10
+ TEST_URL = "https://test-api.xolphin.com/v1/".freeze
11
+
12
+ def initialize(username, password, options = {})
13
+ @username = username
14
+ @password = password
15
+ @test = options[:test]
16
+ end
17
+
18
+ def get(path, params = {})
19
+ uri = URI.parse(File.join(api_url, path))
20
+ uri.query = URI.encode_www_form(params) unless params.empty?
21
+
22
+ request = Net::HTTP::Get.new(uri)
23
+ request.basic_auth(@username, @password)
24
+
25
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
26
+ http.request(request)
27
+ end
28
+
29
+ JSON.parse(response.body)
30
+ end
31
+
32
+ def post(path, params = {})
33
+ uri = URI.parse(File.join(api_url, path))
34
+
35
+ request = Net::HTTP::Post.new(uri)
36
+ request.basic_auth(@username, @password)
37
+ request.set_form_data(params)
38
+
39
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
40
+ http.request(request)
41
+ end
42
+
43
+ JSON.parse(response.body)
44
+ end
45
+
46
+ def download(path, params = {})
47
+ uri = URI.parse(File.join(api_url, path))
48
+ uri.query = URI.encode_www_form(params) unless params.empty?
49
+
50
+ request = Net::HTTP::Get.new(uri)
51
+ request.basic_auth(@username, @password)
52
+
53
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
54
+ http.request(request)
55
+ end
56
+
57
+ response.body
58
+ end
59
+
60
+ private
61
+
62
+ def api_url
63
+ @test ? TEST_URL : LIVE_URL
64
+ end
65
+ end
66
+ end
67
+ end