Class: NIFTY::Base
- Inherits:
-
Object
- Object
- NIFTY::Base
- Defined in:
- lib/NIFTY.rb
Overview
HTTPリクエストの生成、実行、レスポンス解析を行う共通クラス
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_CONNECTION_TIMEOUT =
30
- DEFAULT_SOCKET_TIMEOUT =
30
- DEFAULT_PORT =
443
- DEFAULT_CONTENT_TYPE =
'application/x-www-form-urlencoded;charset=UTF-8'
- PROTOCOL_HTTPS =
'https'
- SIGNATURE_METHOD_SHA1 =
'HmacSHA1'
- SIGNATURE_METHOD_SHA256 =
'HmacSHA256'
- PORT_RANGE =
(0..65535)
- SIGNATURE_VERSION =
["0", "1", "2"]
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#connection_timeout ⇒ Object
readonly
Returns the value of attribute connection_timeout.
-
#max_retry ⇒ Object
readonly
Returns the value of attribute max_retry.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#proxy_server ⇒ Object
readonly
Returns the value of attribute proxy_server.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#signature_method ⇒ Object
readonly
Returns the value of attribute signature_method.
-
#signature_version ⇒ Object
readonly
Returns the value of attribute signature_version.
-
#socket_timeout ⇒ Object
readonly
Returns the value of attribute socket_timeout.
-
#use_ssl ⇒ Object
readonly
Returns the value of attribute use_ssl.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
オプションを指定してニフティクラウドAPIクライアントを生成します。.
Constructor Details
#initialize(options = {}) ⇒ Base
オプションを指定してニフティクラウドAPIクライアントを生成します。
@option options [String] :access_key 公開キー
@option options [String] :secret_key 秘密キー
@option options [Boolean] :use_ssl SSL暗号化(true or false)
@option options [String] :server APIホスト
@option options [String] :path APIパス
@option options [String] :proxy_server プロキシサーバーのURL
@option options [String] :port 接続先ポート番号
@option options [Integer] :connection_timeout 接続タイムアウト(秒)
@option options [Integer] :socket_timeout ソケットタイムアウト(秒)
@option options [String] :user_agent ユーザーエージェント
@option options [Integer] :max_retry 最大リトライ回数
@option options [String] :signature_version 認証バージョン
@option options [String] :signature_method APIの認証ロジック
@return [Base] ニフティクラウドAPIクライアントオブジェクト
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/NIFTY.rb', line 103 def initialize( = {} ) @default_host = @default_path = @default_port = nil if blank?([:server]) # options[:server]の指定がない場合はデフォルトのエンドポイントを使用する raise ConfigurationError, "No ENDPOINT_URL provided." if blank?(@default_endpoint) uri = URI.parse(@default_endpoint) raise ConfigurationError, "Invalid ENDPOINT_URL provided." unless PROTOCOL_HTTPS == uri.scheme @default_host = uri.host || (raise ConfigurationError, "Invalid ENDPOINT_URL provided.") @default_path = uri.path @default_port = uri.port end = { :access_key => @default_access_key, :secret_key => @default_secret_key, :use_ssl => true, :server => @default_host, :path => @default_path, :proxy_server => @default_proxy_server, :port => @default_port, :connection_timeout => @default_connection_timeout, :socket_timeout => @default_socket_timeout, :user_agent => @default_user_agent, :max_retry => @default_max_retry, :signature_version => @default_signature_version, :signature_method => @default_signature_method }.merge() [:port] = DEFAULT_PORT if blank?([:port]) raise ArgumentError, "No :access_key provided." if blank?([:access_key]) raise ArgumentError, "No :secret_key provided." if blank?([:secret_key]) raise ArgumentError, "No :use_ssl provided." if blank?([:use_ssl]) raise ArgumentError, "Invalid :use_ssl provided. only 'true' allowed." unless true == [:use_ssl] raise ArgumentError, "No :server provided." if blank?([:server]) raise ArgumentError, "No :path provided." if blank?([:path]) raise ArgumentError, "Invalid :port provided." unless valid_port?([:port]) raise ArgumentError, "Invalid :signature_version provided." unless SIGNATURE_VERSION.include?([:signature_version].to_s) raise ArgumentError, "Invalid :signature_method provided." unless [SIGNATURE_METHOD_SHA1, SIGNATURE_METHOD_SHA256].include?([:signature_method].to_s) @access_key = [:access_key].to_s @secret_key = [:secret_key].to_s @use_ssl = [:use_ssl] @server = [:server].to_s @path = [:path].to_s @proxy_server = [:proxy_server].to_s @port = [:port].to_i @connection_timeout = [:connection_timeout].to_s.to_i @socket_timeout = [:socket_timeout].to_s.to_i @user_agent = [:user_agent].to_s @max_retry = [:max_retry].to_s.to_i @signature_version = [:signature_version].to_s @signature_method = [:signature_method].to_s make_http end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def access_key @access_key end |
#connection_timeout ⇒ Object (readonly)
Returns the value of attribute connection_timeout.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def connection_timeout @connection_timeout end |
#max_retry ⇒ Object (readonly)
Returns the value of attribute max_retry.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def max_retry @max_retry end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def port @port end |
#proxy_server ⇒ Object (readonly)
Returns the value of attribute proxy_server.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def proxy_server @proxy_server end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def secret_key @secret_key end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def server @server end |
#signature_method ⇒ Object (readonly)
Returns the value of attribute signature_method.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def signature_method @signature_method end |
#signature_version ⇒ Object (readonly)
Returns the value of attribute signature_version.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def signature_version @signature_version end |
#socket_timeout ⇒ Object (readonly)
Returns the value of attribute socket_timeout.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def socket_timeout @socket_timeout end |
#use_ssl ⇒ Object (readonly)
Returns the value of attribute use_ssl.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def use_ssl @use_ssl end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
82 83 84 |
# File 'lib/NIFTY.rb', line 82 def user_agent @user_agent end |