reisbalans-hr-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e56254a810f2ec9affcbf28621de1148b0bb2fa9
4
+ data.tar.gz: b1869d694bb3849645377fdfa7c8abe8286cd726
5
+ SHA512:
6
+ metadata.gz: 631c6716967151fa308329707d5e271fc348753a1a95264e45f43d3c42b02816d04ee6e6843ee86605475645786394feff2c12892c3e4dae0a52b397d9d960c1
7
+ data.tar.gz: 3b1ec94425ab0828138d5d70f57b0cbe8c3b1b4ed87d58b4cfc46130a3cc015badb0c9c5b6c4b0457ba6db3b36dd9c38a185a2d21153477ae34fe9ac4bef6934
@@ -0,0 +1,8 @@
1
+ require 'yaml'
2
+ require_relative 'reisbalans_hr/client'
3
+
4
+ module ReisbalansHR
5
+ def self.client(base_url:, client_id:, client_secret:)
6
+ Client.new(base_url: base_url, client_id: client_id, client_secret: client_secret)
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ require 'oauth2'
2
+ require_relative 'employees'
3
+ require_relative 'organization_intermediate_settlements'
4
+ require_relative 'employee_intermediate_settlements'
5
+
6
+ module ReisbalansHR
7
+ class Client
8
+ attr_reader :base_url, :client_id, :client_secret
9
+
10
+ def initialize(base_url:, client_id:, client_secret:)
11
+ @base_url = base_url
12
+ @client_id = client_id
13
+ @client_secret = client_secret
14
+ end
15
+
16
+ def employees
17
+ Employees.new(oauth2_client)
18
+ end
19
+
20
+ def organization_intermediate_settlements
21
+ OrganizationIntermediateSettlements.new(oauth2_client)
22
+ end
23
+
24
+ def employee_intermediate_settlements
25
+ EmployeeIntermediateSettlements.new(oauth2_client)
26
+ end
27
+
28
+ def oauth2_client
29
+ opts = {site: base_url, token_url: '/oauth/token'}
30
+ OAuth2::Client.new(client_id, client_secret, opts)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'resources'
2
+
3
+ module ReisbalansHR
4
+ class EmployeeIntermediateSettlements < Resources
5
+ def initialize(oauth2_client)
6
+ super(oauth2_client, '/employee_intermediate_settlements')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'resources'
2
+
3
+ module ReisbalansHR
4
+ class Employees < Resources
5
+ def initialize(oauth2_client)
6
+ super(oauth2_client, '/employees')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'resources'
2
+
3
+ module ReisbalansHR
4
+ class OrganizationIntermediateSettlements < Resources
5
+ def initialize(oauth2_client)
6
+ super(oauth2_client, '/organization_intermediate_settlements')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,62 @@
1
+ module ReisbalansHR
2
+ class Resources
3
+ attr_reader :oauth2_client, :path
4
+
5
+ def initialize(oauth2_client, path)
6
+ @oauth2_client = oauth2_client
7
+ @path = path
8
+ end
9
+
10
+ def index
11
+ get base_url
12
+ end
13
+
14
+ def show(id)
15
+ get [base_url, id].join('/')
16
+ end
17
+
18
+ def create(params, &block)
19
+ post base_url, {body: params}, &block
20
+ end
21
+
22
+ def update(id, params, &block)
23
+ put [base_url, id].join('/'), {body: params}, &block
24
+ end
25
+
26
+ private
27
+
28
+ def access_token
29
+ oauth2_client.client_credentials.get_token('scope' => 'hr')
30
+ end
31
+
32
+ def get(url)
33
+ response = access_token.get(url)
34
+ assert_status_code!(response, 200)
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+ def post(url, opts, &_block)
39
+ response = access_token.post(url, opts)
40
+ yield response if block_given?
41
+ assert_status_code!(response, 204)
42
+ end
43
+
44
+ def put(url, opts, &_block)
45
+ response = access_token.put(url, opts)
46
+ yield response if block_given?
47
+ assert_status_code!(response, 204)
48
+ end
49
+
50
+ def base_url
51
+ "/api/hr#{path}"
52
+ end
53
+
54
+ def assert_status_code!(response, code)
55
+ fail "Expected status code #{code}, but got: #{response.inspect}" unless response.status == code
56
+ end
57
+
58
+ def resource_name
59
+ self.class.name.demodulize.underscore.humanize.downcase
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reisbalans-hr-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zilverline
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
27
+ description: A gem to query the reisbalans hr client
28
+ email: info@zilverline.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/reisbalans_hr.rb
34
+ - lib/reisbalans_hr/client.rb
35
+ - lib/reisbalans_hr/employee_intermediate_settlements.rb
36
+ - lib/reisbalans_hr/employees.rb
37
+ - lib/reisbalans_hr/organization_intermediate_settlements.rb
38
+ - lib/reisbalans_hr/resources.rb
39
+ homepage: http://rubygems.org/gems/reisbalans-hr-client
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.5.1
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Query the reisbalans hr client
63
+ test_files: []