module RegApi2
Provides r/w settings for API connection:
-
{RegApi2.username} - Your user name. ‘test` by default.
-
{RegApi2.password} - Your password. ‘test` by default.
-
{RegApi2.io_encoding} - Input/ouput encoding. ‘utf-8` by default.
-
{RegApi2.lang} - Language of API answers. ‘en` by default.
-
{RegApi2.ca_cert_path}, {RegApi2.pem} and {RegApi2.pem_password} - optional certification properties. nils by default.
Provides shortcuts for API categories:
-
{RegApi2.common} API category implemented as {RegApi2::Common} methods.
-
{RegApi2.domain} API category implemented as {RegApi2::Domain} methods.
-
{RegApi2.user} API category implemented as {RegApi2::User} methods.
-
{RegApi2.service} API category implemented as {RegApi2::Service} methods.
-
{RegApi2.bill} API category implemented as {RegApi2::Bill} methods.
-
{RegApi2.folder} API category implemented as {RegApi2::Folder} methods.
-
{RegApi2.zone} API category implemented as {RegApi2::Zone} methods.
-
{RegApi2.hosting} API category implemented as {RegApi2::Hosting} methods.
-
{RegApi2.shop} API category implemented as {RegApi2::Shop} methods.
Provides dump hooks:
-
{RegApi2.dump_requests} to dump outgoing API request forms.
-
{RegApi2.dump_responses} to dump incoming API responses.
Please read {file:README.md} for API overview.
@example List of services by specified identifiers
RegApi2.service.nop(services: [ { dname:"test.ru" }, { dname: "test.su", servtype: "srv_hosting_ispmgr" }, { service_id: 111111 }, { service_id: "22bug22" }, { surprise: "surprise.ru" } ])
@example Dump incoming API responses to ‘$stderr`
RegApi2.dump_responses :stderr
Constants
- VERSION
Gem version.
Attributes
@!attribute [rw] ca_cert_path
@return [String] Path to certification authority certificate (nil by default).
@!attribute [rw] dump_requests_to
@return [String,Symbol,Lambda] Where to dump outgoing API request (nil by default).
| Value | Dump to | | ----- | ------- | | nil | Nothing | | :stdout, "stdout" | $stdout | | :stderr, "stderr" | $stderr | | lambda | Calls this lambda with requested path and form hash |
@!attribute [rw] dump_responses_to
@return [String,Symbol,Lambda] Where to dump incoming API response (nil by default).
| Value | Dump to | | ----- | ------- | | nil | Nothing | | :stdout, "stdout" | $stdout | | :stderr, "stderr" | $stderr | | lambda | Calls this lambda with incoming parsed JSON data |
@!attribute [rw] io_encoding
@return [String] IO encoding (‘utf-8` by default).
@!attribute [rw] lang @return [String] Language (‘en` by default).
@!attribute [rw] password @return [String] Password (‘test` by default).
@!attribute [rw] pem @return [String] X.509 certificate (nil by default).
@!attribute [rw] pem_password
@return [String] X.509 certificate password (nil by default).
@!attribute [rw] username @return [String] User
name (‘test` by default).
Public Class Methods
Shortcut for {RegApi2::Bill} methods. @return [Module] {RegApi2::Bill} @api Shortcuts
# File lib/reg_api2.rb, line 91 def bill; RegApi2::Bill; end
Shortcut for {RegApi2::Common} methods @return [Module] {RegApi2::Common} @api Shortcuts
# File lib/reg_api2.rb, line 67 def common; RegApi2::Common; end
Shortcut for {RegApi2::Domain} methods. @return [Module] {RegApi2::Domain} @api Shortcuts
# File lib/reg_api2.rb, line 73 def domain; RegApi2::Domain; end
Dumps outgoing API requests to given ‘to` or code block. @param [String,Symbol,Lambda] to Where to dump incoming API response (nil by default).
| Value | Dump to | | ----- | ------- | | nil | Nothing | | :stdout, "stdout" | $stdout | | :stderr, "stderr" | $stderr | | lambda | Calls this lambda with requested path and form hash |
@param [Code] code_block Code block to be executed on every API request. @yield [path, form] Request path and form to be sent. @return [NilClass] nil @example Dump outgoing API requests to code block
RegApi2.dump_requests { |path, form| p path; p form }
# File lib/reg_api2/impl.rb, line 65 def dump_requests(to = nil, &code_block) if to.nil? && block_given? to = code_block end self.dump_requests_to = to nil end
Dumps incoming API responses to given ‘to` or code block. @param [String,Symbol,Lambda] to Where to dump outgoing API response (nil by default).
| Value | Dump to | | ----- | ------- | | nil | Nothing | | :stdout, "stdout" | $stdout | | :stderr, "stderr" | $stderr | | lambda | Calls this lambda with incoming parsed JSON data |
@param [Code] code_block Code block to be executed on every API response. @yield [json] Response parsed JSON data to be handled. @return [NilClass] nil @example Dump incoming API responses to ‘$stdout`
RegApi2.dump_responses :stdout
# File lib/reg_api2/impl.rb, line 88 def dump_responses(to = nil, &code_block) if to.nil? && block_given? to = code_block end self.dump_responses_to = to nil end
Shortcut for {RegApi2::Folder} methods. @return [Module] {RegApi2::Folder} @api Shortcuts
# File lib/reg_api2.rb, line 97 def folder; RegApi2::Folder; end
Placeholder to inspect sent form @param [String] path @param [Hash] form @return void
# File lib/reg_api2/impl.rb, line 100 def form_to_be_sent(path, form) case dump_requests_to when :stderr, "stderr" $stderr.puts "RegApi2.Request:\n#{path}\n#{form}" when :stdout, "stdout" $stdout.puts "RegApi2.Request:\n#{path}\n#{form}" when Proc dump_requests_to.call(path, form) when nil ; else raise ArgumentError.new( "Bad dump_requests_to field: #{dump_requests_to.inspect}" ) end nil end
Placeholder to inspect got response. @param [Net::HTTPResponse] response @return void
# File lib/reg_api2/impl.rb, line 119 def got_response(response) case dump_responses_to when :stderr, "stderr" $stderr.puts "RegApi2.Response:\n#{response}" when :stdout, "stdout" $stdout.puts "RegApi2.Response:\n#{response}" when Proc dump_responses_to.call(response) when nil ; else raise ArgumentError.new( "Bad dump_responses_to field: #{dump_responses_to.inspect}" ) end nil end
Shortcut for {RegApi2::Hosting} methods. @return [Module] {RegApi2::Hosting} @api Shortcuts
# File lib/reg_api2.rb, line 109 def hosting; RegApi2::Hosting; end
Shortcut for {RegApi2::Service} methods. @return [Module] {RegApi2::Service} @api Shortcuts
# File lib/reg_api2.rb, line 85 def service; RegApi2::Service; end
Shortcut for {RegApi2::Shop} methods. @return [Module] {RegApi2::Shop} @api Shortcuts
# File lib/reg_api2.rb, line 115 def shop; RegApi2::Shop; end
Shortcut for {RegApi2::User} methods. @return [Module] {RegApi2::User} @api Shortcuts
# File lib/reg_api2.rb, line 79 def user; RegApi2::User; end
Shortcut for {RegApi2::Zone} methods. @return [Module] {RegApi2::Zone} @api Shortcuts
# File lib/reg_api2.rb, line 103 def zone; RegApi2::Zone; end
Private Instance Methods
Shortcut for {RegApi2::Bill} methods. @return [Module] {RegApi2::Bill} @api Shortcuts
# File lib/reg_api2.rb, line 91 def bill; RegApi2::Bill; end
Shortcut for {RegApi2::Common} methods @return [Module] {RegApi2::Common} @api Shortcuts
# File lib/reg_api2.rb, line 67 def common; RegApi2::Common; end
Shortcut for {RegApi2::Domain} methods. @return [Module] {RegApi2::Domain} @api Shortcuts
# File lib/reg_api2.rb, line 73 def domain; RegApi2::Domain; end
Shortcut for {RegApi2::Folder} methods. @return [Module] {RegApi2::Folder} @api Shortcuts
# File lib/reg_api2.rb, line 97 def folder; RegApi2::Folder; end
Shortcut for {RegApi2::Hosting} methods. @return [Module] {RegApi2::Hosting} @api Shortcuts
# File lib/reg_api2.rb, line 109 def hosting; RegApi2::Hosting; end
Shortcut for {RegApi2::Service} methods. @return [Module] {RegApi2::Service} @api Shortcuts
# File lib/reg_api2.rb, line 85 def service; RegApi2::Service; end
Shortcut for {RegApi2::Shop} methods. @return [Module] {RegApi2::Shop} @api Shortcuts
# File lib/reg_api2.rb, line 115 def shop; RegApi2::Shop; end
Shortcut for {RegApi2::User} methods. @return [Module] {RegApi2::User} @api Shortcuts
# File lib/reg_api2.rb, line 79 def user; RegApi2::User; end
Shortcut for {RegApi2::Zone} methods. @return [Module] {RegApi2::Zone} @api Shortcuts
# File lib/reg_api2.rb, line 103 def zone; RegApi2::Zone; end