globessl 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ module GlobeSSL
2
+ class AccountBalance < Base
3
+ attribute :errors, Array[String]
4
+ attribute :balance, Float
5
+ attribute :currency, String
6
+
7
+ def fetch
8
+ @errors.clear
9
+
10
+ response = Client.get('/account/balance')
11
+
12
+ case response.code
13
+ when '200'
14
+ json = response.body
15
+ hash = JSON.parse(json)
16
+
17
+ @balance = hash["balance"]
18
+ @currency = hash["currency"]
19
+
20
+ return true
21
+ when '400', '401', '403'
22
+ set_errors(response)
23
+ return false
24
+ else
25
+ return false
26
+ end
27
+ end
28
+
29
+ def set_errors(response)
30
+ json = response.body
31
+ hash = JSON.parse(json)
32
+ @errors << hash["message"]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ module GlobeSSL
2
+ class AccountDetails < Base
3
+ attribute :errors, Array[String]
4
+ attribute :status, String
5
+ attribute :account_id, Integer
6
+ attribute :balance, Float
7
+ attribute :total_balance, Float
8
+ attribute :account_type, Integer
9
+ attribute :email_address, String
10
+ attribute :name, String
11
+ attribute :company, String
12
+ attribute :address, String
13
+ attribute :city, String
14
+ attribute :state, String
15
+ attribute :country, String
16
+ attribute :postal_code, String
17
+
18
+ def fetch
19
+ @errors.clear
20
+
21
+ response = Client.get('/account/details')
22
+
23
+ case response.code
24
+ when '200'
25
+ json = response.body
26
+ hash = JSON.parse(json)
27
+
28
+ @status = hash["status"]
29
+ @account_id = hash["account_id"]
30
+ @balance = hash["balance"]
31
+ @total_balance = hash["total_balance"]
32
+ @account_type = hash["account_type"]
33
+ @email_address = hash["email"]
34
+ @name = hash["name"]
35
+ @company = hash["company"]
36
+ @address = hash["address"]
37
+ @city = hash["city"]
38
+ @state = hash["state"]
39
+ @country = hash["country"]
40
+ @postal_code = hash["postal_code"]
41
+
42
+ return true
43
+ when '400', '401', '403'
44
+ set_errors(response)
45
+ return false
46
+ else
47
+ return false
48
+ end
49
+ end
50
+
51
+ def set_errors(response)
52
+ json = response.body
53
+ hash = JSON.parse(json)
54
+ @errors << hash["message"]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,13 @@
1
+ require 'virtus'
2
+
3
+ module GlobeSSL
4
+ class Base
5
+ include Virtus.model
6
+ include Virtus::Equalizer.new(name || inspect)
7
+
8
+ def inspect
9
+ values = Hash[instance_variables.map{ |name| [name, instance_variable_get(name)] }]
10
+ "<#{self.class.name} #{values}>"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,129 @@
1
+ require_relative 'country_codes'
2
+
3
+ module GlobeSSL
4
+ class CertificateSigningRequest < Base
5
+ attribute :errors, Array[String]
6
+ attribute :country_name, String # Must be one in COUNTRY_CODES
7
+ attribute :state_or_province_name, String
8
+ attribute :locality_name, String
9
+ attribute :organization_name, String
10
+ attribute :organizational_unit_name, String
11
+ attribute :common_name, String
12
+ attribute :email_address, String
13
+ attribute :csr_code, String
14
+ attribute :csr_code_decoded, String
15
+ attribute :private_key, String
16
+ attribute :fingerprint_sha1, String
17
+ attribute :fingerprint_md5, String
18
+
19
+ def country_name=(value)
20
+ if value
21
+ @country_name = value.upcase
22
+ else
23
+ @country_name = value # nil
24
+ end
25
+ end
26
+
27
+ def fetch
28
+ @errors.clear
29
+
30
+ return false unless valid?
31
+
32
+ params = {
33
+ "countryName" => @country_name,
34
+ "stateOrProvinceName" => @state_or_province_name,
35
+ "localityName" => @locality_name,
36
+ "organizationName" => @organization_name,
37
+ "organizationalUnitName" => @organizational_unit_name,
38
+ "commonName" => @common_name,
39
+ "emailAddress" => @email_address
40
+ }
41
+
42
+ response = Client.post('/tools/autocsr', params)
43
+
44
+ case response.code
45
+ when '200'
46
+ json = response.body
47
+ hash = JSON.parse(json)
48
+
49
+ @private_key = hash["key"] #.delete!("\n") # delete newlines
50
+ @csr_code = hash["csr"] #.delete!("\n") # delete newlines
51
+ @fingerprint_sha1 = hash["sha1"]
52
+ @fingerprint_md5 = hash["md5"]
53
+
54
+ return true
55
+ when '400', '401', '403'
56
+ set_errors(response)
57
+ return false
58
+ else
59
+ return false
60
+ end
61
+ end
62
+
63
+ def decode
64
+ @errors.clear
65
+ response = Client.post('/tools/decodecsr', { "csr" => @csr_code })
66
+
67
+ case response.code
68
+ when '200'
69
+ @csr_code_decoded = response.body
70
+ return true
71
+ when '400', '401', '403'
72
+ set_errors(response)
73
+ return false
74
+ else
75
+ return false
76
+ end
77
+ end
78
+
79
+ def set_errors(response)
80
+ json = response.body
81
+ hash = JSON.parse(json)
82
+ @errors << hash["message"]
83
+ end
84
+
85
+ def valid?
86
+ validate
87
+ end
88
+
89
+ def validate
90
+ unless @country_name
91
+ @errors << "country_name is required"
92
+ end
93
+
94
+ unless COUNTRY_CODES.has_key?(@country_name)
95
+ @errors << "country_name must be one in COUNTRY_CODES"
96
+ end
97
+
98
+ unless @state_or_province_name
99
+ @errors << "state_or_province_name is required"
100
+ end
101
+
102
+ unless @locality_name
103
+ @errors << "locality_name is required"
104
+ end
105
+
106
+ unless @organization_name
107
+ @errors << "organization_name is required"
108
+ end
109
+
110
+ unless @organizational_unit_name
111
+ @errors << "organizational_unit_name is required"
112
+ end
113
+
114
+ unless @common_name
115
+ @errors << "common_name is required"
116
+ end
117
+
118
+ unless @email_address
119
+ @errors << "email_address is required"
120
+ end
121
+
122
+ if @errors.any?
123
+ return false
124
+ else
125
+ return true
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,42 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+
4
+ module GlobeSSL
5
+ class Client
6
+ @headers = {
7
+ 'User-Agent' => GlobeSSL::VERSION::SUMMARY,
8
+ 'Accept' => 'application/json',
9
+ 'X-API-KEY' => GlobeSSL.api_key
10
+ }
11
+
12
+ def self.get(endpoint, params = {})
13
+ begin
14
+ uri = URI.parse([GlobeSSL.api_uri, endpoint].join)
15
+ uri.query = URI.encode_www_form(params) if params.any?
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ http.use_ssl = true
18
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
19
+ request = Net::HTTP::Get.new(uri, @headers)
20
+ response = http.request(request)
21
+ rescue StandardError => error
22
+ puts "HTTP Request failed (#{error.message})"
23
+ end
24
+ end
25
+
26
+ def self.post(endpoint, params = {})
27
+ begin
28
+ uri = URI.parse([GlobeSSL.api_uri, endpoint].join)
29
+ body = URI.encode_www_form(params)
30
+ http = Net::HTTP.new(uri.host, uri.port)
31
+ http.use_ssl = true
32
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
33
+ request = Net::HTTP::Post.new(uri, @headers)
34
+ request.add_field "Content-Type", "application/x-www-form-urlencoded"
35
+ request.body = body
36
+ response = http.request(request)
37
+ rescue StandardError => error
38
+ puts "HTTP Request failed (#{error.message})"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ module GlobeSSL
2
+ class Configuration
3
+ attr_writer :api_key, :api_uri
4
+
5
+ def api_key
6
+ @api_key ||= ENV['GLOBESSL_API_KEY']
7
+ end
8
+
9
+ def api_uri
10
+ @api_uri ||= "https://api.globessl.com/v2"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,257 @@
1
+ module GlobeSSL
2
+ # This list is derived from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2.
3
+ # The hash keys are ISO_3166-1_alpha-2 codes and the values are the country display name.
4
+ # The top 20 countries by number of Internet users are grouped first, see
5
+ # https://en.wikipedia.org/wiki/List_of_countries_by_number_of_Internet_users.
6
+ COUNTRY_CODES = {
7
+ "BR" => "Brazil",
8
+ "CA" => "Canada",
9
+ "CN" => "China",
10
+ "EG" => "Egypt",
11
+ "FR" => "France",
12
+ "DE" => "Germany",
13
+ "IN" => "India",
14
+ "ID" => "Indonesia",
15
+ "IT" => "Italy",
16
+ "JP" => "Japan",
17
+ "MX" => "Mexico",
18
+ "NG" => "Nigeria",
19
+ "PH" => "Philippines",
20
+ "RU" => "Russian Federation",
21
+ "ES" => "Spain",
22
+ "KR" => "South Korea",
23
+ "TR" => "Turkey",
24
+ "GB" => "United Kingdom",
25
+ "US" => "United States",
26
+ "VN" => "Vietnam",
27
+ "AD" => "Andorra",
28
+ "AE" => "United Arab Emirates",
29
+ "AF" => "Afghanistan",
30
+ "AG" => "Antigua and Barbuda",
31
+ "AI" => "Anguilla",
32
+ "AL" => "Albania",
33
+ "AM" => "Armenia",
34
+ "AO" => "Angola",
35
+ "AQ" => "Antarctica",
36
+ "AR" => "Argentina",
37
+ "AS" => "American Samoa",
38
+ "AT" => "Austria",
39
+ "AU" => "Australia",
40
+ "AW" => "Aruba",
41
+ "AX" => "Åland Islands",
42
+ "AZ" => "Azerbaijan",
43
+ "BA" => "Bosnia and Herzegovina",
44
+ "BB" => "Barbados",
45
+ "BD" => "Bangladesh",
46
+ "BE" => "Belgium",
47
+ "BF" => "Burkina Faso",
48
+ "BG" => "Bulgaria",
49
+ "BH" => "Bahrain",
50
+ "BI" => "Burundi",
51
+ "BJ" => "Benin",
52
+ "BL" => "Saint Barthélemy",
53
+ "BM" => "Bermuda",
54
+ "BN" => "Brunei",
55
+ "BO" => "Bolivia",
56
+ "BQ" => "Bonaire, Sint Eustatius and Saba Caribbean Netherlands",
57
+ "BS" => "Bahamas",
58
+ "BT" => "Bhutan",
59
+ "BV" => "Bouvet Island",
60
+ "BW" => "Botswana",
61
+ "BY" => "Belarus",
62
+ "BZ" => "Belize",
63
+ "CC" => "Cocos (Keeling) Islands",
64
+ "CD" => "Congo, the Democratic Republic of",
65
+ "CF" => "Central African Republic",
66
+ "CG" => "Congo",
67
+ "CH" => "Switzerland",
68
+ "CI" => "Côte d'Ivoire",
69
+ "CK" => "Cook Islands",
70
+ "CL" => "Chile",
71
+ "CM" => "Cameroon",
72
+ "CO" => "Colombia",
73
+ "CR" => "Costa Rica",
74
+ "CU" => "Cuba",
75
+ "CV" => "Cabo Verde",
76
+ "CW" => "Curaçao",
77
+ "CX" => "Christmas Island",
78
+ "CY" => "Cyprus",
79
+ "CZ" => "Czech Republic",
80
+ "DJ" => "Djibouti",
81
+ "DK" => "Denmark",
82
+ "DM" => "Dominica",
83
+ "DO" => "Dominican Republic",
84
+ "DZ" => "Algeria",
85
+ "EC" => "Ecuador",
86
+ "EE" => "Estonia",
87
+ "EH" => "Western Sahara",
88
+ "ER" => "Eritrea",
89
+ "ET" => "Ethiopia",
90
+ "FI" => "Finland",
91
+ "FJ" => "Fiji",
92
+ "FK" => "Falkland Islands (Malvinas)",
93
+ "FM" => "Federated States of Micronesia",
94
+ "FO" => "Faroe Islands",
95
+ "GA" => "Gabon",
96
+ "GD" => "Grenada",
97
+ "GE" => "Georgia",
98
+ "GF" => "French Guiana",
99
+ "GG" => "Guernsey",
100
+ "GH" => "Ghana",
101
+ "GI" => "Gibraltar",
102
+ "GL" => "Greenland",
103
+ "GM" => "Gambia",
104
+ "GN" => "Guinea",
105
+ "GP" => "Guadeloupe",
106
+ "GQ" => "Equatorial Guinea",
107
+ "GR" => "Greece",
108
+ "GS" => "South Georgia and the South Sandwich Islands",
109
+ "GT" => "Guatemala",
110
+ "GU" => "Guam",
111
+ "GW" => "Guinea-Bissau",
112
+ "GY" => "Guyana",
113
+ "HK" => "Hong Kong",
114
+ "HM" => "Heard Island and McDonald Islands",
115
+ "HN" => "Honduras",
116
+ "HR" => "Croatia",
117
+ "HT" => "Haiti",
118
+ "HU" => "Hungary",
119
+ "IE" => "Ireland",
120
+ "IL" => "Israel",
121
+ "IM" => "Isle of Man",
122
+ "IO" => "British Indian Ocean Territory",
123
+ "IQ" => "Iraq",
124
+ "IR" => "Iran",
125
+ "IS" => "Iceland",
126
+ "JE" => "Jersey",
127
+ "JM" => "Jamaica",
128
+ "JO" => "Jordan",
129
+ "KE" => "Kenya",
130
+ "KG" => "Kyrgyzstan",
131
+ "KH" => "Cambodia",
132
+ "KI" => "Kiribati",
133
+ "KM" => "Comoros",
134
+ "KN" => "Saint Kitts and Nevis",
135
+ "KP" => "North Korea",
136
+ "KW" => "Kuwait",
137
+ "KY" => "Cayman Islands",
138
+ "KZ" => "Kazakhstan",
139
+ "LA" => "Laos",
140
+ "LB" => "Lebanon",
141
+ "LC" => "Saint Lucia",
142
+ "LI" => "Liechtenstein",
143
+ "LK" => "Sri Lanka",
144
+ "LR" => "Liberia",
145
+ "LS" => "Lesotho",
146
+ "LT" => "Lithuania",
147
+ "LU" => "Luxembourg",
148
+ "LV" => "Latvia",
149
+ "LY" => "Libya",
150
+ "MA" => "Morocco",
151
+ "MC" => "Monaco",
152
+ "MD" => "Moldova",
153
+ "ME" => "Montenegro",
154
+ "MF" => "Saint Martin (French part)",
155
+ "MG" => "Madagascar",
156
+ "MH" => "Marshall Islands",
157
+ "MK" => "Macedonia",
158
+ "ML" => "Mali",
159
+ "MM" => "Myanmar",
160
+ "MN" => "Mongolia",
161
+ "MO" => "Macao",
162
+ "MP" => "Northern Mariana Islands",
163
+ "MQ" => "Martinique",
164
+ "MR" => "Mauritania",
165
+ "MS" => "Montserrat",
166
+ "MT" => "Malta",
167
+ "MU" => "Mauritius",
168
+ "MV" => "Maldives",
169
+ "MW" => "Malawi",
170
+ "MY" => "Malaysia",
171
+ "MZ" => "Mozambique",
172
+ "NA" => "Namibia",
173
+ "NC" => "New Caledonia",
174
+ "NE" => "Niger",
175
+ "NF" => "Norfolk Island",
176
+ "NI" => "Nicaragua",
177
+ "NL" => "Netherlands",
178
+ "NO" => "Norway",
179
+ "NP" => "Nepal",
180
+ "NR" => "Nauru",
181
+ "NU" => "Niue",
182
+ "NZ" => "New Zealand",
183
+ "OM" => "Oman",
184
+ "PA" => "Panama",
185
+ "PE" => "Peru",
186
+ "PF" => "French Polynesia",
187
+ "PG" => "Papua New Guinea",
188
+ "PK" => "Pakistan",
189
+ "PL" => "Poland",
190
+ "PM" => "Saint Pierre and Miquelon",
191
+ "PN" => "Pitcairn",
192
+ "PR" => "Puerto Rico",
193
+ "PS" => "Palestine",
194
+ "PT" => "Portugal",
195
+ "PW" => "Palau",
196
+ "PY" => "Paraguay",
197
+ "QA" => "Qatar",
198
+ "RE" => "Réunion",
199
+ "RO" => "Romania",
200
+ "RS" => "Serbia",
201
+ "RW" => "Rwanda",
202
+ "SA" => "Saudi Arabia",
203
+ "SB" => "Solomon Islands",
204
+ "SC" => "Seychelles",
205
+ "SD" => "Sudan",
206
+ "SE" => "Sweden",
207
+ "SG" => "Singapore",
208
+ "SH" => "Saint Helena, Ascension and Tristan da Cunha",
209
+ "SI" => "Slovenia",
210
+ "SJ" => "Svalbard and Jan Mayen",
211
+ "SK" => "Slovakia",
212
+ "SL" => "Sierra Leone",
213
+ "SM" => "San Marino",
214
+ "SN" => "Senegal",
215
+ "SO" => "Somalia",
216
+ "SR" => "Suriname",
217
+ "SS" => "South Sudan",
218
+ "ST" => "Sao Tome and Principe",
219
+ "SV" => "El Salvador",
220
+ "SX" => "Sint Maarten (Dutch part)",
221
+ "SY" => "Syria",
222
+ "SZ" => "Swaziland",
223
+ "TC" => "Turks and Caicos Islands",
224
+ "TD" => "Chad",
225
+ "TF" => "French Southern Territories",
226
+ "TG" => "Togo",
227
+ "TH" => "Thailand",
228
+ "TJ" => "Tajikistan",
229
+ "TK" => "Tokelau",
230
+ "TL" => "Timor-Leste",
231
+ "TM" => "Turkmenistan",
232
+ "TN" => "Tunisia",
233
+ "TO" => "Tonga",
234
+ "TT" => "Trinidad and Tobago",
235
+ "TV" => "Tuvalu",
236
+ "TW" => "Taiwan",
237
+ "TZ" => "Tanzania",
238
+ "UA" => "Ukraine",
239
+ "UG" => "Uganda",
240
+ "UM" => "United States Minor Outlying Islands",
241
+ "UY" => "Uruguay",
242
+ "UZ" => "Uzbekistan",
243
+ "VA" => "Vatican City",
244
+ "VC" => "Saint Vincent and the Grenadines",
245
+ "VE" => "Venezuela",
246
+ "VG" => "Virgin Islands, British",
247
+ "VI" => "Virgin Islands, U.S.",
248
+ "VU" => "Vanuatu",
249
+ "WF" => "Wallis and Futuna",
250
+ "WS" => "Samoa",
251
+ "YE" => "Yemen",
252
+ "YT" => "Mayotte",
253
+ "ZA" => "South Africa",
254
+ "ZM" => "Zambia",
255
+ "ZW" => "Zimbabwe"
256
+ }
257
+ end