riaction 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +47 -26
- data/README.md +101 -52
- data/db/riaction.db +0 -0
- data/lib/riaction.rb +1 -1
- data/lib/riaction/constants.rb +10 -0
- data/lib/riaction/crud_event_callback.rb +3 -3
- data/lib/riaction/event_performer.rb +11 -16
- data/lib/riaction/profile_creation_callback.rb +1 -1
- data/lib/riaction/profile_creator.rb +13 -6
- data/lib/riaction/railtie.rb +4 -0
- data/lib/riaction/riaction.rb +302 -282
- data/lib/riaction/version.rb +1 -1
- data/lib/tasks/riaction.rake +16 -14
- data/riaction.gemspec +3 -2
- data/spec/event_performer_spec.rb +233 -0
- data/spec/profile_creation_spec.rb +135 -0
- data/spec/riaction_spec.rb +820 -253
- data/spec/spec_helper.rb +8 -1
- metadata +38 -71
- data/lib/riaction/iactionable/api.rb +0 -170
- data/lib/riaction/iactionable/connection.rb +0 -114
- data/lib/riaction/iactionable/error.rb +0 -17
- data/lib/riaction/iactionable/objects.rb +0 -27
- data/lib/riaction/iactionable/objects/achievement.rb +0 -29
- data/lib/riaction/iactionable/objects/awardable.rb +0 -50
- data/lib/riaction/iactionable/objects/challenge.rb +0 -27
- data/lib/riaction/iactionable/objects/goal.rb +0 -30
- data/lib/riaction/iactionable/objects/i_actionable_object.rb +0 -36
- data/lib/riaction/iactionable/objects/identifier.rb +0 -17
- data/lib/riaction/iactionable/objects/leaderboard.rb +0 -15
- data/lib/riaction/iactionable/objects/leaderboard_report.rb +0 -30
- data/lib/riaction/iactionable/objects/level.rb +0 -24
- data/lib/riaction/iactionable/objects/level_type.rb +0 -15
- data/lib/riaction/iactionable/objects/point_type.rb +0 -15
- data/lib/riaction/iactionable/objects/profile_achievements.rb +0 -20
- data/lib/riaction/iactionable/objects/profile_challenges.rb +0 -20
- data/lib/riaction/iactionable/objects/profile_goals.rb +0 -20
- data/lib/riaction/iactionable/objects/profile_level.rb +0 -20
- data/lib/riaction/iactionable/objects/profile_notifications.rb +0 -29
- data/lib/riaction/iactionable/objects/profile_points.rb +0 -29
- data/lib/riaction/iactionable/objects/profile_summary.rb +0 -37
- data/lib/riaction/iactionable/objects/progress.rb +0 -46
- data/lib/riaction/iactionable/settings.rb +0 -30
- data/spec/api_spec.rb +0 -314
- data/spec/connection_spec.rb +0 -111
- data/spec/get_achievements_api_response_spec.rb +0 -46
- data/spec/get_challenges_api_response_spec.rb +0 -42
- data/spec/get_goals_api_response_spec.rb +0 -46
- data/spec/get_leaderboard_api_response_spec.rb +0 -76
- data/spec/get_profile_achievements_api_response_spec.rb +0 -99
- data/spec/get_profile_api_response_spec.rb +0 -103
- data/spec/get_profile_challenges_api_response_spec.rb +0 -85
- data/spec/get_profile_goals_api_response_spec.rb +0 -89
- data/spec/get_profile_notifications_api_response_spec.rb +0 -75
- data/spec/get_profile_points_api_response_spec.rb +0 -67
- data/spec/settings_spec.rb +0 -52
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# CHANGELOG #
|
2
2
|
|
3
|
+
## 1.1.0 ##
|
4
|
+
|
5
|
+
* Entire re-spec and re-factor of gem
|
6
|
+
* A class may declare multiple profile types
|
7
|
+
* Events may specify which profile type of a profile object to use when firing event
|
8
|
+
* Backwards-compatible with previous version
|
9
|
+
|
3
10
|
## 1.0.0 ##
|
4
11
|
|
5
12
|
* API return values are now all objects, not mix of key/value pairs and objects.
|
data/Gemfile.lock
CHANGED
@@ -1,43 +1,46 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
riaction (0.
|
4
|
+
riaction (1.0.0)
|
5
5
|
activerecord (>= 3.0.0)
|
6
6
|
activesupport (>= 3.0.0)
|
7
|
-
faraday
|
8
|
-
faraday-stack
|
9
7
|
rake
|
10
8
|
resque
|
9
|
+
ruby-iactionable (>= 0.0.2)
|
11
10
|
|
12
11
|
GEM
|
13
12
|
remote: http://rubygems.org/
|
14
13
|
specs:
|
15
|
-
activemodel (3.1
|
16
|
-
activesupport (= 3.1
|
14
|
+
activemodel (3.2.1)
|
15
|
+
activesupport (= 3.2.1)
|
17
16
|
builder (~> 3.0.0)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
arel (~> 2.2.1)
|
17
|
+
activerecord (3.2.1)
|
18
|
+
activemodel (= 3.2.1)
|
19
|
+
activesupport (= 3.2.1)
|
20
|
+
arel (~> 3.0.0)
|
23
21
|
tzinfo (~> 0.3.29)
|
24
|
-
activesupport (3.1
|
22
|
+
activesupport (3.2.1)
|
23
|
+
i18n (~> 0.6)
|
25
24
|
multi_json (~> 1.0)
|
26
25
|
addressable (2.2.6)
|
27
|
-
|
26
|
+
archive-tar-minitar (0.5.2)
|
27
|
+
arel (3.0.0)
|
28
28
|
builder (3.0.0)
|
29
|
+
columnize (0.3.6)
|
29
30
|
diff-lcs (1.1.3)
|
30
|
-
faraday (0.7.
|
31
|
-
addressable (~> 2.2
|
32
|
-
multipart-post (~> 1.1
|
33
|
-
rack (
|
34
|
-
faraday-stack (0.1.
|
35
|
-
faraday (
|
31
|
+
faraday (0.7.6)
|
32
|
+
addressable (~> 2.2)
|
33
|
+
multipart-post (~> 1.1)
|
34
|
+
rack (~> 1.1)
|
35
|
+
faraday-stack (0.1.5)
|
36
|
+
faraday (>= 0.6, < 0.8)
|
36
37
|
i18n (0.6.0)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
linecache19 (0.5.12)
|
39
|
+
ruby_core_source (>= 0.1.4)
|
40
|
+
multi_json (1.0.4)
|
41
|
+
multipart-post (1.1.4)
|
42
|
+
rack (1.4.1)
|
43
|
+
rack-protection (1.2.0)
|
41
44
|
rack
|
42
45
|
rake (0.9.2.2)
|
43
46
|
redis (2.2.2)
|
@@ -56,13 +59,29 @@ GEM
|
|
56
59
|
rspec-expectations (2.7.0)
|
57
60
|
diff-lcs (~> 1.1.2)
|
58
61
|
rspec-mocks (2.7.0)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
ruby-debug-base19 (0.11.25)
|
63
|
+
columnize (>= 0.3.1)
|
64
|
+
linecache19 (>= 0.5.11)
|
65
|
+
ruby_core_source (>= 0.1.4)
|
66
|
+
ruby-debug19 (0.11.6)
|
67
|
+
columnize (>= 0.3.1)
|
68
|
+
linecache19 (>= 0.5.11)
|
69
|
+
ruby-debug-base19 (>= 0.11.19)
|
70
|
+
ruby-iactionable (0.0.2)
|
71
|
+
activesupport (>= 3.0.0)
|
72
|
+
faraday
|
73
|
+
faraday-stack
|
74
|
+
rake
|
75
|
+
ruby_core_source (0.1.5)
|
76
|
+
archive-tar-minitar (>= 0.5.2)
|
77
|
+
sinatra (1.3.2)
|
78
|
+
rack (~> 1.3, >= 1.3.6)
|
79
|
+
rack-protection (~> 1.2)
|
62
80
|
tilt (~> 1.3, >= 1.3.3)
|
81
|
+
sqlite3 (1.3.5)
|
63
82
|
tilt (1.3.3)
|
64
83
|
tzinfo (0.3.31)
|
65
|
-
vegas (0.1.
|
84
|
+
vegas (0.1.11)
|
66
85
|
rack (>= 1.0.0)
|
67
86
|
|
68
87
|
PLATFORMS
|
@@ -71,3 +90,5 @@ PLATFORMS
|
|
71
90
|
DEPENDENCIES
|
72
91
|
riaction!
|
73
92
|
rspec (>= 2.6)
|
93
|
+
ruby-debug19
|
94
|
+
sqlite3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Overview #
|
2
2
|
|
3
|
-
|
3
|
+
You've [gamified](http://en.wikipedia.org/wiki/Gamification) your Rails app using IActionable's services, or maybe you're thinking about it. IActionable offers a restful API to log events from your game; these events ("sign in", "write a review", etc) earn points, achievements and more for the users that perform them. This gem provides a way to tie these events to the CRUD actions of the ActiveRecord models that make up your restful Rails app. Through an "acts-as" style mix-in, riaction takes the "write a review" event defined in your IActionable game, and drives it with the actual creation of a review object. Riaction makes use of the [Ruby-IActionable gem](https://github.com/zortnac/Ruby-IActionable) to connect to the IActionable API.
|
4
4
|
|
5
5
|
# How To Use #
|
6
6
|
|
@@ -8,26 +8,9 @@ riaction provides both a ruby wrapper for IActionable's restful API and an "acts
|
|
8
8
|
|
9
9
|
gem install riaction
|
10
10
|
|
11
|
-
##
|
11
|
+
## Requirements and Dependencies ##
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
IActionable::Api.init_settings( :app_key => "12345",
|
16
|
-
:api_key => "abcde",
|
17
|
-
:version => 3 )
|
18
|
-
@api = IActionable::Api.new
|
19
|
-
|
20
|
-
IActionable's API speaks in JSON, and here those responses are wrapped in simple objects where nesting and variable names are determined by [IActionable's documentation](http://www.iactionable.com/api/). For example, here the wrapper is making a call to load a profile summary:
|
21
|
-
|
22
|
-
profile_summary = @api.get_profile_summary("user", "username", "zortnac", 10)
|
23
|
-
profile_summary.display_name # => "Chris Eberz"
|
24
|
-
profile_summary.identifiers.first # => instance of IActionable::Objects::Identifier
|
25
|
-
profile_summary.identifiers.first.id_type # => "username"
|
26
|
-
profile_summary.identifiers.first.id # => "zortnac"
|
27
|
-
|
28
|
-
## Using riaction In Rails ##
|
29
|
-
|
30
|
-
While the API wrapper in riaction can be used directly (and I ought just pull it out as a separate gem), the rest of riaction consists of an "acts-as" style interface for your application's ActiveRecord models that leverages the API wrapper to associate your models with IActionable profiles and to have IActionable event logging be driven by your models' CRUD actions. riaction relies on Resque for tasking all of the requests made to IActionable's service.
|
13
|
+
Riaction uses [Resque](https://github.com/defunkt/resque) to schedule and perform all requests to IActionable.
|
31
14
|
|
32
15
|
### Generators ###
|
33
16
|
|
@@ -37,10 +20,10 @@ Riaction comes with a generator for creating a YAML file to contain your credent
|
|
37
20
|
|
38
21
|
### Declaring A Model As A Profile ###
|
39
22
|
|
40
|
-
|
23
|
+
In IActionable's API, events are explicitly tied to the user that generated them; an event cannot exist or be logged that doesn't belong to a user. In order to log an event for writing a review, we need to decide which model in our application will behave as the "profile" in IActionable's system. Here our user model will serve that purpose:
|
41
24
|
|
42
25
|
class User < ActiveRecord::Base
|
43
|
-
riaction :profile, :type => :player, :
|
26
|
+
riaction :profile, :type => :player, :custom => :id
|
44
27
|
end
|
45
28
|
|
46
29
|
# == Schema Information
|
@@ -50,47 +33,69 @@ Models in your application may declare themselves as profiles that exist on IAct
|
|
50
33
|
# id :integer(4)
|
51
34
|
# nickname :string(255)
|
52
35
|
|
53
|
-
|
36
|
+
In the above example, the class User declares itself as a profile of type "player". Profile types are defined on IActionable's account dashboard. Profiles are identifiable by a number of supported identifier types, and in the above example we'll be relying on the "custom" identifier type, which will point to the value of the model's unique key in the database. In other words, the user in our Rails app with an id of 7 will map to a profile on IActionable of type "player", and a "custom" identifier with a value of "7."
|
37
|
+
|
38
|
+
By declaring our user class as a riaction profile, an after-create callback will be registered on the class to create the corresponding profile on IActionable.
|
54
39
|
|
55
|
-
|
40
|
+
IActionable's profiles also have a "display name" property which can also be given here, and which should be a method that the object responds to:
|
56
41
|
|
57
42
|
class User < ActiveRecord::Base
|
58
|
-
riaction :profile, :type => :player, :
|
59
|
-
end
|
60
|
-
|
43
|
+
riaction :profile, :type => :player, :custom => :id, :display_name => :nickname
|
44
|
+
end
|
61
45
|
|
62
46
|
#### Profile Instance Methods ####
|
63
47
|
|
64
|
-
Classes that declare themselves as
|
48
|
+
Classes that declare themselves as riaction profiles are given instance methods that hit various points in the IActionable API for loading a profile's data from the game, using the [Ruby-IActionable gem](https://github.com/zortnac/Ruby-IActionable).
|
65
49
|
|
66
|
-
@
|
67
|
-
|
50
|
+
@user_instance = User.first
|
51
|
+
|
52
|
+
# return the user's profile summary and (up to) 10 of their recent achievements
|
68
53
|
@user_instance.riaction_profile_summary(10)
|
69
54
|
|
70
|
-
|
71
|
-
# is equivalent to the following...
|
55
|
+
# return the user's summary of challenges, limited to the ones already completed
|
72
56
|
@user_instance.riaction_profile_challenges(:completed)
|
57
|
+
|
58
|
+
#### Multiple Profile Types ####
|
59
|
+
|
60
|
+
Riaction will support a model in your app to map to multiple profiles defined in IActionable, if your situation calls for that:
|
61
|
+
|
62
|
+
class User < ActiveRecord::Base
|
63
|
+
riaction :profile, :type => :light_world_player, :custom => :id
|
64
|
+
riaction :profile, :type => :dark_world_player, :custom => :id
|
65
|
+
end
|
73
66
|
|
74
|
-
|
75
|
-
#
|
76
|
-
|
67
|
+
# == Schema Information
|
68
|
+
#
|
69
|
+
# Table name: users
|
70
|
+
#
|
71
|
+
# id :integer(4)
|
72
|
+
# nickname :string(255)
|
77
73
|
|
78
|
-
|
74
|
+
In the above example we want to define our user model as two types of players in our (apparently Zelda-inspired) game. The model will behave exactly as it would with only a single profile declared, and the first one declared ( `:light_world_player` ) will always be the default used, unless a different profile type is set explicitly:
|
79
75
|
|
80
|
-
|
76
|
+
@user_instance.riaction_set_profile(:dark_world_player)
|
81
77
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
* Any optional parameters (key-value pairs) that you want to pass.
|
78
|
+
Setting the profile type only affects the instance it is called on, and the change will persist for the life of the object or until changed again.
|
79
|
+
|
80
|
+
### Declaring Events ###
|
86
81
|
|
87
|
-
|
82
|
+
Models in your application may declare any number of events that they wish to log through IActionable. Just as an event on IActionable must belong to a profile, in this example the model generating the event belongs to the model that behaves as a profile:
|
88
83
|
|
89
|
-
class
|
84
|
+
class Review
|
90
85
|
belongs_to :user
|
91
|
-
belongs_to :post
|
92
86
|
|
93
|
-
riaction :event, :name => :
|
87
|
+
riaction :event, :name => :write_a_review, :trigger => :create, :profile => :user
|
88
|
+
|
89
|
+
def length
|
90
|
+
text.size
|
91
|
+
end
|
92
|
+
|
93
|
+
def stats
|
94
|
+
{
|
95
|
+
:length => text.length,
|
96
|
+
:rating => stars
|
97
|
+
}
|
98
|
+
end
|
94
99
|
end
|
95
100
|
|
96
101
|
# == Schema Information
|
@@ -99,19 +104,63 @@ Models in your application may declare any number of events that they wish to lo
|
|
99
104
|
#
|
100
105
|
# id :integer(4)
|
101
106
|
# user_id :integer(4)
|
102
|
-
#
|
107
|
+
# stars :integer(4)
|
108
|
+
# text :string(255)
|
109
|
+
|
110
|
+
In the above example, `:write_a_review` is the name of the event and should match the key used on IActionable. The value for `:trigger` determines the action that will cause the event to fire, and can also be `:update` or `:destroy`, and will automatically fire when a record is created, updated, or destroyed, respectively. The value given to `:profile` should return the riaction profile object that this event will be logged under.
|
111
|
+
|
112
|
+
#### Event Parameters ####
|
113
|
+
|
114
|
+
Part of the power in the way IActionable may be configured to process your events is in the key-value parameters you can send along with the event itself. Riaction allows you to define an event with these parameters. Parameters may be a hash with static values:
|
115
|
+
|
116
|
+
riaction :event, :name => :write_a_review, :trigger => :create, :profile => :user, :params => {:foo => 'bar'}
|
117
|
+
|
118
|
+
...a hash where some values reference methods:
|
119
|
+
|
120
|
+
riaction :event, :name => :write_a_review, :trigger => :create, :profile => :user, :params => {:review_length => :length}
|
121
|
+
|
122
|
+
...a proc:
|
123
|
+
|
124
|
+
riaction :event, :name => :write_a_review, :trigger => :create, :profile => :user, :params => Proc.new{|record| {:length => record.text.length}}
|
125
|
+
|
126
|
+
...or the name of an instance method (which ought to return a hash)
|
127
|
+
|
128
|
+
riaction :event, :name => :write_a_review, :trigger => :create, :profile => :user, :params => :stats
|
129
|
+
|
130
|
+
#### Conditional Events ####
|
131
|
+
|
132
|
+
The logging of an event may be conditional:
|
133
|
+
|
134
|
+
riaction :event, :name => :write_a_review, :trigger => :create, :profile => :user, :if => Proc.new{|record| record.stars > 3}
|
135
|
+
|
136
|
+
...where the value of `:if` may be an instance method or a proc.
|
137
|
+
|
138
|
+
### Things To Note ###
|
139
|
+
|
140
|
+
#### Non-CRUD Actions ####
|
141
|
+
|
142
|
+
Sometimes when create, update, and destroy just don't really make sense for the event, custom triggers may be declared:
|
143
|
+
|
144
|
+
riaction :event, :name => :receive_thumbs_up, :trigger => :thumbs_up, :profile => :user
|
145
|
+
|
146
|
+
In the above example, in order to have the review fire an event when it gets a thumbs up from another user, we declare a trigger called `:thumbs_up`. Since this won't be fired automatically like a CRUD action, an instance method will be provided to fire it by hand:
|
147
|
+
|
148
|
+
@review_instance.trigger_thumbs_up!
|
149
|
+
|
150
|
+
#### Events and Multiple Profile Types ####
|
103
151
|
|
104
|
-
|
152
|
+
If the object given as the riaction profile for an event defines more than one profile type, the default profile type (the first one declared in the class) will be used. To use a different one, pass in the name of the alternate type:
|
105
153
|
|
106
|
-
|
154
|
+
riaction :event, :name => :write_a_review, :trigger => :create, :profile => :user, :profile_type => :dark_world_player
|
107
155
|
|
108
|
-
|
156
|
+
#### Profiles With Their Own Events ####
|
109
157
|
|
110
|
-
|
158
|
+
A class the declares itself as a profile may also declare events which rely on that same class as the profile object:
|
111
159
|
|
112
|
-
|
160
|
+
riaction :profile, :type => :player, :custom => :id
|
161
|
+
riaction :event, :name => :join_the_game, :trigger => :create, :profile => :self
|
113
162
|
|
114
|
-
|
163
|
+
In the above example of a declaration on the User class, the user will fire a `:join_the_game` event using itself as the profile upon its creation. The profile declaration should come before the event declaration.
|
115
164
|
|
116
165
|
### Rails Rake Tasks ###
|
117
166
|
|
data/db/riaction.db
ADDED
Binary file
|
data/lib/riaction.rb
CHANGED
data/lib/riaction/constants.rb
CHANGED
@@ -7,5 +7,15 @@ module Riaction
|
|
7
7
|
def self.retry_attempts_for_internal_error
|
8
8
|
3
|
9
9
|
end
|
10
|
+
|
11
|
+
def self.supported_identifier_types
|
12
|
+
[:email,:username,:custom,:facebook,:twitter,:salesforce]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.riaction_options
|
16
|
+
{
|
17
|
+
:default_event_params => {}
|
18
|
+
}
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
@@ -8,19 +8,19 @@ module Riaction
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def after_create(record)
|
11
|
-
if record.riaction_log_event?(@event_name)
|
11
|
+
if record.riaction_log_event?(@event_name) && !record.class.riactionless?
|
12
12
|
Resque.enqueue(::Riaction::EventPerformer, @event_name, record.class.base_class.to_s, record.id)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def after_update(record)
|
17
|
-
if record.riaction_log_event?(@event_name)
|
17
|
+
if record.riaction_log_event?(@event_name) && !record.class.riactionless?
|
18
18
|
Resque.enqueue(::Riaction::EventPerformer, @event_name, record.class.base_class.to_s, record.id)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def after_destroy(record)
|
23
|
-
if record.riaction_log_event?(@event_name)
|
23
|
+
if record.riaction_log_event?(@event_name) && !record.class.riactionless?
|
24
24
|
Resque.enqueue(::Riaction::EventPerformer, @event_name, record.class.base_class.to_s, record.id)
|
25
25
|
end
|
26
26
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'riaction/iactionable/api'
|
2
1
|
require 'riaction/constants'
|
3
2
|
require "resque"
|
4
3
|
|
@@ -8,28 +7,24 @@ module Riaction
|
|
8
7
|
|
9
8
|
def self.perform(event_name, klass_name, id, attempt=0)
|
10
9
|
iactionable_api = IActionable::Api.new
|
11
|
-
|
12
10
|
event_object = klass_name.constantize.find_by_id!(id)
|
13
|
-
|
14
|
-
profile_keys = event_details[:profile].riaction_profile_keys
|
11
|
+
event_params = event_object.riaction_event_params
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
if ( klass_name.constantize.riactionary? &&
|
14
|
+
klass_name.constantize.riaction_events? &&
|
15
|
+
klass_name.constantize.riaction_defines_event?(event_name) )
|
16
|
+
iactionable_api.log_event( event_params[event_name][:profile][:type],
|
17
|
+
event_params[event_name][:profile][:id_type],
|
18
|
+
event_params[event_name][:profile][:id],
|
19
|
+
event_name,
|
20
|
+
event_params[event_name][:params])
|
21
|
+
else
|
22
|
+
raise ::Riaction::ConfigurationError.new("#{klass_name} does not define event #{event_name}")
|
23
23
|
end
|
24
|
-
|
25
|
-
# Log the event
|
26
|
-
iactionable_api.log_event(profile_keys[:profile_type], profile_keys[:id_type], profile_keys[:id], event_details[:key], event_details[:params])
|
27
24
|
rescue ActiveRecord::RecordNotFound => e
|
28
25
|
# event_object no longer exists; no means to recover
|
29
26
|
rescue IActionable::Error::BadRequest => e
|
30
27
|
# Log event should never throw this as of IActionable API v3
|
31
|
-
rescue NoMethodError => e
|
32
|
-
raise NoEventDefined.new
|
33
28
|
rescue IActionable::Error::Internal => e
|
34
29
|
# upon an intenal error from IActionable, retry some set number of times by requeueing the task through Resque
|
35
30
|
# after the max number of attempts, re-raise
|
@@ -4,7 +4,7 @@ require 'riaction/profile_creator'
|
|
4
4
|
module Riaction
|
5
5
|
class ProfileCreationCallback
|
6
6
|
def after_create(record)
|
7
|
-
Resque.enqueue(::Riaction::ProfileCreator, record.class.base_class.to_s, record.id)
|
7
|
+
Resque.enqueue(::Riaction::ProfileCreator, record.class.base_class.to_s, record.id) unless record.class.riactionless?
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'riaction/iactionable/api'
|
2
1
|
require 'riaction/constants'
|
3
2
|
require "resque"
|
4
3
|
|
@@ -7,13 +6,21 @@ module Riaction
|
|
7
6
|
@queue = :riaction_profile_creator
|
8
7
|
|
9
8
|
def self.perform(klass_name, id, attempt=0)
|
10
|
-
if klass_name.constantize.
|
9
|
+
if klass_name.constantize.riactionary? &&
|
10
|
+
klass_name.constantize.riaction_profile? &&
|
11
|
+
klass_name.constantize.riaction_profile_types_defined > 0
|
12
|
+
record = klass_name.constantize.find_by_id!(id)
|
11
13
|
iactionable_api = IActionable::Api.new
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
record.riaction_profile_keys.each_pair do |profile_type, ids|
|
15
|
+
identifiers = ids.to_a
|
16
|
+
first_defined = identifiers.shift
|
17
|
+
iactionable_api.create_profile(profile_type.to_s, first_defined.first.to_s, first_defined.last.to_s, record.riaction_set_profile(profile_type).riaction_profile_display_name )
|
18
|
+
identifiers.each do |identifier|
|
19
|
+
iactionable_api.add_profile_identifier(profile_type.to_s, first_defined.first.to_s, first_defined.last.to_s, identifier.first.to_s, identifier.last.to_s)
|
20
|
+
end
|
21
|
+
end
|
15
22
|
else
|
16
|
-
raise
|
23
|
+
raise ::Riaction::RuntimeError.new("#{klass_name} does not define any riaction profiles")
|
17
24
|
end
|
18
25
|
rescue ActiveRecord::RecordNotFound => e
|
19
26
|
# event_object no longer exists; no means to recover
|