traitify 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddc1513959fbaa40d7eee6277c6f8c78579750bb
4
- data.tar.gz: f70c23b1ebd7962997aac709f8b596c8fd7e38ad
3
+ metadata.gz: 6a9b25173520896cbdd7d47c2b7a18c19022b199
4
+ data.tar.gz: 41173e061c58c3417c68cc19293ae5c6ccf0e06d
5
5
  SHA512:
6
- metadata.gz: fccc6837f3529e1c3fe1eaf46e62c3298b1aaf5683463168dbe6bf9509ebdf4d59aca0bb7ba503061517fdd78c038d3e5ff681984f58537eda3291e76bea0b86
7
- data.tar.gz: 568cb75b501279b86d7eaea660893f068d92c7e30572a8400e6bd19590162684de06db3ecae8e22a2ea9db4d18c8714b79a3af0e81d80794165ba7eb582c3879
6
+ metadata.gz: d04436ef921a63fc4e1f712ee2bd90bd9118e23e02539ef02c81ae870f148e4563ce5d8f3602d29fe1031fe1dbf5fd4e7b9e15bfed1578c523cb9e33b74f38fb
7
+ data.tar.gz: 06d27eab98ea81dfa76af8c7a686eeb462f86ebc3ee3dbbc6cb3d096ea0149ec5bd58e00202a9a2e56ca3d8b698ac62f5677c189422739d8301bc777da46e61d
@@ -1,3 +1,8 @@
1
+ ### 1.1.2
2
+
3
+ * Features
4
+ * Newer version of Faraday
5
+
1
6
  ### 1.1.1
2
7
 
3
8
  * Features
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- traitify (1.1.0)
5
- faraday (~> 0.8.0)
4
+ traitify (1.2.0)
5
+ faraday (~> 0.9.0)
6
6
  faraday_middleware (~> 0.9.0)
7
7
  hashie
8
8
 
@@ -17,16 +17,16 @@ GEM
17
17
  safe_yaml (~> 1.0.0)
18
18
  debug_inspector (0.0.2)
19
19
  diff-lcs (1.2.5)
20
- faraday (0.8.9)
21
- multipart-post (~> 1.2.0)
20
+ faraday (0.9.0)
21
+ multipart-post (>= 1.2, < 3)
22
22
  faraday_middleware (0.9.1)
23
23
  faraday (>= 0.7.4, < 0.10)
24
- hashie (2.1.1)
24
+ hashie (3.3.1)
25
25
  method_source (0.8.2)
26
- multipart-post (1.2.0)
27
- pry (0.9.12.6)
28
- coderay (~> 1.0)
29
- method_source (~> 0.8)
26
+ multipart-post (2.0.0)
27
+ pry (0.10.0)
28
+ coderay (~> 1.1.0)
29
+ method_source (~> 0.8.1)
30
30
  slop (~> 3.4)
31
31
  rake (10.1.1)
32
32
  rspec (2.14.1)
@@ -1,20 +1,22 @@
1
1
  module Traitify
2
+
2
3
  class Client
3
4
  module Assessment
4
5
  def create_assessment(options = {})
5
- deck_id = options[:deck_id] || options["deck_id"] || self.deck_id
6
- assessment_params = { deck_id: deck_id }
7
- response = post("/assessments", assessment_params)
8
-
9
- Hashie::Mash.new(response)
6
+ Hashie::Mash.new post("/assessments", { deck_id: deck_id_from(options) })
10
7
  end
11
8
 
12
9
  def assessment(assessment_id)
13
- response = get("/assessments/#{assessment_id}")
10
+ Hashie::Mash.new get("/assessments/#{assessment_id}")
11
+ end
12
+ alias :find_assessment :assessment
14
13
 
15
- Hashie::Mash.new(response)
14
+ private
15
+
16
+ def deck_id_from(options)
17
+ options[:deck_id] || deck_id
16
18
  end
17
- alias_method :find_assessment, :assessment
19
+
18
20
  end
19
21
  end
20
22
  end
@@ -1,8 +1,12 @@
1
1
  module Traitify
2
2
  class Client
3
3
  module Deck
4
- def decks
5
- response = get("/decks")
4
+ def decks(image_pack = nil)
5
+ image_pack ||= self.image_pack
6
+
7
+ response = image_pack ?
8
+ get("/decks?image_pack=#{image_pack}") :
9
+ get("/decks")
6
10
 
7
11
  response.collect { |deck| Hashie::Mash.new(deck) }
8
12
  end
@@ -4,26 +4,27 @@ module Traitify
4
4
  def results(assessment_id, image_pack = nil)
5
5
  image_pack ||= self.image_pack
6
6
 
7
- if image_pack
8
- response = get("/assessments/#{assessment_id}/personality_types?image_pack=#{image_pack}")
9
- else
10
- response = get("/assessments/#{assessment_id}/personality_types")
11
- end
7
+ response = image_pack ?
8
+ get("/assessments/#{assessment_id}/personality_types?image_pack=#{image_pack}") :
9
+ get("/assessments/#{assessment_id}/personality_types")
12
10
 
13
11
  Hashie::Mash.new(response)
14
12
  end
15
13
  alias_method :find_results, :results
16
14
 
17
15
  def assessment_personality_traits(assessment_id, personality_type_id = nil)
18
- if personality_type_id
19
- response = get("/assessments/#{assessment_id}/personality_types/#{personality_type_id}/personality_traits")
20
- else
21
- response = get("/assessments/#{assessment_id}/personality_traits")
22
- end
16
+ response = personality_type_id ?
17
+ get("/assessments/#{assessment_id}/personality_types/#{personality_type_id}/personality_traits") :
18
+ get("/assessments/#{assessment_id}/personality_traits")
23
19
 
24
20
  response.collect { |personality_trait| Hashie::Mash.new(personality_trait) }
25
21
  end
26
22
  alias_method :find_assessment_personality_traits, :assessment_personality_traits
23
+
24
+ def career_matches(assessment_id, number_of_matches=10)
25
+ response = get("/assessments/#{assessment_id}/matches/careers?number_of_matches=#{number_of_matches}")
26
+ response.collect { |career| Hashie::Mash.new(career) }
27
+ end
27
28
  end
28
29
  end
29
30
  end
@@ -1,28 +1,33 @@
1
1
  module Traitify
2
2
  class Client
3
3
  module Slide
4
- def find_slides(assessment_id)
5
- response = get("/assessments/#{assessment_id}/slides")
4
+ def url_for_slides_by(assessment_id)
5
+ "/assessments/#{assessment_id}/slides"
6
+ end
6
7
 
7
- response.collect { |slide| Hashie::Mash.new(slide) }
8
+ def find_slides(assessment_id)
9
+ url = url_for_slides_by(assessment_id)
10
+ get(url).collect do |slide|
11
+ Hashie::Mash.new(slide)
12
+ end
8
13
  end
9
14
 
10
15
  def update_slides(assessment_id, slides)
11
- response = put("/assessments/#{assessment_id}/slides", slides)
12
-
13
- response.collect { |slide| Hashie::Mash.new(slide) }
16
+ url = url_for_slides_by(assessment_id)
17
+ put(url, slides).collect do |slide|
18
+ Hashie::Mash.new(slide)
19
+ end
14
20
  end
15
21
 
16
22
  def update_slide(assessment_id, slide)
17
- slide_id = slide["id"] || slide[:id] || slide.id
23
+ slide_id = slide[:id] || slide.id
18
24
  params = {
19
- response: slide["response"] || slide[:response] || slide.response,
20
- time_taken: slide["time_taken"] || slide[:time_taken] || slide.time_taken,
25
+ response: slide[:response] || slide.response,
26
+ time_taken: slide[:time_taken] || slide.time_taken,
21
27
  }
22
28
 
23
- response = put("/assessments/#{assessment_id}/slides/#{slide_id}", params)
24
-
25
- Hashie::Mash.new(response)
29
+ url = [url_for_slides_by(assessment_id), "/", slide_id].join
30
+ Hashie::Mash.new put(url, params)
26
31
  end
27
32
  end
28
33
  end
@@ -3,8 +3,8 @@ require "traitify/error"
3
3
 
4
4
  module Traitify
5
5
  module Connection
6
- def connection(options = {})
7
- connection ||= Faraday.new(options) do |faraday|
6
+ def conn(options = {})
7
+ Faraday.new(options) do |faraday|
8
8
  faraday.request :url_encoded
9
9
  faraday.request :basic_auth, self.secret, "x"
10
10
  faraday.use ContentTypeMiddleware
@@ -12,11 +12,10 @@ module Traitify
12
12
  faraday.response :json, :content_type => /\bjson$/
13
13
  faraday.adapter Faraday.default_adapter
14
14
  end
15
-
16
- connection
17
15
  end
18
16
 
19
17
  private
18
+
20
19
  class ContentTypeMiddleware < Faraday::Middleware
21
20
  def initialize(app)
22
21
  @app = app
@@ -36,7 +35,7 @@ module Traitify
36
35
 
37
36
  def call(env)
38
37
  @app.call(env).on_complete do |e|
39
- if error = Traitify::Error.from(e[:response])
38
+ if error = Traitify::Error.from(e.status)
40
39
  raise error
41
40
  end
42
41
  end
@@ -2,16 +2,13 @@ module Traitify
2
2
  class Error < StandardError
3
3
  attr_accessor :response
4
4
 
5
- def self.from(response)
6
- status = response.status
7
-
5
+ def self.from(status)
8
6
  if klass = case status
9
7
  when 400 then Traitify::BadRequest
10
8
  when 401 then Traitify::Unauthorized
11
9
  when 404 then Traitify::NotFound
12
10
  when 422 then Traitify::UnprocessableEntity
13
11
  end
14
-
15
12
  klass.new(response)
16
13
  end
17
14
  end
@@ -1,46 +1,18 @@
1
1
  module Traitify
2
2
  module Request
3
- def get(path, options = {})
4
- request(:get, path, options)
5
- end
6
-
7
- def post(path, options = {})
8
- request(:post, path, options)
9
- end
10
-
11
- def put(path, options = {})
12
- request(:put, path, options)
13
- end
14
-
15
- def delete(path, options = {})
16
- request(:delete, path, options)
17
- end
18
-
19
- def last_response
20
- @last_response
3
+ def method_missing(meth, *args, &block)
4
+ if [:get, :post, :put, :delete].include? meth
5
+ request(meth, *args)
6
+ else
7
+ super
8
+ end
21
9
  end
22
10
 
23
- private
24
11
  def request(method, path, options = {})
25
- path = "#{self.api_version}#{path}"
26
- connection_options = {}.merge!(url: self.api_host)
27
-
28
- response = connection(connection_options).send(method) do |request|
12
+ conn(url: api_host).send(method) do |request|
13
+ request.url [api_version, path].join
29
14
  request.body = options.to_json if options
30
- case method
31
- when :get
32
- request.url(path)
33
- when :post
34
- request.url(path)
35
- when :put
36
- request.url(path)
37
- when :delete
38
- request.url(path)
39
- end
40
- end
41
-
42
- @last_response = response
43
- response.body
15
+ end.body
44
16
  end
45
17
  end
46
18
  end
@@ -1,3 +1,3 @@
1
1
  module Traitify
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ [
2
+ {
3
+ "id": "career-id",
4
+ "title": "Career Title",
5
+ "description": "Career Description",
6
+ "majors": [
7
+ {
8
+ "id": "major-id",
9
+ "title": "Major Title",
10
+ "description": "Major Description",
11
+ "group_id": "Major Group ID"
12
+ }
13
+ ]
14
+ }
15
+ ]
@@ -77,4 +77,17 @@ describe Traitify::Client do
77
77
  end
78
78
  end
79
79
  end
80
- end
80
+
81
+ describe ".career_matches" do
82
+ let(:careers) { tom.career_matches("assessment-uuid") }
83
+
84
+ before(:each) do
85
+ stub_it(:get, "/assessments/assessment-uuid/matches/careers?number_of_matches=10", "careers")
86
+ end
87
+
88
+ it "returns a result" do
89
+ expect(careers.first.title).to eq("Career Title")
90
+ expect(careers.first.majors.first.title).to eq("Major Title")
91
+ end
92
+ end
93
+ end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = "tom@tomprats.com"
10
10
  spec.description = %q{Traitify Developer Gem}
11
11
  spec.summary = spec.description
12
- spec.homepage = ""
12
+ spec.homepage = "https://www.traitify.com"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "hashie"
21
- spec.add_dependency "faraday", "~> 0.8.0"
21
+ spec.add_dependency "faraday", "~> 0.9.0"
22
22
  spec.add_dependency "faraday_middleware", "~> 0.9.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traitify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Prats
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.0
33
+ version: 0.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.8.0
40
+ version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday_middleware
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -161,6 +161,7 @@ files:
161
161
  - lib/traitify/version.rb
162
162
  - spec/spec_helper.rb
163
163
  - spec/support/mocks/assessment.json
164
+ - spec/support/mocks/careers.json
164
165
  - spec/support/mocks/decks.json
165
166
  - spec/support/mocks/personality_traits.json
166
167
  - spec/support/mocks/result.json
@@ -172,7 +173,7 @@ files:
172
173
  - spec/traitify-ruby/client/result_spec.rb
173
174
  - spec/traitify-ruby/client/slide_spec.rb
174
175
  - traitify.gemspec
175
- homepage: ''
176
+ homepage: https://www.traitify.com
176
177
  licenses:
177
178
  - MIT
178
179
  metadata: {}
@@ -199,6 +200,7 @@ summary: Traitify Developer Gem
199
200
  test_files:
200
201
  - spec/spec_helper.rb
201
202
  - spec/support/mocks/assessment.json
203
+ - spec/support/mocks/careers.json
202
204
  - spec/support/mocks/decks.json
203
205
  - spec/support/mocks/personality_traits.json
204
206
  - spec/support/mocks/result.json
@@ -209,4 +211,3 @@ test_files:
209
211
  - spec/traitify-ruby/client/deck_spec.rb
210
212
  - spec/traitify-ruby/client/result_spec.rb
211
213
  - spec/traitify-ruby/client/slide_spec.rb
212
- has_rdoc: