playlyfe_client 1.1.3 → 1.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4549bdc5003bfa8c2b4b19d533e09366d559d7e
4
- data.tar.gz: d8b2c05c743b2a77f4aec671077cfafd99328b80
3
+ metadata.gz: 8265086137f61b104bb1fb4e923a52b09094515e
4
+ data.tar.gz: b4f4076b06867d22b939a672f571661743ab3593
5
5
  SHA512:
6
- metadata.gz: c1637aff895cfac6c19c533d5afc97665f5e9e6fc802a0a7312132272b929e3f15025b2f1374f2672ba50f983ee93d15efc4ace91cf904a232bf4f25d02e7657
7
- data.tar.gz: 361ada6176c4f977bda0feccecc12e465c8bdae34a932c5d2c2bbfab78879af5cb1b923cf3b1cd1fd5be7f1e54128f9a63fa17a533494719a333e3fc4dd149a5
6
+ metadata.gz: 9f68d2764d0ed795b3a5933905cbb87909a162cbb19cb20dec674a923e110540b4009a872bf784228d075cb0e8f59273f7d8eda6e2ad30a7f51fcd4c1fc63cc4
7
+ data.tar.gz: 6763e192900cd50707181517b22fb2b7b5eff4b11b712bc26640a1a3dfa120b40e0d546fb0fcea0eb487d7edbcdcb7d0df3c4341ad53fbf950a3c69b62e2772b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- playlyfe_client (1.1.3)
4
+ playlyfe_client (1.1.5)
5
5
  json
6
6
  jwt
7
7
  rest-client
@@ -9,8 +9,17 @@ module PlaylyfeClient
9
9
  game.avaliable_actions
10
10
  end
11
11
 
12
- def play_by(player)
13
- player.play(self)
12
+ def play_by(player, variables_for_play ={})
13
+ @variables_for_play=variables_for_play
14
+ fail_if_variables_are_wrong
15
+
16
+ begin
17
+ game.connection.post_play_action(self.id, player.id, { "variables" => variables_for_play})
18
+ rescue PlaylyfeClient::ActionRateLimitExceededError => e
19
+ unless game.ignore_rate_limit_errors
20
+ fail e
21
+ end
22
+ end
14
23
  end
15
24
 
16
25
  def apply_rewards_on_scores(scores)
@@ -21,12 +30,23 @@ module PlaylyfeClient
21
30
  new_scores
22
31
  end
23
32
 
33
+ def variables
34
+ []
35
+ end
36
+
37
+ def required_variables
38
+ []
39
+ end
40
+
24
41
  private
25
42
 
26
43
  def initialize(game)
27
44
  @game=game
28
45
  end
29
46
 
47
+ def fail_if_variables_are_wrong
48
+ #not implemented here
49
+ end
30
50
  end
31
51
  end
32
52
 
@@ -13,6 +13,8 @@ module PlaylyfeClient
13
13
  class PlaylyfeClient::PlayerExistsError < PlaylyfeClient::PlayerError; end
14
14
  class PlaylyfeClient::CollectionFindOneIsNotSupportedError < PlaylyfeClient::Error; end
15
15
  class PlaylyfeClient::ApiCallsLimitExceededError < PlaylyfeClient::Error; end
16
+ class PlaylyfeClient::ActionPlayedWithoutRequiredVariables < PlaylyfeClient::ActionError; end
17
+ class PlaylyfeClient::ActionPlayedWithWrongVariables < PlaylyfeClient::ActionError; end
16
18
 
17
19
  class Error < StandardError
18
20
  attr_accessor :name, :message
@@ -16,6 +16,10 @@ module PlaylyfeClient
16
16
  def play(action)
17
17
  false
18
18
  end
19
+
20
+ def reload!
21
+ nil
22
+ end
19
23
 
20
24
  def scores
21
25
  {points: {} ,sets: {}, states: {}, compound: {}}
@@ -5,6 +5,10 @@ module PlaylyfeClient
5
5
  class Action < PlaylyfeClient::Action
6
6
  attr_reader :id, :name, :description, :rewards, :variables, :times_played
7
7
 
8
+ def required_variables
9
+ @required_variables||=variables.select {|v| v["required"]}
10
+ end
11
+
8
12
  private
9
13
 
10
14
  def initialize(action_hash, game)
@@ -52,6 +56,47 @@ module PlaylyfeClient
52
56
  items
53
57
  end
54
58
 
59
+ def fail_if_variables_are_wrong
60
+ return true if self.variables.empty?
61
+
62
+ missing_variables=[]
63
+ wrong_variables=[]
64
+
65
+ self.variables.each do |v|
66
+ vfp=@variables_for_play[v["name"]] || @variables_for_play[v["name"].to_sym]
67
+ if vfp.nil?
68
+ if self.required_variables.include?(v)
69
+ missing_variables << v
70
+ end
71
+ else
72
+ unless check_type_of_variable_for_play(v,vfp)
73
+ wrong_variables << [v,vfp]
74
+ end
75
+ end
76
+ end
77
+
78
+ unless missing_variables.empty?
79
+ fail PlaylyfeClient::ActionPlayedWithoutRequiredVariables.new("{\"error\": \"missing_required_variables\", \"error_description\": \"The Action '#{self.id}' can only be played with required variables [#{self.required_variables.collect {|v| "'#{v["name"]}'"}.join(", ")}].\"}", "")
80
+ end
81
+
82
+ unless wrong_variables.empty?
83
+ list=wrong_variables.collect {|wv| "'#{wv.first["name"]}[#{wv.first["type"]}] => #{wv.last}'"}
84
+ fail PlaylyfeClient::ActionPlayedWithWrongVariables.new("{\"error\": \"variables_have_wrong_types\", \"error_description\": \"Given variables for action '#{self.id}' have wrong types [#{list.join(", ")}].\"}", "")
85
+ end
86
+ end
87
+
88
+ def check_type_of_variable_for_play(v,vfp)
89
+ case v["type"]
90
+ when "int"
91
+ vfp.kind_of?(Integer)
92
+ when "string"
93
+ vfp.kind_of?(String)
94
+ else
95
+ false
96
+ end
97
+ end
98
+
99
+
55
100
  end
56
101
  end
57
102
  end
@@ -24,17 +24,15 @@ module PlaylyfeClient
24
24
  enabled
25
25
  end
26
26
 
27
- def play(action)
28
- begin
29
- game.connection.post_play_action(action.id, self.id)
30
- @profile_hash= game.connection.get_full_player_profile_hash(self.id)
31
- @scores=fill_scores
32
- rescue PlaylyfeClient::ActionRateLimitExceededError => e
33
- unless game.ignore_rate_limit_errors
34
- fail e
35
- end
36
- end
27
+ def play(action, variables={})
28
+ action.play_by(self, variables)
29
+ reload!
37
30
  end
31
+
32
+ def reload!
33
+ @profile_hash= game.connection.get_full_player_profile_hash(self.id)
34
+ @scores=fill_scores
35
+ end
38
36
 
39
37
  def scores(force_refill=false)
40
38
  if (!defined?(@scores) || force_refill)
@@ -1,3 +1,3 @@
1
1
  module PlaylyfeClient
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playlyfe_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json