libgss 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +16 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/lib/libgss/action.rb +25 -0
- data/lib/libgss/action_request.rb +302 -0
- data/lib/libgss/asset_request.rb +29 -0
- data/lib/libgss/network.rb +105 -0
- data/lib/libgss/outputs.rb +23 -0
- data/lib/libgss/version.rb +3 -0
- data/lib/libgss.rb +11 -0
- data/libgss.gemspec +27 -0
- data/spec/libgss/action_request_spec.rb +160 -0
- data/spec/libgss/actions/dictionary_spec.rb +39 -0
- data/spec/libgss/actions/friendship_spec.rb +139 -0
- data/spec/libgss/actions/game_data_spec.rb +81 -0
- data/spec/libgss/actions/int_range_spec.rb +46 -0
- data/spec/libgss/actions/log_spec.rb +58 -0
- data/spec/libgss/actions/master_spec.rb +142 -0
- data/spec/libgss/actions/probability_spec.rb +70 -0
- data/spec/libgss/actions/ruby_stored_script_spec.rb +62 -0
- data/spec/libgss/actions/schedule_spec.rb +49 -0
- data/spec/libgss/asset_request_spec.rb +33 -0
- data/spec/libgss/network_spec.rb +75 -0
- data/spec/protected_assets/Icon.png +0 -0
- data/spec/public_assets/Default.png +0 -0
- data/spec/spec_helper.rb +9 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjBlOTY0MzIyNTBkNDMzY2ExMGE5NDk2YzQzOTg2NWExNmJhOWQ0Yg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2IyMzllMWM1ZWMyY2M3ZGFmOTA2MTJhNWQzNWNlNGE1ODJhOTMwYQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2M1YWZkNmQ2NTk0NzMwOWRlY2U3NGMwYjE5MDNkZTVkNWM3Yjg5ZWVlZjli
|
10
|
+
MmU2OTU4MDFiMDZhNzc3OGUwZWU2MzIyNGYxMTZhMTA5Njk3NzQ5NmFiNjU5
|
11
|
+
MTdmNDJiNDdkYjhjOGNkMmExNWRlOTA4MTNkMTBiM2RjYTg5ZGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTU1OWRkNmMyODk4OWRjNDRlYmM3OTVjYmEzNzVjYTVhNGU1Y2FkNDc4NDYw
|
14
|
+
NjhhYmYzMGM1YmMxMWU1M2ZkMzJjNzA1ZDIyMjM2NTMyNzRiMjcxN2M0OTBj
|
15
|
+
ZDRlMDdkZjFkNmVjZDcyNDNiMzEwODMwZDU1ZmIyYTY3MjY2ZTY=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
libgss (0.0.1)
|
5
|
+
httpclient
|
6
|
+
json
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.2.3)
|
12
|
+
httpclient (2.3.3)
|
13
|
+
json (1.7.7)
|
14
|
+
rake (10.0.4)
|
15
|
+
rspec (2.13.0)
|
16
|
+
rspec-core (~> 2.13.0)
|
17
|
+
rspec-expectations (~> 2.13.0)
|
18
|
+
rspec-mocks (~> 2.13.0)
|
19
|
+
rspec-core (2.13.1)
|
20
|
+
rspec-expectations (2.13.0)
|
21
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
22
|
+
rspec-mocks (2.13.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler (~> 1.3)
|
29
|
+
libgss!
|
30
|
+
rake
|
31
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 akima
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Libgss
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'libgss'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install libgss
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'libgss'
|
3
|
+
|
4
|
+
module Libgss
|
5
|
+
|
6
|
+
class Action
|
7
|
+
|
8
|
+
attr_accessor :id
|
9
|
+
|
10
|
+
def initialize(id, args)
|
11
|
+
@id = id
|
12
|
+
@args = args
|
13
|
+
end
|
14
|
+
|
15
|
+
def with(new_id)
|
16
|
+
@id = new_id
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
{"id" => id}.update(@args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'libgss'
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Libgss
|
8
|
+
|
9
|
+
class ActionRequest
|
10
|
+
|
11
|
+
STATUS_PREPARING = 0
|
12
|
+
STATUS_SENDING = 1
|
13
|
+
STATUS_WAITING = 2
|
14
|
+
STATUS_RECEIVED = 3
|
15
|
+
STATUS_SUCCESS = 4
|
16
|
+
STATUS_ERROR = 5
|
17
|
+
STATUS_TIMEOUT = 6
|
18
|
+
|
19
|
+
|
20
|
+
# 読み込みのみ、書き込み不可
|
21
|
+
attr_reader :action_url
|
22
|
+
attr_reader :status, :outputs
|
23
|
+
|
24
|
+
# コンストラクタ
|
25
|
+
def initialize(httpclient, action_url)
|
26
|
+
@httpclient = httpclient
|
27
|
+
@action_url = action_url
|
28
|
+
@status = STATUS_PREPARING
|
29
|
+
@actions = []
|
30
|
+
@action_id = 0;
|
31
|
+
end
|
32
|
+
|
33
|
+
def next_action_id
|
34
|
+
@action_id += 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_action(hash)
|
38
|
+
action = Action.new(next_action_id, hash)
|
39
|
+
@actions << action
|
40
|
+
action
|
41
|
+
end
|
42
|
+
|
43
|
+
# アクション群を実行するために実際にHTTPリクエストを送信します。
|
44
|
+
def send_request(&callback)
|
45
|
+
res = @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json)
|
46
|
+
r = JSON.parse(res.body)
|
47
|
+
# puts res.body
|
48
|
+
@outputs = Outputs.new(r["outputs"])
|
49
|
+
callback.call(@outputs) if callback
|
50
|
+
end
|
51
|
+
|
52
|
+
# 条件に該当するデータを取得
|
53
|
+
# @param [String] name 対象となるコレクション名
|
54
|
+
# @param [Hash] conditions 検索条件
|
55
|
+
# @param [Array<Array<String, Integer>>] order フィールド名と(1 or -1)の組み合わせの配列
|
56
|
+
# @return [Array<Libgss::JsonObject>]該当したデータを表すJSONオブジェクトの配列
|
57
|
+
def find_all(name, conditions = nil, order = nil)
|
58
|
+
args = {action: "all", name: name}
|
59
|
+
args[:conditions] = conditions if conditions
|
60
|
+
args[:order] = order if order
|
61
|
+
add_action(args)
|
62
|
+
end
|
63
|
+
|
64
|
+
# ページネーション付きで条件に該当するデータを取得
|
65
|
+
# @param [String] name 対象となるコレクション名
|
66
|
+
# @param [String] page 取得するページ
|
67
|
+
# @param [String] per_page 1ページあたりの件数
|
68
|
+
# @param [Hash] conditions 検索条件
|
69
|
+
# @param [Array<Array<String, Integer>>] order フィールド名と(1 or -1)の組み合わせの配列
|
70
|
+
# @return [Array<Libgss::JsonObject>]該当したデータを表すJSONオブジェクトの配列
|
71
|
+
def paginate(name, page, per_page, conditions = nil, order = nil)
|
72
|
+
args = {action: "all", name: name, page: page, per_page: per_page}
|
73
|
+
args[:conditions] = conditions if conditions
|
74
|
+
args[:order] = order if order
|
75
|
+
add_action(args)
|
76
|
+
end
|
77
|
+
|
78
|
+
# 条件に該当するデータを取得
|
79
|
+
# @param [String] name 対象となるコレクション名
|
80
|
+
# @param [Hash] conditions 検索条件
|
81
|
+
# @return [Integer] 該当したデータの件数
|
82
|
+
def count(name, conditions = nil)
|
83
|
+
args = {action: "count", name: name}
|
84
|
+
args[:conditions] = conditions if conditions
|
85
|
+
add_action(args)
|
86
|
+
end
|
87
|
+
|
88
|
+
# 条件に該当するデータを1件だけ取得
|
89
|
+
# @param [String] name 対象となるコレクション名
|
90
|
+
# @param [Hash] conditions 検索条件
|
91
|
+
# @param [Array<Array<String, Integer>>] order フィールド名と(1 or -1)の組み合わせの配列
|
92
|
+
# @return [Libgss::JsonObject] 該当したデータを表すJSONオブジェクト
|
93
|
+
def find_first(name, conditions = nil, order = nil)
|
94
|
+
args = {action: "first", name: name}
|
95
|
+
args[:conditions] = conditions if conditions
|
96
|
+
args[:order] = order if order
|
97
|
+
add_action(args)
|
98
|
+
end
|
99
|
+
|
100
|
+
# 辞書テーブルからinputに対応するoutputの値を返します。
|
101
|
+
# @param [String] name 対象となる辞書のコレクション名
|
102
|
+
# @param [String] input 入力オブジェクトの文字列表現
|
103
|
+
# @param [Hash] conditions 検索条件
|
104
|
+
# @return [Object] outputの値を示すJSONオブジェクト
|
105
|
+
def get_by_dictionary(name, input, conditions = nil)
|
106
|
+
args = {action: "get", name: name, input: input}
|
107
|
+
args[:conditions] = conditions if conditions
|
108
|
+
add_action(args)
|
109
|
+
end
|
110
|
+
|
111
|
+
# 期間テーブルからinputに対応するoutputの値を返します。
|
112
|
+
# @param [String] name 対象となる機関テーブルのコレクション名
|
113
|
+
# @param [Integer] time 対象となるUNIX時刻
|
114
|
+
# @param [Hash] conditions 検索条件
|
115
|
+
# @return [Object] outputの値を示すJSONオブジェクト
|
116
|
+
def get_by_schedule(name, time = Time.now.to_i, conditions = nil)
|
117
|
+
args = {action: "get", name: name, time: time}
|
118
|
+
args[:conditions] = conditions if conditions
|
119
|
+
add_action(args)
|
120
|
+
end
|
121
|
+
|
122
|
+
# 整数範囲テーブルからinputに対応するoutputの値を返します。
|
123
|
+
# @param [String] name 対象となる整数範囲テーブルのコレクション名
|
124
|
+
# @param [Integer] input 対象となる入力値
|
125
|
+
# @param [Hash] conditions 検索条件
|
126
|
+
# @return [Object] outputの値を示すJSONオブジェクト
|
127
|
+
def get_by_int_range(name, input, conditions = nil)
|
128
|
+
args = {action: "get", name: name, input: input}
|
129
|
+
args[:conditions] = conditions if conditions
|
130
|
+
add_action(args)
|
131
|
+
end
|
132
|
+
|
133
|
+
# 確率テーブルからinputに対応するoutputの値を返します。
|
134
|
+
# diceがあるのであまり使われないはず。
|
135
|
+
#
|
136
|
+
# @param [String] name 対象となる確率テーブルのコレクション名
|
137
|
+
# @param [String] value 対象となるオブジェクトの文字列表現
|
138
|
+
# @param [Hash] conditions 検索条件
|
139
|
+
# @return [Object] valueの値を示すJSONオブジェクト
|
140
|
+
def get_by_probability(name, value, conditions = nil)
|
141
|
+
args = {action: "get", name: name, value: value}
|
142
|
+
args[:conditions] = conditions if conditions
|
143
|
+
add_action(args)
|
144
|
+
end
|
145
|
+
|
146
|
+
# プレイヤーからplayer_idに対応するプレイヤーを返します
|
147
|
+
#
|
148
|
+
# @param [String] name 対象となるコレクション名
|
149
|
+
# @param [String] player_id 対象となるplayer_id
|
150
|
+
# @param [Hash] conditions 検索条件
|
151
|
+
# @return [Object] プレイヤーを表すJSONオブジェクト
|
152
|
+
def get_by_player(name = "Player", player_id = nil)
|
153
|
+
args = {action: "get"}
|
154
|
+
args[:name] = name if name
|
155
|
+
args[:player_id] = player_id.to_s if player_id
|
156
|
+
add_action(args)
|
157
|
+
end
|
158
|
+
|
159
|
+
# ゲームデータからplayer_idに対応するゲームデータを返します
|
160
|
+
#
|
161
|
+
# @param [String] name 対象となるコレクション名
|
162
|
+
# @param [String] player_id 対象となるplayer_id
|
163
|
+
# @param [Hash] conditions 検索条件
|
164
|
+
# @return [Object] ゲームデータを表すJSONオブジェクト
|
165
|
+
def get_by_game_data(name = "GameData", player_id = nil)
|
166
|
+
args = {action: "get"}
|
167
|
+
args[:name] = name if name
|
168
|
+
args[:player_id] = player_id.to_s if player_id
|
169
|
+
add_action(args)
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
# ログあるいは履歴を登録します。
|
176
|
+
#
|
177
|
+
# @param [String] name 対象となるコレクション名
|
178
|
+
# @param [Hash] attrs 属性
|
179
|
+
# @return
|
180
|
+
def create(name, attrs)
|
181
|
+
args = {action: "create", name: name, attrs: attrs}
|
182
|
+
add_action(args)
|
183
|
+
end
|
184
|
+
|
185
|
+
# プレイヤー、ゲームデータを更新します。
|
186
|
+
# @param [String] name 対象となるコレクション名
|
187
|
+
# @param [Hash] player_id 対象を特定するためのID。
|
188
|
+
# @param [Hash] attrs 属性。対象を特定するためのplayer_idを含みません。
|
189
|
+
# @return
|
190
|
+
def update(name, attrs, player_id = nil)
|
191
|
+
args = {action: "update", name: name, attrs: attrs}
|
192
|
+
args[:player_id] = player_id.to_s if player_id
|
193
|
+
add_action(args)
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
# 確率テーブルに従って、発生させた乱数から得られた値
|
198
|
+
# @param [String] name 対象となるコレクション名
|
199
|
+
# @param [Hash] conditions 検索条件
|
200
|
+
# @return [Object] 確率テーブルの値
|
201
|
+
def dice(name, conditions = nil)
|
202
|
+
args = {action: "dice", name: name}
|
203
|
+
args[:conditions] = conditions if conditions
|
204
|
+
add_action(args)
|
205
|
+
end
|
206
|
+
|
207
|
+
# ストアドスクリプトを実行します。
|
208
|
+
# @param [String] name 対象となるコレクション名
|
209
|
+
# @param [Hash] key 対象となるスクリプトのキー
|
210
|
+
# @param [Hash] args スクリプトに渡す引数
|
211
|
+
# @return [Object] ストアドスクリプトの結果
|
212
|
+
def execute(name, key, args = nil)
|
213
|
+
action_args = {action: "execute", name: name, key: key}
|
214
|
+
action_args[:args] = args if args
|
215
|
+
add_action(action_args)
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
# サーバの現在時刻を返します。
|
221
|
+
# @return [Time] 現在時刻を表すUNIX時刻
|
222
|
+
def server_time()
|
223
|
+
add_action(action: "server_time")
|
224
|
+
end
|
225
|
+
|
226
|
+
# 引数timeに指定された時刻の運用日付を返します。
|
227
|
+
# 「運用日付」とは AppGarden の[ゲーム内日付変更時刻]で
|
228
|
+
# 設定された時刻を日付の開始時刻とした場合の日付(Ruby
|
229
|
+
# ストアドスクリプト内ではDateオブジェクト)を返します。
|
230
|
+
#
|
231
|
+
# @param [Time] time time に指定された時刻(省略時は現在時刻)の運用日付
|
232
|
+
# @return [Date] timeが属する運用日付
|
233
|
+
def server_date(time = nil)
|
234
|
+
args = {action: "server_date"}
|
235
|
+
args[:time] = time if time
|
236
|
+
add_action(args)
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
# # フレンドシップを更新します。
|
242
|
+
# # @param [String] name 対象となるコレクション名
|
243
|
+
# # @param [Hash] attrs 属性。対象を特定するためのIDを含みます。
|
244
|
+
# # @return
|
245
|
+
# def update_friendship(name, attrs)
|
246
|
+
# end
|
247
|
+
|
248
|
+
# # フレンドシップを削除します。
|
249
|
+
# # @param [String] name 対象となるコレクション名
|
250
|
+
# # @param [Hash] target 対象となるフレンドのID
|
251
|
+
# # @return
|
252
|
+
# def delete_friendship(name, target)
|
253
|
+
# end
|
254
|
+
|
255
|
+
# フレンドシップを申請をします。
|
256
|
+
# @param [String] name 対象となるコレクション名
|
257
|
+
# @param [Hash] target 対象となるフレンドのID
|
258
|
+
# @return
|
259
|
+
def apply(name, target)
|
260
|
+
args = {action: "apply", name: name, target: target}
|
261
|
+
add_action(args)
|
262
|
+
end
|
263
|
+
|
264
|
+
# フレンドシップの申請を承認します。
|
265
|
+
# @param [String] name 対象となるコレクション名
|
266
|
+
# @param [Hash] target 対象となるフレンドのID
|
267
|
+
# @return
|
268
|
+
def approve(name, target)
|
269
|
+
args = {action: "approve", name: name, target: target}
|
270
|
+
add_action(args)
|
271
|
+
end
|
272
|
+
|
273
|
+
# フレンドシップの申請のキャンセル、申請却下、フレンド解除をします。
|
274
|
+
# @param [String] name 対象となるコレクション名
|
275
|
+
# @param [Hash] target 対象となるフレンドのID
|
276
|
+
# @return
|
277
|
+
def breakoff(name, target)
|
278
|
+
args = {action: "breakoff", name: name, target: target}
|
279
|
+
add_action(args)
|
280
|
+
end
|
281
|
+
|
282
|
+
# フレンドをブロック(ブラックリスト追加)します。
|
283
|
+
# @param [String] name 対象となるコレクション名
|
284
|
+
# @param [Hash] target 対象となるフレンドのID
|
285
|
+
# @return
|
286
|
+
def block(name, target)
|
287
|
+
args = {action: "block", name: name, target: target}
|
288
|
+
add_action(args)
|
289
|
+
end
|
290
|
+
|
291
|
+
# フレンドをブロックの解除(ブラックリストから除外)します。
|
292
|
+
# @param [String] name 対象となるコレクション名
|
293
|
+
# @param [Hash] target 対象となるフレンドのID
|
294
|
+
# @return
|
295
|
+
def unblock(name, target)
|
296
|
+
args = {action: "unblock", name: name, target: target}
|
297
|
+
add_action(args)
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Libgss
|
3
|
+
class AssetRequest
|
4
|
+
|
5
|
+
STATUS_PREPARING = 0
|
6
|
+
STATUS_SENDING = 1
|
7
|
+
STATUS_WAITING = 2
|
8
|
+
STATUS_RECEIVED = 3
|
9
|
+
STATUS_SUCCESS = 4
|
10
|
+
STATUS_ERROR = 5
|
11
|
+
STATUS_TIMEOUT = 6
|
12
|
+
|
13
|
+
attr_reader :url, :status, :response_data
|
14
|
+
|
15
|
+
# コンストラクタ
|
16
|
+
def initialize(httpclient, url)
|
17
|
+
@httpclient = httpclient
|
18
|
+
@url = url
|
19
|
+
@response_data = nil
|
20
|
+
@status = STATUS_PREPARING
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_request(&callback)
|
24
|
+
res = @httpclient.get(url)
|
25
|
+
@response_data = res.body
|
26
|
+
callback.call(@response_data) if callback
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'libgss'
|
3
|
+
|
4
|
+
require 'httpclient'
|
5
|
+
require 'json'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module Libgss
|
9
|
+
|
10
|
+
class Network
|
11
|
+
|
12
|
+
API_VERSION = "1.0.0".freeze
|
13
|
+
|
14
|
+
attr_reader :base_url
|
15
|
+
attr_reader :ssl_base_url
|
16
|
+
attr_reader :ssl_disabled
|
17
|
+
|
18
|
+
attr_reader :auth_token, :signature_key
|
19
|
+
|
20
|
+
attr_accessor :api_version
|
21
|
+
attr_accessor :platform
|
22
|
+
attr_accessor :player_id
|
23
|
+
attr_accessor :public_asset_url_prefix
|
24
|
+
attr_accessor :public_asset_url_suffix
|
25
|
+
|
26
|
+
|
27
|
+
DEFAULT_HTTP_PORT = (ENV['DEFAULT_HTTP_PORT'] || 80).to_i
|
28
|
+
DEFAULT_HTTPS_PORT = (ENV['DEFAULT_HTTPS_PORT'] || 443).to_i
|
29
|
+
|
30
|
+
def initialize(base_url_or_host, options = {})
|
31
|
+
@ssl_disabled = options.delete(:ssl_disabled)
|
32
|
+
if base_url_or_host =~ URI.regexp
|
33
|
+
@base_url = base_url_or_host
|
34
|
+
uri = URI.parse(@base_url)
|
35
|
+
@ssl_base_url = build_https_url(uri)
|
36
|
+
else
|
37
|
+
uri = URI::Generic.build({scheme: "http", host: base_url_or_host, port: DEFAULT_HTTP_PORT}.update(options))
|
38
|
+
@base_url = uri.to_s
|
39
|
+
@ssl_base_url = build_https_url(uri)
|
40
|
+
end
|
41
|
+
@ssl_base_url = @base_url if @ssl_disabled
|
42
|
+
@platform = "fontana"
|
43
|
+
@httpclient = HTTPClient.new
|
44
|
+
@httpclient.ssl_config.verify_mode = nil # 自己署名の証明書をOKにする
|
45
|
+
end
|
46
|
+
|
47
|
+
def login
|
48
|
+
raise "player_id is not set." if player_id.nil? || player_id.empty?
|
49
|
+
res = @httpclient.post(login_url, "player[id]" => player_id)
|
50
|
+
case res.status
|
51
|
+
when 200...300 then # OK
|
52
|
+
when 300...400 then return false # リダイレクト対応はしません
|
53
|
+
when 400...500 then return false
|
54
|
+
when 500...600 then return false
|
55
|
+
else raise "invalid http status: #{res.status}"
|
56
|
+
end
|
57
|
+
begin
|
58
|
+
obj = JSON.parse(res.content)
|
59
|
+
rescue JSON::ParserError => e
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
@auth_token = obj["auth_token"]
|
63
|
+
@signature_key = obj["signature_key"]
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
def new_action_request
|
68
|
+
ActionRequest.new(@httpclient, action_url)
|
69
|
+
end
|
70
|
+
|
71
|
+
def new_public_asset_request(asset_path)
|
72
|
+
AssetRequest.new(@httpclient, public_asset_url(asset_path))
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_protected_asset_request(asset_path)
|
76
|
+
AssetRequest.new(@httpclient, protected_asset_url(asset_path))
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def build_https_url(uri)
|
82
|
+
uri.scheme = "https"
|
83
|
+
uri.port = DEFAULT_HTTPS_PORT
|
84
|
+
uri.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
def login_url
|
88
|
+
@login_url ||= ssl_base_url + "/platforms/#{platform}/sign_in.json"
|
89
|
+
end
|
90
|
+
|
91
|
+
def action_url
|
92
|
+
@action_url ||= base_url + "/api/#{API_VERSION}/actions.json?auth_token=#{auth_token}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def public_asset_url(asset_path)
|
96
|
+
"#{@public_asset_url_prefix}#{asset_path}#{@public_asset_url_suffix}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def protected_asset_url(asset_path)
|
100
|
+
path = URI.encode(asset_path) # パラメータとして渡されるのでURLエンコードする必要がある
|
101
|
+
@action_url ||= base_url + "/api/#{API_VERSION}/assets?path=#{path}&auth_token=#{auth_token}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'libgss'
|
3
|
+
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
module Libgss
|
7
|
+
|
8
|
+
class Outputs
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def initialize(array)
|
12
|
+
@array = array
|
13
|
+
end
|
14
|
+
|
15
|
+
# メソッドを@arrayに移譲する
|
16
|
+
def_delegators :@array, :[], :length, :first, :last
|
17
|
+
|
18
|
+
def get(id)
|
19
|
+
@array.detect{|output| output["id"] == id}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/libgss.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "libgss/version"
|
2
|
+
|
3
|
+
module Libgss
|
4
|
+
|
5
|
+
autoload :Network , "libgss/network"
|
6
|
+
autoload :Action , "libgss/action"
|
7
|
+
autoload :ActionRequest, "libgss/action_request"
|
8
|
+
autoload :Outputs , "libgss/outputs"
|
9
|
+
|
10
|
+
autoload :AssetRequest , "libgss/asset_request"
|
11
|
+
end
|
data/libgss.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'libgss/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "libgss"
|
8
|
+
spec.version = Libgss::VERSION
|
9
|
+
spec.authors = ["akima"]
|
10
|
+
spec.email = ["t-akima@groovenauts.jp"]
|
11
|
+
spec.description = %q{network library for Groovenauts GSS}
|
12
|
+
spec.summary = %q{network library for Groovenauts GSS}
|
13
|
+
spec.homepage = "http://www.groovenauts.jp/service/#gss"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "httpclient"
|
26
|
+
spec.add_runtime_dependency "json"
|
27
|
+
end
|