libgss 0.7.5 → 0.7.6

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: ac0dc188f313e4a363e43888f2d009610e52c49c
4
- data.tar.gz: 1fb0499645fbe896d93e46bba73a433b8170a92a
3
+ metadata.gz: 41ec932303909de4bd6ba629106d6090c7c0c301
4
+ data.tar.gz: 3918ed995b910482bb17d3dcee64b55a0dc97eb5
5
5
  SHA512:
6
- metadata.gz: 5bfa50dc8dffb1e771b4d3adbed0953bbd5af0089a4fa17b982906983180279f93464a09720b31483e3ceb01b63fa54bad06bfbd544a427fde6ed560b14551fe
7
- data.tar.gz: a73e6a043c3535df90f30d1d126e6ff525b8c4824edfec24dcc28ac6e05c11360d3da0c05ae3088ad231d03c86aa2ddf18d2d7eef3128576f8c17f8527d16718
6
+ metadata.gz: b0e92ac070c31f742624157721a56016078471ef9463a2158e65bca6c3db7c1574f9b6eb6d33ccdc93d42fd8129a4667964cc3dad77060f3955e447e35ee1e7c
7
+ data.tar.gz: a73d09d54c21f757ab590d88abbb4096ece741e89f6c48a3c07612acf887f2c648281cba9869fcdb19ad51a30500b1f62f43bbcefbe11f6cd8000a3cc67213f1
data/Gemfile.lock CHANGED
@@ -11,17 +11,31 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
+ activemodel (3.2.14)
15
+ activesupport (= 3.2.14)
16
+ builder (~> 3.0.0)
14
17
  activesupport (3.2.14)
15
18
  i18n (~> 0.6, >= 0.6.4)
16
19
  multi_json (~> 1.0)
20
+ builder (3.0.4)
17
21
  diff-lcs (1.2.3)
22
+ factory_girl (4.2.0)
23
+ activesupport (>= 3.0.0)
24
+ fontana_client_support (0.7.2)
18
25
  httpclient (2.3.4.1)
19
26
  i18n (0.6.5)
20
27
  json (1.8.0)
21
28
  macaddr (1.6.1)
22
29
  systemu (~> 2.5.0)
30
+ mongoid (3.1.5)
31
+ activemodel (~> 3.2)
32
+ moped (~> 1.4)
33
+ origin (~> 1.0)
34
+ tzinfo (~> 0.3.29)
35
+ moped (1.5.1)
23
36
  multi_json (1.7.9)
24
37
  oauth (0.4.7)
38
+ origin (1.1.0)
25
39
  rake (10.0.4)
26
40
  rspec (2.13.0)
27
41
  rspec-core (~> 2.13.0)
@@ -34,6 +48,7 @@ GEM
34
48
  systemu (2.5.2)
35
49
  tengine_support (1.2.2)
36
50
  activesupport (>= 3.0.0, < 4.0.0)
51
+ tzinfo (0.3.37)
37
52
  uuid (2.3.7)
38
53
  macaddr (~> 1.0)
39
54
 
@@ -42,6 +57,9 @@ PLATFORMS
42
57
 
43
58
  DEPENDENCIES
44
59
  bundler (~> 1.3)
60
+ factory_girl
61
+ fontana_client_support
45
62
  libgss!
63
+ mongoid
46
64
  rake
47
65
  rspec
data/Rakefile CHANGED
@@ -4,8 +4,8 @@ require "rspec/core/rake_task"
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
- ENV['DEFAULT_HTTP_PORT'] ||= '3000'
8
- ENV['DEFAULT_HTTPS_PORT'] ||= '3001'
7
+ ENV['DEFAULT_HTTP_PORT'] ||= '4000'
8
+ ENV['DEFAULT_HTTPS_PORT'] ||= '4001'
9
9
 
10
10
  require 'fileutils'
11
11
 
@@ -21,12 +21,13 @@ module Libgss
21
21
 
22
22
 
23
23
  # 読み込みのみ、書き込み不可
24
+ attr_reader :network
24
25
  attr_reader :action_url, :req_headers
25
26
  attr_reader :status, :outputs
26
27
 
27
28
  # コンストラクタ
28
- def initialize(httpclient, action_url, req_headers)
29
- @httpclient = httpclient
29
+ def initialize(network, action_url, req_headers)
30
+ @network = network
30
31
  @action_url = action_url
31
32
  @req_headers = req_headers
32
33
  @status = STATUS_PREPARING
@@ -36,7 +37,7 @@ module Libgss
36
37
 
37
38
  def inspect
38
39
  r = "#<#{self.class.name}:#{self.object_id} "
39
- fields = (instance_variables - [:@httpclient]).map{|f| "#{f}=#{instance_variable_get(f).inspect}"}
40
+ fields = (instance_variables - [:@network]).map{|f| "#{f}=#{instance_variable_get(f).inspect}"}
40
41
  r << fields.join(", ") << ">"
41
42
  end
42
43
 
@@ -53,7 +54,7 @@ module Libgss
53
54
  # アクション群を実行するために実際にHTTPリクエストを送信します。
54
55
  def send_request(&callback)
55
56
  res = Libgss.with_retry("action_request") do
56
- @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
57
+ network.httpclient_for_action.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
57
58
  end
58
59
  r = process_response(res, :async_request)
59
60
  @outputs = Outputs.new(r["outputs"])
@@ -20,24 +20,23 @@ module Libgss
20
20
  end
21
21
 
22
22
  # アクション群を実行するために実際にHTTPリクエストを送信します。
23
- def send_request(&callback)
24
- res = @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
23
+ def send_request
24
+ res = network.httpclient_for_action.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
25
25
  r = process_response(res, :async_request)
26
- @outputs = Outputs.new(r["outputs"])
27
- callback.call(@outputs) if callback
28
-
29
- @ids = @outputs.map do |output|
30
- output['id']
31
- end
32
-
33
- @outputs
26
+ outputs = Outputs.new(r["outputs"])
27
+ @ids = outputs.map{|output| output['id'] }
28
+ outputs
34
29
  end
35
30
 
36
- def async_status()
37
- raise Error, "failed to get response. please exec send_request before call." unless @ids
31
+ def async_status(ids=nil)
32
+ ids ||= @ids
33
+ ids = [ids] unless ids.is_a?(::Array)
34
+ raise Error, "failed to get response. please exec send_request before call." unless ids
38
35
 
39
- res = @httpclient.get(result_url, {input_ids: @ids.join(',')}, req_headers)
40
- r = process_response(res, :aync_status)
36
+ res = network.httpclient_for_action.post(result_url, {'input_ids' => ids}.to_json, req_headers)
37
+ r = process_response(res, :aync_results)
38
+ Outputs.new(r["outputs"])
41
39
  end
40
+ alias :async_results :async_status
42
41
  end
43
42
  end
@@ -139,12 +139,12 @@ module Libgss
139
139
 
140
140
  # @return [Libgss::ActionRequest] アクション用リクエストを生成して返します
141
141
  def new_action_request
142
- ActionRequest.new(httpclient_for_action, action_url, req_headers)
142
+ ActionRequest.new(self, action_url, req_headers)
143
143
  end
144
144
 
145
145
  # @return [Libgss::AsyncActionRequest] 非同期アクション用リクエストを生成して返します
146
146
  def new_async_action_request
147
- AsyncActionRequest.new(httpclient_for_action, async_action_url, async_result_url, req_headers)
147
+ AsyncActionRequest.new(self, async_action_url, async_result_url, req_headers)
148
148
  end
149
149
 
150
150
  # @return [Libgss::AssetRequest] 公開アセットを取得するリクエストを生成して返します
@@ -198,6 +198,13 @@ module Libgss
198
198
  @uuid_gen ||= UUID.new
199
199
  end
200
200
 
201
+ def httpclient_for_action
202
+ @httpclient_for_action ||=
203
+ @ignore_signature_key ? @httpclient :
204
+ HttpClientWithSignatureKey.new(@httpclient, self)
205
+ end
206
+
207
+
201
208
  private
202
209
 
203
210
  def req_headers
@@ -207,12 +214,6 @@ module Libgss
207
214
  }
208
215
  end
209
216
 
210
- def httpclient_for_action
211
- @httpclient_for_action ||=
212
- @ignore_signature_key ? @httpclient :
213
- HttpClientWithSignatureKey.new(@httpclient, self)
214
- end
215
-
216
217
  # ストレージからplayer_idをロードします
217
218
  # 保存されていたらtrueを、保存されていなかったらfalseを返します。
218
219
  #
@@ -1,3 +1,3 @@
1
1
  module Libgss
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.6"
3
3
  end
data/libgss.gemspec CHANGED
@@ -21,6 +21,9 @@ 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 "fontana_client_support"
25
+ spec.add_development_dependency "mongoid"
26
+ spec.add_development_dependency "factory_girl"
24
27
 
25
28
  spec.add_runtime_dependency "httpclient"
26
29
  spec.add_runtime_dependency "json"
@@ -0,0 +1,38 @@
1
+
2
+ require 'factory_girl'
3
+
4
+ FactoryGirl.define do
5
+
6
+ factory :async_action01, class: AsyncAction do
7
+ player
8
+ action_id "1"
9
+ request_url "http://localhost:3000/api/1.0.0/async_actions.json?auth_token=CzyWmCg3vjpxeYuHL8dr"
10
+ request({"id"=>1, "action"=>"server_time"})
11
+ # response({"result"=>1379990870, "id"=>1})
12
+ attempts 0
13
+ end
14
+
15
+ factory :async_action02, class: AsyncAction do
16
+ player
17
+ action_id "2"
18
+ request_url "http://localhost:3000/api/1.0.0/async_actions.json?auth_token=CzyWmCg3vjpxeYuHL8dr"
19
+ request({"id"=>2, "action"=>"server_time"})
20
+ response({"result"=>1379990870, "id"=>"2"})
21
+ attempts 0
22
+ end
23
+
24
+ factory :player, class: Player do
25
+ player_id "1000001"
26
+ nickname "ichiro"
27
+ pf_player_id "150001"
28
+ pf_player_info ({})
29
+ first_login_at Time.zone.parse("2012-07-15T21:50:00+09:00")
30
+ current_login_at Time.zone.parse("2012-08-15T18:50:00+09:00")
31
+ last_login_at Time.zone.parse("2012-08-15T18:50:00+09:00")
32
+ login_days 100
33
+ login_count_this_day 3
34
+ continuous_login_days 5
35
+ created_at Time.zone.parse("2012-08-15T18:50:00+09:00")
36
+ updated_at Time.zone.parse("2012-08-15T18:50:00+09:00")
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+
2
+ require 'factory_girl'
3
+
4
+ FactoryGirl.define do
5
+
6
+ factory :client_release01, class: ClientRelease do
7
+ status_cd 2
8
+ device_type_cd 1
9
+ version '2013073101'
10
+ url "https://itunes.apple.com/jp/app/xxxxxxxxxx/id123456789?mt=8"
11
+ created_at 1375364758
12
+ updated_at 1375364758
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+
2
+ require 'factory_girl'
3
+
4
+ FactoryGirl.define do
5
+
6
+ factory :client_release_device_type01, class: ClientRelease::DeviceType do
7
+ cd 1
8
+ name "iOS"
9
+ end
10
+
11
+ factory :client_release_device_type02, class: ClientRelease::DeviceType do
12
+ cd 2
13
+ name "Android"
14
+ end
15
+ end
@@ -0,0 +1,112 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # このファイルは生成されたファイルです。
4
+ #
5
+ # このファイルを変更する際には、再度生成され、上書きされる
6
+ # かもしれないことを考慮してください。
7
+ #
8
+
9
+ require 'factory_girl'
10
+
11
+ FactoryGirl.define do
12
+
13
+ factory :game_data01, class: GameData do
14
+ player_id "1000001"
15
+ content ({"hp"=>15, "max_hp"=>15, "mp"=>5, "max_mp"=>5, "exp"=>100, "money"=>200, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
16
+ login_bonus [[10001, 1]]
17
+ read_notifications []
18
+ created_at Time.zone.parse("2012-08-15T18:50:00+09:00")
19
+ updated_at Time.zone.parse("2012-08-15T18:50:00+09:00")
20
+ gender 1
21
+ end
22
+
23
+ factory :game_data02, class: GameData do
24
+ player_id "1000002"
25
+ content ({"hp"=>30, "max_hp"=>30, "mp"=>10, "max_mp"=>10, "exp"=>200, "money"=>400, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
26
+ greeting_points 10
27
+ login_bonus [[20001, 1]]
28
+ invite_player "1000003"
29
+ read_notifications []
30
+ created_at Time.zone.parse("2012-08-12T10:00:00+09:00")
31
+ updated_at Time.zone.parse("2012-08-15T10:00:00+09:00")
32
+ gender 1
33
+ end
34
+
35
+ factory :game_data03, class: GameData do
36
+ player_id "1000003"
37
+ content ({"hp"=>45, "max_hp"=>45, "mp"=>15, "max_mp"=>15, "exp"=>300, "money"=>600, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
38
+ greeting_points 20
39
+ invitation_code "abcdABCD42"
40
+ read_notifications []
41
+ created_at Time.zone.parse("2012-08-10T01:10:00+09:00")
42
+ updated_at Time.zone.parse("2012-08-15T01:10:00+09:00")
43
+ gender 1
44
+ end
45
+
46
+ factory :game_data04, class: GameData do
47
+ player_id "1000004"
48
+ content ({"hp"=>10, "max_hp"=>15, "mp"=>5, "max_mp"=>5, "exp"=>100, "money"=>200, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
49
+ login_bonus [[10001, 1]]
50
+ read_notifications []
51
+ created_at Time.zone.parse("2012-08-15T18:50:00+09:00")
52
+ updated_at Time.zone.parse("2012-08-15T18:50:00+09:00")
53
+ gender 2
54
+ end
55
+
56
+ factory :game_data05, class: GameData do
57
+ player_id "1000005"
58
+ content ({"hp"=>20, "max_hp"=>30, "mp"=>5, "max_mp"=>10, "exp"=>200, "money"=>400, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
59
+ greeting_points 10
60
+ login_bonus [[20001, 1]]
61
+ invite_player "1000006"
62
+ read_notifications []
63
+ created_at Time.zone.parse("2012-08-12T10:00:00+09:00")
64
+ updated_at Time.zone.parse("2012-08-15T10:00:00+09:00")
65
+ gender 2
66
+ end
67
+
68
+ factory :game_data06, class: GameData do
69
+ player_id "1000006"
70
+ content ({"hp"=>40, "max_hp"=>45, "mp"=>15, "max_mp"=>15, "exp"=>300, "money"=>600, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
71
+ greeting_points 20
72
+ invitation_code "abcdABCD42"
73
+ read_notifications []
74
+ created_at Time.zone.parse("2012-08-10T01:10:00+09:00")
75
+ updated_at Time.zone.parse("2012-08-15T01:10:00+09:00")
76
+ gender 1
77
+ end
78
+
79
+ factory :game_data07, class: GameData do
80
+ player_id "1000007"
81
+ content ({"hp"=>1, "max_hp"=>15, "mp"=>5, "max_mp"=>5, "exp"=>100, "money"=>200, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
82
+ login_bonus [[10001, 1]]
83
+ read_notifications []
84
+ created_at Time.zone.parse("2012-08-15T18:50:00+09:00")
85
+ updated_at Time.zone.parse("2012-08-15T18:50:00+09:00")
86
+ gender 1
87
+ end
88
+
89
+ factory :game_data08, class: GameData do
90
+ player_id "1000008"
91
+ content ({"hp"=>3, "max_hp"=>30, "mp"=>1, "max_mp"=>10, "exp"=>200, "money"=>400, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
92
+ greeting_points 10
93
+ login_bonus [[20001, 1]]
94
+ invite_player "1000009"
95
+ read_notifications []
96
+ created_at Time.zone.parse("2012-08-12T10:00:00+09:00")
97
+ updated_at Time.zone.parse("2012-08-15T10:00:00+09:00")
98
+ gender 1
99
+ end
100
+
101
+ factory :game_data09, class: GameData do
102
+ player_id "1000009"
103
+ content ({"hp"=>1, "max_hp"=>45, "mp"=>1, "max_mp"=>15, "exp"=>300, "money"=>600, "items"=>{"20001"=>3, "20005"=>1}, "equipments"=>{"head"=>10018, "body"=>10012, "right_hand"=>10001, "left_hand"=>nil}})
104
+ greeting_points 20
105
+ invitation_code "abcdABCD42"
106
+ read_notifications []
107
+ created_at Time.zone.parse("2012-08-10T01:10:00+09:00")
108
+ updated_at Time.zone.parse("2012-08-15T01:10:00+09:00")
109
+ gender 2
110
+ end
111
+
112
+ end
@@ -0,0 +1,155 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # このファイルは生成されたファイルです。
4
+ #
5
+ # このファイルを変更する際には、再度生成され、上書きされる
6
+ # かもしれないことを考慮してください。
7
+ #
8
+
9
+ require 'factory_girl'
10
+
11
+ FactoryGirl.define do
12
+
13
+ factory :player01, class: Player do
14
+ player_id "1000001"
15
+ nickname "ichiro"
16
+ pf_player_id "150001"
17
+ pf_player_info ({})
18
+ first_login_at Time.zone.parse("2012-07-15T21:50:00+09:00")
19
+ current_login_at Time.zone.parse("2012-08-15T18:50:00+09:00")
20
+ last_login_at Time.zone.parse("2012-08-15T18:50:00+09:00")
21
+ login_days 100
22
+ login_count_this_day 3
23
+ continuous_login_days 5
24
+ created_at Time.zone.parse("2012-08-15T18:50:00+09:00")
25
+ updated_at Time.zone.parse("2012-08-15T18:50:00+09:00")
26
+ end
27
+
28
+ factory :player02, class: Player do
29
+ player_id "1000002"
30
+ nickname "jiro"
31
+ level 2
32
+ pf_player_id "150002"
33
+ pf_player_info ({})
34
+ first_login_at Time.zone.parse("2012-07-21T10:00:00+09:00")
35
+ current_login_at Time.zone.parse("2012-08-15T10:00:00+09:00")
36
+ last_login_at Time.zone.parse("2012-08-15T10:00:00+09:00")
37
+ first_paid_at Time.zone.parse("2012-08-01T12:00:00+09:00")
38
+ last_paid_at Time.zone.parse("2012-08-15T12:00:00+09:00")
39
+ login_days 20
40
+ login_count_this_day 1
41
+ created_at Time.zone.parse("2012-08-15T12:00:00+09:00")
42
+ updated_at Time.zone.parse("2012-08-15T12:00:00+09:00")
43
+ end
44
+
45
+ factory :player03, class: Player do
46
+ player_id "1000003"
47
+ nickname "subrow"
48
+ level 3
49
+ pf_player_id "150003"
50
+ pf_player_info ({})
51
+ first_login_at Time.zone.parse("2012-07-26T22:10:00+09:00")
52
+ current_login_at Time.zone.parse("2012-08-15T01:10:00+09:00")
53
+ last_login_at Time.zone.parse("2012-08-15T01:10:00+09:00")
54
+ first_paid_at Time.zone.parse("2012-08-10T20:00:00+09:00")
55
+ last_paid_at Time.zone.parse("2012-08-10T20:00:00+09:00")
56
+ login_days 30
57
+ login_count_this_day 1
58
+ continuous_login_days 3
59
+ created_at Time.zone.parse("2012-08-15T01:10:00+09:00")
60
+ updated_at Time.zone.parse("2012-08-15T01:10:00+09:00")
61
+ end
62
+
63
+ factory :player04, class: Player do
64
+ player_id "1000004"
65
+ nickname "shirow"
66
+ level 4
67
+ pf_player_id "150004"
68
+ pf_player_info ({})
69
+ first_login_at Time.zone.parse("2012-08-01T10:20:00+09:00")
70
+ current_login_at Time.zone.parse("2012-08-14T16:20:00+09:00")
71
+ last_login_at Time.zone.parse("2012-08-14T16:20:00+09:00")
72
+ login_days 5
73
+ created_at Time.zone.parse("2012-08-14T16:20:00+09:00")
74
+ updated_at Time.zone.parse("2012-08-14T16:20:00+09:00")
75
+ end
76
+
77
+ factory :player05, class: Player do
78
+ player_id "1000005"
79
+ nickname "gorow"
80
+ pf_player_id "150005"
81
+ pf_player_info ({})
82
+ first_login_at Time.zone.parse("2012-07-15T21:50:00+09:00")
83
+ current_login_at Time.zone.parse("2012-08-15T18:50:00+09:00")
84
+ last_login_at Time.zone.parse("2012-08-15T18:50:00+09:00")
85
+ login_days 10
86
+ login_count_this_day 3
87
+ continuous_login_days 5
88
+ created_at Time.zone.parse("2012-08-15T18:50:00+09:00")
89
+ updated_at Time.zone.parse("2012-08-15T18:50:00+09:00")
90
+ end
91
+
92
+ factory :player06, class: Player do
93
+ player_id "1000006"
94
+ nickname "rockrow"
95
+ level 2
96
+ pf_player_id "150006"
97
+ pf_player_info ({})
98
+ first_login_at Time.zone.parse("2012-07-21T10:00:00+09:00")
99
+ current_login_at Time.zone.parse("2012-08-15T10:00:00+09:00")
100
+ last_login_at Time.zone.parse("2012-08-15T10:00:00+09:00")
101
+ first_paid_at Time.zone.parse("2012-08-01T12:00:00+09:00")
102
+ last_paid_at Time.zone.parse("2012-08-15T12:00:00+09:00")
103
+ login_days 2
104
+ login_count_this_day 1
105
+ created_at Time.zone.parse("2012-08-15T12:00:00+09:00")
106
+ updated_at Time.zone.parse("2012-08-15T12:00:00+09:00")
107
+ end
108
+
109
+ factory :player07, class: Player do
110
+ player_id "1000007"
111
+ nickname "nanarow"
112
+ level 3
113
+ pf_player_id "150007"
114
+ pf_player_info ({})
115
+ first_login_at Time.zone.parse("2012-07-26T22:10:00+09:00")
116
+ current_login_at Time.zone.parse("2012-08-15T01:10:00+09:00")
117
+ last_login_at Time.zone.parse("2012-08-15T01:10:00+09:00")
118
+ first_paid_at Time.zone.parse("2012-08-10T20:00:00+09:00")
119
+ last_paid_at Time.zone.parse("2012-08-10T20:00:00+09:00")
120
+ login_days 3
121
+ login_count_this_day 1
122
+ continuous_login_days 3
123
+ created_at Time.zone.parse("2012-08-15T01:10:00+09:00")
124
+ updated_at Time.zone.parse("2012-08-15T01:10:00+09:00")
125
+ end
126
+
127
+ factory :player08, class: Player do
128
+ player_id "1000008"
129
+ nickname "hachi"
130
+ level 4
131
+ pf_player_id "150008"
132
+ pf_player_info ({})
133
+ first_login_at Time.zone.parse("2012-08-01T10:20:00+09:00")
134
+ current_login_at Time.zone.parse("2012-08-14T16:20:00+09:00")
135
+ last_login_at Time.zone.parse("2012-08-14T16:20:00+09:00")
136
+ login_days 1
137
+ created_at Time.zone.parse("2012-08-14T16:20:00+09:00")
138
+ updated_at Time.zone.parse("2012-08-14T16:20:00+09:00")
139
+ end
140
+
141
+ factory :player09, class: Player do
142
+ player_id "1000009"
143
+ nickname "kurow"
144
+ level 5
145
+ pf_player_id "150009"
146
+ pf_player_info ({})
147
+ first_login_at Time.zone.parse("2012-08-01T10:20:00+09:00")
148
+ current_login_at Time.zone.parse("2012-08-14T16:20:00+09:00")
149
+ last_login_at Time.zone.parse("2012-08-14T16:20:00+09:00")
150
+ login_days 1
151
+ created_at Time.zone.parse("2012-08-14T16:20:00+09:00")
152
+ updated_at Time.zone.parse("2012-08-14T16:20:00+09:00")
153
+ end
154
+
155
+ end
@@ -2,28 +2,117 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Libgss::AsyncActionRequest do
5
- before do
6
- request_fixture_load("01_basic")
7
- end
8
5
 
9
- let(:network) do
10
- network = new_network
11
- network.login.should == true
12
- network
6
+ before(:all) do
7
+ ClientRelease.delete_all
8
+ FactoryGirl.create(:client_release01)
13
9
  end
14
10
 
15
- let(:request) do
16
- network.new_async_action_request
11
+ let(:network){ @network }
12
+
13
+ describe "POST async_action.json" do
14
+ before do
15
+ Player.delete_all
16
+ AsyncAction.delete_all
17
+ create(:player01)
18
+ @network = new_network.login!
19
+ end
20
+
21
+ context "success" do
22
+ it do
23
+ r = network.new_async_action_request
24
+ r.server_time
25
+ r.send_request.to_a.should == [{"id" => 1, "status" => "executing" }]
26
+ end
27
+
28
+ it "id is string" do
29
+ r = network.new_async_action_request
30
+ r.server_time.with("10001")
31
+ r.send_request.to_a.should == [{"id" => "10001", "status" => "executing" }]
32
+ end
33
+
34
+ it "id is integer" do
35
+ r = network.new_async_action_request
36
+ r.server_time.with(10001)
37
+ r.send_request.to_a.should == [{"id" => 10001, "status" => "executing" }]
38
+ end
39
+ end
40
+
41
+ context "failed" do
42
+ it "action_id is empty" do
43
+ r = network.new_async_action_request
44
+ r.server_time.with(nil)
45
+ r.send_request.to_a.should == [{"id" => nil, "status" => "failed", "reason"=>{"action_id"=>["can't be blank"]}}]
46
+ end
47
+
48
+ it "action_id is duplicated" do
49
+ r = network.new_async_action_request
50
+ r.server_time.with(1)
51
+ r.server_time.with(1)
52
+ r.send_request.to_a.should == [
53
+ {"id" => 1, "status" => "executing"},
54
+ {"id" => 1, "status" => "failed", "reason"=>{"action_id"=>["is already taken"]}},
55
+ ]
56
+ end
57
+
58
+ it "request is empty" do
59
+ r = network.new_async_action_request
60
+ a = r.add_action({})
61
+ a.should_receive(:to_hash).and_return({})
62
+ r.send_request.to_a.should == [
63
+ {"id" => nil, "status" => "failed", "reason"=>{
64
+ "action_id"=>["can't be blank"],
65
+ "request"=>["can't be blank"]
66
+ }}]
67
+ end
68
+ end
69
+
17
70
  end
18
71
 
19
- describe "#get" do
20
- context "Player" do
72
+ describe "async_status(POST: async_results.json)" do
73
+
74
+ context "working async_action" do
75
+ before do
76
+ Player.delete_all
77
+ AsyncAction.delete_all
78
+ @async_action01 = FactoryGirl.create(:async_action01)
79
+ @player01 = @async_action01.player
80
+ @network = new_network(@player01.player_id).login!
81
+ end
82
+
83
+ it do
84
+ r = network.new_async_action_request
85
+ r.async_status(['1']).to_a.should == [{"id" => '1', "status" => "executing" }]
86
+ end
87
+ end
88
+
89
+ context "executed async_action" do
90
+ before do
91
+ Player.delete_all
92
+ AsyncAction.delete_all
93
+ @async_action02 = create(:async_action02)
94
+ @player02 = @async_action02.player
95
+ @network = new_network(@player02.player_id).login!
96
+ end
97
+
98
+ it do
99
+ r = network.new_async_action_request
100
+ r.async_status(['2']).to_a.should == [{"id" => '2', "result" => 1379990870}]
101
+ end
102
+ end
103
+
104
+ context "action_id is not exists" do
105
+ before do
106
+ Player.delete_all
107
+ AsyncAction.delete_all
108
+ @async_action01 = FactoryGirl.create(:async_action01)
109
+ @player01 = @async_action01.player
110
+ @network = new_network(@player01.player_id).login!
111
+ end
112
+
21
113
  it do
22
- request.get_by_player
23
- request.send_request do |outputs|
24
- outputs.length.should == 1
25
- outputs[0]['status'].should eq('executing')
26
- end
114
+ r = network.new_async_action_request
115
+ r.async_status(['3']).to_a.should == [{"id" => '3', "status" => "not_found", "message"=>"not found for id: \"3\""}]
27
116
  end
28
117
  end
29
118
 
@@ -30,7 +30,7 @@ describe Libgss::Network do
30
30
 
31
31
  describe "#initialize" do
32
32
  context "with_trail_slash" do
33
- let(:target){ new_network("http://localhost:4000/") }
33
+ let(:target){ new_network_with_options(url: "http://localhost:4000/") }
34
34
  it{ target.base_url.should == network.base_url }
35
35
  it{ target.ssl_base_url.should == network.ssl_base_url }
36
36
  end
data/spec/spec_helper.rb CHANGED
@@ -1,35 +1,44 @@
1
+ # -*- coding: utf-8 -*-
1
2
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
3
  require 'libgss'
3
4
  require 'tengine/support/yaml_with_erb'
4
5
 
5
- # see https://github.com/tengine/fontana/pull/3
6
- require 'httpclient'
7
- def request_fixture_load(fixture_name)
8
- c = HTTPClient.new
9
- c.post("http://localhost:4000/libgss_test/fixture_loadings/#{fixture_name}.json", "_method" => "put")
10
- end
6
+ require 'fontana_client_support'
7
+ require 'mongoid'
11
8
 
12
9
 
13
- def new_network(url = "http://localhost:4000", player_id = "1000001")
14
- config = YAML.load_file(File.expand_path("../../fontana_sample/config/app_garden.yml", __FILE__))
15
- opts = {
16
- device_type_cd: 1,
17
- client_version: "2013073101",
18
- consumer_secret: config["consumer_secret"],
19
- player_id: player_id,
20
- # ssl_disabled: true,
21
- }
22
- Libgss::Network.new(url, opts)
23
- end
10
+ Mongoid.logger.level = 0
11
+ log_path = File.expand_path("../../tmp/test.log", __FILE__)
12
+ FileUtils.mkdir_p(File.dirname(log_path))
13
+ logger = Logger.new(log_path)
14
+ logger.level = Logger::DEBUG
15
+ Mongoid.logger = logger
16
+
17
+
18
+ Mongoid.load!(File.expand_path("../../fontana_sample/config/fontana_mongoid.yml", __FILE__), :development)
19
+
20
+ require 'active_support/dependencies'
21
+
22
+ Time.zone = ActiveSupport::TimeZone.zones_map["Tokyo"]
23
+
24
+ d = File.expand_path("../support/models", __FILE__)
25
+ "Directory not found: #{d.inspect}" unless Dir.exist?(d)
26
+ ActiveSupport::Dependencies.autoload_paths << d
27
+
28
+ Dir[File.expand_path("../support/auto/**/*.rb", __FILE__)].each {|f| require f}
29
+
30
+
31
+ require 'factory_girl'
32
+ FactoryGirl.find_definitions
24
33
 
25
- def new_network_with_options(opts={}, url = "http://localhost:4000", player_id = "1000001")
26
- config = YAML.load_file(File.expand_path("../../fontana_sample/config/app_garden.yml", __FILE__))
27
- opts = {
28
- device_type_cd: 1,
29
- client_version: "2013073101",
30
- consumer_secret: config["consumer_secret"],
31
- player_id: player_id,
32
- # ssl_disabled: true,
33
- }.update(opts)
34
- Libgss::Network.new(url, opts)
34
+ RSpec.configure do |config|
35
+ # iOS開発環境が整っていない場合、SSLで接続する https://sandbox.itunes.apple.com/verifyreceipt
36
+ # オレオレ証明書を使っているので、その検証をができなくてエラーになってしまいます。
37
+ # 本来ならば、信頼する証明書として追加する方が良いと思われますが、
38
+ # ( http://d.hatena.ne.jp/komiyak/20130508/1367993536 )
39
+ # 証明書自身の検証はローカルの開発環境で行うことができるので、ここでは単純に検証をスキップする
40
+ # ように設定してしまいます。
41
+ require 'openssl'
42
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
43
+ config.include FactoryGirl::Syntax::Methods
35
44
  end
@@ -0,0 +1,12 @@
1
+ require 'yaml'
2
+ require 'tengine/support/yaml_with_erb'
3
+
4
+ module AppGarden
5
+ CONFIG_PATH = File.expand_path("../../../../fontana_sample/config/app_garden.yml", __FILE__)
6
+
7
+ module_function
8
+
9
+ def config
10
+ @config ||= YAML.load_file(CONFIG_PATH)
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+
2
+ # see https://github.com/tengine/fontana/pull/3
3
+ require 'httpclient'
4
+ def request_fixture_load(fixture_name)
5
+ c = HTTPClient.new
6
+ res = c.post("http://localhost:4000/libgss_test/fixture_loadings/#{fixture_name}.json", "_method" => "put")
7
+ raise "#{res.code} #{res.http_body.content}" unless res.code.to_s =~ /\A2\d\d\Z/
8
+ end
9
+
10
+ def fixtures(name)
11
+ before do
12
+ request_fixture_load(name)
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ def new_network(player_id = "1000001")
2
+ new_network_with_options({}, player_id)
3
+ end
4
+
5
+ def new_network_with_options(opts={}, player_id = "1000001")
6
+ config = YAML.load_file(File.expand_path("../../../../fontana_sample/config/app_garden.yml", __FILE__))
7
+ opts = {
8
+ device_type_cd: 1,
9
+ client_version: "2013073101",
10
+ consumer_secret: config["consumer_secret"],
11
+ player_id: player_id,
12
+ # ssl_disabled: true,
13
+ url: "http://localhost:4000",
14
+ }.update(opts)
15
+ url = opts.delete(:url)
16
+ Libgss::Network.new(url, opts)
17
+ end
@@ -0,0 +1,26 @@
1
+ class AsyncAction
2
+ include Mongoid::Document
3
+
4
+ field :player_id, type: Moped::BSON::ObjectId
5
+ field :action_id , type: Object
6
+ field :request_url, type: String
7
+ field :request # anything
8
+ field :response # anything, can be null
9
+ field :attempts, type: Integer, default: 0
10
+
11
+ index({ player_id: 1, action_id: 1 }, { unique: true })
12
+
13
+ validates_presence_of :player_id
14
+ validates_presence_of :action_id
15
+ validates_presence_of :request_url
16
+ validates_presence_of :request
17
+ validates_uniqueness_of :action_id, scope: :player_id
18
+
19
+ Player # in order to find with ActiveSupport::Dependency
20
+ if defined? ::Player
21
+ belongs_to :player # for Rails Admin
22
+ class ::Player; has_many :async_actions end
23
+ else
24
+ raise "Player class not found!"
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+ class ClientRelease
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ # include Userstamps
6
+ # include SelectableAttr::Base
7
+
8
+ field :device_type_cd , type: Integer , label: "デバイス種別コード"
9
+ field :version , type: String , label: "クライアントバージョン"
10
+ field :status_cd , type: Integer, default: 0, label: "ステータス"
11
+ field :url , type: String , label: "ダウンロードページURL"
12
+ field :plan_released_at, type: Time , label: "予定リリース日時" # どこにも使われていません。メモ扱いです。
13
+
14
+ index({status_cd: 1, device_type_cd: 1, plan_released_at: -1})
15
+
16
+ validates :device_type_cd, presence: true
17
+ validates :version , presence: true
18
+ validates :status_cd , presence: true
19
+ # validates :url , presence: true
20
+
21
+ # selectable_attr :status_cd do
22
+ # entry 0, :develop , "開発中"
23
+ # entry 1, :ready , "リリース可能"
24
+ # entry 2, :enabled , "有効" # リリース済み
25
+ # entry 3, :disabled , "無効" # リリース済み
26
+ # end
27
+
28
+ class DeviceType
29
+ include Mongoid::Document
30
+ field :cd , type: Integer, label: "デバイス種別コード"
31
+ field :name, type: String , label: "デバイス種別名"
32
+
33
+ validates :cd , presence: true
34
+ validates :name, presence: true
35
+
36
+ # has_many :client_releases, class_name: "ClientRelease", foreign_key: "device_type_cd", inverse_of: "device_type"
37
+
38
+ DEFAULTS = [
39
+ {cd: 1, name: "iOS"}.freeze,
40
+ {cd: 2, name: "Android"}.freeze,
41
+ ].freeze
42
+
43
+ class << self
44
+ def create_defaults
45
+ DEFAULTS.map{|attrs| ClientRelease::DeviceType.create!(attrs) }
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # このファイルは生成されたファイルです。
4
+ #
5
+ # このモデルはテストデータの登録のためのものであり、実際のサーバ上での
6
+ # データの操作に使用されるモデルとは異なります。
7
+ #
8
+ # このモデルをテストデータの登録以外の目的で使用しないでください。
9
+ #
10
+ class GameData
11
+ include Mongoid::Document
12
+
13
+ include Mongoid::Timestamps::Created
14
+ include Mongoid::Timestamps::Updated
15
+ field :player_id, type: String, label: "プレイヤーID", default: nil
16
+ field :content, type: Hash, label: "内容", default: nil
17
+ field :greeting_points, type: Integer, label: "あいさつポイント", default: 0.0
18
+ field :login_bonus, type: Object, label: "ログインボーナス", default: nil
19
+ field :invitation_code, type: String, label: "招待コード", default: nil
20
+ field :invite_player, type: String, label: "招待プレイヤーID", default: nil
21
+ field :read_notifications, type: Object, label: "既読お知らせリスト", default: nil
22
+ field :created_at, type: ActiveSupport::TimeWithZone, label: "登録日時", default: nil
23
+ field :updated_at, type: ActiveSupport::TimeWithZone, label: "更新日時", default: nil
24
+ field :gender, type: Integer, label: "性別", default: 0.0
25
+ validates(:player_id, presence: true)
26
+ validates(:gender, presence: true)
27
+ index({"player_id"=>1}, :name => "主キー")
28
+ index({"invitation_code"=>1}, :name => "idx_invitation")
29
+ end
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # このファイルは生成されたファイルです。
4
+ #
5
+ # このモデルはテストデータの登録のためのものであり、実際のサーバ上での
6
+ # データの操作に使用されるモデルとは異なります。
7
+ #
8
+ # このモデルをテストデータの登録以外の目的で使用しないでください。
9
+ #
10
+ class Player
11
+ include Mongoid::Document
12
+
13
+ include Mongoid::Timestamps::Created
14
+ include Mongoid::Timestamps::Updated
15
+ field :player_id, type: String, label: "プレイヤーID", default: nil
16
+ field :nickname, type: String, label: "ニックネーム", default: nil
17
+ field :level, type: Integer, label: "レベル", default: 1.0
18
+ field :authentication_token, type: String, label: "認証トークン", default: nil
19
+ field :signature_key, type: String, label: "署名キー", default: nil
20
+ field :pf_player_id, type: String, label: "プラットフォームプレイヤーID", default: nil
21
+ field :pf_player_info, type: Hash, label: "プラットフォームプレイヤー情報", default: nil
22
+ field :first_login_at, type: ActiveSupport::TimeWithZone, label: "初回ログイン日時", default: nil
23
+ field :current_login_at, type: ActiveSupport::TimeWithZone, label: "現在ログイン日時", default: nil
24
+ field :last_login_at, type: ActiveSupport::TimeWithZone, label: "最終ログイン日時", default: nil
25
+ field :first_paid_at, type: ActiveSupport::TimeWithZone, label: "初回課金日時", default: nil
26
+ field :last_paid_at, type: ActiveSupport::TimeWithZone, label: "最終課金日時", default: nil
27
+ field :login_days, type: Integer, label: "ログイン日数", default: 0.0
28
+ field :login_count_this_day, type: Integer, label: "当日ログイン回数", default: 0.0
29
+ field :continuous_login_days, type: Integer, label: "連続ログイン日数", default: 0.0
30
+ field :banned, type: Boolean, label: "アカウント停止フラグ", default: nil
31
+ field :created_at, type: ActiveSupport::TimeWithZone, label: "登録日時", default: nil
32
+ field :updated_at, type: ActiveSupport::TimeWithZone, label: "更新日時", default: nil
33
+ validates(:player_id, presence: true)
34
+ index({"player_id"=>1}, :name => "主キー")
35
+ index({"authentication_token"=>1}, :name => "idx_auth")
36
+ index({"pf_player_id"=>1}, :name => "idx_switch_login")
37
+ end
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.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-20 00:00:00.000000000 Z
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fontana_client_support
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: httpclient
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +194,11 @@ files:
152
194
  - lib/libgss/outputs.rb
153
195
  - lib/libgss/version.rb
154
196
  - libgss.gemspec
197
+ - spec/factories/async_action.rb
198
+ - spec/factories/client_release.rb
199
+ - spec/factories/device_type.rb
200
+ - spec/factories/game_data.rb
201
+ - spec/factories/player.rb
155
202
  - spec/libgss/action_request_spec.rb
156
203
  - spec/libgss/actions/dictionary_spec.rb
157
204
  - spec/libgss/actions/friendship_spec.rb
@@ -168,6 +215,13 @@ files:
168
215
  - spec/protected_assets/Icon.png
169
216
  - spec/public_assets/Default.png
170
217
  - spec/spec_helper.rb
218
+ - spec/support/auto/app_garden.rb
219
+ - spec/support/auto/fixtures.rb
220
+ - spec/support/auto/network.rb
221
+ - spec/support/models/async_action.rb
222
+ - spec/support/models/client_release.rb
223
+ - spec/support/models/game_data.rb
224
+ - spec/support/models/player.rb
171
225
  homepage: http://www.groovenauts.jp/service/#gss
172
226
  licenses:
173
227
  - MIT
@@ -193,6 +247,11 @@ signing_key:
193
247
  specification_version: 4
194
248
  summary: network library for Groovenauts GSS
195
249
  test_files:
250
+ - spec/factories/async_action.rb
251
+ - spec/factories/client_release.rb
252
+ - spec/factories/device_type.rb
253
+ - spec/factories/game_data.rb
254
+ - spec/factories/player.rb
196
255
  - spec/libgss/action_request_spec.rb
197
256
  - spec/libgss/actions/dictionary_spec.rb
198
257
  - spec/libgss/actions/friendship_spec.rb
@@ -209,4 +268,11 @@ test_files:
209
268
  - spec/protected_assets/Icon.png
210
269
  - spec/public_assets/Default.png
211
270
  - spec/spec_helper.rb
271
+ - spec/support/auto/app_garden.rb
272
+ - spec/support/auto/fixtures.rb
273
+ - spec/support/auto/network.rb
274
+ - spec/support/models/async_action.rb
275
+ - spec/support/models/client_release.rb
276
+ - spec/support/models/game_data.rb
277
+ - spec/support/models/player.rb
212
278
  has_rdoc: