Class: NIFTY::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/NIFTY.rb

Overview

HTTPリクエストの生成、実行、レスポンス解析を行う共通クラス

Direct Known Subclasses

Cloud::Base

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

オプションを指定してニフティクラウドAPIクライアントを生成します。

@option options [String] :access_key           

Raises:



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( options = {} )
  @default_host = @default_path = @default_port = nil

  if blank?(options[: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

  options = { 
    :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(options)

  options[:port] = DEFAULT_PORT if blank?(options[:port])

  raise ArgumentError, "No :access_key provided." if blank?(options[:access_key])
  raise ArgumentError, "No :secret_key provided." if blank?(options[:secret_key])
  raise ArgumentError, "No :use_ssl provided." if blank?(options[:use_ssl])
  raise ArgumentError, "Invalid :use_ssl provided. only 'true' allowed." unless true == options[:use_ssl]
  raise ArgumentError, "No :server provided." if blank?(options[:server])
  raise ArgumentError, "No :path provided." if blank?(options[:path])
  raise ArgumentError, "Invalid :port provided." unless valid_port?(options[:port])
  raise ArgumentError, "Invalid :signature_version provided." unless SIGNATURE_VERSION.include?(options[:signature_version].to_s)
  raise ArgumentError, "Invalid :signature_method provided." unless [SIGNATURE_METHOD_SHA1, SIGNATURE_METHOD_SHA256].include?(options[:signature_method].to_s)

  @access_key         = options[:access_key].to_s
  @secret_key         = options[:secret_key].to_s
  @use_ssl            = options[:use_ssl]
  @server             = options[:server].to_s
  @path               = options[:path].to_s
  @proxy_server       = options[:proxy_server].to_s
  @port               = options[:port].to_i
  @connection_timeout = options[:connection_timeout].to_s.to_i
  @socket_timeout     = options[:socket_timeout].to_s.to_i
  @user_agent         = options[:user_agent].to_s
  @max_retry          = options[:max_retry].to_s.to_i
  @signature_version  = options[:signature_version].to_s
  @signature_method   = options[:signature_method].to_s

  make_http
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



82
83
84
# File 'lib/NIFTY.rb', line 82

def access_key
  @access_key
end

#connection_timeoutObject (readonly)

Returns the value of attribute connection_timeout.



82
83
84
# File 'lib/NIFTY.rb', line 82

def connection_timeout
  @connection_timeout
end

#max_retryObject (readonly)

Returns the value of attribute max_retry.



82
83
84
# File 'lib/NIFTY.rb', line 82

def max_retry
  @max_retry
end

#pathObject (readonly)

Returns the value of attribute path.



82
83
84
# File 'lib/NIFTY.rb', line 82

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



82
83
84
# File 'lib/NIFTY.rb', line 82

def port
  @port
end

#proxy_serverObject (readonly)

Returns the value of attribute proxy_server.



82
83
84
# File 'lib/NIFTY.rb', line 82

def proxy_server
  @proxy_server
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



82
83
84
# File 'lib/NIFTY.rb', line 82

def secret_key
  @secret_key
end

#serverObject (readonly)

Returns the value of attribute server.



82
83
84
# File 'lib/NIFTY.rb', line 82

def server
  @server
end

#signature_methodObject (readonly)

Returns the value of attribute signature_method.



82
83
84
# File 'lib/NIFTY.rb', line 82

def signature_method
  @signature_method
end

#signature_versionObject (readonly)

Returns the value of attribute signature_version.



82
83
84
# File 'lib/NIFTY.rb', line 82

def signature_version
  @signature_version
end

#socket_timeoutObject (readonly)

Returns the value of attribute socket_timeout.



82
83
84
# File 'lib/NIFTY.rb', line 82

def socket_timeout
  @socket_timeout
end

#use_sslObject (readonly)

Returns the value of attribute use_ssl.



82
83
84
# File 'lib/NIFTY.rb', line 82

def use_ssl
  @use_ssl
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



82
83
84
# File 'lib/NIFTY.rb', line 82

def user_agent
  @user_agent
end