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
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,27 @@
1
- require "Traitify"
1
+ require "active_support/core_ext/object/conversions"
2
+ require "active_support/core_ext/object/json"
2
3
  require "webmock/rspec"
3
4
  require "pry"
5
+ require "simplecov"
6
+
7
+ SimpleCov.start :test_frameworks
8
+
9
+ require "Traitify"
4
10
 
5
- Dir[File.expand_path("spec/support/**/*.rb", __FILE__)].each{|f| require f}
11
+ Dir[File.expand_path("spec/support/**/*.rb", __FILE__)].each{ |f| require f }
6
12
 
7
13
  RSpec.configure do |config|
8
14
  config.color = true
9
15
  config.order = "random"
10
16
  end
11
17
 
12
- def stub_it(http_method = :any, endpoint = "/", status = 200, response)
13
- url = "https://secret:x@example.com/v1#{endpoint}"
14
- stub_request(http_method, url).to_return(
18
+ def stub_it(http_method, endpoint, response, body: nil, status: 200)
19
+ url = "https://example.com/v1#{endpoint}"
20
+ stub = stub_request(http_method, url)
21
+ stub = stub.with(body: body.to_json) if body
22
+ stub.to_return(
15
23
  status: status,
16
24
  body: File.read(File.expand_path("../support/mocks/#{response}.json", __FILE__)),
17
- headers: { 'Content-type' => "application/json" }
25
+ headers: {"Content-type" => "application/json"}
18
26
  )
19
27
  end
@@ -0,0 +1,7 @@
1
+ {
2
+ "assessments": {
3
+ "completed_count": 5,
4
+ "created_count": 20,
5
+ "started_count": 10
6
+ }
7
+ }
@@ -4,4 +4,4 @@
4
4
  "user_id": "toms-uuid",
5
5
  "created_at": 1392153790744,
6
6
  "completed_at": 1392153790744
7
- }
7
+ }
@@ -0,0 +1,7 @@
1
+ [{
2
+ "id": "assessment-analytics-uuid",
3
+ "deck_id": "deck-uuid",
4
+ "user_id": "toms-uuid",
5
+ "created_at": 1392153790744,
6
+ "completed_at": 1392153790744
7
+ }]
File without changes
@@ -6,8 +6,7 @@
6
6
  {
7
7
  "id": "major-id",
8
8
  "title": "Major Title",
9
- "description": "Major Description",
10
- "group_id": "Major Group ID"
9
+ "description": "Major Description"
11
10
  }
12
11
  ]
13
12
  }
@@ -7,9 +7,8 @@
7
7
  {
8
8
  "id": "major-id",
9
9
  "title": "Major Title",
10
- "description": "Major Description",
11
- "group_id": "Major Group ID"
10
+ "description": "Major Description"
12
11
  }
13
12
  ]
14
13
  }
15
- ]
14
+ ]
@@ -2,11 +2,8 @@
2
2
  {
3
3
  "id": "deck-uuid",
4
4
  "name": "Career Deck",
5
- "personality_group_id": "personality-group-uuid",
6
- "personality_group_name": null,
7
5
  "created_at": 1396230166317,
8
6
  "active": true,
9
- "slide_count": null,
10
- "personality_group": null
7
+ "slide_count": null
11
8
  }
12
9
  ]
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "6aae2f07-1594-4aa0-a639-39ca489395aa",
3
+ "key": "en-us",
4
+ "language_name": "English",
5
+ "language_code": "en",
6
+ "country_name": "United States",
7
+ "country_code": "US",
8
+ "variant_name": null,
9
+ "variant_code": null
10
+ }
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "id": "6aae2f07-1594-4aa0-a639-39ca489395aa",
4
+ "key": "en-us",
5
+ "language_name": "English",
6
+ "language_code": "en",
7
+ "country_name": "United States",
8
+ "country_code": "US",
9
+ "variant_name": null,
10
+ "variant_code": null
11
+ }
12
+ ]
@@ -0,0 +1,5 @@
1
+ {
2
+ "id": "profile-uuid",
3
+ "created_at": 1392153790744,
4
+ "completed_at": 1392153790744
5
+ }
@@ -0,0 +1,5 @@
1
+ [{
2
+ "id": "profile-uuid",
3
+ "created_at": 1392153790744,
4
+ "completed_at": 1392153790744
5
+ }]
@@ -0,0 +1,7 @@
1
+ [{
2
+ "id": "trait-analytics-uuid",
3
+ "deck_id": "deck-uuid",
4
+ "user_id": "toms-uuid",
5
+ "created_at": 1392153790744,
6
+ "completed_at": 1392153790744
7
+ }]
@@ -0,0 +1,7 @@
1
+ [{
2
+ "id": "type-analytics-uuid",
3
+ "deck_id": "deck-uuid",
4
+ "user_id": "toms-uuid",
5
+ "created_at": 1392153790744,
6
+ "completed_at": 1392153790744
7
+ }]
@@ -0,0 +1,69 @@
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 ".analytics" do
17
+ context ".aggregate" do
18
+ let(:data){
19
+ client.analytics.decks("big-five")
20
+ .aggregate(stats: [:created_count, :started_count, :completed_count]).data
21
+ }
22
+
23
+ before(:each) do
24
+ query = "locale_key=en-us&stats=created_count&stats=started_count&stats=completed_count"
25
+ stub_it(:get, "/analytics/decks/big-five/aggregate?#{query}", "aggregate")
26
+ end
27
+
28
+ it "returns assessments" do
29
+ expect(data.assessments.started_count).to eq(10)
30
+ end
31
+ end
32
+
33
+ context ".assessments" do
34
+ let(:assessments){ client.analytics.decks("deck-id").assessments.data }
35
+
36
+ before(:each) do
37
+ stub_it(:get, "/analytics/decks/deck-id/assessments?locale_key=en-us", "assessment")
38
+ end
39
+
40
+ it "returns assessments" do
41
+ expect(assessments.deck_id).to eq(client.deck_id)
42
+ end
43
+ end
44
+
45
+ context ".personality_traits" do
46
+ let(:personality_traits){ client.analytics.decks("deck-id").personality_traits.data }
47
+
48
+ before(:each) do
49
+ stub_it(:get, "/analytics/decks/deck-id/personality_traits?locale_key=en-us", "assessment")
50
+ end
51
+
52
+ it "returns an personality_traits" do
53
+ expect(personality_traits.deck_id).to eq(client.deck_id)
54
+ end
55
+ end
56
+
57
+ context ".personality_types" do
58
+ let(:personality_types){ client.analytics.decks("deck-id").personality_types.data }
59
+
60
+ before(:each) do
61
+ stub_it(:get, "/analytics/decks/deck-id/personality_types?locale_key=en-us", "assessment")
62
+ end
63
+
64
+ it "returns an personality_types" do
65
+ expect(personality_types.deck_id).to eq(client.deck_id)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -2,31 +2,32 @@ require "spec_helper"
2
2
 
3
3
  describe Traitify::Client do
4
4
  before do
5
- Traitify.configure do |tom|
6
- tom.secret = "secret"
7
- tom.api_host = "https://example.com"
8
- tom.api_version = "v1"
9
- tom.deck_id = "deck-uuid"
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")
10
11
  end
11
12
  end
12
13
 
13
- let(:tom) { Traitify.new }
14
+ let(:client){ Traitify.new }
14
15
 
15
16
  describe ".create_assessment" do
16
17
  context "without a user" do
17
- let(:assessment) { tom.create_assessment }
18
+ let(:assessment){ client.assessments.create.data }
18
19
 
19
20
  before(:each) do
20
21
  stub_it(:post, "/assessments", "assessment")
21
22
  end
22
23
 
23
24
  it "returns an assessment" do
24
- expect(assessment.deck_id).to eq(tom.deck_id)
25
+ expect(assessment.deck_id).to eq(client.deck_id)
25
26
  end
26
27
  end
27
28
 
28
29
  context "with a user" do
29
- let(:assessment) { tom.create_assessment(user_id: "toms-uuid") }
30
+ let(:assessment){ client.assessments.create(user_id: "clients-uuid").data }
30
31
 
31
32
  before(:each) do
32
33
  stub_it(:post, "/assessments", "assessment")
@@ -38,7 +39,7 @@ describe Traitify::Client do
38
39
  end
39
40
 
40
41
  context "with a deck" do
41
- let(:assessment) { tom.create_assessment(deck_id: "other-deck-uuid") }
42
+ let(:assessment){ client.assessments.create(deck_id: "other-deck-uuid").data }
42
43
 
43
44
  before(:each) do
44
45
  stub_it(:post, "/assessments", "assessment")
@@ -51,10 +52,10 @@ describe Traitify::Client do
51
52
  end
52
53
 
53
54
  describe ".find_assessment" do
54
- let(:assessment) { tom.find_assessment("assessment-uuid") }
55
+ let(:assessment){ client.assessments("assessment-uuid").data }
55
56
 
56
57
  before(:each) do
57
- stub_it(:get, "/assessments/assessment-uuid", "assessment")
58
+ stub_it(:get, "/assessments/assessment-uuid?locale_key=en-us", "assessment")
58
59
  end
59
60
 
60
61
  it "returns an assessment" do
@@ -63,10 +64,14 @@ describe Traitify::Client do
63
64
  end
64
65
 
65
66
  describe ".assessment_with_results" do
66
- let(:result) { tom.assessment_with_results("assessment-uuid", nil, %w(traits types blend)) }
67
+ let(:result){ client.assessments("assessment-uuid").find(data: [:traits, :types, :blend]).data }
67
68
 
68
69
  before(:each) do
69
- stub_it(:get, "/assessments/assessment-uuid?data=traits,types,blend", "assessment_with_results")
70
+ stub_it(
71
+ :get,
72
+ "/assessments/assessment-uuid?data=traits,types,blend&locale_key=en-us",
73
+ "assessment_with_results"
74
+ )
70
75
  end
71
76
 
72
77
  it "returns an assessment with results" do
@@ -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.logger = Logger.new("/dev/null")
10
+ end
11
+ end
12
+
13
+ let(:client){ Traitify.new }
14
+
15
+ describe ".careers" do
16
+ context "without params" do
17
+ let(:careers){ client.careers.data }
18
+
19
+ before(:each) do
20
+ stub_it(:get, "/careers?locale_key=en-us", "careers")
21
+ end
22
+
23
+ it "returns careers" do
24
+ expect(careers.first.title).to eq("Career Title")
25
+ end
26
+ end
27
+
28
+ context "with params" do
29
+ let(:careers){ client.careers(page: 1, careers_per_page: 50).data }
30
+
31
+ before(:each) do
32
+ stub_it(:get, "/careers?careers_per_page=50&page=1&locale_key=en-us", "careers")
33
+ end
34
+
35
+ it "returns careers" do
36
+ expect(careers.first.title).to eq("Career Title")
37
+ end
38
+ end
39
+ end
40
+
41
+ describe ".career" do
42
+ let(:career){ client.careers("career-id").data }
43
+
44
+ before(:each) do
45
+ stub_it(:get, "/careers/career-id?locale_key=en-us", "career")
46
+ end
47
+
48
+ it "returns career" do
49
+ expect(career.title).to eq("Career Title")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe Traitify::Client do
4
+ let(:traitify){ Traitify.new }
5
+
6
+ context "config setters" do
7
+ before do
8
+ Traitify.configure do |client|
9
+ client.secret_key = "secret"
10
+ client.host = "https://example.com"
11
+ client.version = "v1"
12
+ client.deck_id = "deck-uuid"
13
+ client.logger = Logger.new("/dev/null")
14
+ end
15
+ end
16
+
17
+ it "assigns secret" do
18
+ expect(traitify.secret_key).to eq("secret")
19
+ end
20
+
21
+ it "assigns api_host" do
22
+ expect(traitify.host).to eq("https://example.com")
23
+ end
24
+
25
+ it "assigns api_version" do
26
+ expect(traitify.version).to eq("v1")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
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 ".decks" do
17
+ context "without a user" do
18
+ let(:decks){ client.decks.data }
19
+
20
+ before(:each) do
21
+ stub_it(:get, "/decks?locale_key=en-us", "decks")
22
+ end
23
+
24
+ it "returns an array of decks" do
25
+ expect(decks.first.id).to eq("deck-uuid")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,39 @@
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 ".locales" do
17
+ let(:locales){ client.locales.data }
18
+
19
+ before(:each) do
20
+ stub_it(:get, "/locales", "locales")
21
+ end
22
+
23
+ it "returns an array of locales" do
24
+ expect(locales.first.country_code).to eq("US")
25
+ end
26
+ end
27
+
28
+ describe ".locale" do
29
+ let(:locale){ client.locales("en-us").data }
30
+
31
+ before(:each) do
32
+ stub_it(:get, "/locales/en-us", "locale")
33
+ end
34
+
35
+ it "returns a locale" do
36
+ expect(locale.country_code).to eq("US")
37
+ end
38
+ end
39
+ end
@@ -2,21 +2,22 @@ require "spec_helper"
2
2
 
3
3
  describe Traitify::Client do
4
4
  before do
5
- Traitify.configure do |tom|
6
- tom.secret_key = "secret"
7
- tom.host = "https://example.com"
8
- tom.version = "v1"
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")
9
10
  end
10
11
  end
11
12
 
12
- let(:tom) { Traitify.new }
13
+ let(:client){ Traitify.new }
13
14
 
14
15
  describe ".majors" do
15
16
  context "without params" do
16
- let(:majors) { tom.majors }
17
+ let(:majors){ client.majors.data }
17
18
 
18
19
  before(:each) do
19
- stub_it(:get, "/majors", "majors")
20
+ stub_it(:get, "/majors?locale_key=en-us", "majors")
20
21
  end
21
22
 
22
23
  it "returns majors" do
@@ -25,10 +26,10 @@ describe Traitify::Client do
25
26
  end
26
27
 
27
28
  context "with params" do
28
- let(:majors) { tom.majors(page: 1, majors_per_page: 50) }
29
+ let(:majors){ client.majors(page: 1, majors_per_page: 50).data }
29
30
 
30
31
  before(:each) do
31
- stub_it(:get, "/majors?majors_per_page=50&page=1", "majors")
32
+ stub_it(:get, "/majors?majors_per_page=50&page=1&locale_key=en-us", "majors")
32
33
  end
33
34
 
34
35
  it "returns majors" do
@@ -38,10 +39,10 @@ describe Traitify::Client do
38
39
  end
39
40
 
40
41
  describe ".major" do
41
- let(:major) { tom.major("major-id") }
42
+ let(:major){ client.majors("major-id").data }
42
43
 
43
44
  before(:each) do
44
- stub_it(:get, "/majors/major-id", "major")
45
+ stub_it(:get, "/majors/major-id?locale_key=en-us", "major")
45
46
  end
46
47
 
47
48
  it "returns major" do
@@ -0,0 +1,66 @@
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 ".profiles" do
17
+ let(:profiles){ client.profiles.data }
18
+
19
+ before(:each) do
20
+ stub_it(:get, "/profiles?locale_key=en-us", "profiles")
21
+ end
22
+
23
+ it "returns an array of decks" do
24
+ expect(profiles.first.id).to eq("profile-uuid")
25
+ end
26
+ end
27
+
28
+ describe ".profile" do
29
+ let(:profile){ client.profiles(:uuid).data }
30
+
31
+ before(:each) do
32
+ stub_it(:get, "/profiles/uuid?locale_key=en-us", "profile")
33
+ end
34
+
35
+ it "returns an array of decks" do
36
+ expect(profile.id).to eq("profile-uuid")
37
+ end
38
+ end
39
+
40
+ describe ".create_profile" do
41
+ let(:profile){ client.profiles.create({first_name: "Carson"}).data }
42
+
43
+ before(:each) do
44
+ stub_it(:post, "/profiles", "profile", body: {
45
+ first_name: "Carson",
46
+ locale_key: "en-us"
47
+ })
48
+ end
49
+
50
+ it "returns an array of decks" do
51
+ expect(profile.id).to eq("profile-uuid")
52
+ end
53
+ end
54
+
55
+ describe ".matches.profiles(...)" do
56
+ let(:match){ client.profiles(:uuid).matches.profiles(:profile_id).data }
57
+
58
+ before(:each) do
59
+ stub_it(:get, "/profiles/uuid/matches/profiles/profile_id?locale_key=en-us", "profile")
60
+ end
61
+
62
+ it "returns an array of decks" do
63
+ expect(match.id).to eq("profile-uuid")
64
+ end
65
+ end
66
+ end