Class: Libgss::Network
- Inherits:
-
Object
- Object
- Libgss::Network
- Defined in:
- lib/libgss/network.rb
Constant Summary collapse
- Error =
Libgss::Error
- PRODUCTION_HTTP_PORT =
80
- PRODUCTION_HTTPS_PORT =
443
- DEFAULT_HTTP_PORT =
(ENV['DEFAULT_HTTP_PORT' ] || 80).to_i
- DEFAULT_HTTPS_PORT =
(ENV['DEFAULT_HTTPS_PORT'] || 443).to_i
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#client_version ⇒ Object
Returns the value of attribute client_version.
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#device_type_cd ⇒ Object
Returns the value of attribute device_type_cd.
-
#ignore_oauth_nonce ⇒ Object
Returns the value of attribute ignore_oauth_nonce.
-
#oauth_nonce ⇒ Object
Returns the value of attribute oauth_nonce.
-
#oauth_timestamp ⇒ Object
Returns the value of attribute oauth_timestamp.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#player_id ⇒ Object
Returns the value of attribute player_id.
-
#player_info ⇒ Object
Returns the value of attribute player_info.
-
#public_asset_url_prefix ⇒ Object
Returns the value of attribute public_asset_url_prefix.
-
#public_asset_url_suffix ⇒ Object
Returns the value of attribute public_asset_url_suffix.
-
#signature_key ⇒ Object
readonly
Returns the value of attribute signature_key.
-
#skip_verifying_signature ⇒ Object
Returns the value of attribute skip_verifying_signature.
-
#ssl_base_url ⇒ Object
readonly
Returns the value of attribute ssl_base_url.
-
#ssl_disabled ⇒ Object
readonly
Returns the value of attribute ssl_disabled.
Instance Method Summary collapse
-
#generate_device_id(options = {device_type: 1}) ⇒ String
device_idを生成します.
- #httpclient_for_action ⇒ Object
-
#ignore_signature_key? ⇒ Boolean
コンストラクタに指定されたignore_signature_keyを返します.
-
#initialize(base_url_or_host, options = {}) ⇒ Network
constructor
Libgss::Networkのコンストラクタです。.
- #inspect ⇒ Object
-
#load_app_garden(path = nil) ⇒ Libgss::Network
Selfを返します。.
-
#login(extra = {}) ⇒ Boolean
GSSサーバに接続してログインの検証と処理を行います。.
-
#login!(extra = {}) ⇒ Object
GSSサーバに接続してログインの検証と処理を行います。.
-
#login_and_status(extra = {}) ⇒ Integer, ...
GSSサーバに接続してログインの検証と処理を行います。.
-
#new_action_request ⇒ Libgss::ActionRequest
アクション用リクエストを生成して返します.
-
#new_async_action_request ⇒ Libgss::AsyncActionRequest
非同期アクション用リクエストを生成して返します.
-
#new_protected_asset_request(asset_path) ⇒ Libgss::AssetRequest
保護付きアセットを取得するリクエストを生成して返します.
-
#new_public_asset_request(asset_path) ⇒ Libgss::AssetRequest
公開アセットを取得するリクエストを生成して返します.
-
#set_device_id(device_id, options = {device_type: 1}) ⇒ Object
device_idを設定します.
-
#setup ⇒ Object
load_player_id メソッドをオーバーライドした場合に使用することを想定しています。 それ以外の場合は使用しないでください。.
-
#skip_verifying_signature? ⇒ Boolean
コンストラクタに指定されたskip_verifying_signatureを返します.
-
#status ⇒ Hash
サーバの諸情報を表すデータ.
- #uuid_gen ⇒ Object
Constructor Details
#initialize(base_url_or_host, options = {}) ⇒ Network
Libgss::Networkのコンストラクタです。
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/libgss/network.rb', line 66 def initialize(base_url_or_host, = {}) if base_url_or_host =~ URI.regexp @base_url = base_url_or_host.sub(/\/\Z/, '') uri = URI.parse(@base_url) else if config_path = search_file(".libgss.yml") config = YAML.load_file_with_erb(config_path) = config[base_url_or_host.to_s].deep_symbolize_keys.update() end uri = URI::Generic.build({scheme: "http", host: base_url_or_host, port: DEFAULT_HTTP_PORT}.update()) @base_url = uri.to_s end @ssl_base_url = build_https_url(uri, [:https_port]) @ssl_disabled = .delete(:ssl_disabled) @ssl_base_url = @base_url if @ssl_disabled @platform = [:platform] || "fontana" @api_version = [:api_version] || "1.0.0" @player_id = [:player_id] @player_info = [:player_info] || {} @consumer_secret = [:consumer_secret] || ENV["CONSUMER_SECRET"] @ignore_signature_key = !![:ignore_signature_key] @ignore_oauth_nonce = !![:ignore_oauth_nonce] @oauth_nonce = [:oauth_nonce] || nil @oauth_timestamp = [:oauth_timestamp] || nil @device_type_cd = [:device_type_cd] @client_version = [:client_version] @skip_verifying_signature = [:skip_verifying_signature] @httpclient = HTTPClient.new @httpclient.ssl_config.verify_mode = nil # 自己署名の証明書をOKにする load_app_garden end |
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
30 31 32 |
# File 'lib/libgss/network.rb', line 30 def api_version @api_version end |
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
22 23 24 |
# File 'lib/libgss/network.rb', line 22 def auth_token @auth_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
18 19 20 |
# File 'lib/libgss/network.rb', line 18 def base_url @base_url end |
#client_version ⇒ Object
Returns the value of attribute client_version.
37 38 39 |
# File 'lib/libgss/network.rb', line 37 def client_version @client_version end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
25 26 27 |
# File 'lib/libgss/network.rb', line 25 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
24 25 26 |
# File 'lib/libgss/network.rb', line 24 def consumer_secret @consumer_secret end |
#device_type_cd ⇒ Object
Returns the value of attribute device_type_cd.
38 39 40 |
# File 'lib/libgss/network.rb', line 38 def device_type_cd @device_type_cd end |
#ignore_oauth_nonce ⇒ Object
Returns the value of attribute ignore_oauth_nonce.
26 27 28 |
# File 'lib/libgss/network.rb', line 26 def ignore_oauth_nonce @ignore_oauth_nonce end |
#oauth_nonce ⇒ Object
Returns the value of attribute oauth_nonce.
27 28 29 |
# File 'lib/libgss/network.rb', line 27 def oauth_nonce @oauth_nonce end |
#oauth_timestamp ⇒ Object
Returns the value of attribute oauth_timestamp.
28 29 30 |
# File 'lib/libgss/network.rb', line 28 def @oauth_timestamp end |
#platform ⇒ Object
Returns the value of attribute platform.
31 32 33 |
# File 'lib/libgss/network.rb', line 31 def platform @platform end |
#player_id ⇒ Object
Returns the value of attribute player_id.
32 33 34 |
# File 'lib/libgss/network.rb', line 32 def player_id @player_id end |
#player_info ⇒ Object
Returns the value of attribute player_info.
33 34 35 |
# File 'lib/libgss/network.rb', line 33 def player_info @player_info end |
#public_asset_url_prefix ⇒ Object
Returns the value of attribute public_asset_url_prefix.
34 35 36 |
# File 'lib/libgss/network.rb', line 34 def public_asset_url_prefix @public_asset_url_prefix end |
#public_asset_url_suffix ⇒ Object
Returns the value of attribute public_asset_url_suffix.
35 36 37 |
# File 'lib/libgss/network.rb', line 35 def public_asset_url_suffix @public_asset_url_suffix end |
#signature_key ⇒ Object (readonly)
Returns the value of attribute signature_key.
22 23 24 |
# File 'lib/libgss/network.rb', line 22 def signature_key @signature_key end |
#skip_verifying_signature ⇒ Object
Returns the value of attribute skip_verifying_signature.
40 41 42 |
# File 'lib/libgss/network.rb', line 40 def @skip_verifying_signature end |
#ssl_base_url ⇒ Object (readonly)
Returns the value of attribute ssl_base_url.
19 20 21 |
# File 'lib/libgss/network.rb', line 19 def ssl_base_url @ssl_base_url end |
#ssl_disabled ⇒ Object (readonly)
Returns the value of attribute ssl_disabled.
20 21 22 |
# File 'lib/libgss/network.rb', line 20 def ssl_disabled @ssl_disabled end |
Instance Method Details
#generate_device_id(options = {device_type: 1}) ⇒ String
device_idを生成します
240 241 242 243 244 245 |
# File 'lib/libgss/network.rb', line 240 def generate_device_id( = {device_type: 1}) result = uuid_gen.generate player_info.update() player_info[:device_id] = result result end |
#httpclient_for_action ⇒ Object
262 263 264 265 266 |
# File 'lib/libgss/network.rb', line 262 def httpclient_for_action @httpclient_for_action ||= @ignore_signature_key ? @httpclient : HttpClientWithSignatureKey.new(@httpclient, self) end |
#ignore_signature_key? ⇒ Boolean
Returns コンストラクタに指定されたignore_signature_keyを返します.
173 174 175 |
# File 'lib/libgss/network.rb', line 173 def ignore_signature_key? @ignore_signature_key end |
#inspect ⇒ Object
109 110 111 112 113 |
# File 'lib/libgss/network.rb', line 109 def inspect r = "#<#{self.class.name}:#{self.object_id} " fields = (instance_variables - [:@httpclient]).map{|f| "#{f}=#{instance_variable_get(f).inspect}"} r << fields.join(", ") << ">" end |
#load_app_garden(path = nil) ⇒ Libgss::Network
Returns selfを返します。.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/libgss/network.rb', line 211 def load_app_garden(path = nil) if path raise ArgumentError, "file not found config/app_garden.yml* at #{Dir.pwd}" unless File.readable?(path) else path = search_file("app_garden.yml") return self unless path end # hash = YAML.load_file_with_erb(path, binding: binding) # tengine_supportが対応したらこんな感じで書きたい puts "loading #{path}" erb = ERB.new(IO.read(path)) erb.filename = path text = erb.result(binding) # Libgss::FontanaをFontanaとしてアクセスできるようにしたいので、このbindingの指定が必要です hash = YAML.load(text) self.consumer_secret = hash["consumer_secret"] if platform = hash["platform"] name = (platform["name"] || "").strip unless name.empty? self.platform = name end end return self end |
#login(extra = {}) ⇒ Boolean
GSSサーバに接続してログインの検証と処理を行います。
143 144 145 146 147 148 |
# File 'lib/libgss/network.rb', line 143 def login(extra = {}) case login_and_status(extra) when 200...300 then true else false end end |
#login!(extra = {}) ⇒ Object
GSSサーバに接続してログインの検証と処理を行います。
155 156 157 158 159 160 161 162 |
# File 'lib/libgss/network.rb', line 155 def login!(extra = {}) result = login_and_status(extra) case result when 200...300 then return self when ErrorResponse then raise result else raise Error, "Login Failure" end end |
#login_and_status(extra = {}) ⇒ Integer, ...
GSSサーバに接続してログインの検証と処理を行います。
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/libgss/network.rb', line 121 def login_and_status(extra = {}) @player_info[:id] = player_id @player_info.update(extra) # attrs = @player_info.each_with_object({}){|(k,v), d| d[ "player[#{k}]" ] = v } json = {"player" => @player_info}.to_json res = Libgss.with_retry("login") do @httpclient.post(login_url, json, req_headers) end process_json_response(res) do |obj| @player_id ||= obj["player_id"] @auth_token = obj["auth_token"] @signature_key = obj["signature_key"] !!@auth_token && !!@signature_key end end |
#new_action_request ⇒ Libgss::ActionRequest
Returns アクション用リクエストを生成して返します.
190 191 192 |
# File 'lib/libgss/network.rb', line 190 def new_action_request ActionRequest.new(self, action_url, req_headers) end |
#new_async_action_request ⇒ Libgss::AsyncActionRequest
Returns 非同期アクション用リクエストを生成して返します.
195 196 197 |
# File 'lib/libgss/network.rb', line 195 def new_async_action_request AsyncActionRequest.new(self, async_action_url, async_result_url, req_headers) end |
#new_protected_asset_request(asset_path) ⇒ Libgss::AssetRequest
Returns 保護付きアセットを取得するリクエストを生成して返します.
205 206 207 |
# File 'lib/libgss/network.rb', line 205 def new_protected_asset_request(asset_path) AssetRequest.new(@httpclient, protected_asset_url(asset_path), req_headers) end |
#new_public_asset_request(asset_path) ⇒ Libgss::AssetRequest
Returns 公開アセットを取得するリクエストを生成して返します.
200 201 202 |
# File 'lib/libgss/network.rb', line 200 def new_public_asset_request(asset_path) AssetRequest.new(@httpclient, public_asset_url(asset_path), req_headers) end |
#set_device_id(device_id, options = {device_type: 1}) ⇒ Object
device_idを設定します
252 253 254 255 256 |
# File 'lib/libgss/network.rb', line 252 def set_device_id(device_id, = {device_type: 1}) if player_info[:device_id] = device_id player_info.update() end end |
#setup ⇒ Object
load_player_id メソッドをオーバーライドした場合に使用することを想定しています。 それ以外の場合は使用しないでください。
184 185 186 187 |
# File 'lib/libgss/network.rb', line 184 def setup load_player_id login end |
#skip_verifying_signature? ⇒ Boolean
Returns コンストラクタに指定されたskip_verifying_signatureを返します.
178 179 180 |
# File 'lib/libgss/network.rb', line 178 def @skip_verifying_signature end |
#status ⇒ Hash
Returns サーバの諸情報を表すデータ.
165 166 167 168 169 170 |
# File 'lib/libgss/network.rb', line 165 def status res = Libgss.with_retry("status"){ @httpclient.get(status_url) } process_json_response(res) do |obj| return obj end end |
#uuid_gen ⇒ Object
258 259 260 |
# File 'lib/libgss/network.rb', line 258 def uuid_gen @uuid_gen ||= UUID.new end |