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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 24bde91c41b325a8994be3a3f1805ebdf42bc8f7
4
- data.tar.gz: acf84dc451aba15a7fc5c16b393c302742318e86
2
+ SHA256:
3
+ metadata.gz: ac1ecd58611516c2f31b6e56e290c1efc0ee7e1842cce7b48a0157c8b5687acf
4
+ data.tar.gz: 84f2887d1ae2bd1fd6ded295cb864596d41fa3a3aad1b1a9dcffe02e22142015
5
5
  SHA512:
6
- metadata.gz: cda6f5736bfaf4375b3c5d155f5d364ae76ddc01a97839ac9403cdf8b62c8cb7b7349a8dbf196f7aeca964eee5d9551e35e51d1461059b62dbca707b612d59e9
7
- data.tar.gz: 31af9c23e1533318a3a8a70c95cd294d0f401d936a96f8e7fc649f99f861473ce3617d7a13084f57727c627e0ad33bff9c89cb8c2956f047a8ca23dad970bd6c
6
+ metadata.gz: 535343ccff192c9a91c2b3fa4f1495e38c3fbd9bc02d30312718f6a36d230262a280ae8b59947b4f97104c4d6926cf1f88e5c303f71ca9acacb1afc613c2c546
7
+ data.tar.gz: a882126511dbb26e8dc2bb92a78393943296488b97a246799fe187b51e2e6ac58c8a9d499d50fd9229c1c28125cf03d8bf62ef6ae0222268af616b966100bb59
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ inherit_gem:
2
+ rubocop-traitify: .rubocop_traitify.yml
3
+
4
+ Rails:
5
+ Enabled: false
6
+
7
+ # Requires breaking change
8
+ Airbnb/OptArgParameters:
9
+ Enabled: true
10
+ Exclude:
11
+ - lib/traitify/client/model.rb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 1.9.0
2
+
3
+ * Features
4
+ * Added locales
5
+
1
6
  ### 1.8.4
2
7
 
3
8
  * Bug Fixes
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in traitify.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem "rubocop-traitify"
8
+ end
data/Gemfile.lock CHANGED
@@ -1,56 +1,123 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- traitify (1.8.4)
5
- faraday (~> 0.9)
6
- faraday_middleware (~> 0.9)
7
- hashie (~> 3.0)
4
+ traitify (2.0.1)
5
+ activesupport (>= 5.1, < 8.x)
6
+ faraday (~> 2.5)
7
+ faraday-net_http (~> 3.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- addressable (2.3.8)
13
- binding_of_caller (0.7.2)
12
+ activesupport (7.0.3.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ addressable (2.8.1)
18
+ public_suffix (>= 2.0.2, < 6.0)
19
+ ast (2.4.2)
20
+ binding_of_caller (1.0.0)
14
21
  debug_inspector (>= 0.0.1)
15
- coderay (1.1.0)
16
- crack (0.4.2)
17
- safe_yaml (~> 1.0.0)
18
- debug_inspector (0.0.2)
19
- diff-lcs (1.2.5)
20
- faraday (0.9.1)
21
- multipart-post (>= 1.2, < 3)
22
- faraday_middleware (0.9.1)
23
- faraday (>= 0.7.4, < 0.10)
24
- hashie (3.4.1)
25
- method_source (0.8.2)
26
- multipart-post (2.0.0)
27
- pry (0.10.1)
28
- coderay (~> 1.1.0)
29
- method_source (~> 0.8.1)
30
- slop (~> 3.4)
31
- rake (10.4.2)
32
- rspec (2.99.0)
33
- rspec-core (~> 2.99.0)
34
- rspec-expectations (~> 2.99.0)
35
- rspec-mocks (~> 2.99.0)
36
- rspec-core (2.99.2)
37
- rspec-expectations (2.99.2)
38
- diff-lcs (>= 1.1.3, < 2.0)
39
- rspec-mocks (2.99.3)
40
- safe_yaml (1.0.4)
41
- slop (3.6.0)
42
- webmock (1.21.0)
43
- addressable (>= 2.3.6)
22
+ coderay (1.1.3)
23
+ concurrent-ruby (1.1.10)
24
+ crack (0.4.5)
25
+ rexml
26
+ debug_inspector (1.1.0)
27
+ diff-lcs (1.5.0)
28
+ docile (1.4.0)
29
+ faraday (2.5.2)
30
+ faraday-net_http (>= 2.0, < 3.1)
31
+ ruby2_keywords (>= 0.0.4)
32
+ faraday-net_http (3.0.0)
33
+ hashdiff (1.0.1)
34
+ i18n (1.12.0)
35
+ concurrent-ruby (~> 1.0)
36
+ method_source (1.0.0)
37
+ minitest (5.16.3)
38
+ parallel (1.22.1)
39
+ parser (3.1.2.1)
40
+ ast (~> 2.4.1)
41
+ pry (0.14.1)
42
+ coderay (~> 1.1)
43
+ method_source (~> 1.0)
44
+ public_suffix (5.0.0)
45
+ rack (2.2.4)
46
+ rainbow (3.1.1)
47
+ rake (13.0.6)
48
+ regexp_parser (2.5.0)
49
+ rexml (3.2.5)
50
+ rspec (3.11.0)
51
+ rspec-core (~> 3.11.0)
52
+ rspec-expectations (~> 3.11.0)
53
+ rspec-mocks (~> 3.11.0)
54
+ rspec-core (3.11.0)
55
+ rspec-support (~> 3.11.0)
56
+ rspec-expectations (3.11.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.11.0)
59
+ rspec-mocks (3.11.1)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.11.0)
62
+ rspec-support (3.11.0)
63
+ rubocop (0.93.1)
64
+ parallel (~> 1.10)
65
+ parser (>= 2.7.1.5)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.8)
68
+ rexml
69
+ rubocop-ast (>= 0.6.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 2.0)
72
+ rubocop-airbnb (4.0.0)
73
+ rubocop (~> 0.93.1)
74
+ rubocop-performance (~> 1.10.2)
75
+ rubocop-rails (~> 2.9.1)
76
+ rubocop-rspec (~> 1.44.1)
77
+ rubocop-ast (1.21.0)
78
+ parser (>= 3.1.1.0)
79
+ rubocop-performance (1.10.2)
80
+ rubocop (>= 0.90.0, < 2.0)
81
+ rubocop-ast (>= 0.4.0)
82
+ rubocop-rails (2.9.1)
83
+ activesupport (>= 4.2.0)
84
+ rack (>= 1.1)
85
+ rubocop (>= 0.90.0, < 2.0)
86
+ rubocop-rspec (1.44.1)
87
+ rubocop (~> 0.87)
88
+ rubocop-ast (>= 0.7.1)
89
+ rubocop-traitify (1.1.0)
90
+ rubocop-airbnb (~> 4.0.0)
91
+ ruby-progressbar (1.11.0)
92
+ ruby2_keywords (0.0.5)
93
+ simplecov (0.21.2)
94
+ docile (~> 1.1)
95
+ simplecov-html (~> 0.11)
96
+ simplecov_json_formatter (~> 0.1)
97
+ simplecov-html (0.12.3)
98
+ simplecov_json_formatter (0.1.4)
99
+ tzinfo (2.0.5)
100
+ concurrent-ruby (~> 1.0)
101
+ unicode-display_width (1.8.0)
102
+ webmock (3.18.1)
103
+ addressable (>= 2.8.0)
44
104
  crack (>= 0.3.2)
105
+ hashdiff (>= 0.4.0, < 2.0.0)
45
106
 
46
107
  PLATFORMS
47
- ruby
108
+ arm64-darwin-20
109
+ arm64-darwin-21
48
110
 
49
111
  DEPENDENCIES
50
- binding_of_caller (~> 0.7)
51
- bundler (~> 1.3)
52
- pry (~> 0.10)
53
- rake (~> 10.1)
54
- rspec (~> 2.14)
112
+ binding_of_caller (~> 1.0)
113
+ bundler (~> 2.2)
114
+ pry (~> 0.14)
115
+ rake (~> 13.0)
116
+ rspec (~> 3.11)
117
+ rubocop-traitify
118
+ simplecov (~> 0.21.2)
55
119
  traitify!
56
- webmock (~> 1.13)
120
+ webmock (~> 3.18)
121
+
122
+ BUNDLED WITH
123
+ 2.2.33
data/README.md CHANGED
@@ -14,11 +14,13 @@ Or install it yourself with:
14
14
 
15
15
  ## Usage
16
16
 
17
- First, it is helpful to configure Traitify, otherwise everytime you create a Traitify object you must add the configuration
17
+ 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.
18
+
19
+ It is helpful to configure Traitify, otherwise everytime you create a Traitify object you must add the configuration options.
18
20
 
19
21
  ### Configuration
20
22
 
21
- All the configuration options can be found in `lib/Traitify/configuration.rb`
23
+ All the configuration options can be found in `lib/traitify/configuration.rb`
22
24
 
23
25
  Traitify.configure do |traitify|
24
26
  traitify.host = "https://api-sandbox.traitify.com"
@@ -27,12 +29,13 @@ All the configuration options can be found in `lib/Traitify/configuration.rb`
27
29
  traitify.public_key = "public" # Optional
28
30
  traitify.deck_id = "deck-uuid" # Optional
29
31
  traitify.image_pack = "image-pack-type" # Optional
32
+ traitify.locale_key = "en-us" # Optional
30
33
  end
31
34
 
32
35
  #### With config file:
33
36
 
34
37
  traitify = Traitify.new
35
- traitify.create_assessment
38
+ traitify.assessments.create
36
39
 
37
40
  #### Without config file:
38
41
 
@@ -42,13 +45,13 @@ All the configuration options can be found in `lib/Traitify/configuration.rb`
42
45
  secret_key: "secret",
43
46
  deck_id: "deck-uuid"
44
47
  )
45
- traitify.create_assessment
48
+ traitify.assessments.create
46
49
 
47
50
  ### Decks
48
51
 
49
52
  #### Getting all the decks:
50
53
 
51
- decks = traitify.decks
54
+ decks = traitify.decks.data
52
55
 
53
56
  Returns an array of Deck objects:
54
57
 
@@ -62,26 +65,27 @@ Returns an array of Deck objects:
62
65
 
63
66
  #### Creating an assessment:
64
67
 
65
- assessment = traitify.create_assessment
68
+ assessment = traitify.assessments.create
66
69
 
67
70
  You must can specify the deck in your configuration or override it here
68
71
 
69
- assessment = traitify.create_assessment(deck_id: "deck-uuid")
72
+ assessment = traitify.assessments.create(deck_id: "deck-uuid")
70
73
 
71
- You can also specify an image pack, otherwise a default image pack associated with the secret is used
74
+ You can optionally specify image pack or locale
72
75
 
73
- assessment = traitify.create_assessment(image_pack: "full-color")
76
+ assessment = traitify.assessments.create(image_pack: "full-color")
74
77
 
75
78
  Returns an assessment object:
76
79
 
77
- assessment.id #=> "assessment-uuid"
78
- assessment.deck_id #=> "deck-uuid"
79
- assessment.created_at #=> Returns time in Epoch format
80
- assessment.completed_at #=> nil
80
+ data = assessment.data
81
+ data.id #=> "assessment-uuid"
82
+ data.deck_id #=> "deck-uuid"
83
+ data.created_at #=> Returns time in Epoch format
84
+ data.completed_at #=> nil
81
85
 
82
86
  #### Finding an assessment:
83
87
 
84
- assessment = traitify.find_assessment("assessment-uuid")
88
+ assessment = traitify.assessments("assessment-uuid").data
85
89
 
86
90
  Returns an assessment object as seen above
87
91
 
@@ -91,7 +95,7 @@ An assessment can be taken through our javascript plugin or by getting the slide
91
95
 
92
96
  #### Finding an assessment's slides:
93
97
 
94
- slides = traitify.find_slides("assessment-uuid")
98
+ slides = traitify.assessments("assessment-uuid").slides.data
95
99
 
96
100
  Returns an array of slides
97
101
 
@@ -105,20 +109,20 @@ Returns an array of slides
105
109
  slide
106
110
  end
107
111
 
108
- traitify.update_slides("assessment-uuid", slides)
112
+ traitify.assessments("assessment-uuid").slides.update(slides)
109
113
 
110
114
  #### Updating a single assessment slide:
111
115
 
112
- slide = assessment.slides.first
116
+ slide = assessment.slides.data.first
113
117
  slide.response = true
114
118
  slide.time_taken = 600
115
- traitify.update_slide(assessment.id, slide)
119
+ traitify.assessments(assessment.id).slides(slide.id).update(slide.to_h)
116
120
 
117
121
  ### Results
118
122
 
119
123
  #### Getting an assessment's results
120
124
 
121
- results = traitify.find_results("assessment-uuid")
125
+ results = traitify.assessments("assessment-uuid").personality_types.data
122
126
 
123
127
  Returns a results object:
124
128
 
@@ -147,7 +151,7 @@ Returns a results object:
147
151
 
148
152
  #### Getting an assessment's personality traits
149
153
 
150
- traits = traitify.assessment_personality_traits("assessment-uuid")
154
+ traits = traitify.assessments("assessment-uuid").personality_traits.data
151
155
  trait = traits.first
152
156
  trait.score #=> 100
153
157
  personality_trait = trait.personality_trait
@@ -155,10 +159,31 @@ Returns a results object:
155
159
  personality_trait.definition #=> "Able to think symbolically and play with ideas."
156
160
  personality_trait.description #=> "Coming Soon"
157
161
 
158
- #### More results
162
+ #### Getting an assessment's analytics
163
+
164
+ traits = traitify.analytics.decks("deck-uuid").personality_traits.data
165
+ types = traitify.analytics.decks("deck-uuid").personality_types.data
166
+ assessments = traitify.analytics.decks("deck-uuid").assessments.data
167
+
168
+ #### Getting a profile
169
+
170
+ profile = traitify.profiles("profile-uuid").data
171
+ profile.first_name #=> "John"
172
+ profile.last_name #=> "Doe"
173
+ profile.email #=> "johndoe@example.com"
159
174
 
160
- More API endpoints may be available. You can find more at [developer.traitify.com](http://developer.traitify.com/documentation).
161
- To make authenticated calls to new endpoints use the syntax below:
175
+ #### Creating a profile
176
+
177
+ profile = traitify.profiles.create({
178
+ first_name: "John",
179
+ last_name: "Doe",
180
+ email: "johndoe@example.com"
181
+ }).data
182
+
183
+ profile.first_name #=> "John"
184
+ profile.last_name #=> "Doe"
185
+ profile.email #=> "johndoe@example.com"
186
+
187
+ #### More results
162
188
 
163
- traitify.get("/new/endpoint")
164
- traitify.post("/new/endpoint", { ready: true })
189
+ More API endpoints may be available. You can find more at [app.traitify.com/developer](https://app.traitify.com/developer).
@@ -0,0 +1,23 @@
1
+ require "faraday"
2
+ require "faraday/net_http"
3
+ require "traitify/middleware/formatter"
4
+ require "traitify/middleware/raise_error"
5
+
6
+ module Traitify
7
+ class Client
8
+ module Connection
9
+ def connection(options = {})
10
+ Faraday.new(options) do |faraday|
11
+ faraday.request :authorization, :basic, secret_key || public_key, "x"
12
+ faraday.request :json
13
+ faraday.headers["Accept"] = "application/json"
14
+ faraday.options.params_encoder = Faraday::FlatParamsEncoder
15
+ faraday.response :logger, Traitify.logger, formatter: Traitify::Middleware::Formatter
16
+ faraday.response :raise_traitify_error
17
+ faraday.response :json
18
+ faraday.adapter :net_http
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ module Traitify
2
+ class Client
3
+ module Model
4
+ def find(params = {})
5
+ copy.set(verb: :get).add_params(params).request
6
+ end
7
+ alias_method :all, :find
8
+
9
+ def create(params = {})
10
+ copy.set(verb: :post, params: params).request
11
+ end
12
+
13
+ def destroy
14
+ copy.set(verb: :delete).request
15
+ end
16
+
17
+ def update(params, verb = :put)
18
+ copy.set(verb: verb, params: params).request
19
+ end
20
+
21
+ def base(name, params = {})
22
+ client = copy.set(type: name, verb: :get).add_path("/#{name}")
23
+
24
+ if [NilClass, Hash, Array].include? params.class
25
+ client.set(params: params)
26
+ else
27
+ client.add_path("/#{params}")
28
+ end
29
+
30
+ client
31
+ end
32
+
33
+ private
34
+
35
+ def copy
36
+ Traitify.new(options).set(
37
+ type: type.deep_dup,
38
+ verb: verb.deep_dup,
39
+ path: path.deep_dup,
40
+ params: params.deep_dup
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ module Traitify
2
+ class Client
3
+ module Overrides
4
+ def perform_overrides
5
+ send("#{type}_override") if respond_to? "#{type}_override"
6
+
7
+ self
8
+ end
9
+
10
+ def assessments_override
11
+ if params[:data] && params[:data].is_a?(Array)
12
+ @params[:data] = params[:data].join(",")
13
+ end
14
+ end
15
+
16
+ def personality_types_override
17
+ if image_pack && params[:image_pack].nil?
18
+ @params[:image_pack] = image_pack
19
+ end
20
+ end
21
+
22
+ def locales_override
23
+ @params.delete(:locale_key)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module Traitify
2
+ class Client
3
+ module Request
4
+ [:get, :post, :put, :delete, :patch].each do |verb|
5
+ define_method verb do |path, params = {}|
6
+ copy.set(verb: verb, path: path, params: params).request
7
+ end
8
+ end
9
+
10
+ def request
11
+ @request = Traitify::Response.new(base_request)
12
+ end
13
+ alias_method :fetch, :request
14
+
15
+ def data
16
+ @data ||= request.data
17
+ end
18
+
19
+ private
20
+
21
+ def base_request
22
+ unless locale_key.nil? || params.is_a?(Array) || params[:locale_key]
23
+ set_param(:locale_key, locale_key)
24
+ end
25
+
26
+ request_path = [version, path].join
27
+ request_params = params&.as_json
28
+
29
+ connection(url: host).public_send(verb, request_path, request_params)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module Traitify
2
+ class Client
3
+ module Setup
4
+ def set(options)
5
+ @type = options[:type] if options[:type]
6
+ @verb = options[:verb] if options[:verb]
7
+ @path = options[:path] if options[:path]
8
+ @params = options[:params] if options[:params]
9
+ perform_overrides
10
+ end
11
+
12
+ def set_param(key, value)
13
+ set(params: params.merge(key => value))
14
+ end
15
+
16
+ def add_params(new_params)
17
+ set(params: params.merge(new_params))
18
+ end
19
+
20
+ def add_path(value)
21
+ set(path: path + value)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,40 +1,33 @@
1
- # require base modules
2
- require "traitify/connection"
3
- require "traitify/request"
4
- require "hashie"
5
- # require client modules in lib/Traitify/client
6
- Dir[File.expand_path("../client/*.rb", __FILE__)].each {|f| require f }
1
+ require "uri"
2
+ Dir[File.expand_path("../client/*.rb", __FILE__)].each{ |f| require f }
7
3
 
8
4
  module Traitify
9
5
  class Client
10
6
  attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
11
-
12
- alias_method :api_host, :host
13
- alias_method :api_host=, :host=
14
-
15
- alias_method :api_version, :version
16
- alias_method :api_version=, :version=
17
-
18
- alias_method :secret, :secret_key
19
- alias_method :secret=, :secret_key=
7
+ attr_reader :type, :verb, :path, :params
20
8
 
21
9
  def initialize(options = {})
22
- options = Traitify.options.merge(options)
23
-
24
- options.each do |key, value|
10
+ Traitify.options.merge(options).each do |key, value|
25
11
  send("#{key}=", value) unless value.nil?
26
12
  end
13
+
14
+ set(verb: :get, path: "", params: {})
27
15
  end
28
16
 
29
- include Traitify::Connection
30
- include Traitify::Configuration
31
- include Traitify::Request
17
+ def method_missing(method_name, *args, &block)
18
+ base(method_name, *args)
19
+ end
32
20
 
33
- include Traitify::Client::Deck
34
- include Traitify::Client::Assessment
35
- include Traitify::Client::Slide
36
- include Traitify::Client::Result
37
- include Traitify::Client::Career
38
- include Traitify::Client::Major
21
+ def to_hash
22
+ Hash[instance_variables.collect{ |key| [key.to_s.delete("@"), instance_variable_get(key)] }]
23
+ end
24
+ alias_method :to_h, :to_hash
25
+
26
+ include Traitify::Configuration
27
+ include Traitify::Client::Connection
28
+ include Traitify::Client::Model
29
+ include Traitify::Client::Overrides
30
+ include Traitify::Client::Request
31
+ include Traitify::Client::Setup
39
32
  end
40
33
  end
@@ -6,26 +6,18 @@ module Traitify
6
6
  :secret_key,
7
7
  :version,
8
8
  :deck_id,
9
- :image_pack
10
- ]
9
+ :image_pack,
10
+ :locale_key
11
+ ].freeze
11
12
 
12
13
  attr_accessor(*VALID_OPTIONS_KEYS)
13
14
 
14
- alias_method :api_host, :host
15
- alias_method :api_host=, :host=
16
-
17
- alias_method :api_version, :version
18
- alias_method :api_version=, :version=
19
-
20
- alias_method :secret, :secret_key
21
- alias_method :secret=, :secret_key=
22
-
23
15
  def configure
24
16
  yield self
25
17
  end
26
18
 
27
19
  def options
28
- VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
20
+ Hash[VALID_OPTIONS_KEYS.collect{ |key| [key, send(key)] }]
29
21
  end
30
22
  end
31
23
  end
@@ -0,0 +1,18 @@
1
+ module Traitify
2
+ class Data < OpenStruct
3
+ def self.new(data)
4
+ case data
5
+ when Array
6
+ data.collect{ |row| new row }
7
+ when Hash
8
+ super data.transform_values{ |value| new value }
9
+ else
10
+ data
11
+ end
12
+ end
13
+
14
+ def as_json(*args)
15
+ @table.as_json(*args)
16
+ end
17
+ end
18
+ end