bobhr 0.3.2 → 0.4.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
  SHA256:
3
- metadata.gz: a6122504e4286621796c2d41792db07c90fc0796412d519f3bc928b64cc11b84
4
- data.tar.gz: c1afdd126a7c552d9a63a82b50711746f038721593d920bf50e8852ca515a08d
3
+ metadata.gz: 4a4cfc182047ea0cc73d936310c357503289d39887a234d5ec98d4342912d340
4
+ data.tar.gz: 3ded6f900318c2984a2fb02784b4ecdbd880ac3ddf711d31207d852c38f869e7
5
5
  SHA512:
6
- metadata.gz: 96d3120c6a4a060c88e4f09b2594385e3f97367d89ef4564719ed2f442b53ed5d507b973740b3d48245701987d9d8da0149e599d55c73124c103277d00b4c69a
7
- data.tar.gz: 6d3cff522342f7f0edd116c500f5e7941fcf2249596409503200266aa0a80535198ab689e8b4ddf8cc3339a917dfcc35a6ee930fd9b6587d8eca38655582e9df
6
+ metadata.gz: e894d067445285d3dd4beafb06f8bc62e7d5aaedc9c47131ef8db93c2af2a357c222de13205fdd948fb47ad346941c9533dde687de3416cee7192ebdee2382e9
7
+ data.tar.gz: b6582c5fb8de24a7d76b368061224359c2a0f02ece2cfc02510d115fd97dbfedf7775083d31ddc22c528f0bd900f20cb0038d8462874bafadc4661a1844abc82
data/lib/bob/api.rb CHANGED
@@ -4,14 +4,17 @@ require 'rest-client'
4
4
  require 'json'
5
5
  require 'uri'
6
6
  require 'base64'
7
+ require 'csv'
7
8
 
8
9
  module Bob
9
10
  class API
10
11
  BASE_URL = 'https://api.hibob.com'
11
12
 
12
- def self.get(endpoint, params = {})
13
+ def self.get(endpoint, params = {}, csv_response: false)
13
14
  url = build_url(endpoint, params)
14
15
  response = RestClient.get(url, headers)
16
+ return create_csv(response.body) if csv_response
17
+
15
18
  JSON.parse(response.body)
16
19
  end
17
20
 
@@ -52,5 +55,20 @@ module Bob
52
55
 
53
56
  url
54
57
  end
58
+
59
+ def self.create_csv(content)
60
+ file_name = SecureRandom.alphanumeric(15)
61
+
62
+ content.gsub!("\r", '').gsub!('', '')
63
+ splitted = content.split("\n")
64
+ CSV.open("tmp/#{file_name}.csv", 'wb') do |csv|
65
+ csv << splitted.shift.split(',')
66
+ splitted.each do |row|
67
+ csv << row.split(',')
68
+ end
69
+ end
70
+
71
+ "tmp/#{file_name}.csv"
72
+ end
55
73
  end
56
74
  end
data/lib/bob/reports.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'net/sftp'
4
+
3
5
  module Bob
4
6
  class Reports < API
5
7
  def self.all
@@ -7,7 +9,15 @@ module Bob
7
9
  end
8
10
 
9
11
  def self.read(report_id)
10
- get("company/reports/#{report_id}/download?format=csv")
12
+ get("company/reports/#{report_id}/download?format=csv", {}, csv_response: true)
13
+ end
14
+
15
+ def self.sftp_upload(sftp_details:, report_id:)
16
+ file_name = read(report_id)
17
+
18
+ Net::SFTP.start(sftp_details[:host], sftp_details[:user], password: sftp_details[:password]) do |sftp|
19
+ sftp.upload!(file_name, sftp_details[:remote_file_path])
20
+ end
11
21
  end
12
22
  end
13
23
  end
data/lib/bob/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bob
4
- VERSION = '0.3.2'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bob
4
+ class Webhooks
5
+ def self.calculate_signature(body:, key: ENV['BOB_WEBHOOK_SECRET'])
6
+ digest = OpenSSL::Digest.new('sha512')
7
+ Base64.strict_encode64(OpenSSL::HMAC.digest(digest, key, body))
8
+ end
9
+ end
10
+ end
data/lib/bob.rb CHANGED
@@ -8,6 +8,7 @@ require_relative 'bob/time_off'
8
8
  require_relative 'bob/onboarding_wizards'
9
9
  require_relative 'bob/metadata'
10
10
  require_relative 'bob/reports'
11
+ require_relative 'bob/webhooks'
11
12
 
12
13
  module Bob
13
14
  extend Configuration
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bobhr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lien Van Den Steen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-sftp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Ruby gem for Bob API
42
56
  email:
43
57
  - lienvandensteen@gmail.com
@@ -64,6 +78,7 @@ files:
64
78
  - lib/bob/reports.rb
65
79
  - lib/bob/time_off.rb
66
80
  - lib/bob/version.rb
81
+ - lib/bob/webhooks.rb
67
82
  - lib/bobhr.rb
68
83
  homepage: https://github.com/lienvdsteen/hibob
69
84
  licenses:
@@ -85,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
100
  - !ruby/object:Gem::Version
86
101
  version: '0'
87
102
  requirements: []
88
- rubygems_version: 3.2.32
103
+ rubygems_version: 3.3.7
89
104
  signing_key:
90
105
  specification_version: 4
91
106
  summary: Ruby gem for Bob API