cb-api 1.3.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/lib/cb.rb +7 -99
  2. data/lib/cb/clients/anon_saved_search.rb +42 -0
  3. data/lib/cb/clients/application.rb +53 -0
  4. data/lib/cb/clients/application_external.rb +24 -0
  5. data/lib/cb/clients/category.rb +49 -0
  6. data/lib/cb/clients/company.rb +34 -0
  7. data/lib/cb/clients/education.rb +28 -0
  8. data/lib/cb/clients/email_subscription.rb +55 -0
  9. data/lib/cb/clients/employee_types.rb +31 -0
  10. data/lib/cb/clients/job.rb +57 -0
  11. data/lib/cb/clients/job_branding.rb +21 -0
  12. data/lib/cb/clients/recommendation.rb +76 -0
  13. data/lib/cb/clients/saved_search.rb +66 -0
  14. data/lib/cb/clients/spot.rb +27 -0
  15. data/lib/cb/clients/talent_network.rb +51 -0
  16. data/lib/cb/clients/user.rb +94 -0
  17. data/lib/cb/convenience.rb +83 -0
  18. data/lib/cb/criteria/job/details.rb +11 -0
  19. data/lib/cb/criteria/job/search.rb +25 -0
  20. data/lib/cb/criteria/spot/retrieve.rb +12 -0
  21. data/lib/cb/exceptions.rb +2 -1
  22. data/lib/cb/models/implementations/application.rb +92 -0
  23. data/lib/cb/models/implementations/application_external.rb +28 -0
  24. data/lib/cb/models/implementations/application_schema.rb +75 -0
  25. data/lib/cb/models/implementations/branding/media.rb +14 -14
  26. data/lib/cb/models/implementations/branding/section.rb +14 -15
  27. data/lib/cb/models/implementations/branding/style.rb +10 -10
  28. data/lib/cb/models/implementations/branding/styles/base.rb +12 -10
  29. data/lib/cb/models/implementations/branding/styles/buttons.rb +7 -6
  30. data/lib/cb/models/implementations/branding/styles/company_info.rb +14 -12
  31. data/lib/cb/models/implementations/branding/styles/container.rb +7 -6
  32. data/lib/cb/models/implementations/branding/styles/content.rb +7 -5
  33. data/lib/cb/models/implementations/branding/styles/css_adapter.rb +39 -41
  34. data/lib/cb/models/implementations/branding/styles/headings.rb +7 -5
  35. data/lib/cb/models/implementations/branding/styles/job_details.rb +12 -11
  36. data/lib/cb/models/implementations/branding/styles/page.rb +7 -5
  37. data/lib/cb/models/implementations/branding/widget.rb +9 -7
  38. data/lib/cb/models/implementations/category.rb +24 -0
  39. data/lib/cb/models/implementations/company.rb +135 -0
  40. data/lib/cb/models/implementations/education.rb +17 -0
  41. data/lib/cb/models/implementations/email_subscription.rb +17 -0
  42. data/lib/cb/models/implementations/employee_type.rb +13 -0
  43. data/lib/cb/models/implementations/job.rb +167 -0
  44. data/lib/cb/models/implementations/job_branding.rb +34 -0
  45. data/lib/cb/models/implementations/saved_search.rb +159 -0
  46. data/lib/cb/models/implementations/spot.rb +30 -0
  47. data/lib/cb/models/implementations/talent_network.rb +156 -0
  48. data/lib/cb/models/implementations/user.rb +58 -0
  49. data/lib/cb/responses/anonymous_saved_search/create.rb +36 -0
  50. data/lib/cb/responses/anonymous_saved_search/delete.rb +23 -0
  51. data/lib/cb/responses/api_response.rb +64 -0
  52. data/lib/cb/responses/employee_types/search.rb +48 -0
  53. data/lib/cb/responses/errors.rb +47 -0
  54. data/lib/cb/responses/metadata.rb +27 -0
  55. data/lib/cb/responses/saved_search/delete.rb +28 -0
  56. data/lib/cb/responses/saved_search/list.rb +43 -0
  57. data/lib/cb/responses/saved_search/singular.rb +50 -0
  58. data/lib/cb/responses/spot/retrieve_response.rb +31 -20
  59. data/lib/cb/responses/timing.rb +37 -0
  60. data/lib/cb/utils/api.rb +2 -2
  61. data/lib/cb/utils/response_array_extractor.rb +14 -4
  62. data/lib/cb/version.rb +1 -1
  63. metadata +114 -69
  64. data/lib/cb/clients/anon_saved_search_api.rb +0 -41
  65. data/lib/cb/clients/application_api.rb +0 -78
  66. data/lib/cb/clients/application_external_api.rb +0 -30
  67. data/lib/cb/clients/category_api.rb +0 -51
  68. data/lib/cb/clients/company_api.rb +0 -39
  69. data/lib/cb/clients/education_api.rb +0 -37
  70. data/lib/cb/clients/email_subscription_api.rb +0 -68
  71. data/lib/cb/clients/employee_types_api.rb +0 -48
  72. data/lib/cb/clients/job_api.rb +0 -70
  73. data/lib/cb/clients/job_branding_api.rb +0 -24
  74. data/lib/cb/clients/recommendation_api.rb +0 -98
  75. data/lib/cb/clients/resume_api.rb +0 -185
  76. data/lib/cb/clients/saved_search_api.rb +0 -139
  77. data/lib/cb/clients/spot_api.rb +0 -25
  78. data/lib/cb/clients/talent_network_api.rb +0 -70
  79. data/lib/cb/clients/user_api.rb +0 -118
  80. data/lib/cb/criteria/job_details_criteria.rb +0 -11
  81. data/lib/cb/criteria/job_search_criteria.rb +0 -29
  82. data/lib/cb/criteria/spot_retrieve_criteria.rb +0 -12
  83. data/lib/cb/models/implementations/cb_application.rb +0 -91
  84. data/lib/cb/models/implementations/cb_application_external.rb +0 -31
  85. data/lib/cb/models/implementations/cb_application_schema.rb +0 -78
  86. data/lib/cb/models/implementations/cb_category.rb +0 -22
  87. data/lib/cb/models/implementations/cb_company.rb +0 -133
  88. data/lib/cb/models/implementations/cb_education.rb +0 -25
  89. data/lib/cb/models/implementations/cb_email_subscription.rb +0 -19
  90. data/lib/cb/models/implementations/cb_employee_type.rb +0 -12
  91. data/lib/cb/models/implementations/cb_job.rb +0 -175
  92. data/lib/cb/models/implementations/cb_job_branding.rb +0 -33
  93. data/lib/cb/models/implementations/cb_resume.rb +0 -221
  94. data/lib/cb/models/implementations/cb_saved_search.rb +0 -228
  95. data/lib/cb/models/implementations/cb_spot.rb +0 -32
  96. data/lib/cb/models/implementations/cb_talent_network.rb +0 -155
  97. data/lib/cb/models/implementations/cb_user.rb +0 -56
  98. data/lib/cb/responses/raw_api_response.rb +0 -34
@@ -0,0 +1,23 @@
1
+ module Cb
2
+ module Responses
3
+ module AnonymousSavedSearch
4
+
5
+ class Delete < ApiResponse
6
+ protected
7
+
8
+ def hash_containing_metadata
9
+ response
10
+ end
11
+
12
+ def validate_api_hash
13
+ required_response_field('Status', response)
14
+ end
15
+
16
+ def extract_models
17
+ Models::SavedSearch::Delete.new(response)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ require 'forwardable'
2
+
3
+ module Cb
4
+ module Responses
5
+
6
+ class ApiResponse
7
+ extend Forwardable
8
+ delegate [:timing, :errors] => :metadata
9
+ delegate :[] => :response
10
+
11
+ attr_reader :models, :response
12
+ alias_method :model, :models
13
+
14
+ def initialize(raw_response_hash)
15
+ set_response_variable(raw_response_hash)
16
+ @metadata = extract_metadata
17
+ @models = validated_models
18
+ end
19
+
20
+ protected
21
+ attr_reader :metadata
22
+
23
+ def extract_models
24
+ raise NotImplementedError.new(__method__)
25
+ end
26
+
27
+ def validate_api_hash
28
+ raise NotImplementedError.new(__method__)
29
+ end
30
+
31
+ def hash_containing_metadata
32
+ raise NotImplementedError.new(__method__)
33
+ end
34
+
35
+ def raise_on_timing_parse_error
36
+ true
37
+ end
38
+
39
+ def required_response_field(field_name, parent_hash)
40
+ raise ArgumentError.new("field_name can't be nil!") if field_name.nil?
41
+ raise ArgumentError.new("parent_hash can't be nil!") if parent_hash.nil?
42
+ raise ExpectedResponseFieldMissing.new(field_name) unless parent_hash.has_key?(field_name)
43
+ end
44
+
45
+ private
46
+
47
+ def set_response_variable(response_hash)
48
+ should_raise = response_hash.nil? || response_hash.empty?
49
+ raise ApiResponseError.new('Response is empty!') if should_raise
50
+ @response = response_hash
51
+ end
52
+
53
+ def extract_metadata
54
+ Metadata.new(hash_containing_metadata, raise_on_timing_parse_error)
55
+ end
56
+
57
+ def validated_models
58
+ validate_api_hash
59
+ extract_models
60
+ end
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,48 @@
1
+ module Cb
2
+ module Responses
3
+ module EmployeeTypes
4
+
5
+ class Search < ApiResponse
6
+ protected
7
+
8
+ def hash_containing_metadata
9
+ response[root_node]
10
+ end
11
+
12
+ def validate_api_hash
13
+ required_response_field(root_node, response)
14
+ required_response_field(outer_collection_node, response[root_node])
15
+ required_response_field(inner_collection_node, employee_types_data)
16
+ end
17
+
18
+ def extract_models
19
+ extracted_employee_types_data.map { |emp_type| Models::EmployeeType.new(emp_type) }
20
+ end
21
+
22
+ private
23
+
24
+ def root_node
25
+ 'ResponseEmployeeTypes'
26
+ end
27
+
28
+ def outer_collection_node
29
+ 'EmployeeTypes'
30
+ end
31
+
32
+ def inner_collection_node
33
+ 'EmployeeType'
34
+ end
35
+
36
+ def employee_types_data
37
+ response[root_node][outer_collection_node]
38
+ end
39
+
40
+ def extracted_employee_types_data
41
+ Utils::ResponseArrayExtractor.extract(response[root_node], outer_collection_node)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,47 @@
1
+ module Cb
2
+ module Responses
3
+
4
+ class Errors
5
+ attr_reader :parsed
6
+
7
+ def initialize(raw_response_hash, raise_on_error = true)
8
+ @response = raw_response_hash
9
+ @should_raise = raise_on_error
10
+ @parsed = parsed_errors
11
+ end
12
+
13
+ private
14
+ attr_reader :response, :should_raise
15
+
16
+ def parsed_errors
17
+ return Array.new unless response.respond_to?(:map)
18
+ errors = response.map { |key, value| parsed_error(key, value) }.flatten
19
+ raise ApiResponseError.new(errors.to_s) if errors.any? && should_raise
20
+ errors
21
+ end
22
+
23
+ def parsed_error(key, value)
24
+ if hashy_errors?(key, value)
25
+ value.values
26
+ elsif error_array?(key, value)
27
+ value
28
+ else
29
+ Array.new
30
+ end
31
+ end
32
+
33
+ def hashy_errors?(key, value)
34
+ key.downcase == 'errors' && value.is_a?(Hash)
35
+ end
36
+
37
+ def error_array?(key, value)
38
+ (key.downcase == 'error' || key.downcase == 'errors') && value.is_a?(Array)
39
+ end
40
+
41
+ def method_missing(method, *args, &block)
42
+ parsed.send(method, *args, &block)
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ module Cb
2
+ module Responses
3
+
4
+ class Metadata
5
+ attr_reader :errors, :timing
6
+
7
+ def initialize(raw_response_hash, raise_on_timing_missing = true)
8
+ @response = raw_response_hash
9
+ @should_raise = raise_on_timing_missing
10
+ @errors = parsed_errors
11
+ @timing = parsed_timing_info
12
+ end
13
+
14
+ private
15
+ attr_reader :response, :should_raise
16
+
17
+ def parsed_errors
18
+ Errors.new(response)
19
+ end
20
+
21
+ def parsed_timing_info
22
+ Timing.new(response, should_raise)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module Cb
2
+ module Responses
3
+ module SavedSearch
4
+
5
+ class Delete < ApiResponse
6
+ protected
7
+
8
+ def validate_api_hash
9
+ raise "Response can't be nil!" if response.nil?
10
+ required_response_field('Status', response)
11
+ end
12
+
13
+ def hash_containing_metadata
14
+ response
15
+ end
16
+
17
+ def extract_models
18
+ Models::SavedSearch::Delete.new(response)
19
+ end
20
+
21
+ def raise_on_timing_parse_error
22
+ false
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,43 @@
1
+ module Cb
2
+ module Responses
3
+ module SavedSearch
4
+
5
+ class List < ApiResponse
6
+ protected
7
+
8
+ def validate_api_hash
9
+ required_response_field(root_node, response)
10
+ required_response_field(outer_collection_node, response[root_node])
11
+ required_response_field(inner_collection_node, response[root_node][outer_collection_node])
12
+ end
13
+
14
+ def hash_containing_metadata
15
+ response
16
+ end
17
+
18
+ def extract_models
19
+ model_hashes.map { |model_data| Models::SavedSearch.new(model_data) }
20
+ end
21
+
22
+ private
23
+
24
+ def root_node
25
+ 'SavedJobSearches'
26
+ end
27
+
28
+ def outer_collection_node
29
+ 'SavedSearches'
30
+ end
31
+
32
+ def inner_collection_node
33
+ 'SavedSearch'
34
+ end
35
+
36
+ def model_hashes
37
+ Utils::ResponseArrayExtractor.extract(response[root_node], outer_collection_node, inner_collection_node)
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ module Cb
2
+ module Responses
3
+ module SavedSearch
4
+
5
+ class Singular < ApiResponse
6
+ protected
7
+
8
+ def validate_api_hash
9
+ required_response_field(root_node, response)
10
+ required_response_field(model_node, response[root_node])
11
+ end
12
+
13
+ def hash_containing_metadata
14
+ response[root_node]
15
+ end
16
+
17
+ def extract_models
18
+ # these IDs comes back in weird places in the response hash,
19
+ # we need to move them around a little bit so things work correctly.
20
+ model_hash[user_id_node] = response[user_id_node]
21
+ model_hash[search_id_node] = response[search_id_node]
22
+ Models::SavedSearch.new(model_hash)
23
+ end
24
+
25
+ private
26
+
27
+ def root_node
28
+ 'SavedJobSearch'
29
+ end
30
+
31
+ def model_node
32
+ 'SavedSearch'
33
+ end
34
+
35
+ def user_id_node
36
+ 'ExternalUserID'
37
+ end
38
+
39
+ def search_id_node
40
+ 'ExternalID'
41
+ end
42
+
43
+ def model_hash
44
+ response[root_node][model_node]
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -1,28 +1,39 @@
1
- module Cb::Responses::Spot
2
- class Retrieve < Cb::Responses::RawApiResponse
1
+ module Cb
2
+ module Responses
3
+ module Spot
3
4
 
4
- ROOT_NODE = 'ResponseRetrieve'
5
- SPOT_COLLECTION = 'SpotData'
5
+ class Retrieve < Responses::ApiResponse
6
6
 
7
- class << self
8
- def extract_models(raw_api_response)
9
- new(raw_api_response).extract_models
10
- end
11
- end
7
+ protected
12
8
 
13
- def initialize(raw_api_response={})
14
- super(raw_api_response)
15
- end
9
+ def validate_api_hash
10
+ required_response_field(root_node, response)
11
+ required_response_field(spot_collection, response[root_node])
12
+ end
16
13
 
17
- def validate_raw_api_response
18
- required_response_field ROOT_NODE, raw_api_hash
19
- required_response_field SPOT_COLLECTION, raw_api_hash[ROOT_NODE]
20
- end
14
+ def extract_models
15
+ spot_hashes.map { |spot_data| Cb::Models::Spot.new(spot_data) }
16
+ end
21
17
 
22
- def extract_models
23
- spot_models = raw_api_hash[ROOT_NODE][SPOT_COLLECTION].map { |spot_data| Cb::Models::Spot.new(spot_data) }
24
- Cb::Utils::Api.new.append_api_responses(spot_models, raw_api_hash[ROOT_NODE])
25
- end
18
+ def hash_containing_metadata
19
+ response[root_node]
20
+ end
21
+
22
+ private
26
23
 
24
+ def root_node
25
+ @root_node ||= 'ResponseRetrieve'
26
+ end
27
+
28
+ def spot_collection
29
+ @spot_collection ||= 'SpotData'
30
+ end
31
+
32
+ def spot_hashes
33
+ response[root_node][spot_collection]
34
+ end
35
+ end
36
+
37
+ end
27
38
  end
28
39
  end
@@ -0,0 +1,37 @@
1
+ module Cb
2
+ module Responses
3
+
4
+ class Timing
5
+ attr_reader :response_sent, :elapsed
6
+
7
+ def initialize(response, raise_on_parse_fail = true)
8
+ @response = response
9
+ @should_raise_on_parse_fail = raise_on_parse_fail
10
+ post_initialize
11
+ end
12
+
13
+ private
14
+ attr_reader :response, :should_raise_on_parse_fail
15
+
16
+ def post_initialize
17
+ raise_on_empty_timing_info
18
+ @response_sent = parsed_response_sent
19
+ @elapsed = parsed_time_elapsed
20
+ end
21
+
22
+ def raise_on_empty_timing_info
23
+ should_raise = (response.nil? || !response.respond_to?(:[])) && should_raise_on_parse_fail
24
+ raise ExpectedResponseFieldMissing.new('Missing/malformed timing info!') if should_raise
25
+ end
26
+
27
+ def parsed_response_sent
28
+ DateTime.parse(response['TimeResponseSent']) rescue nil
29
+ end
30
+
31
+ def parsed_time_elapsed
32
+ response.include?('TimeElapsed') ? response['TimeElapsed'].to_f : nil
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -32,7 +32,8 @@ module Cb
32
32
  end
33
33
 
34
34
  def append_api_responses(obj, resp)
35
- meta_class = obj.respond_to?('cb_response') && !obj.cb_response.nil? ? obj.cb_response : Cb::Utils::MetaValues.new
35
+ meta_class = obj.respond_to?('cb_response') ? obj.cb_response : Cb::Utils::MetaValues.new
36
+
36
37
  resp.each do |api_key, api_value|
37
38
  meta_name = format_hash_key(api_key)
38
39
  unless meta_name.empty?
@@ -51,7 +52,6 @@ module Cb
51
52
  end
52
53
  end
53
54
 
54
- # Convenience method on the response data model
55
55
  obj.class.send(:attr_reader, 'api_error')
56
56
  obj.instance_variable_set(:@api_error, @api_error)
57
57