traitify 1.8.4 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +11 -0
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +5 -1
  5. data/Gemfile.lock +109 -42
  6. data/README.md +50 -25
  7. data/lib/traitify/client/connection.rb +23 -0
  8. data/lib/traitify/client/model.rb +45 -0
  9. data/lib/traitify/client/overrides.rb +27 -0
  10. data/lib/traitify/client/request.rb +33 -0
  11. data/lib/traitify/client/setup.rb +25 -0
  12. data/lib/traitify/client.rb +20 -27
  13. data/lib/traitify/configuration.rb +4 -12
  14. data/lib/traitify/data.rb +18 -0
  15. data/lib/traitify/error.rb +18 -16
  16. data/lib/traitify/middleware/formatter.rb +52 -0
  17. data/lib/traitify/middleware/raise_error.rb +38 -0
  18. data/lib/traitify/response.rb +44 -0
  19. data/lib/traitify/version.rb +1 -1
  20. data/lib/traitify.rb +29 -1
  21. data/paths.yml +1352 -0
  22. data/spec/spec_helper.rb +14 -6
  23. data/spec/support/mocks/aggregate.json +7 -0
  24. data/spec/support/mocks/assessment.json +1 -1
  25. data/spec/support/mocks/assessment_analytics.json +7 -0
  26. data/spec/support/mocks/blank.json +0 -0
  27. data/spec/support/mocks/career.json +1 -2
  28. data/spec/support/mocks/careers.json +2 -3
  29. data/spec/support/mocks/decks.json +1 -4
  30. data/spec/support/mocks/locale.json +10 -0
  31. data/spec/support/mocks/locales.json +12 -0
  32. data/spec/support/mocks/profile.json +5 -0
  33. data/spec/support/mocks/profiles.json +5 -0
  34. data/spec/support/mocks/trait_analytics.json +7 -0
  35. data/spec/support/mocks/type_analytics.json +7 -0
  36. data/spec/traitify/client/examples/analytics_spec.rb +69 -0
  37. data/spec/{traitify-ruby/client → traitify/client/examples}/assessment_spec.rb +19 -14
  38. data/spec/traitify/client/examples/career_spec.rb +52 -0
  39. data/spec/traitify/client/examples/configuration_spec.rb +29 -0
  40. data/spec/traitify/client/examples/deck_spec.rb +29 -0
  41. data/spec/traitify/client/examples/locale_spec.rb +39 -0
  42. data/spec/{traitify-ruby/client → traitify/client/examples}/major_spec.rb +12 -11
  43. data/spec/traitify/client/examples/profiles_spec.rb +66 -0
  44. data/spec/traitify/client/examples/result_spec.rb +130 -0
  45. data/spec/traitify/client/examples/slide_spec.rb +95 -0
  46. data/spec/traitify/client/model_spec.rb +73 -0
  47. data/spec/traitify/client/request_spec.rb +85 -0
  48. data/spec/traitify/client/setup_spec.rb +62 -0
  49. data/spec/traitify/client_spec.rb +52 -0
  50. data/spec/traitify/data_spec.rb +105 -0
  51. data/spec/traitify/error_spec.rb +117 -0
  52. data/spec/traitify/response_spec.rb +82 -0
  53. data/spec/traitify/version_spec.rb +7 -0
  54. data/traitify.gemspec +14 -12
  55. metadata +115 -53
  56. data/lib/traitify/client/assessments.rb +0 -29
  57. data/lib/traitify/client/careers.rb +0 -25
  58. data/lib/traitify/client/decks.rb +0 -16
  59. data/lib/traitify/client/majors.rb +0 -25
  60. data/lib/traitify/client/results.rb +0 -37
  61. data/lib/traitify/client/slides.rb +0 -34
  62. data/lib/traitify/connection.rb +0 -33
  63. data/lib/traitify/request.rb +0 -18
  64. data/spec/traitify-ruby/client/career_spec.rb +0 -51
  65. data/spec/traitify-ruby/client/configuration_spec.rb +0 -51
  66. data/spec/traitify-ruby/client/deck_spec.rb +0 -28
  67. data/spec/traitify-ruby/client/result_spec.rb +0 -93
  68. data/spec/traitify-ruby/client/slide_spec.rb +0 -82
@@ -0,0 +1,130 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Client do
4
+ before do
5
+ Traitify.configure do |client|
6
+ client.secret_key = "secret"
7
+ client.host = "https://example.com"
8
+ client.version = "v1"
9
+ client.logger = Logger.new("/dev/null")
10
+ end
11
+ end
12
+
13
+ let(:client){ Traitify.new }
14
+ let(:base_image_url){ "https://traitify-api.s3.amazonaws.com/traitify-api" }
15
+
16
+ describe ".find_results" do
17
+ context "without an image pack" do
18
+ let(:result){ client.assessments("assessment-uuid").personality_types.data }
19
+
20
+ before(:each) do
21
+ stub_it(:get, "/assessments/assessment-uuid/personality_types?locale_key=en-us", "result")
22
+ end
23
+
24
+ it "returns a result" do
25
+ expect(result.personality_types.first.personality_type.name).to eq("Analyzer")
26
+ end
27
+ end
28
+
29
+ context "with an image pack" do
30
+ context "set in the configurations" do
31
+ let(:client){ Traitify.new }
32
+ let(:result) do
33
+ Traitify.image_pack = "full-color"
34
+ res = Traitify.new.assessments("assessment-uuid").personality_types.data
35
+ Traitify.image_pack = nil
36
+ res
37
+ end
38
+
39
+ before(:each) do
40
+ stub_it(
41
+ :get,
42
+ "/assessments/assessment-uuid/personality_types?image_pack=full-color&locale_key=en-us",
43
+ "result"
44
+ )
45
+ end
46
+
47
+ it "returns a result" do
48
+ expect(result.personality_blend.personality_type_1.badge.image_large).to(
49
+ eq("#{base_image_url}/badges/analayzer/full-color/large")
50
+ )
51
+ end
52
+ end
53
+
54
+ context "set in the call" do
55
+ let(:result){
56
+ client.assessments("assessment-uuid").personality_types({image_pack: "full-color"}).data
57
+ }
58
+
59
+ before(:each) do
60
+ stub_it(
61
+ :get,
62
+ "/assessments/assessment-uuid/personality_types?image_pack=full-color&locale_key=en-us",
63
+ "result"
64
+ )
65
+ end
66
+
67
+ it "returns a result" do
68
+ expect(result.personality_blend.personality_type_1.badge.image_large).to(
69
+ eq("#{base_image_url}/badges/analayzer/full-color/large")
70
+ )
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ describe ".assessment_personality_type" do
77
+ context "with a personality type" do
78
+ let(:personality_traits){
79
+ client.assessments("assessment-uuid")
80
+ .personality_types("personality-type-uuid")
81
+ .personality_traits.data
82
+ }
83
+
84
+ before(:each) do
85
+ stub_it(
86
+ :get,
87
+ [
88
+ "/assessments/assessment-uuid",
89
+ "/personality_types/personality-type-uuid",
90
+ "/personality_traits?locale_key=en-us"
91
+ ].join,
92
+ "personality_traits"
93
+ )
94
+ end
95
+
96
+ it "returns a result" do
97
+ expect(personality_traits.first.personality_trait.name).to eq("Imaginative")
98
+ end
99
+ end
100
+
101
+ context "without a personality type" do
102
+ let(:personality_traits){ client.assessments("assessment-uuid").personality_traits.data }
103
+
104
+ before(:each) do
105
+ stub_it(
106
+ :get,
107
+ "/assessments/assessment-uuid/personality_traits?locale_key=en-us",
108
+ "personality_traits"
109
+ )
110
+ end
111
+
112
+ it "returns a result" do
113
+ expect(personality_traits.first.personality_trait.name).to eq("Imaginative")
114
+ end
115
+ end
116
+ end
117
+
118
+ describe ".career_matches" do
119
+ let(:careers){ client.assessments("assessment-uuid").matches.careers.data }
120
+
121
+ before(:each) do
122
+ stub_it(:get, "/assessments/assessment-uuid/matches/careers?locale_key=en-us", "careers")
123
+ end
124
+
125
+ it "returns a result" do
126
+ expect(careers.first.title).to eq("Career Title")
127
+ expect(careers.first.majors.first.title).to eq("Major Title")
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,95 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Client do
4
+ before do
5
+ Traitify.configure do |client|
6
+ client.secret_key = "secret"
7
+ client.host = "https://example.com"
8
+ client.version = "v1"
9
+ client.deck_id = "deck-uuid"
10
+ client.logger = Logger.new("/dev/null")
11
+ end
12
+ end
13
+
14
+ let(:client){ Traitify.new }
15
+
16
+ describe ".find_slides" do
17
+ let(:slides){ client.assessments("assessment-uuid").slides.data }
18
+
19
+ before(:each) do
20
+ stub_it(:get, "/assessments/assessment-uuid/slides?locale_key=en-us", "slides")
21
+ end
22
+
23
+ it "returns each slide's uuid" do
24
+ expect(slides.first.id).to eq("slide-uuid")
25
+ end
26
+ end
27
+
28
+ describe ".update_slides" do
29
+ let(:slides){ client.assessments("assessment-uuid").slides.data }
30
+ let(:slides_complete){ client.assessments("assessment-uuid").slides.update(slides).data }
31
+
32
+ before(:each) do
33
+ stub_it(:get, "/assessments/assessment-uuid/slides?locale_key=en-us", "slides")
34
+ body = slides.collect do |slide|
35
+ slide.response = 0
36
+ slide.time_taken = 1000
37
+ slide
38
+ end
39
+
40
+ stub_it(:put, "/assessments/assessment-uuid/slides", "slides_complete", body: body)
41
+ end
42
+
43
+ it "returns an assessment" do
44
+ expect(slides_complete.first.response).to eq(true)
45
+ end
46
+ end
47
+
48
+ describe ".update_slide" do
49
+ context "with hash" do
50
+ let(:slides){ client.assessments("assessment-uuid").slides.data }
51
+ let(:slide_params) do
52
+ {
53
+ id: slides.first.id,
54
+ response: true,
55
+ time_taken: 1000
56
+ }
57
+ end
58
+ let(:slide){
59
+ client.assessments("assessment-uuid").slides(slide_params[:id]).update(slide_params).data
60
+ }
61
+
62
+ before(:each) do
63
+ stub_it(:get, "/assessments/assessment-uuid/slides?locale_key=en-us", "slides")
64
+ stub_it(
65
+ :put,
66
+ "/assessments/assessment-uuid/slides/slide-uuid",
67
+ "slide",
68
+ body: slide_params.merge({locale_key: "en-us"})
69
+ )
70
+ end
71
+
72
+ it "returns a slide" do
73
+ expect(slide.response).to eq(true)
74
+ end
75
+ end
76
+
77
+ context "with slide" do
78
+ let(:slides){ client.assessments("assessment-uuid").slides.data }
79
+ let(:slide){ slides.first }
80
+
81
+ before(:each) do
82
+ stub_it(:get, "/assessments/assessment-uuid/slides?locale_key=en-us", "slides")
83
+ stub_it(:put, "/assessments/assessment-uuid/slides/slide-uuid", "slide")
84
+
85
+ slide.response = true
86
+ slide.time_taken = 1000
87
+ client.assessments("assessment-uuid").slides("slide-uuid").update(slide.to_h)
88
+ end
89
+
90
+ it "returns a slide" do
91
+ expect(slide.response).to eq(true)
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Client::Model do
4
+ before do
5
+ Traitify.configure do |client|
6
+ client.secret_key = "secret"
7
+ client.host = "https://example.com"
8
+ client.version = "v1"
9
+ client.deck_id = "deck-uuid"
10
+ client.logger = Logger.new("/dev/null")
11
+ end
12
+ end
13
+
14
+ let(:client){ Traitify.new }
15
+
16
+ describe ".all" do
17
+ it "returns response" do
18
+ stub_it(:get, "/profiles?locale_key=en-us", "blank")
19
+
20
+ expect(client.profiles.find).to be_instance_of(Traitify::Response)
21
+ end
22
+
23
+ it "sends params" do
24
+ stub_it(:get, "/profiles?foo=bar&locale_key=en-us", "blank")
25
+
26
+ expect(client.profiles.find(foo: :bar)).to be_instance_of(Traitify::Response)
27
+ end
28
+ end
29
+
30
+ describe ".create" do
31
+ it "returns response" do
32
+ stub_it(:post, "/profiles", "blank", body: {locale_key: "en-us"})
33
+
34
+ expect(client.profiles.create).to be_instance_of(Traitify::Response)
35
+ end
36
+
37
+ it "sends params" do
38
+ stub_it(:post, "/profiles", "blank", body: {foo: "bar", locale_key: "en-us"})
39
+
40
+ expect(client.profiles.create(foo: :bar)).to be_instance_of(Traitify::Response)
41
+ end
42
+ end
43
+
44
+ describe ".destroy" do
45
+ it "returns response" do
46
+ stub_it(:delete, "/profiles?locale_key=en-us", "blank")
47
+
48
+ expect(client.profiles.destroy).to be_instance_of(Traitify::Response)
49
+ end
50
+
51
+ it "sends params" do
52
+ stub_it(:delete, "/profiles/profile-id?locale_key=en-us", "blank")
53
+
54
+ expect(client.profiles("profile-id").destroy).to be_instance_of(Traitify::Response)
55
+ end
56
+ end
57
+
58
+ describe ".update" do
59
+ it "returns response" do
60
+ stub_it(:put, "/profiles/profile-id", "blank", body: {foo: "bar", locale_key: "en-us"})
61
+
62
+ expect(client.profiles("profile-id").update(foo: :bar)).to be_instance_of(Traitify::Response)
63
+ end
64
+
65
+ it "uses verb" do
66
+ stub_it(:patch, "/profiles/profile-id", "blank", body: {foo: "bar", locale_key: "en-us"})
67
+
68
+ expect(client.profiles("profile-id").update({foo: :bar}, :patch)).to(
69
+ be_instance_of(Traitify::Response)
70
+ )
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,85 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Client::Request do
4
+ before do
5
+ Traitify.configure do |client|
6
+ client.secret_key = "secret"
7
+ client.host = "https://example.com"
8
+ client.version = "v1"
9
+ client.deck_id = "deck-uuid"
10
+ client.logger = Logger.new("/dev/null")
11
+ end
12
+ end
13
+
14
+ let(:client){ Traitify.new }
15
+
16
+ describe ".delete" do
17
+ it "returns response" do
18
+ stub_it(:delete, "/profiles?locale_key=en-us", "blank")
19
+
20
+ expect(client.delete("/profiles")).to be_instance_of(Traitify::Response)
21
+ end
22
+
23
+ it "sends params" do
24
+ stub_it(:delete, "/profiles?foo=bar&locale_key=en-us", "blank")
25
+
26
+ expect(client.delete("/profiles", foo: :bar)).to be_instance_of(Traitify::Response)
27
+ end
28
+ end
29
+
30
+ describe ".get" do
31
+ it "returns response" do
32
+ stub_it(:get, "/profiles?locale_key=en-us", "blank")
33
+
34
+ expect(client.get("/profiles")).to be_instance_of(Traitify::Response)
35
+ end
36
+
37
+ it "sends params" do
38
+ stub_it(:get, "/profiles?foo=bar&locale_key=en-us", "blank")
39
+
40
+ expect(client.get("/profiles", foo: :bar)).to be_instance_of(Traitify::Response)
41
+ end
42
+ end
43
+
44
+ describe ".patch" do
45
+ it "returns response" do
46
+ stub_it(:patch, "/profiles", "blank", body: {locale_key: "en-us"})
47
+
48
+ expect(client.patch("/profiles")).to be_instance_of(Traitify::Response)
49
+ end
50
+
51
+ it "sends params" do
52
+ stub_it(:patch, "/profiles", "blank", body: {foo: "bar", locale_key: "en-us"})
53
+
54
+ expect(client.patch("/profiles", foo: :bar)).to be_instance_of(Traitify::Response)
55
+ end
56
+ end
57
+
58
+ describe ".post" do
59
+ it "returns response" do
60
+ stub_it(:post, "/profiles", "blank", body: {locale_key: "en-us"})
61
+
62
+ expect(client.post("/profiles")).to be_instance_of(Traitify::Response)
63
+ end
64
+
65
+ it "sends params" do
66
+ stub_it(:post, "/profiles", "blank", body: {foo: "bar", locale_key: "en-us"})
67
+
68
+ expect(client.post("/profiles", foo: :bar)).to be_instance_of(Traitify::Response)
69
+ end
70
+ end
71
+
72
+ describe ".put" do
73
+ it "returns response" do
74
+ stub_it(:put, "/profiles", "blank", body: {locale_key: "en-us"})
75
+
76
+ expect(client.put("/profiles")).to be_instance_of(Traitify::Response)
77
+ end
78
+
79
+ it "sends params" do
80
+ stub_it(:put, "/profiles", "blank", body: {foo: "bar", locale_key: "en-us"})
81
+
82
+ expect(client.put("/profiles", foo: :bar)).to be_instance_of(Traitify::Response)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,62 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Client::Setup do
4
+ before do
5
+ Traitify.configure do |client|
6
+ client.secret_key = "secret"
7
+ client.host = "https://example.com"
8
+ client.version = "v1"
9
+ client.deck_id = "deck-uuid"
10
+ client.logger = Logger.new("/dev/null")
11
+ end
12
+ end
13
+
14
+ let(:client){ Traitify.new }
15
+
16
+ describe ".add_params" do
17
+ it "adds param" do
18
+ client.set(params: {this: "that"})
19
+ client.add_params(foo: "bar", vampire: "weekend")
20
+
21
+ expect(client.params).to match({foo: "bar", this: "that", vampire: "weekend"})
22
+ end
23
+
24
+ it "overrides param" do
25
+ client.set(params: {foo: "bar", this: "that"})
26
+ client.add_params(foo: "boo", vampire: "weekend")
27
+
28
+ expect(client.params).to match({foo: "boo", this: "that", vampire: "weekend"})
29
+ end
30
+ end
31
+
32
+ describe ".add_path" do
33
+ it "adds path" do
34
+ client.set(path: "/little")
35
+ client.add_path("/path")
36
+
37
+ expect(client.path).to eq("/little/path")
38
+ end
39
+
40
+ it "creates path" do
41
+ client.add_path("/path")
42
+
43
+ expect(client.path).to eq("/path")
44
+ end
45
+ end
46
+
47
+ describe ".set_param" do
48
+ it "overrides param" do
49
+ client.set(params: {foo: "bar", this: "that"})
50
+ client.set_param(:foo, "boo")
51
+
52
+ expect(client.params).to match({foo: "boo", this: "that"})
53
+ end
54
+
55
+ it "sets param" do
56
+ client.set(params: {this: "that"})
57
+ client.set_param(:foo, "bar")
58
+
59
+ expect(client.params).to match({foo: "bar", this: "that"})
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Client do
4
+ before do
5
+ Traitify.configure do |client|
6
+ client.secret_key = "secret"
7
+ client.host = "https://example.com"
8
+ client.version = "v1"
9
+ client.deck_id = "deck-uuid"
10
+ client.logger = Logger.new("/dev/null")
11
+ end
12
+ end
13
+
14
+ describe "#new" do
15
+ it "sets options" do
16
+ result = Traitify::Client.new
17
+
18
+ expect(result.deck_id).to eq("deck-uuid")
19
+ expect(result.host).to eq("https://example.com")
20
+ expect(result.secret_key).to eq("secret")
21
+ expect(result.version).to eq("v1")
22
+ end
23
+
24
+ it "merges options" do
25
+ result = Traitify::Client.new(version: "v2")
26
+
27
+ expect(result.deck_id).to eq("deck-uuid")
28
+ expect(result.host).to eq("https://example.com")
29
+ expect(result.secret_key).to eq("secret")
30
+ expect(result.version).to eq("v2")
31
+ end
32
+ end
33
+
34
+ describe "#to_hash" do
35
+ it "returns state" do
36
+ result = Traitify::Client.new(version: "v2")
37
+ result = result.profiles(:profile_id).set(params: {foo: :bar}, verb: :post)
38
+
39
+ expect(result.to_hash.symbolize_keys).to match(
40
+ deck_id: "deck-uuid",
41
+ host: "https://example.com",
42
+ locale_key: "en-us",
43
+ params: {foo: :bar},
44
+ path: "/profiles/profile_id",
45
+ secret_key: "secret",
46
+ type: :profiles,
47
+ verb: :post,
48
+ version: "v2"
49
+ )
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,105 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Data do
4
+ describe "#new" do
5
+ context "with array" do
6
+ it "returns array" do
7
+ data = Traitify::Data.new([])
8
+
9
+ expect(data).to eq([])
10
+ end
11
+
12
+ it "converts each element" do
13
+ data = Traitify::Data.new([{traitify: ""}])
14
+
15
+ expect(data[0]).to be_a(Traitify::Data)
16
+ end
17
+ end
18
+
19
+ context "with hash" do
20
+ it "returns data" do
21
+ data = Traitify::Data.new({})
22
+
23
+ expect(data).to be_a(Traitify::Data)
24
+ end
25
+
26
+ it "converts each value" do
27
+ data = Traitify::Data.new({traitify: {}})
28
+
29
+ expect(data.traitify).to be_a(Traitify::Data)
30
+ end
31
+ end
32
+
33
+ context "with simple objects" do
34
+ it "returns boolean" do
35
+ data = Traitify::Data.new(true)
36
+
37
+ expect(data).to eq(true)
38
+ end
39
+
40
+ it "returns number" do
41
+ data = Traitify::Data.new(42)
42
+
43
+ expect(data).to eq(42)
44
+ end
45
+
46
+ it "returns string" do
47
+ data = Traitify::Data.new("Traitify")
48
+
49
+ expect(data).to eq("Traitify")
50
+ end
51
+
52
+ it "returns symbol" do
53
+ data = Traitify::Data.new(:traitify)
54
+
55
+ expect(data).to eq(:traitify)
56
+ end
57
+ end
58
+ end
59
+
60
+ describe ".as_json" do
61
+ context "with array" do
62
+ it "returns array" do
63
+ data = Traitify::Data.new([])
64
+
65
+ expect(data.as_json).to eq([])
66
+ end
67
+
68
+ it "returns equivalent elements" do
69
+ data = Traitify::Data.new([{traitify: ""}])
70
+
71
+ expect(data.as_json.map(&:symbolize_keys)).to eq([{traitify: ""}])
72
+ end
73
+ end
74
+
75
+ context "with hash" do
76
+ it "returns data" do
77
+ data = Traitify::Data.new({})
78
+
79
+ expect(data.as_json).to eq({})
80
+ end
81
+
82
+ it "returns equivalent values" do
83
+ data = Traitify::Data.new({traitify: {}})
84
+
85
+ expect(data.as_json.symbolize_keys).to eq({traitify: {}})
86
+ end
87
+ end
88
+
89
+ context "with options" do
90
+ context "with hash" do
91
+ it "returns array data" do
92
+ data = Traitify::Data.new({
93
+ burritos: [{meat: "chicken"}],
94
+ tacos: [{meat: "chicken"}, {meat: "steak"}]
95
+ })
96
+
97
+ # Rails' as_json passes full options down to nested objects
98
+ expect(data.as_json(only: [:meat, :tacos]).deep_symbolize_keys).to(
99
+ eq({tacos: [{meat: "chicken"}, {meat: "steak"}]})
100
+ )
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end