libgss 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/README_ja.md +5 -1
- data/lib/libgss/network.rb +54 -17
- data/lib/libgss/version.rb +1 -1
- data/spec/libgss/action_request_spec.rb +1 -1
- data/spec/libgss/network_spec.rb +52 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDEzZGE2OTI5OGE3MDMzNTgxZjU2Zjg0ZmY4YzVlMDAzYzMwOGQzOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjExOGRiOGM5NzlhNDNjNTNkMmRiODM4NDc5MTVhM2ExZjBkNzVhZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmU2NzFiYThmNDIzMTA0MDk4ODg1NDQzYmIzODYyN2I0MDI1ZmZhY2QzOGJi
|
10
|
+
YzkwMjY1NDkzNTI1NWIxNDAzYjg5Njc4NDYzOWY2OTdmMWJjYWQ2MWFlOWNk
|
11
|
+
M2Y1ODdkMjE3MzVhMjllNmViYzI0YTFhYWZkNmI1MjA3Zjc5MjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2Y2NzE0MjEzMGU4MjcwMDc1Mzc4NTBkNTFlMTU5ZmNjOGMyOGRmMDU0Mzc1
|
14
|
+
ZDY3NTdmYjYyOGJhMmYzZjQ2OTNjMWM2NzM0ZjY3NWM3NDkwNjdmZjA1NTQ3
|
15
|
+
MjlhOTQ1MjBmODMxYjJhOGFiZjZlMWExMjNjZTM0MWY4NTM5NjE=
|
data/Gemfile.lock
CHANGED
data/README_ja.md
CHANGED
@@ -11,7 +11,11 @@ libgss-rubyはGroovenautsのGSS用通信ライブラリです。
|
|
11
11
|
|
12
12
|
## インストール方法
|
13
13
|
|
14
|
-
|
14
|
+
以下の2つの方法があります。プロジェクトを作成してGemfileが定義されている場合は、bundlerを使う方法をおすすめします。
|
15
|
+
それ以外の場合は、手動でインストールする方法でインストールしてください。
|
16
|
+
|
17
|
+
|
18
|
+
### プロジェクトを作ってbundlerを使う方法
|
15
19
|
|
16
20
|
アプリケーションのGemfileに以下の行を追加します:
|
17
21
|
|
data/lib/libgss/network.rb
CHANGED
@@ -24,9 +24,12 @@ module Libgss
|
|
24
24
|
attr_accessor :public_asset_url_suffix
|
25
25
|
|
26
26
|
|
27
|
-
DEFAULT_HTTP_PORT
|
27
|
+
DEFAULT_HTTP_PORT = (ENV['DEFAULT_HTTP_PORT' ] || 80).to_i
|
28
28
|
DEFAULT_HTTPS_PORT = (ENV['DEFAULT_HTTPS_PORT'] || 443).to_i
|
29
29
|
|
30
|
+
TEST_HTTP_PORT = 3000
|
31
|
+
TEST_HTTPS_PORT = 3001
|
32
|
+
|
30
33
|
def initialize(base_url_or_host, options = {})
|
31
34
|
@ssl_disabled = options.delete(:ssl_disabled)
|
32
35
|
if base_url_or_host =~ URI.regexp
|
@@ -50,24 +53,26 @@ module Libgss
|
|
50
53
|
r << fields.join(", ") << ">"
|
51
54
|
end
|
52
55
|
|
56
|
+
def register
|
57
|
+
res = @httpclient.post(registration_url)
|
58
|
+
process_json_response(res) do |obj|
|
59
|
+
self.player_id = obj["player_id"].sub(/\Afontana:/, '')
|
60
|
+
!!self.player_id
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
53
64
|
def login
|
54
|
-
raise "player_id is not set." if player_id.nil? || player_id.empty?
|
55
65
|
res = @httpclient.post(login_url, "player[id]" => player_id)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
else raise "invalid http status: #{res.status}"
|
66
|
+
process_json_response(res) do |obj|
|
67
|
+
@player_id ||= obj["player_id"]
|
68
|
+
@auth_token = obj["auth_token"]
|
69
|
+
@signature_key = obj["signature_key"]
|
70
|
+
!!@auth_token && !!@signature_key
|
62
71
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
@auth_token = obj["auth_token"]
|
69
|
-
@signature_key = obj["signature_key"]
|
70
|
-
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def setup
|
75
|
+
(load_player_id || register) && login
|
71
76
|
end
|
72
77
|
|
73
78
|
def new_action_request
|
@@ -84,12 +89,44 @@ module Libgss
|
|
84
89
|
|
85
90
|
private
|
86
91
|
|
92
|
+
# ストレージからplayer_idをロードします
|
93
|
+
# 保存されていたらtrueを、保存されていなかったらfalseを返します。
|
94
|
+
#
|
95
|
+
# ストレージは、cocos2d-x ならば CCUserDefault のようにデータを永続化するものを指します。
|
96
|
+
# http://www.cocos2d-x.org/reference/native-cpp/d0/d79/classcocos2d_1_1_c_c_user_default.html
|
97
|
+
#
|
98
|
+
# ただし、libgss-rubyはテスト用なので毎回違うplayer_idを使います。
|
99
|
+
# もし保存したい場合は、別途ファイルなどに記録してください。
|
100
|
+
def load_player_id
|
101
|
+
return false
|
102
|
+
end
|
103
|
+
|
104
|
+
def process_json_response(res)
|
105
|
+
case res.status
|
106
|
+
when 200...300 then # OK
|
107
|
+
when 300...400 then return false # リダイレクト対応はしません
|
108
|
+
when 400...500 then return false
|
109
|
+
when 500...600 then return false
|
110
|
+
else raise "invalid http status: #{res.status}"
|
111
|
+
end
|
112
|
+
begin
|
113
|
+
obj = JSON.parse(res.content)
|
114
|
+
return yield(obj)
|
115
|
+
rescue JSON::ParserError => e
|
116
|
+
return false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
87
120
|
def build_https_url(uri)
|
88
121
|
uri.scheme = "https"
|
89
|
-
uri.port = DEFAULT_HTTPS_PORT
|
122
|
+
uri.port = (uri.port == TEST_HTTP_PORT) ? TEST_HTTPS_PORT : DEFAULT_HTTPS_PORT
|
90
123
|
uri.to_s
|
91
124
|
end
|
92
125
|
|
126
|
+
def registration_url
|
127
|
+
@registration_url ||= ssl_base_url + "/platforms/#{platform}/registration.json"
|
128
|
+
end
|
129
|
+
|
93
130
|
def login_url
|
94
131
|
@login_url ||= ssl_base_url + "/platforms/#{platform}/sign_in.json"
|
95
132
|
end
|
data/lib/libgss/version.rb
CHANGED
data/spec/libgss/network_spec.rb
CHANGED
@@ -3,15 +3,45 @@ require 'spec_helper'
|
|
3
3
|
describe Libgss::Network do
|
4
4
|
|
5
5
|
let(:network) do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
Libgss::Network.new("http://localhost:3000")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#registration" do
|
10
|
+
context "valid" do
|
11
|
+
it do
|
12
|
+
network.player_id.should == nil
|
13
|
+
network.register
|
14
|
+
network.player_id.should_not == nil
|
15
|
+
network.player_id.should_not =~ /^fontana:/
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#setup" do
|
21
|
+
context "valid" do
|
22
|
+
it do
|
23
|
+
network.player_id.should == nil
|
24
|
+
network.auth_token.should == nil
|
25
|
+
network.signature_key.should == nil
|
26
|
+
res = network.setup
|
27
|
+
network.player_id.should_not == nil
|
28
|
+
network.player_id.should_not =~ /^fontana:/
|
29
|
+
network.auth_token.should_not == nil
|
30
|
+
network.signature_key.should_not == nil
|
31
|
+
res.should == true
|
32
|
+
end
|
33
|
+
end
|
9
34
|
end
|
10
35
|
|
11
36
|
describe "#login" do
|
37
|
+
before do
|
38
|
+
network.player_id = "1000001"
|
39
|
+
end
|
40
|
+
|
12
41
|
context "success" do
|
13
|
-
shared_examples_for "Libgss::Network#login success" do |block|
|
42
|
+
shared_examples_for "Libgss::Network#login success" do |block, after_block = nil|
|
14
43
|
before(&block)
|
44
|
+
after(&after_block) if after_block
|
15
45
|
|
16
46
|
it do
|
17
47
|
network.auth_token.should == nil
|
@@ -24,10 +54,27 @@ describe Libgss::Network do
|
|
24
54
|
end
|
25
55
|
|
26
56
|
it_should_behave_like "Libgss::Network#login success", Proc.new{ network.player_id = "1000001" }
|
27
|
-
it_should_behave_like "Libgss::Network#login success", Proc.new{ network.player_id = "unregistered" }
|
57
|
+
# it_should_behave_like "Libgss::Network#login success", Proc.new{ network.player_id = "unregistered" }
|
58
|
+
|
59
|
+
it_should_behave_like "Libgss::Network#login success",
|
60
|
+
Proc.new{ network.player_id = nil },
|
61
|
+
Proc.new{ network.player_id.should_not == nil }
|
62
|
+
|
28
63
|
end
|
29
64
|
|
30
65
|
context "failure" do
|
66
|
+
it "unregistered (maybe invalid) player_id" do
|
67
|
+
network.player_id = "unregistered"
|
68
|
+
network.auth_token.should == nil
|
69
|
+
network.signature_key.should == nil
|
70
|
+
res = network.login
|
71
|
+
network.auth_token.should == nil
|
72
|
+
network.signature_key.should == nil
|
73
|
+
res.should == false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "error" do
|
31
78
|
shared_examples_for "Libgss::Network#login failure" do
|
32
79
|
it do
|
33
80
|
network.auth_token.should == nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libgss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|