Class: Libgss::Network
- Inherits:
-
Object
- Object
- Libgss::Network
- Defined in:
- lib/libgss/network.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- 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) ⇒ Object
成功した場合自身のオブジェクトを返します。.
-
#login(extra = {}) ⇒ Boolean
GSSサーバに接続してログインの検証と処理を行います。.
-
#login!(extra = {}) ⇒ Object
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を返します.
- #uuid_gen ⇒ Object
Constructor Details
#initialize(base_url_or_host, options = {}) ⇒ Network
Libgss::Networkのコンストラクタです。
64 65 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 |
# File 'lib/libgss/network.rb', line 64 def initialize(base_url_or_host, = {}) @ssl_disabled = .delete(:ssl_disabled) if base_url_or_host =~ URI.regexp @base_url = base_url_or_host.sub(/\/\Z/, '') uri = URI.parse(@base_url) @ssl_base_url = build_https_url(uri) else uri = URI::Generic.build({scheme: "http", host: base_url_or_host, port: DEFAULT_HTTP_PORT}.update()) @base_url = uri.to_s @ssl_base_url = build_https_url(uri) end @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にする 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を生成します
197 198 199 200 201 202 |
# File 'lib/libgss/network.rb', line 197 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
219 220 221 222 223 |
# File 'lib/libgss/network.rb', line 219 def httpclient_for_action @httpclient_for_action ||= @ignore_signature_key ? @httpclient : HttpClientWithSignatureKey.new(@httpclient, self) end |
#ignore_signature_key? ⇒ Boolean
Returns コンストラクタに指定されたignore_signature_keyを返します.
134 135 136 |
# File 'lib/libgss/network.rb', line 134 def ignore_signature_key? @ignore_signature_key end |
#inspect ⇒ Object
96 97 98 99 100 |
# File 'lib/libgss/network.rb', line 96 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) ⇒ Object
Returns 成功した場合自身のオブジェクトを返します。.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/libgss/network.rb', line 172 def load_app_garden(path = nil) path ||= Dir.glob("config/app_garden.yml*").first raise ArgumentError, "file not found config/app_garden.yml* at #{Dir.pwd}" unless path # hash = YAML.load_file_with_erb(path, binding: binding) # tengine_supportが対応したらこんな感じで書きたい 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 self end |
#login(extra = {}) ⇒ Boolean
GSSサーバに接続してログインの検証と処理を行います。
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/libgss/network.rb', line 108 def login(extra = {}) @player_info[:id] = player_id @player_info.update(extra) attrs = @player_info.each_with_object({}){|(k,v), d| d[ "player[#{k}]" ] = v } res = Libgss.with_retry("login") do @httpclient.post(login_url, attrs, 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 |
#login!(extra = {}) ⇒ Object
GSSサーバに接続してログインの検証と処理を行います。
128 129 130 131 |
# File 'lib/libgss/network.rb', line 128 def login!(extra = {}) raise Error, "Login Failure" unless login(extra) self end |
#new_action_request ⇒ Libgss::ActionRequest
Returns アクション用リクエストを生成して返します.
151 152 153 |
# File 'lib/libgss/network.rb', line 151 def new_action_request ActionRequest.new(self, action_url, req_headers) end |
#new_async_action_request ⇒ Libgss::AsyncActionRequest
Returns 非同期アクション用リクエストを生成して返します.
156 157 158 |
# File 'lib/libgss/network.rb', line 156 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 保護付きアセットを取得するリクエストを生成して返します.
166 167 168 |
# File 'lib/libgss/network.rb', line 166 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 公開アセットを取得するリクエストを生成して返します.
161 162 163 |
# File 'lib/libgss/network.rb', line 161 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を設定します
209 210 211 212 213 |
# File 'lib/libgss/network.rb', line 209 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 メソッドをオーバーライドした場合に使用することを想定しています。それ以外の場合は使用しないでください。
145 146 147 148 |
# File 'lib/libgss/network.rb', line 145 def setup load_player_id login end |
#skip_verifying_signature? ⇒ Boolean
Returns コンストラクタに指定されたskip_verifying_signatureを返します.
139 140 141 |
# File 'lib/libgss/network.rb', line 139 def @skip_verifying_signature end |
#uuid_gen ⇒ Object
215 216 217 |
# File 'lib/libgss/network.rb', line 215 def uuid_gen @uuid_gen ||= UUID.new end |