riaction 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG #
2
2
 
3
+ ## 0.5.0 ##
4
+
5
+ * Added ability to specify a display name for a profile. new feature; all existing features work the same.
6
+
7
+
3
8
  ## 0.4.2 ##
4
9
 
5
10
  * Fixed NameError bug in tasks. For realsies.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riaction (0.2.0)
4
+ riaction (0.4.2)
5
5
  activerecord (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
7
  faraday
data/README.md CHANGED
@@ -52,6 +52,13 @@ Models in your application may declare themselves as profiles that exist on IAct
52
52
 
53
53
  Here, the class User declares itself as a profile of type "player", identifiable by two of IActionable's supported identifier types, username and custom. The values of these identifiers are the fields nickname and id, respectively, and can be any method that an instance of the class responds to. When a class declares itself as a riaction profile, an after_create callback will be added to create the profile on IActionable with the identifiers declared in the class.
54
54
 
55
+ An optional display name can be given, which should be a method that the object responds to:
56
+
57
+ class User < ActiveRecord::Base
58
+ riaction :profile, :type => :player, :username => :nickname, :custom => :id, :display_name => :nickname
59
+ end
60
+
61
+
55
62
  #### Profile Instance Methods ####
56
63
 
57
64
  Classes that declare themselves as IActionable profiles are given instance methods that tie in to the IActionable API, as many uses of the API treat the profile as a top-level resource.
@@ -81,9 +81,9 @@ module Riaction
81
81
  true
82
82
  end
83
83
  end
84
-
84
+
85
85
  # store the profile
86
- riaction_profiles.store(type, fields)
86
+ riaction_profiles.store(type, {:display_name_method => fields.delete(:display_name), :identifiers => fields})
87
87
  end
88
88
 
89
89
  def riaction_profile?
@@ -182,10 +182,10 @@ module Riaction
182
182
  def riaction_profile_keys(profile_type=nil, id_type=nil)
183
183
  if self.class.riaction_profiles.size > 0
184
184
  if profile_type && self.class.riaction_profiles.has_key?(profile_type)
185
- ids = self.class.riaction_profiles.fetch(profile_type)
185
+ ids = self.class.riaction_profiles.fetch(profile_type)[:identifiers]
186
186
  else
187
187
  profile_type = self.class.riaction_profiles.first[0]
188
- ids = self.class.riaction_profiles.first[1]
188
+ ids = self.class.riaction_profiles.first[1][:identifiers]
189
189
  end
190
190
 
191
191
  if id_type && ids.has_key?(id_type)
@@ -199,6 +199,34 @@ module Riaction
199
199
  rescue KeyError, NoMethodError => e
200
200
  {}
201
201
  end
202
+
203
+ def riaction_profile_display_name(profile_type=nil)
204
+ if self.class.riaction_profiles.size > 0
205
+ if profile_type && self.class.riaction_profiles.has_key?(profile_type)
206
+ method = self.class.riaction_profiles.fetch(profile_type)[:display_name_method]
207
+ else
208
+ method = self.class.riaction_profiles.first[1][:display_name_method]
209
+ end
210
+
211
+ if method
212
+ if method.kind_of? Symbol
213
+ begin
214
+ self.send(method)
215
+ rescue NoMethodError => e
216
+ nil
217
+ end
218
+ else
219
+ nil
220
+ end
221
+ else
222
+ nil
223
+ end
224
+ else
225
+ nil
226
+ end
227
+ rescue KeyError, NoMethodError => e
228
+ nil
229
+ end
202
230
 
203
231
  #################
204
232
  # API wrappers #
@@ -222,7 +250,7 @@ module Riaction
222
250
  existing = riaction_profile_summary
223
251
  unless existing
224
252
  @iactionable_api ||= IActionable::Api.new
225
- @iactionable_api.create_profile(keys[:profile_type], keys[:id_type], keys[:id])
253
+ @iactionable_api.create_profile(keys[:profile_type], keys[:id_type], keys[:id], riaction_profile_display_name)
226
254
  else
227
255
  existing
228
256
  end
@@ -1,3 +1,3 @@
1
1
  module Riaction
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -48,7 +48,7 @@ describe Riaction do
48
48
  riaction :profile, :type => :user, :custom => :id
49
49
  end
50
50
  RiactionClass.riaction_profile?.should be_true
51
- hash_including(:custom => :id).should == RiactionClass.riaction_profiles[:user]
51
+ hash_including(:custom => :id).should == RiactionClass.riaction_profiles[:user][:identifiers]
52
52
  end
53
53
  end
54
54
 
@@ -280,7 +280,7 @@ describe Riaction do
280
280
  super
281
281
  end
282
282
 
283
- riaction :profile, :type => :user, :custom => :id, :username => :name
283
+ riaction :profile, :type => :user, :display_name => :full_name, :custom => :id, :username => :name
284
284
 
285
285
  def id
286
286
  42
@@ -289,6 +289,10 @@ describe Riaction do
289
289
  def name
290
290
  "zortnac"
291
291
  end
292
+
293
+ def full_name
294
+ "zortnac pah"
295
+ end
292
296
  end
293
297
 
294
298
  describe "creation triggering" do
@@ -312,9 +316,9 @@ describe Riaction do
312
316
  end
313
317
 
314
318
  describe "for creating a profile" do
315
- it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance" do
319
+ it "should make the correct call to the API with the parameters given in the class, and the values provided by the instance, including the display name" do
316
320
  @api.stub!(:get_profile_summary).and_return(nil)
317
- @api.should_receive(:create_profile).once.with("user", "custom", @instance.id.to_s).and_return(@mock_response)
321
+ @api.should_receive(:create_profile).once.with("user", "custom", @instance.id.to_s, @instance.full_name).and_return(@mock_response)
318
322
  @instance.riaction_create_profile.should == @mock_response
319
323
  end
320
324
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000Z
12
+ date: 2012-01-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2161189540 !ruby/object:Gem::Requirement
16
+ requirement: &2160485300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2161189540
24
+ version_requirements: *2160485300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2161189120 !ruby/object:Gem::Requirement
27
+ requirement: &2160484880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2161189120
35
+ version_requirements: *2160484880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: faraday
38
- requirement: &2161188660 !ruby/object:Gem::Requirement
38
+ requirement: &2160484420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2161188660
46
+ version_requirements: *2160484420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday-stack
49
- requirement: &2161188240 !ruby/object:Gem::Requirement
49
+ requirement: &2160484000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2161188240
57
+ version_requirements: *2160484000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activerecord
60
- requirement: &2161187740 !ruby/object:Gem::Requirement
60
+ requirement: &2160483440 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 3.0.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2161187740
68
+ version_requirements: *2160483440
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &2161187240 !ruby/object:Gem::Requirement
71
+ requirement: &2160482900 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 3.0.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2161187240
79
+ version_requirements: *2160482900
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: resque
82
- requirement: &2161186860 !ruby/object:Gem::Requirement
82
+ requirement: &2160482360 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *2161186860
90
+ version_requirements: *2160482360
91
91
  description: Wrapper for IActionable's restful API and an "acts-as" style interface
92
92
  for models to behave as profiles and drive game events.
93
93
  email: