traitify 1.8.4 → 2.0.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 +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 +22 -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/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 +53 -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 +113 -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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '080c41445afd77a214878d4d168ec0282c57e67a9d4c35d87e41de7313d903c1'
|
4
|
+
data.tar.gz: 65c2e954bf74dda9d72a0d99907794310b2497af7360f10922f25a7dfdfddb66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01f85cca8ab81448f68e9b5c105678186e330280b12ac2d0aeca3cba8ab5995cc444516b592e2c793c1e29009b8fe8bf149e6d18e4712c637a5cfc0e88e07427
|
7
|
+
data.tar.gz: ea19044bc059b70eef832b98edead636712727e6fc00508639e4d0ec452b327a27209834118af5b300abd298f770f9dd4fd27f1ee88d062d04ebca5d2b641ec0
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,56 +1,123 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
traitify (
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
traitify (2.0.0)
|
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
|
-
|
13
|
-
|
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.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
faraday (>= 0
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
108
|
+
arm64-darwin-20
|
109
|
+
arm64-darwin-21
|
48
110
|
|
49
111
|
DEPENDENCIES
|
50
|
-
binding_of_caller (~> 0
|
51
|
-
bundler (~>
|
52
|
-
pry (~> 0.
|
53
|
-
rake (~>
|
54
|
-
rspec (~>
|
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 (~>
|
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
|
-
|
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/
|
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.
|
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.
|
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.
|
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.
|
72
|
+
assessment = traitify.assessments.create(deck_id: "deck-uuid")
|
70
73
|
|
71
|
-
You can
|
74
|
+
You can optionally specify image pack or locale
|
72
75
|
|
73
|
-
assessment = traitify.
|
76
|
+
assessment = traitify.assessments.create(image_pack: "full-color")
|
74
77
|
|
75
78
|
Returns an assessment object:
|
76
79
|
|
77
|
-
assessment.
|
78
|
-
|
79
|
-
|
80
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
-
####
|
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
|
-
|
161
|
-
|
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
|
-
|
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,22 @@
|
|
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.response :logger, Traitify.logger, formatter: Traitify::Middleware::Formatter
|
15
|
+
faraday.response :raise_traitify_error
|
16
|
+
faraday.response :json
|
17
|
+
faraday.adapter :net_http
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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
|
data/lib/traitify/client.rb
CHANGED
@@ -1,40 +1,33 @@
|
|
1
|
-
|
2
|
-
require
|
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
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
17
|
+
def method_missing(method_name, *args, &block)
|
18
|
+
base(method_name, *args)
|
19
|
+
end
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
include Traitify::
|
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.
|
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
|