traitify 1.8.4 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +5 -1
- data/Gemfile.lock +109 -42
- data/README.md +50 -25
- data/lib/traitify/client/connection.rb +23 -0
- data/lib/traitify/client/model.rb +45 -0
- data/lib/traitify/client/overrides.rb +27 -0
- data/lib/traitify/client/request.rb +33 -0
- data/lib/traitify/client/setup.rb +25 -0
- data/lib/traitify/client.rb +20 -27
- data/lib/traitify/configuration.rb +4 -12
- data/lib/traitify/data.rb +18 -0
- data/lib/traitify/error.rb +18 -16
- data/lib/traitify/middleware/formatter.rb +52 -0
- data/lib/traitify/middleware/raise_error.rb +38 -0
- data/lib/traitify/response.rb +44 -0
- data/lib/traitify/version.rb +1 -1
- data/lib/traitify.rb +29 -1
- data/paths.yml +1352 -0
- data/spec/spec_helper.rb +14 -6
- data/spec/support/mocks/aggregate.json +7 -0
- data/spec/support/mocks/assessment.json +1 -1
- data/spec/support/mocks/assessment_analytics.json +7 -0
- data/spec/support/mocks/blank.json +0 -0
- data/spec/support/mocks/career.json +1 -2
- data/spec/support/mocks/careers.json +2 -3
- data/spec/support/mocks/decks.json +1 -4
- data/spec/support/mocks/locale.json +10 -0
- data/spec/support/mocks/locales.json +12 -0
- data/spec/support/mocks/profile.json +5 -0
- data/spec/support/mocks/profiles.json +5 -0
- data/spec/support/mocks/trait_analytics.json +7 -0
- data/spec/support/mocks/type_analytics.json +7 -0
- data/spec/traitify/client/examples/analytics_spec.rb +69 -0
- data/spec/{traitify-ruby/client → traitify/client/examples}/assessment_spec.rb +19 -14
- data/spec/traitify/client/examples/career_spec.rb +52 -0
- data/spec/traitify/client/examples/configuration_spec.rb +29 -0
- data/spec/traitify/client/examples/deck_spec.rb +29 -0
- data/spec/traitify/client/examples/locale_spec.rb +39 -0
- data/spec/{traitify-ruby/client → traitify/client/examples}/major_spec.rb +12 -11
- data/spec/traitify/client/examples/profiles_spec.rb +66 -0
- data/spec/traitify/client/examples/result_spec.rb +130 -0
- data/spec/traitify/client/examples/slide_spec.rb +95 -0
- data/spec/traitify/client/model_spec.rb +73 -0
- data/spec/traitify/client/request_spec.rb +85 -0
- data/spec/traitify/client/setup_spec.rb +62 -0
- data/spec/traitify/client_spec.rb +52 -0
- data/spec/traitify/data_spec.rb +105 -0
- data/spec/traitify/error_spec.rb +117 -0
- data/spec/traitify/response_spec.rb +82 -0
- data/spec/traitify/version_spec.rb +7 -0
- data/traitify.gemspec +14 -12
- metadata +115 -53
- data/lib/traitify/client/assessments.rb +0 -29
- data/lib/traitify/client/careers.rb +0 -25
- data/lib/traitify/client/decks.rb +0 -16
- data/lib/traitify/client/majors.rb +0 -25
- data/lib/traitify/client/results.rb +0 -37
- data/lib/traitify/client/slides.rb +0 -34
- data/lib/traitify/connection.rb +0 -33
- data/lib/traitify/request.rb +0 -18
- data/spec/traitify-ruby/client/career_spec.rb +0 -51
- data/spec/traitify-ruby/client/configuration_spec.rb +0 -51
- data/spec/traitify-ruby/client/deck_spec.rb +0 -28
- data/spec/traitify-ruby/client/result_spec.rb +0 -93
- data/spec/traitify-ruby/client/slide_spec.rb +0 -82
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,27 @@
|
|
1
|
-
require "
|
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
|
13
|
-
url = "https://
|
14
|
-
stub_request(http_method, url)
|
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: {
|
25
|
+
headers: {"Content-type" => "application/json"}
|
18
26
|
)
|
19
27
|
end
|
File without changes
|
@@ -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,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 |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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(:
|
14
|
+
let(:client){ Traitify.new }
|
14
15
|
|
15
16
|
describe ".create_assessment" do
|
16
17
|
context "without a user" do
|
17
|
-
let(: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(
|
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)
|
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)
|
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)
|
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)
|
67
|
+
let(:result){ client.assessments("assessment-uuid").find(data: [:traits, :types, :blend]).data }
|
67
68
|
|
68
69
|
before(:each) do
|
69
|
-
stub_it(
|
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 |
|
6
|
-
|
7
|
-
|
8
|
-
|
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(:
|
13
|
+
let(:client){ Traitify.new }
|
13
14
|
|
14
15
|
describe ".majors" do
|
15
16
|
context "without params" do
|
16
|
-
let(: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)
|
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)
|
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
|