clinch-talent 0.2 → 0.2.1

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
  SHA256:
3
- metadata.gz: 3c91e6dc9be2c4c9b4a1e419160f7c365b3474812765a7a0948dad810565d52d
4
- data.tar.gz: 7f41ff0f51fc0dfdae028a77ac8e0f79c07c1e7f9361d315249bfe60af814ada
3
+ metadata.gz: 231b908831adf498b598d6eef29152e51e4764ce109c01615b3d59b27cbeede1
4
+ data.tar.gz: 0ccf8a2b09778626d1ed884b417d4cb32c3f28227eddf4ef992bf56921f0c128
5
5
  SHA512:
6
- metadata.gz: dee36046767ca1069f7d0a1b2ce452923dee4e854e0bab187755158b4717abf0613c8464890fcfbdda0a76a5ac124e729020a9f30bfbe4dceeb62e072e795a14
7
- data.tar.gz: 0d1c72e1a4bf4d20a4d80bca2aed4c3db2b1c725096c31df8759115515dd6c538ccf54a151b34851ce173b19f4acaa1ebb82a09382c0fe9e43834beabd8ef8b2
6
+ metadata.gz: cf868b3ef0822074f3ee5e287dcc31ec2442c6f8fe8efe45d1b499c3774a961b8ed832d24ea3df62dd3f1f657e1435b270114f514310fac42ae6a1a5e668d26a
7
+ data.tar.gz: d411d3a6e4d0d1c07182cc69a2eb54f2470375076f854bee96216ee0b2e8f0905f5999437f0f5d6066e02acbb834eb3647a1b183f155977256397dbd832e852e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clinch-talent (0.2)
4
+ clinch-talent (0.2.1)
5
5
  json_api_client (~> 1.5)
6
6
 
7
7
  GEM
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'clinch-talent'
3
- s.version = '0.2'
3
+ s.version = '0.2.1'
4
4
  s.summary = 'A ruby client for the Clinch Talent API'
5
5
  s.description = 'A ruby client for the Clinch Talent API. Requests are HMAC signed. Responses are in JSON API format (https://jsonapi.org). See https://support.clinchtalent.com/article/77-getting-started'
6
6
  s.authors = ['Damien Glancy', 'Steve Quinlan']
@@ -12,32 +12,11 @@ module ClinchTalent
12
12
  env.request_headers['Authorization'] = "APIAuth #{@options[:access_id]}:#{hmac_signature(env, @options[:secret])}"
13
13
  @app.call(env)
14
14
  end
15
- private
16
- def calculated_md5(env)
17
- # if env.request.body
18
- # body = env.request.body
19
- # else
20
- # body = ''
21
- # end
22
- #excluding the body as part of the md5'ing
23
- md5_base64digest('')
24
- end
25
15
 
26
- def md5_base64digest(string)
27
- if Digest::MD5.respond_to?(:base64digest)
28
- Digest::MD5.base64digest(string)
29
- else
30
- b64_encode(Digest::MD5.digest(string))
31
- end
32
- end
16
+ private
33
17
 
34
- def b64_encode(string)
35
- if Base64.respond_to?(:strict_encode64)
36
- Base64.strict_encode64(string)
37
- else
38
- # Fall back to stripping out newlines on Ruby 1.8.
39
- Base64.encode64(string).gsub(/\n/, '')
40
- end
18
+ def calculated_md5(env)
19
+ Digest::MD5.base64digest(env.body || '')
41
20
  end
42
21
 
43
22
  def fetch_headers(env)
@@ -46,21 +25,21 @@ private
46
25
 
47
26
  def capitalize_keys(hsh)
48
27
  capitalized_hash = {}
49
- hsh.each_pair {|k,v| capitalized_hash[k.to_s.upcase] = v }
28
+ hsh.each_pair {|k, v| capitalized_hash[k.to_s.upcase] = v}
50
29
  capitalized_hash
51
30
  end
52
31
 
53
32
  def hmac_signature(env, secret_key)
54
33
  canonical_string = canonical_string(env)
55
34
  digest = OpenSSL::Digest.new('sha1')
56
- b64_encode(OpenSSL::HMAC.digest(digest, secret_key, canonical_string))
35
+ Base64.strict_encode64(OpenSSL::HMAC.digest(digest, secret_key, canonical_string))
57
36
  end
58
37
 
59
38
  def canonical_string(env)
60
- [ content_type(env),
61
- content_md5(env),
62
- parse_uri(env.url.to_s),
63
- timestamp(env)
39
+ [content_type(env),
40
+ content_md5(env),
41
+ parse_uri(env.url.to_s),
42
+ timestamp(env)
64
43
  ].join(',')
65
44
  end
66
45
 
@@ -80,7 +59,7 @@ private
80
59
  end
81
60
 
82
61
  def find_header(env, keys)
83
- keys.map {|key| env.request_headers[key] }.compact.first
62
+ keys.map {|key| env.request_headers[key]}.compact.first
84
63
  end
85
64
 
86
65
  def parse_uri(uri)
@@ -2,11 +2,11 @@ require_relative '../test_helper'
2
2
 
3
3
  module ClinchTalent
4
4
  class CandidateTest < Minitest::Test
5
- def test_signing
5
+ def setup
6
6
  Time.stubs(:now).returns(Time.new(2014, 01, 01, 01, 01, 01))
7
+ end
7
8
 
8
- # Having problem stubbing the body response, so not doing this now
9
-
9
+ def test_get_signing
10
10
  stub_request(:get, 'https://api.clinchtalent.com/v1/candidates').
11
11
  with(:headers => {'Accept' => 'application/vnd.api+json',
12
12
  'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
@@ -18,5 +18,40 @@ module ClinchTalent
18
18
  ClinchTalent::Base.config('access_id', 'secret')
19
19
  ClinchTalent::Candidate.all
20
20
  end
21
+
22
+ def test_post_signing
23
+ stub_request(:post, "https://api.clinchtalent.com/v1/candidates").
24
+ with(
25
+ body: "{\"data\":{\"type\":\"candidates\",\"attributes\":{\"first_name\":\"Steve\",\"last_name\":\"Jobs\",\"email\":\"steve.jobs@example.com\"}}}",
26
+ headers: {
27
+ 'Accept' => 'application/vnd.api+json',
28
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
29
+ 'Authorization' => 'APIAuth access_id:GpqVWbyL6re9hA4PVFciK9JGXtE=',
30
+ 'Content-Md5' => 'BHelHgS90QHICtQEYCK1CA==',
31
+ 'Content-Type' => 'application/vnd.api+json',
32
+ 'Date' => 'Wed, 01 Jan 2014 01:01:01 GMT',
33
+ 'User-Agent' => 'Faraday v0.15.2'
34
+ }).
35
+ to_return(status: 200, body: "", headers: {})
36
+
37
+ ClinchTalent::Base.config('access_id', 'secret')
38
+ ClinchTalent::Candidate.create("first_name": "Steve", "last_name": "Jobs", "email": "steve.jobs@example.com")
39
+ end
40
+
41
+ def test_post_signing_no_body
42
+ stub_request(:post, "https://api.clinchtalent.com/v1/candidates").
43
+ with(:body => "{\"data\":{\"type\":\"candidates\",\"attributes\":{}}}",
44
+ :headers => {'Accept'=>'application/vnd.api+json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
45
+ 'Authorization'=>'APIAuth access_id:P9RDanGcxbHK/aWLPC/T6Eitplc=',
46
+ 'Content-Md5'=>'hy9ALXrYXtG7YZXuVdXzjA==',
47
+ 'Content-Type'=>'application/vnd.api+json',
48
+ 'Date'=>'Wed, 01 Jan 2014 01:01:01 GMT',
49
+ 'User-Agent'=>'Faraday v0.15.2'}).
50
+ to_return(:status => 200, :body => "", :headers => {})
51
+
52
+ ClinchTalent::Base.config('access_id', 'secret')
53
+ ClinchTalent::Candidate.create
54
+ end
55
+
21
56
  end
22
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clinch-talent
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Glancy