Traitify is a ruby gem wrapper for Traitify's Personality API
Add this line to your Gemfile (using bundler):
gem "traitify"
Or install it yourself with:
gem install traitify
The Traitify Client supports dynamically creating resource routes as seen in the examples below. Alternatively, HTTP methods (get, post, put, delete, path) can be used directly.
It is helpful to configure Traitify, otherwise everytime you create a Traitify object you must add the configuration options.
All the configuration options can be found in lib/traitify/configuration.rb
Traitify.configure do |traitify|
traitify.host = "https://api-sandbox.traitify.com"
traitify.version = "v1"
traitify.secret_key = "secret"
traitify.public_key = "public" # Optional
traitify.deck_id = "deck-uuid" # Optional
traitify.image_pack = "image-pack-type" # Optional
traitify.locale_key = "en-us" # Optional
end
traitify = Traitify.new
traitify.assessments.create
traitify = Traitify.new(
host: "https://api-sandbox.traitify.com",
version: "v1",
secret_key: "secret",
deck_id: "deck-uuid"
)
traitify.assessments.create
Requests that fail can be automatically retried.
Retrying can be configured in multiple ways.
Through the general config:
Traitify.configure do |traitify|
traitify.auto_retry = true
traitify.retry_options = retry_options
end
traitify = Traitify.new
assessment = traitify.assessments("assessment-uuid").data
On a specific request:
traitify = Traitify.new
assessment = traitify.retriable(retry_options).assessments("assessment-uuid").data
Or with both:
Traitify.configure do |traitify|
traitify.auto_retry = false
traitify.retry_options = retry_options
end
traitify = Traitify.new
assessment = traitify.retriable.assessments("assessment-uuid").data
This allows fine tuned control when and what to retry.
The options are passed to the Faraday Retry middleware. Supported options can be found in their documentation.
retry_options = {
methods: [:get, :post],
retry_statuses: [429, 500]
}
decks = traitify.decks.data
Returns an array of Deck objects:
deck = decks.first
deck.id #=> "deck-uuid"
deck.name #=> "Career"
deck.description #=> "Description of deck"
# And more
assessment = traitify.assessments.create
You must can specify the deck in your configuration or override it here
assessment = traitify.assessments.create(deck_id: "deck-uuid")
You can optionally specify image pack or locale
assessment = traitify.assessments.create(image_pack: "full-color")
Returns an assessment object:
data = assessment.data
data.id #=> "assessment-uuid"
data.deck_id #=> "deck-uuid"
data.created_at #=> Returns time in Epoch format
data.completed_at #=> nil
assessment = traitify.assessments("assessment-uuid").data
Returns an assessment object as seen above
An assessment can be taken through our javascript plugin or by getting the slides and iterating through them
slides = traitify.assessments("assessment-uuid").slides.data
Returns an array of slides
slides.map! do |slide|
# true for me, false for not me
slide.response = true
# Pass in the time it took to make that choice (milliseconds)
slide.time_taken = 600
slide
end
traitify.assessments("assessment-uuid").slides.update(slides)
slide = assessment.slides.data.first
slide.response = true
slide.time_taken = 600
traitify.assessments(assessment.id).slides(slide.id).update(slide.to_h)
results = traitify.assessments("assessment-uuid").personality_types.data
Returns a results object:
results.personality_blend #=> Personality blend object
results.personality_types #=> Array of personality type objects (with scores)
personality_blend = results.personality_blend
personality_blend.personality_type_1 #=> Personality type object
personality_blend.personality_type_2 #=> Personality type object
personality_blend.name #=> "Visionary Creator"
personality_blend.description #=> "Visionary Creator description"
personality_blend.compliments #=> "Visionary Creator compliments"
personality_blend.conflicts #=> "Visionary Creator conflicts"
type = results.personality_types.first
type.score #=> 100
personality_type = type.personality_type
personality_type.name #=> "Creator"
personality_type.description #=> "Creator description"
personality_type.badge #=> Badge object
badge = personality_type.badge
badge.image_small #=> "http://s3.amazonaws.com/traitify-api/badges/creator/flat/small"
badge.image_medium #=> "http://s3.amazonaws.com/traitify-api/badges/creator/flat/medium"
badge.image_large #=> "http://s3.amazonaws.com/traitify-api/badges/creator/flat/large"
traits = traitify.assessments("assessment-uuid").personality_traits.data
trait = traits.first
trait.score #=> 100
personality_trait = trait.personality_trait
personality_trait.name #=> "Imaginative"
personality_trait.definition #=> "Able to think symbolically and play with ideas."
personality_trait.description #=> "Coming Soon"
traits = traitify.analytics.decks("deck-uuid").personality_traits.data
types = traitify.analytics.decks("deck-uuid").personality_types.data
assessments = traitify.analytics.decks("deck-uuid").assessments.data
profile = traitify.profiles("profile-uuid").data
profile.first_name #=> "John"
profile.last_name #=> "Doe"
profile.email #=> "johndoe@example.com"
profile = traitify.profiles.create({
first_name: "John",
last_name: "Doe",
email: "johndoe@example.com"
}).data
profile.first_name #=> "John"
profile.last_name #=> "Doe"
profile.email #=> "johndoe@example.com"
More API endpoints may be available. You can find more at app.traitify.com/developer.