libgss 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d65517f74f8f6290c265bde2dcfa858974f4ee8
4
- data.tar.gz: f1b27493e24d26c5990a5885fede27f07d62bd7b
3
+ metadata.gz: a77c17af378bc6038a7ce58b8a07e4d60757fab3
4
+ data.tar.gz: aaf5b60ce2937cacce2f6fc35a398d446fcd0e9f
5
5
  SHA512:
6
- metadata.gz: 64a4ad4a6de5294fb7f28fef442e51614967e8afc82f227f8307cc15f51f375598c4c48bc51f01cee8008820797443fd62085a6f234fd9f4456163b68ef454e9
7
- data.tar.gz: 0de31d99679a417841856d0b828b210a58ee04f4152f2c66301757ab02740919657fc709e153970a61de6c34d80fcf7c4874e08e71de3298e27caaf93b388ccf
6
+ metadata.gz: fb962ff05a56236c77dda5c1a85c29bb5d9230a285c07784379d63b109db944f24641690f34e680095f8e388aa3a9ca3e500a09a655421e1faa9febed8e5b11a
7
+ data.tar.gz: e91b141a88aee2001402312a5c0b968707d37e3324fea35686ab9825316b68019424ede486313f023a01c212f84c2b98f1ae95f9f2d2a68093602ad12d1a7f8b
data/Gemfile.lock CHANGED
@@ -1,10 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- libgss (0.7.1)
4
+ libgss (0.7.2)
5
5
  httpclient
6
6
  json
7
7
  oauth
8
+ tengine_support
9
+ uuid
8
10
 
9
11
  GEM
10
12
  remote: https://rubygems.org/
@@ -16,6 +18,8 @@ GEM
16
18
  httpclient (2.3.4.1)
17
19
  i18n (0.6.5)
18
20
  json (1.8.0)
21
+ macaddr (1.6.1)
22
+ systemu (~> 2.5.0)
19
23
  multi_json (1.7.9)
20
24
  oauth (0.4.7)
21
25
  rake (10.0.4)
@@ -27,8 +31,11 @@ GEM
27
31
  rspec-expectations (2.13.0)
28
32
  diff-lcs (>= 1.1.3, < 2.0)
29
33
  rspec-mocks (2.13.1)
34
+ systemu (2.5.2)
30
35
  tengine_support (1.2.2)
31
36
  activesupport (>= 3.0.0, < 4.0.0)
37
+ uuid (2.3.7)
38
+ macaddr (~> 1.0)
32
39
 
33
40
  PLATFORMS
34
41
  ruby
@@ -38,4 +45,3 @@ DEPENDENCIES
38
45
  libgss!
39
46
  rake
40
47
  rspec
41
- tengine_support
@@ -4,11 +4,17 @@ require 'libgss'
4
4
  require 'httpclient'
5
5
  require 'json'
6
6
  require 'uri'
7
+ require 'tengine/support/yaml_with_erb'
8
+
9
+ require 'uuid'
7
10
 
8
11
  module Libgss
9
12
 
10
13
  class Network
11
14
 
15
+ class Error < StandardError
16
+ end
17
+
12
18
  API_VERSION = "1.0.0".freeze
13
19
 
14
20
  attr_reader :base_url
@@ -23,6 +29,7 @@ module Libgss
23
29
  attr_accessor :api_version
24
30
  attr_accessor :platform
25
31
  attr_accessor :player_id
32
+ attr_accessor :player_info
26
33
  attr_accessor :public_asset_url_prefix
27
34
  attr_accessor :public_asset_url_suffix
28
35
 
@@ -49,7 +56,7 @@ module Libgss
49
56
  def initialize(base_url_or_host, options = {})
50
57
  @ssl_disabled = options.delete(:ssl_disabled)
51
58
  if base_url_or_host =~ URI.regexp
52
- @base_url = base_url_or_host
59
+ @base_url = base_url_or_host.sub(/\/\Z/, '')
53
60
  uri = URI.parse(@base_url)
54
61
  @ssl_base_url = build_https_url(uri)
55
62
  else
@@ -60,6 +67,7 @@ module Libgss
60
67
  @ssl_base_url = @base_url if @ssl_disabled
61
68
  @platform = options[:platform] || "fontana"
62
69
  @player_id = options[:player_id]
70
+ @player_info = options[:player_info] || {}
63
71
 
64
72
  @consumer_secret = options[:consumer_secret] || ENV["CONSUMER_SECRET"]
65
73
  @ignore_signature_key = !!options[:ignore_signature_key]
@@ -77,21 +85,14 @@ module Libgss
77
85
  r << fields.join(", ") << ">"
78
86
  end
79
87
 
80
- def req_headers
81
- {
82
- "X-Device-Type" => device_type_cd,
83
- "X-Client-Version" => client_version,
84
- }
85
- end
86
-
87
88
  # GSSサーバに接続してログインの検証と処理を行います。
88
89
  #
89
- # @param [String] base_url_or_host 接続先の基準となるURLあるいはホスト名
90
- # @param [Hash] options オプション
91
- # @option options [String] :platform 接続先のGSSサーバの認証のプラットフォーム。デフォルトは"fontana"。
90
+ # @param [Hash] extra オプション
91
+ # @option extra [Integer] :device_type デバイス種別
92
+ # @option extra [Integer] :device_id デバイス識別子
92
93
  # @return [Boolean] ログインに成功した場合はtrue、失敗した場合はfalse
93
94
  def login(extra = {})
94
- attrs = { "player[id]" => player_id }
95
+ attrs = @player_info.merge({ "player[id]" => player_id })
95
96
  extra.each{|k, v| attrs[ "player[#{k}]" ] = v }
96
97
  res = Libgss.with_retry("login") do
97
98
  @httpclient.post(login_url, attrs, req_headers)
@@ -104,39 +105,104 @@ module Libgss
104
105
  end
105
106
  end
106
107
 
108
+ # GSSサーバに接続してログインの検証と処理を行います。
109
+ #
110
+ # @param [Hash] extra オプション
111
+ # @see #login
112
+ # @return ログインに成功した場合は自身のオブジェクト返します。失敗した場合はLibgss::Network::Errorがraiseされます。
113
+ def login!(extra = {})
114
+ raise Error, "Login Failure" unless login(extra)
115
+ self
116
+ end
117
+
118
+ # @return [Boolean] コンストラクタに指定されたignore_signature_keyを返します
107
119
  def ignore_signature_key?
108
120
  @ignore_signature_key
109
121
  end
110
122
 
123
+ # load_player_id メソッドをオーバーライドした場合に使用することを想定しています。
124
+ # それ以外の場合は使用しないでください。
111
125
  def setup
112
126
  load_player_id
113
127
  login
114
128
  end
115
129
 
130
+ # @return [Libgss::ActionRequest] アクション用リクエストを生成して返します
116
131
  def new_action_request
117
132
  ActionRequest.new(httpclient_for_action, action_url, req_headers)
118
133
  end
119
134
 
135
+ # @return [Libgss::AsyncActionRequest] 非同期アクション用リクエストを生成して返します
120
136
  def new_async_action_request
121
137
  AsyncActionRequest.new(httpclient_for_action, async_action_url, async_result_url, req_headers)
122
138
  end
123
139
 
140
+ # @return [Libgss::AssetRequest] 公開アセットを取得するリクエストを生成して返します
124
141
  def new_public_asset_request(asset_path)
125
142
  AssetRequest.new(@httpclient, public_asset_url(asset_path), req_headers)
126
143
  end
127
144
 
145
+ # @return [Libgss::AssetRequest] 保護付きアセットを取得するリクエストを生成して返します
128
146
  def new_protected_asset_request(asset_path)
129
147
  AssetRequest.new(@httpclient, protected_asset_url(asset_path), req_headers)
130
148
  end
131
149
 
150
+ # @param [String] path 対象となるapp_garden.ymlへのパス。デフォルトは "config/app_garden.yml"
151
+ # @return 成功した場合自身のオブジェクトを返します。
152
+ def load_app_garden(path = "config/app_garden.yml")
153
+ hash = YAML.load_file_with_erb(path)
154
+ self.consumer_secret = hash["consumer_secret"]
155
+ if platform = hash["platform"]
156
+ name = (platform["name"] || "").strip
157
+ unless name.empty?
158
+ self.platform = name
159
+ end
160
+ end
161
+ self
162
+ end
163
+
164
+ # device_idを生成します
165
+ #
166
+ # @param [Hash] options オプション
167
+ # @option options [Integer] :device_type デバイス種別
168
+ # @return [String] 生成したUUIDの文字列
169
+ def generate_device_id(options = {device_type: 1})
170
+ result = uuid_gen.generate
171
+ player_info.update(options)
172
+ player_info[:device_id] = result
173
+ result
174
+ end
175
+
176
+ # device_idを設定します
177
+ #
178
+ # @param [String] device_id デバイスID
179
+ # @param [Hash] options オプション
180
+ # @option options [Integer] :device_type デバイス種別
181
+ def set_device_id(device_id, options = {device_type: 1})
182
+ if player_info[:device_id] = device_id
183
+ player_info.update(options)
184
+ end
185
+ end
186
+
187
+ def uuid_gen
188
+ @uuid_gen ||= UUID.new
189
+ end
190
+
191
+ private
192
+
193
+ def req_headers
194
+ {
195
+ "X-Device-Type" => device_type_cd,
196
+ "X-Client-Version" => client_version,
197
+ }
198
+ end
199
+
132
200
  def httpclient_for_action
133
201
  @httpclient_for_action ||=
134
202
  @ignore_signature_key ? @httpclient :
135
203
  HttpClientWithSignatureKey.new(@httpclient, self)
136
204
  end
137
205
 
138
- private
139
-
140
206
  # ストレージからplayer_idをロードします
141
207
  # 保存されていたらtrueを、保存されていなかったらfalseを返します。
142
208
  #
@@ -1,3 +1,3 @@
1
1
  module Libgss
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
data/libgss.gemspec CHANGED
@@ -21,9 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "tengine_support"
25
24
 
26
25
  spec.add_runtime_dependency "httpclient"
27
26
  spec.add_runtime_dependency "json"
28
27
  spec.add_runtime_dependency "oauth"
28
+ spec.add_runtime_dependency "tengine_support"
29
+ spec.add_runtime_dependency "uuid"
29
30
  end
@@ -25,6 +25,7 @@ describe Libgss::ActionRequest do
25
25
  "items"=>{"20001"=>3, "20005"=>1},
26
26
  "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}
27
27
  },
28
+ "gender" => 0,
28
29
  "greeting_points"=>0,
29
30
  "login_bonus"=>[[10001, 1]],
30
31
  "invitation_code"=>nil,
@@ -1,9 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
+ require 'uuid'
4
+
3
5
  describe Libgss::Network do
4
6
 
5
7
  let(:network) do
6
- # Libgss::Network.new("http://localhost:3000")
8
+ # Libgss::Network.new("http://localhost:4000")
7
9
  new_network
8
10
  end
9
11
 
@@ -22,6 +24,19 @@ describe Libgss::Network do
22
24
  end
23
25
  end
24
26
 
27
+ describe "#initialize" do
28
+ context "with_trail_slash" do
29
+ let(:target){ new_network("http://localhost:4000/") }
30
+ it{ target.base_url.should == network.base_url }
31
+ it{ target.ssl_base_url.should == network.ssl_base_url }
32
+ end
33
+ context "hostname only" do
34
+ let(:target){ new_network("localhost") }
35
+ it{ target.base_url.should == "http://localhost:#{ENV['DEFAULT_HTTP_PORT' ] || 80}" }
36
+ it{ target.ssl_base_url.should == "https://localhost:#{ENV['DEFAULT_HTTPS_PORT' ] || 443}" }
37
+ end
38
+ end
39
+
25
40
  describe "#login" do
26
41
  before do
27
42
  network.player_id = "1000001"
@@ -51,21 +66,27 @@ describe Libgss::Network do
51
66
 
52
67
  end
53
68
 
54
- context "failure" do
55
- it "unregistered (maybe invalid) player_id" do
69
+ context "failure with unregistered (maybe invalid) player_id" do
70
+ before do
56
71
  network.player_id = "unregistered"
57
72
  network.auth_token.should == nil
58
73
  network.signature_key.should == nil
74
+ end
75
+
76
+ it "by using login" do
59
77
  res = network.login
60
78
  network.auth_token.should == nil
61
79
  network.signature_key.should == nil
62
80
  res.should == false
63
81
  end
82
+ it "by using login!" do
83
+ expect{ network.login! }.to raise_error(Libgss::Network::Error)
84
+ end
64
85
  end
65
86
 
66
87
  context "error" do
67
88
  shared_examples_for "Libgss::Network#login failure" do
68
- it do
89
+ it "by using login"do
69
90
  network.auth_token.should == nil
70
91
  network.signature_key.should == nil
71
92
  res = network.login
@@ -73,12 +94,17 @@ describe Libgss::Network do
73
94
  network.signature_key.should == nil
74
95
  res.should == false
75
96
  end
97
+ it "by using login"do
98
+ network.auth_token.should == nil
99
+ network.signature_key.should == nil
100
+ expect{ network.login! }.to raise_error(Libgss::Network::Error)
101
+ end
76
102
  end
77
103
 
78
104
  [300, 400, 500].map{|n| (1..10).map{|i| n + i} }.flatten.each do |status_code|
79
105
  context "status_code is #{status_code}" do
80
106
  before do
81
- res = mock(:reponse)
107
+ res = double(:reponse)
82
108
  res.should_receive(:status).and_return(status_code)
83
109
  HTTPClient.any_instance.should_receive(:post).and_return(res)
84
110
  end
@@ -88,7 +114,7 @@ describe Libgss::Network do
88
114
 
89
115
  context "JSON parse Error" do
90
116
  before do
91
- res = mock(:reponse)
117
+ res = double(:reponse)
92
118
  res.stub(:status).and_return(200)
93
119
  res.should_receive(:content).and_return("invalid JSON format string")
94
120
  HTTPClient.any_instance.should_receive(:post).and_return(res)
@@ -118,4 +144,44 @@ describe Libgss::Network do
118
144
  # end
119
145
  end
120
146
 
147
+
148
+ describe "load_app_garden" do
149
+ it "without filepath" do
150
+ network.consumer_secret = nil
151
+ network.platform = nil
152
+ Dir.chdir(File.expand_path("../../../fontana_sample", __FILE__)) do
153
+ network.load_app_garden
154
+ end
155
+ network.consumer_secret.should_not be_nil
156
+ network.platform.should be_nil
157
+ end
158
+
159
+ it "with filepath" do
160
+ network.consumer_secret = nil
161
+ network.platform = "fontana"
162
+ network.load_app_garden(File.expand_path("../../../fontana_sample/config/app_garden.yml", __FILE__))
163
+ network.consumer_secret.should_not be_nil
164
+ network.platform.should == "fontana"
165
+ end
166
+ end
167
+
168
+ describe "generate_device_id" do
169
+ let(:generated){ UUID.new.generate }
170
+
171
+ before do
172
+ network.uuid_gen.should_receive(:generate).and_return(generated)
173
+ network.player_info.should == {}
174
+ end
175
+
176
+ it "without options" do
177
+ network.generate_device_id
178
+ network.player_info.should == {device_type: 1, device_id: generated}
179
+ end
180
+
181
+ it "with device_type" do
182
+ network.generate_device_id(device_type: 2)
183
+ network.player_info.should == {device_type: 2, device_id: generated}
184
+ end
185
+ end
186
+
121
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libgss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
@@ -53,13 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: tengine_support
56
+ name: httpclient
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: httpclient
70
+ name: json
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '>='
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: json
84
+ name: oauth
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '>='
@@ -95,7 +95,21 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: oauth
98
+ name: tengine_support
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: uuid
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - '>='
@@ -195,3 +209,4 @@ test_files:
195
209
  - spec/protected_assets/Icon.png
196
210
  - spec/public_assets/Default.png
197
211
  - spec/spec_helper.rb
212
+ has_rdoc: