Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user data #29

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ mount RailsXapi::Engine, at: "rails-xapi"
Create a service class or controller method within your main application that handles data preparation and invokes `RailsXapi::StatementCreator`:

```ruby
# frozen_string_literal: true

class XapiStatementCreator
extend UserHelper

def self.create_statement(request:, user:, data:)
def self.create_statement(data:, request: nil, user: nil, async: false)
data = data.merge(actor: {objectType: "Agent"}) if data[:actor].blank?

# We can set the actor's data to be able to omit it in the statements declarations.
# This is an example. Adapt depending on your needs:
data = data.merge(
actor: data[:actor].merge(
account: {
homePage: "#{data[:base_url] || request.base_url}/users/#{user&.id}",
name: user_fullname(user)
}
if request.present? && user.present?
data = data.merge(
actor: data[:actor].merge(
account: {
homePage: "#{data[:base_url] || request.base_url}/users/#{user&.id}",
name: "#{user.firstname} #{user.lastname}"
}
)
)
)
end

statement_creator = RailsXapi::StatementCreator.new(data, user)
statement_creator.call_async
return statement_creator.call_async if async

statement_creator.call
end
end
```
Expand Down
4 changes: 3 additions & 1 deletion app/services/rails_xapi/statement_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def call_async
private

def prepare_statement
actor = RailsXapi::Actor.build_from_data(@data[:actor], @user[:email])
# Send the user infos from the call if passed to it.
user_email = @user & [:email] || nil
actor = RailsXapi::Actor.build_from_data(@data[:actor], user_email)

verb = RailsXapi::Verb.find_or_create_by(id: @data[:verb][:id]) do |v|
v.display = @data[:verb][:display]
Expand Down