Class: Libgss::Network
- Inherits:
-
Object
- Object
- Libgss::Network
- Defined in:
- lib/libgss/network.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- API_VERSION =
"1.0.0".freeze
- 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.
-
#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を生成します.
-
#ignore_signature_key? ⇒ Boolean
コンストラクタに指定されたignore_signature_keyを返します.
-
#initialize(base_url_or_host, options = {}) ⇒ Network
constructor
Libgss::Networkのコンストラクタです。.
- #inspect ⇒ Object
-
#load_app_garden(path = "config/app_garden.yml") ⇒ 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 メソッドをオーバーライドした場合に使用することを想定しています。 それ以外の場合は使用しないでください。.
- #uuid_gen ⇒ Object
Constructor Details
#initialize(base_url_or_host, options = {}) ⇒ Network
Libgss::Networkのコンストラクタです。
62 63 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 |
# File 'lib/libgss/network.rb', line 62 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" @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] || nil @device_type_cd = [:device_type_cd] @client_version = [:client_version] @httpclient = HTTPClient.new @httpclient.ssl_config.verify_mode = nil # 自己署名の証明書をOKにする end |
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
32 33 34 |
# File 'lib/libgss/network.rb', line 32 def api_version @api_version end |
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
24 25 26 |
# File 'lib/libgss/network.rb', line 24 def auth_token @auth_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
20 21 22 |
# File 'lib/libgss/network.rb', line 20 def base_url @base_url end |
#client_version ⇒ Object
Returns the value of attribute client_version.
39 40 41 |
# File 'lib/libgss/network.rb', line 39 def client_version @client_version end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
27 28 29 |
# File 'lib/libgss/network.rb', line 27 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
26 27 28 |
# File 'lib/libgss/network.rb', line 26 def consumer_secret @consumer_secret end |
#device_type_cd ⇒ Object
Returns the value of attribute device_type_cd.
40 41 42 |
# File 'lib/libgss/network.rb', line 40 def device_type_cd @device_type_cd end |
#ignore_oauth_nonce ⇒ Object
Returns the value of attribute ignore_oauth_nonce.
28 29 30 |
# File 'lib/libgss/network.rb', line 28 def ignore_oauth_nonce @ignore_oauth_nonce end |
#oauth_nonce ⇒ Object
Returns the value of attribute oauth_nonce.
29 30 31 |
# File 'lib/libgss/network.rb', line 29 def oauth_nonce @oauth_nonce end |
#oauth_timestamp ⇒ Object
Returns the value of attribute oauth_timestamp.
30 31 32 |
# File 'lib/libgss/network.rb', line 30 def end |
#platform ⇒ Object
Returns the value of attribute platform.
33 34 35 |
# File 'lib/libgss/network.rb', line 33 def platform @platform end |
#player_id ⇒ Object
Returns the value of attribute player_id.
34 35 36 |
# File 'lib/libgss/network.rb', line 34 def player_id @player_id end |
#player_info ⇒ Object
Returns the value of attribute player_info.
35 36 37 |
# File 'lib/libgss/network.rb', line 35 def player_info @player_info end |
#public_asset_url_prefix ⇒ Object
Returns the value of attribute public_asset_url_prefix.
36 37 38 |
# File 'lib/libgss/network.rb', line 36 def public_asset_url_prefix @public_asset_url_prefix end |
#public_asset_url_suffix ⇒ Object
Returns the value of attribute public_asset_url_suffix.
37 38 39 |
# File 'lib/libgss/network.rb', line 37 def public_asset_url_suffix @public_asset_url_suffix end |
#signature_key ⇒ Object (readonly)
Returns the value of attribute signature_key.
24 25 26 |
# File 'lib/libgss/network.rb', line 24 def signature_key @signature_key end |
#ssl_base_url ⇒ Object (readonly)
Returns the value of attribute ssl_base_url.
21 22 23 |
# File 'lib/libgss/network.rb', line 21 def ssl_base_url @ssl_base_url end |
#ssl_disabled ⇒ Object (readonly)
Returns the value of attribute ssl_disabled.
22 23 24 |
# File 'lib/libgss/network.rb', line 22 def ssl_disabled @ssl_disabled end |
Instance Method Details
#generate_device_id(options = {device_type: 1}) ⇒ String
device_idを生成します
178 179 180 181 182 183 |
# File 'lib/libgss/network.rb', line 178 def generate_device_id( = {device_type: 1}) result = uuid_gen.generate player_info.update() player_info[:device_id] = result result end |
#ignore_signature_key? ⇒ Boolean
Returns コンストラクタに指定されたignore_signature_keyを返します.
128 129 130 |
# File 'lib/libgss/network.rb', line 128 def ignore_signature_key? @ignore_signature_key end |
#inspect ⇒ Object
91 92 93 94 95 |
# File 'lib/libgss/network.rb', line 91 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 = "config/app_garden.yml") ⇒ Object
Returns 成功した場合自身のオブジェクトを返します。.
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/libgss/network.rb', line 161 def load_app_garden(path = "config/app_garden.yml") hash = YAML.load_file_with_erb(path) 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サーバに接続してログインの検証と処理を行います。
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/libgss/network.rb', line 103 def login(extra = {}) attrs = @player_info.merge({ "player[id]" => player_id }) extra.each{|k, v| attrs[ "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サーバに接続してログインの検証と処理を行います。
122 123 124 125 |
# File 'lib/libgss/network.rb', line 122 def login!(extra = {}) raise Error, "Login Failure" unless login(extra) self end |
#new_action_request ⇒ Libgss::ActionRequest
Returns アクション用リクエストを生成して返します.
140 141 142 |
# File 'lib/libgss/network.rb', line 140 def new_action_request ActionRequest.new(httpclient_for_action, action_url, req_headers) end |
#new_async_action_request ⇒ Libgss::AsyncActionRequest
Returns 非同期アクション用リクエストを生成して返します.
145 146 147 |
# File 'lib/libgss/network.rb', line 145 def new_async_action_request AsyncActionRequest.new(httpclient_for_action, async_action_url, async_result_url, req_headers) end |
#new_protected_asset_request(asset_path) ⇒ Libgss::AssetRequest
Returns 保護付きアセットを取得するリクエストを生成して返します.
155 156 157 |
# File 'lib/libgss/network.rb', line 155 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 公開アセットを取得するリクエストを生成して返します.
150 151 152 |
# File 'lib/libgss/network.rb', line 150 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を設定します
190 191 192 193 194 |
# File 'lib/libgss/network.rb', line 190 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 メソッドをオーバーライドした場合に使用することを想定しています。それ以外の場合は使用しないでください。
134 135 136 137 |
# File 'lib/libgss/network.rb', line 134 def setup load_player_id login end |
#uuid_gen ⇒ Object
196 197 198 |
# File 'lib/libgss/network.rb', line 196 def uuid_gen @uuid_gen ||= UUID.new end |