cb-api 4.3.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cb/clients/job.rb +18 -55
- data/lib/cb/convenience.rb +1 -1
- data/lib/cb/models/implementations/job_results.rb +27 -0
- data/lib/cb/responses/job/search.rb +39 -0
- data/lib/cb/version.rb +1 -1
- metadata +4 -2
data/lib/cb/clients/job.rb
CHANGED
@@ -3,69 +3,32 @@ require 'json'
|
|
3
3
|
module Cb
|
4
4
|
module Clients
|
5
5
|
class Job
|
6
|
+
class << self
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@cb_client ||= Cb.api_client.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.search(api_args_hash)
|
14
|
-
my_api = Cb::Utils::Api.new
|
15
|
-
json_hash = my_api.cb_get(Cb.configuration.uri_job_search, :query => api_args_hash)
|
16
|
-
|
17
|
-
jobs = Array.new
|
18
|
-
if !json_hash['ResponseJobSearch'].nil? && !json_hash['ResponseJobSearch']['Results'].nil?
|
19
|
-
job_results = json_hash['ResponseJobSearch']['Results']['JobSearchResult']
|
20
|
-
job_results = [job_results] unless job_results.is_a?(Array)
|
21
|
-
job_results.each { |job_hash| jobs.push(Models::Job.new(job_hash)) }
|
22
|
-
my_api.append_api_responses(jobs, json_hash['ResponseJobSearch'])
|
23
|
-
|
24
|
-
if response_has_search_metadata?(json_hash['ResponseJobSearch'])
|
25
|
-
my_api.append_api_responses(jobs, json_hash['ResponseJobSearch']['SearchMetaData']['SearchLocations']['SearchLocation'])
|
26
|
-
end
|
8
|
+
def search(args)
|
9
|
+
response = api_client.cb_get(Cb.configuration.uri_job_search, query: args)
|
10
|
+
Cb::Responses::Job::Search.new(response)
|
27
11
|
end
|
28
12
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
my_api = Cb::Utils::Api.new
|
34
|
-
params = my_api.class.criteria_to_hash(criteria)
|
35
|
-
json_hash = my_api.cb_get(Cb.configuration.uri_job_find, :query => params)
|
36
|
-
|
37
|
-
if json_hash.has_key?('ResponseJob')
|
38
|
-
if json_hash['ResponseJob'].has_key?('Job')
|
39
|
-
job = Models::Job.new(json_hash['ResponseJob']['Job'])
|
40
|
-
end
|
41
|
-
my_api.append_api_responses(job, json_hash['ResponseJob'])
|
13
|
+
def find_by_criteria(criteria)
|
14
|
+
query = api_client.class.criteria_to_hash(criteria)
|
15
|
+
json_response = api_client.cb_get(Cb.configuration.uri_job_find, query: query)
|
16
|
+
Responses::Job::Singular.new(json_response)
|
42
17
|
end
|
43
|
-
my_api.append_api_responses(job, json_hash)
|
44
|
-
end
|
45
|
-
|
46
|
-
def find_by_criteria(criteria)
|
47
|
-
query = cb_client.class.criteria_to_hash(criteria)
|
48
|
-
json_response = cb_client.cb_get(Cb.configuration.uri_job_find, :query => query)
|
49
|
-
singular_model_response(json_response, criteria.did)
|
50
|
-
end
|
51
18
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
19
|
+
def find_by_did(did)
|
20
|
+
criteria = Cb::Criteria::Job::Details.new
|
21
|
+
criteria.did = did
|
22
|
+
criteria.show_custom_values = true
|
23
|
+
find_by_criteria(criteria)
|
24
|
+
end
|
58
25
|
|
59
|
-
|
26
|
+
private
|
60
27
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
response_hash['SearchMetaData']['SearchLocations']['SearchLocation']
|
65
|
-
end
|
28
|
+
def api_client
|
29
|
+
@api ||= Cb::Utils::Api.new
|
30
|
+
end
|
66
31
|
|
67
|
-
def singular_model_response(json_hash, did = nil)
|
68
|
-
Responses::Job::Singular.new(json_hash)
|
69
32
|
end
|
70
33
|
end
|
71
34
|
end
|
data/lib/cb/convenience.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Cb
|
2
|
+
module Models
|
3
|
+
class JobResults
|
4
|
+
attr_reader :args_hash, :jobs, :total_count, :last_item_index, :city, :state_code, :postal_code, :search_location
|
5
|
+
def initialize(args_hash, job_hashes)
|
6
|
+
@args_hash = args_hash
|
7
|
+
@jobs = extract_jobs(job_hashes)
|
8
|
+
@total_count = args_hash['TotalCount']
|
9
|
+
@last_item_index = args_hash['LastItemIndex']
|
10
|
+
@city = args_hash['City']
|
11
|
+
@state_code = args_hash['StateCode']
|
12
|
+
@postal_code = args_hash['PostalCode']
|
13
|
+
@search_location = args_hash['SearchMetaData']['SearchLocations']['SearchLocation'] rescue nil
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def extract_jobs(job_hashes)
|
19
|
+
job_hashes.collect do |job_hash|
|
20
|
+
Job.new(job_hash)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Cb
|
2
|
+
module Responses
|
3
|
+
module Job
|
4
|
+
class Search < ApiResponse
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def validate_api_hash
|
9
|
+
required_response_field(root_node, response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def hash_containing_metadata
|
13
|
+
response[root_node]
|
14
|
+
end
|
15
|
+
|
16
|
+
def extract_models
|
17
|
+
Models::JobResults.new(response[root_node], job_hashes)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def root_node
|
23
|
+
'ResponseJobSearch'
|
24
|
+
end
|
25
|
+
|
26
|
+
def job_hashes
|
27
|
+
hashes = response[root_node]['Results']['JobSearchResult'] rescue []
|
28
|
+
|
29
|
+
if hashes.is_a?(Array)
|
30
|
+
hashes
|
31
|
+
else
|
32
|
+
[hashes]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/cb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cb-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- lib/cb/responses/application.rb
|
225
225
|
- lib/cb/responses/metadata.rb
|
226
226
|
- lib/cb/responses/job/singular.rb
|
227
|
+
- lib/cb/responses/job/search.rb
|
227
228
|
- lib/cb/responses/spot/retrieve_response.rb
|
228
229
|
- lib/cb/responses/api_response.rb
|
229
230
|
- lib/cb/responses/user/check_existing.rb
|
@@ -243,6 +244,7 @@ files:
|
|
243
244
|
- lib/cb/models/implementations/application/response.rb
|
244
245
|
- lib/cb/models/implementations/job.rb
|
245
246
|
- lib/cb/models/implementations/user.rb
|
247
|
+
- lib/cb/models/implementations/job_results.rb
|
246
248
|
- lib/cb/models/implementations/education.rb
|
247
249
|
- lib/cb/models/implementations/application_external.rb
|
248
250
|
- lib/cb/models/implementations/saved_search.rb
|