traitify 1.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 63fba7187cd2db760a452ee645019b4b3c7f4639
4
+ data.tar.gz: a4679dc09c00cf736d46499ce4d8b48b35880ed3
5
+ SHA512:
6
+ metadata.gz: a11b1f2283ab1414f20c8e7cab20a9ce555bd90dc17becf00f8af96d15e6c0a1ac78c02b87492f350f19c9884e74b328541da66419ca805977a1eb5a88917b6b
7
+ data.tar.gz: 10f132345ad8f3a41005ad0aaf07c80f38daf94c7c7c283a5a8ef1e07fd7f47d89f1c76ba6b836a827d7ab530b986a6693b21370af0cd1afcaeb11b079b45bee
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ # .dat*
14
+ # .repl_history
15
+ # build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ### 1.1.0
2
+
3
+ * Features
4
+ * Added ability to get results (by [@tomprats])
5
+
6
+ ### 1.0.1
7
+
8
+ * Bug Fixes
9
+ * Fixed error with package requires being capitalized (by [@cpreisinger])
10
+
11
+ [@cpreisinger]:https://github.com/cpreisinger
12
+ [@tomprats]:https://github.com/tomprats
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simplewoo.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ traitify (1.1.0)
5
+ faraday (~> 0.8.0)
6
+ faraday_middleware (~> 0.9.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.6)
12
+ binding_of_caller (0.7.2)
13
+ debug_inspector (>= 0.0.1)
14
+ coderay (1.1.0)
15
+ crack (0.4.2)
16
+ safe_yaml (~> 1.0.0)
17
+ debug_inspector (0.0.2)
18
+ diff-lcs (1.2.5)
19
+ faraday (0.8.9)
20
+ multipart-post (~> 1.2.0)
21
+ faraday_middleware (0.9.1)
22
+ faraday (>= 0.7.4, < 0.10)
23
+ method_source (0.8.2)
24
+ multipart-post (1.2.0)
25
+ pry (0.9.12.6)
26
+ coderay (~> 1.0)
27
+ method_source (~> 0.8)
28
+ slop (~> 3.4)
29
+ rake (10.1.1)
30
+ rspec (2.14.1)
31
+ rspec-core (~> 2.14.0)
32
+ rspec-expectations (~> 2.14.0)
33
+ rspec-mocks (~> 2.14.0)
34
+ rspec-core (2.14.8)
35
+ rspec-expectations (2.14.5)
36
+ diff-lcs (>= 1.1.3, < 2.0)
37
+ rspec-mocks (2.14.6)
38
+ safe_yaml (1.0.3)
39
+ slop (3.5.0)
40
+ webmock (1.13.0)
41
+ addressable (>= 2.2.7)
42
+ crack (>= 0.3.2)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ binding_of_caller
49
+ bundler (~> 1.3)
50
+ pry
51
+ rake (~> 10.1.0)
52
+ rspec (~> 2.14.0)
53
+ traitify!
54
+ webmock (~> 1.13.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tom Prats
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # Traitify
2
+
3
+ Traitify is a ruby gem wrapper for the Traitify Developer's API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Gemfile (using bundler):
8
+
9
+ gem 'traitify'
10
+
11
+ Or install it yourself with:
12
+
13
+ gem install traitify
14
+
15
+ ## Usage
16
+
17
+ First it is helpful to configure Traitify, otherwise everytime you create a Traitify object you must add the configuration
18
+
19
+ ### Configuration
20
+
21
+ All the configuration options can be found in `lib/Traitify/configuration.rb`
22
+
23
+ Traitify.configure do |tom|
24
+ tom.secret = "secret"
25
+ tom.api_host = "http://example.com"
26
+ tom.api_version = "v1"
27
+ tom.deck_id = "deck-uuid"
28
+ end
29
+
30
+ #### With config file:
31
+
32
+ tom = Traitify.new
33
+ tom.create_assessment
34
+
35
+ #### Without config file:
36
+
37
+ tom = Traitify.new(api_host: "http://example.com", api_version: "v1", deck_id: "deck-uuid", secret: "secret")
38
+ tom.create_assessment
39
+
40
+ ### Users
41
+
42
+ #### Creating a user:
43
+
44
+ user = tom.create_user(
45
+ first_name: "Tom",
46
+ last_name: "Prats",
47
+ email: "tom@tomprats.com"
48
+ )
49
+
50
+ Returns a user object:
51
+
52
+ user.id #=> "toms-uuid"
53
+ user.first_name #=> "Tom"
54
+ user.last_name #=> "Prats"
55
+ user.email #=> "tom@tomprats.com"
56
+
57
+ #### Finding a user:
58
+
59
+ tom.find_user("toms-uuid")
60
+
61
+ Returns a user object as seen above
62
+
63
+ ### Assessments
64
+
65
+ #### Creating an assessment:
66
+
67
+ assessment = tom.create_assessment
68
+
69
+ You can also pass a user id to tie it to a user
70
+
71
+ assessment = tom.create_assessment(user_id: "toms-uuid")
72
+
73
+ You must can specify the deck in your configuration or override it here
74
+
75
+ assessment = tom.create_assessment(deck_id: "deck-uuid")
76
+
77
+ Returns an assessment object:
78
+
79
+ assessment.id #=> "assessment-uuid"
80
+ assessment.deck_id #=> "deck-uuid"
81
+ assessment.user_id #=> "toms-uuid"
82
+ assessment.created_at #=> 46197-10-17 12:29:08 -0400
83
+ assessment.completed_at #=> nil
84
+
85
+ #### Finding an assessment:
86
+
87
+ assessment = tom.find_assessment("assessment-uuid")
88
+
89
+ Returns an assessment object as seen above
90
+
91
+ #### Taking an assessment:
92
+
93
+ An assessment can be taken through our javascript plugin or by getting the slides and iterating through them
94
+
95
+ #### Finding an assessment's slides:
96
+
97
+ slides = tom.find_slides("assessment_id")
98
+
99
+ Returns a slides object which has the assessment id but also functions as an array
100
+
101
+ slides.assessment_id #=> "assessment-uuid"
102
+ slides.first #=> Slide object
103
+ slides.all #=> Array of slide objects
104
+
105
+ #### Updating an assessment's slides:
106
+
107
+ slides.all.map! do |slide|
108
+ # true for me, false for not me
109
+ slide.response = true
110
+ # Pass in the time it took to make that choice (milliseconds)
111
+ slide.time_taken = 600
112
+ slide
113
+ end
114
+
115
+ tom.update_slides(slides)
116
+
117
+ #### Updating a single assessment slide:
118
+
119
+ slide = assessment.slides.first
120
+ slide.response = true
121
+ slide.time_taken = 600
122
+ slides.first = tom.update_slide(assessment.id, slide)
123
+
124
+ Or with a hash
125
+
126
+ assessment.slides.first = tom.update_slide(
127
+ assessment_id: assessment.id,
128
+ slide_id: assessment.slides.first.id,
129
+ response: 0,
130
+ time_taken: 600
131
+ )
132
+
133
+
134
+ ### Results
135
+
136
+ #### Getting an assessment's results
137
+
138
+ results = tom.find_results("assessment-uuid")
139
+
140
+ Returns a results object:
141
+
142
+ results.personality_blend #=> Personality blend object
143
+ results.personality_types #=> Array of personality type objects (with scores)
144
+
145
+ personality_blend = results.personality_blend
146
+ personality_blend.personality_type1 #=> Personality type object (without score)
147
+ personality_blend.personality_type2 #=> Personality type object (without score)
148
+ personality_blend.name #=> "Visionary Creator"
149
+ personality_blend.description #=> "Visionary Creator description"
150
+ personality_blend.compliments #=> "Visionary Creator compliments"
151
+ personality_blend.conflicts #=> "Visionary Creator conflicts"
152
+ personality_blend.compatible_work_environment_1 #=> "Example text here"
153
+ personality_blend.compatible_work_environment_2 #=> "Example text here"
154
+ personality_blend.compatible_work_environment_3 #=> "Example text here"
155
+ personality_blend.compatible_work_environment_4 #=> "Example text here"
156
+
157
+ personality_type = results.personality_types.first
158
+ personality_type.name #=> "Creator"
159
+ personality_type.description #=> "Creator description"
160
+ personality_type.badge #=> Badge object
161
+ personality_type.score #=> 100
162
+
163
+ badge = personality_type.badge
164
+ badge.image_small #=> "http://s3.amazonaws.com/traitify-api/badges/creator/flat/small"
165
+ badge.image_medium #=> "http://s3.amazonaws.com/traitify-api/badges/creator/flat/medium"
166
+ badge.image_large #=> "http://s3.amazonaws.com/traitify-api/badges/creator/flat/large"
data/lib/traitify.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "traitify/version"
2
+ require "traitify/configuration"
3
+ require "traitify/client"
4
+
5
+ module Traitify
6
+ extend Configuration
7
+
8
+ class << self
9
+ def new(options = {})
10
+ Traitify::Client.new(options)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ module Traitify
2
+ class Assessment
3
+ attr_accessor :id, :deck_id, :user_id, :created_at, :completed_at
4
+
5
+ def initialize(options = {})
6
+ self.id = options[:id]
7
+ self.deck_id = options[:deck_id]
8
+ self.user_id = options[:user_id]
9
+ self.created_at = options[:created_at]
10
+ self.completed_at = options[:completed_at]
11
+ end
12
+
13
+ def self.parse_json(assessment)
14
+ created_at = assessment["created_at"] ? Time.at(assessment["created_at"]) : nil
15
+ completed_at = assessment["completed_at"] ? Time.at(assessment["completed_at"]) : nil
16
+
17
+ Assessment.new(
18
+ id: assessment["id"],
19
+ deck_id: assessment["deck_id"],
20
+ user_id: assessment["user_id"],
21
+ created_at: created_at,
22
+ completed_at: completed_at
23
+ )
24
+ end
25
+
26
+ def to_hash
27
+ {
28
+ id: id,
29
+ deck_id: deck_id,
30
+ user_id: user_id,
31
+ created_at: created_at,
32
+ completed_at: completed_at
33
+ }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ module Traitify
2
+ class Badge
3
+ attr_accessor :image_small, :image_medium, :image_large, :font_color, :color_1, :color_2, :color_3
4
+
5
+ def initialize(options = {})
6
+ self.image_small = options[:image_small]
7
+ self.image_medium = options[:image_medium]
8
+ self.image_large = options[:image_large]
9
+ self.font_color = options[:font_color]
10
+ self.color_1 = options[:color1]
11
+ self.color_2 = options[:color2]
12
+ self.color_3 = options[:color3]
13
+ end
14
+
15
+ def self.parse_json(badge)
16
+ if badge
17
+ Badge.new(
18
+ image_small: badge["image_small"],
19
+ image_medium: badge["image_medium"],
20
+ image_large: badge["image_large"],
21
+ font_color: badge["font_color"],
22
+ color_1: badge["color_1"],
23
+ color_2: badge["color_2"],
24
+ color_3: badge["color_3"]
25
+ )
26
+ else
27
+ nil
28
+ end
29
+ end
30
+
31
+ def to_hash
32
+ {
33
+ image_small: image_small,
34
+ image_medium: image_medium,
35
+ image_large: image_large,
36
+ font_color: font_color,
37
+ color_1: color1,
38
+ color_2: color2,
39
+ color_3: color3
40
+ }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ # require base modules
2
+ require "traitify/connection"
3
+ require "traitify/request"
4
+ require "traitify/assessments"
5
+ require "traitify/badges"
6
+ require "traitify/personality_blends"
7
+ require "traitify/personality_types"
8
+ require "traitify/results"
9
+ require "traitify/slides"
10
+ require "traitify/users"
11
+ # require client modules in lib/Traitify/client
12
+ Dir[File.expand_path("../client/*.rb", __FILE__)].each {|f| require f }
13
+
14
+ module Traitify
15
+ class Client
16
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
17
+
18
+ def initialize(options = {})
19
+ options = Traitify.options.merge(options)
20
+
21
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
22
+ send("#{key}=", options[key])
23
+ end
24
+ end
25
+
26
+ include Traitify::Connection
27
+ include Traitify::Configuration
28
+ include Traitify::Request
29
+
30
+ include Traitify::Client::Assessment
31
+ include Traitify::Client::User
32
+ include Traitify::Client::Result
33
+ include Traitify::Client::Slide
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ module Traitify
2
+ class Client
3
+ module Assessment
4
+ def create_assessment(options = {})
5
+ assessment_params = { deck_id: self.deck_id }
6
+ assessment_params.merge!(deck_id: options[:deck_id]) if options[:deck_id]
7
+ assessment_params.merge!(user_id: options[:user_id]) if options[:user_id]
8
+ response = post("/assessments", assessment_params)
9
+
10
+ Traitify::Assessment.parse_json(response)
11
+ end
12
+
13
+ def find_assessment(assessment_id)
14
+ response = get("/assessments/#{assessment_id}")
15
+
16
+ Traitify::Assessment.parse_json(response)
17
+ end
18
+ end
19
+ end
20
+ end