reg.api2 0.0.2 → 0.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.
data/lib/reg_api2/impl.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ require 'uri'
2
3
  require 'net/http'
3
4
  require 'net/https'
4
5
  require 'yajl'
@@ -49,6 +50,15 @@ module RegApi2
49
50
  # @!attribute [rw] lang
50
51
  # @return [String] Language ('en' by default).
51
52
  attr_accessor :lang
53
+ # @!attribute [rw] ca_cert_path
54
+ # @return [String] Path to certificate (nil by default).
55
+ attr_accessor :ca_cert_path
56
+ # @!attribute [rw] pem
57
+ # @return [String] PEM (nil by default).
58
+ attr_accessor :pem
59
+ # @!attribute [rw] pem_password
60
+ # @return [String] PEM password (nil by default).
61
+ attr_accessor :pem_password
52
62
 
53
63
  # Default IO encoding
54
64
  DEFAULT_IO_ENCODING = 'utf-8'
@@ -67,6 +77,21 @@ module RegApi2
67
77
  API_URI.port
68
78
  )
69
79
  http.use_ssl = true
80
+ unless ca_cert_path.nil?
81
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
82
+ http.ca_file = ca_cert_path
83
+ else
84
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
85
+ end
86
+ unless pem.nil?
87
+ http.cert = OpenSSL::X509::Certificate.new(pem)
88
+ if pem_password
89
+ raise ArgumentError, "The private key requires a password" if pem_password.empty?
90
+ http.key = OpenSSL::PKey::RSA.new(pem, pem_password)
91
+ else
92
+ http.key = OpenSSL::PKey::RSA.new(pem)
93
+ end
94
+ end
70
95
  http
71
96
  end
72
97
  end
@@ -96,8 +121,6 @@ module RegApi2
96
121
  opts = RegApi2::RequestContract.new(defopts).validate(opts)
97
122
 
98
123
  form = {
99
- 'username' => username,
100
- 'password' => password,
101
124
  'io_encoding' => io_encoding,
102
125
  'lang' => lang || DEFAULT_LANG,
103
126
  'output_format' => 'json',
@@ -106,6 +129,9 @@ module RegApi2
106
129
  'input_data' => Yajl::Encoder.encode(opts)
107
130
  }
108
131
 
132
+ form['username'] = username if username
133
+ form['password'] = password if password
134
+
109
135
  form
110
136
  end
111
137
 
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module RegApi2
3
3
  # Gem version.
4
- VERSION = "0.0.2".freeze
4
+ VERSION = "0.0.3".freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reg.api2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -252,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
252
  version: '0'
253
253
  segments:
254
254
  - 0
255
- hash: -1771662475751154116
255
+ hash: -2651933620898145662
256
256
  required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  none: false
258
258
  requirements:
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  version: '0'
262
262
  segments:
263
263
  - 0
264
- hash: -1771662475751154116
264
+ hash: -2651933620898145662
265
265
  requirements: []
266
266
  rubyforge_project:
267
267
  rubygems_version: 1.8.24