hawatel_search_jobs 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,165 +1,165 @@
1
- module HawatelSearchJobs
2
- ##
3
- # = Client for a jobs search engine
4
- #
5
- # @!attribute [rw] indeed
6
- # @return [Hash] settings of API
7
- # @!attribute [rw] xing
8
- # @return [Hash] settings of API
9
- # @!attribute [rw] reed
10
- # @return [Hash] settings of API
11
- # @!attribute [rw] careerbuilder
12
- # @return [Hash] settings of API
13
- # @!attribute [rw] careerjet
14
- # @return [Hash] settings of API
15
- class Client
16
- include HawatelSearchJobs::Api
17
-
18
- # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
19
- APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet']
20
-
21
- attr_reader :jobs_table
22
-
23
- DEFAULT = {
24
- :keywords => '',
25
- :location => '',
26
- :company => '',
27
- }
28
-
29
- def initialize
30
- APIS.each do |api|
31
- metaclasses.send(:attr_reader, api.downcase.to_sym)
32
- instance_variable_set("@#{api.downcase}", HawatelSearchJobs.instance_variable_get("@"+api.downcase))
33
- end
34
- end
35
-
36
- def metaclasses
37
- class << self; self; end
38
- end
39
-
40
- # Search Jobs by specific criteria
41
- # @param query [Hash]
42
- # @option query [String] :keywords
43
- # @option query [String] :location
44
- # @option query [String] :company not working in Reed API
45
- # @example
46
- # HawatelSearchJobs.configure do |config|
47
- # config.indeed[:activated] = true
48
- # config.indeed[:api] = 'api.indeed.com'
49
- # config.indeed[:version] = '2'
50
- # config.indeed[:publisher] = 'secret-key'
51
- #
52
- # config.xing[:activated] = true
53
- # config.xing[:consumer_key] = 'secret-key'
54
- # config.xing[:consumer_secret] = 'secret-key'
55
- # config.xing[:oauth_token] = 'secret-key'
56
- # config.xing[:oauth_token_secret] = 'secret-key'
57
- #
58
- # config.reed[:activated] = true
59
- # config.reed[:api] = 'reed.co.uk/api'
60
- # config.reed[:clientid] = 'secret-key'
61
- # config.reed[:version] = '1.0'
62
- #
63
- # config.careerbuilder[:activated] = true
64
- # config.careerbuilder[:api] = 'api.careerbuilder.com'
65
- # config.careerbuilder[:clientid] = 'secret-key'
66
- # config.careerbuilder[:version] = 'v2'
67
- #
68
- # config.careerjet[:activated] = true
69
- # config.careerjet[:api] = 'public.api.careerjet.net'
70
- # end
71
- #
72
- # client = HawatelSearchJobs::Client.new
73
- # client.search_jobs({:keywords => 'ruby'})
74
- #
75
- # p client.jobs_table[:indeed]
76
- # p client.jobs_table[:xing]
77
- # p client.jobs_table[:reed]
78
- # p client.jobs_table[:careerbuilder]
79
- # p client.jobs_table[:careerjet]
80
- #
81
- # client.next
82
- # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
83
- def search_jobs(query = {})
84
- query = DEFAULT.merge(query)
85
-
86
- @jobs_table = Hash.new
87
-
88
- APIS.each do |api|
89
- api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
90
- api_inst_var = instance_variable_get("@"+api.downcase)
91
- @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
92
- end
93
-
94
- @jobs_table
95
- end
96
-
97
- # Get next page of result
98
- # @example
99
- # p client.next
100
- # p client.jobs_table
101
- # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
102
- def next
103
- next_result = Hash.new
104
- APIS.each do |api|
105
- api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
106
- api_inst_var = instance_variable_get("@"+api.downcase)
107
- api_sym_name = api.downcase.to_sym
108
-
109
- if api_inst_var[:activated] && next_result?(api_sym_name)
110
- next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
111
- :page => @jobs_table[api_sym_name].page + 1,
112
- :query_key => @jobs_table[api_sym_name].key})
113
- end
114
- end
115
-
116
- return nil if next_result.empty?
117
-
118
- @jobs_table = next_result
119
- end
120
-
121
-
122
- # Sum jobs offers from specified api or count all
123
- #
124
- # @param args [Hash]
125
- # @option args [String] :api name
126
- # @example
127
- # p client.count
128
- # p client.count('indeed')
129
- #
130
- # @return [Integer]
131
- def count(api = nil)
132
- sum = 0
133
-
134
- if api
135
- api = api.downcase
136
- api_inst_var = instance_variable_get("@"+api)
137
- if api_inst_var[:activated]
138
- sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
139
- end
140
- else
141
- APIS.each do |provider|
142
- api_inst_var = instance_variable_get("@"+provider.downcase)
143
- if api_inst_var[:activated]
144
- provider = provider.downcase
145
- sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
146
- end
147
- end
148
- end
149
- return sum
150
- end
151
-
152
- private
153
- def next_result?(provider)
154
- if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
155
- @jobs_table[provider].page < @jobs_table[provider].last
156
- true
157
- else
158
- false
159
- end
160
-
161
- end
162
-
163
- end
164
- end
165
-
1
+ module HawatelSearchJobs
2
+ ##
3
+ # = Client for a jobs search engine
4
+ #
5
+ # @!attribute [rw] indeed
6
+ # @return [Hash] settings of API
7
+ # @!attribute [rw] xing
8
+ # @return [Hash] settings of API
9
+ # @!attribute [rw] reed
10
+ # @return [Hash] settings of API
11
+ # @!attribute [rw] careerbuilder
12
+ # @return [Hash] settings of API
13
+ # @!attribute [rw] careerjet
14
+ # @return [Hash] settings of API
15
+ class Client
16
+ include HawatelSearchJobs::Api
17
+
18
+ # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
19
+ APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet']
20
+
21
+ attr_reader :jobs_table
22
+
23
+ DEFAULT = {
24
+ :keywords => '',
25
+ :location => '',
26
+ :company => '',
27
+ }
28
+
29
+ def initialize
30
+ APIS.each do |api|
31
+ metaclasses.send(:attr_reader, api.downcase.to_sym)
32
+ instance_variable_set("@#{api.downcase}", HawatelSearchJobs.instance_variable_get("@"+api.downcase))
33
+ end
34
+ end
35
+
36
+ def metaclasses
37
+ class << self; self; end
38
+ end
39
+
40
+ # Search Jobs by specific criteria
41
+ # @param query [Hash]
42
+ # @option query [String] :keywords
43
+ # @option query [String] :location
44
+ # @option query [String] :company not working in Reed API
45
+ # @example
46
+ # HawatelSearchJobs.configure do |config|
47
+ # config.indeed[:activated] = true
48
+ # config.indeed[:api] = 'api.indeed.com'
49
+ # config.indeed[:version] = '2'
50
+ # config.indeed[:publisher] = 'secret-key'
51
+ #
52
+ # config.xing[:activated] = true
53
+ # config.xing[:consumer_key] = 'secret-key'
54
+ # config.xing[:consumer_secret] = 'secret-key'
55
+ # config.xing[:oauth_token] = 'secret-key'
56
+ # config.xing[:oauth_token_secret] = 'secret-key'
57
+ #
58
+ # config.reed[:activated] = true
59
+ # config.reed[:api] = 'reed.co.uk/api'
60
+ # config.reed[:clientid] = 'secret-key'
61
+ # config.reed[:version] = '1.0'
62
+ #
63
+ # config.careerbuilder[:activated] = true
64
+ # config.careerbuilder[:api] = 'api.careerbuilder.com'
65
+ # config.careerbuilder[:clientid] = 'secret-key'
66
+ # config.careerbuilder[:version] = 'v2'
67
+ #
68
+ # config.careerjet[:activated] = true
69
+ # config.careerjet[:api] = 'public.api.careerjet.net'
70
+ # end
71
+ #
72
+ # client = HawatelSearchJobs::Client.new
73
+ # client.search_jobs({:keywords => 'ruby'})
74
+ #
75
+ # p client.jobs_table[:indeed]
76
+ # p client.jobs_table[:xing]
77
+ # p client.jobs_table[:reed]
78
+ # p client.jobs_table[:careerbuilder]
79
+ # p client.jobs_table[:careerjet]
80
+ #
81
+ # client.next
82
+ # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
83
+ def search_jobs(query = {})
84
+ query = DEFAULT.merge(query)
85
+
86
+ @jobs_table = Hash.new
87
+
88
+ APIS.each do |api|
89
+ api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
90
+ api_inst_var = instance_variable_get("@"+api.downcase)
91
+ @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
92
+ end
93
+
94
+ @jobs_table
95
+ end
96
+
97
+ # Get next page of result
98
+ # @example
99
+ # p client.next
100
+ # p client.jobs_table
101
+ # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
102
+ def next
103
+ next_result = Hash.new
104
+ APIS.each do |api|
105
+ api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
106
+ api_inst_var = instance_variable_get("@"+api.downcase)
107
+ api_sym_name = api.downcase.to_sym
108
+
109
+ if api_inst_var[:activated] && next_result?(api_sym_name)
110
+ next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
111
+ :page => @jobs_table[api_sym_name].page + 1,
112
+ :query_key => @jobs_table[api_sym_name].key})
113
+ end
114
+ end
115
+
116
+ return nil if next_result.empty?
117
+
118
+ @jobs_table = next_result
119
+ end
120
+
121
+
122
+ # Sum jobs offers from specified api or count all
123
+ #
124
+ # @param args [Hash]
125
+ # @option args [String] :api name
126
+ # @example
127
+ # p client.count
128
+ # p client.count('indeed')
129
+ #
130
+ # @return [Integer]
131
+ def count(api = nil)
132
+ sum = 0
133
+
134
+ if api
135
+ api = api.downcase
136
+ api_inst_var = instance_variable_get("@"+api)
137
+ if api_inst_var[:activated]
138
+ sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
139
+ end
140
+ else
141
+ APIS.each do |provider|
142
+ api_inst_var = instance_variable_get("@"+provider.downcase)
143
+ if api_inst_var[:activated]
144
+ provider = provider.downcase
145
+ sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
146
+ end
147
+ end
148
+ end
149
+ return sum
150
+ end
151
+
152
+ private
153
+ def next_result?(provider)
154
+ if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
155
+ @jobs_table[provider].page < @jobs_table[provider].last
156
+ true
157
+ else
158
+ false
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+ end
165
+
@@ -1,39 +1,39 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'date'
4
-
5
- module HawatelSearchJobs
6
- module Helpers
7
- module Base
8
-
9
- private
10
- def send_request(url, opt = {})
11
- uri = URI.parse(url)
12
- req = Net::HTTP::Get.new(uri)
13
- if opt[:basic_auth] && opt[:basic_auth][:username] && opt[:basic_auth][:password]
14
- req.basic_auth(opt[:basic_auth][:username], opt[:basic_auth][:password])
15
- end
16
- sock = Net::HTTP.new(uri.host, uri.port)
17
- sock.use_ssl = true if uri.scheme == 'https'
18
-
19
- sock.start { |http| http.request(req) }
20
- end
21
-
22
- def convert_empty_to_nil(hash)
23
- new = {}
24
- hash.each do |k,v|
25
- if v.to_s.empty?
26
- new[k] = nil
27
- else
28
- new[k] = v
29
- end
30
- end
31
- new
32
- end
33
-
34
- def convert_date_to_format(date, format)
35
- DateTime.parse(date).to_date.strftime(format) if !date.to_s.empty?
36
- end
37
- end
38
- end
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ module HawatelSearchJobs
6
+ module Helpers
7
+ module Base
8
+
9
+ private
10
+ def send_request(url, opt = {})
11
+ uri = URI.parse(url)
12
+ req = Net::HTTP::Get.new(uri)
13
+ if opt[:basic_auth] && opt[:basic_auth][:username] && opt[:basic_auth][:password]
14
+ req.basic_auth(opt[:basic_auth][:username], opt[:basic_auth][:password])
15
+ end
16
+ sock = Net::HTTP.new(uri.host, uri.port)
17
+ sock.use_ssl = true if uri.scheme == 'https'
18
+
19
+ sock.start { |http| http.request(req) }
20
+ end
21
+
22
+ def convert_empty_to_nil(hash)
23
+ new = {}
24
+ hash.each do |k,v|
25
+ if v.to_s.empty?
26
+ new[k] = nil
27
+ else
28
+ new[k] = v
29
+ end
30
+ end
31
+ new
32
+ end
33
+
34
+ def convert_date_to_format(date, format)
35
+ DateTime.parse(date).to_date.strftime(format) if !date.to_s.empty?
36
+ end
37
+ end
38
+ end
39
39
  end
@@ -1,3 +1,3 @@
1
- module HawatelSearchJobs
2
- VERSION = "0.1.0"
3
- end
1
+ module HawatelSearchJobs
2
+ VERSION = "0.1.1"
3
+ end
@@ -1,87 +1,87 @@
1
- require 'spec_helper'
2
-
3
- describe HawatelSearchJobs::Api::Careerbuilder do
4
- context 'APIs returned jobs' do
5
- before(:each) do
6
- HawatelSearchJobs.configure do |config|
7
- config.careerbuilder[:api] = 'api.careerbuilder.com'
8
- config.careerbuilder[:version] = 'v2'
9
- config.careerbuilder[:clientid] = ''
10
- end
11
-
12
- @query_api = {:keywords => 'ruby', :location => ''}
13
- @result = HawatelSearchJobs::Api::Careerbuilder.search(
14
- :settings => HawatelSearchJobs.careerbuilder,
15
- :query => {
16
- :keywords => @query_api[:keywords],
17
- :location => @query_api[:location]
18
- })
19
- end
20
-
21
- xit '#search' do
22
- validate_result(@result, @query_api)
23
- expect(@result.page).to be >= 0
24
- expect(@result.last).to be >= 0
25
- end
26
-
27
- xit '#page' do
28
- validate_result(@result, @query_api)
29
- page_result = HawatelSearchJobs::Api::Careerbuilder.page({
30
- :settings => HawatelSearchJobs.careerbuilder,
31
- :query_key => @result.key,
32
- :page => 1})
33
- expect(page_result.key).to match(/&PageNumber=2/)
34
- expect(page_result.page).to be == 1
35
- expect(page_result.last).to be >= 0
36
- end
37
- end
38
-
39
- context 'APIs returned empty table' do
40
- before(:each) do
41
- HawatelSearchJobs.configure do |config|
42
- config.careerbuilder[:api] = 'api.careerbuilder.com'
43
- config.careerbuilder[:version] = 'v2'
44
- config.careerbuilder[:clientid] = ''
45
- end
46
-
47
- @query_api = {:keywords => 'job-not-found-zero-records', :location => 'London'}
48
- @result = HawatelSearchJobs::Api::Careerbuilder.search(
49
- :settings => HawatelSearchJobs.careerbuilder,
50
- :query => {
51
- :keywords => @query_api[:keywords],
52
- :location => @query_api[:location]
53
- })
54
- end
55
-
56
- xit '#search' do
57
- validate_result(@result, @query_api)
58
- expect(@result.totalResults).to eq(0)
59
- expect(@result.page).to be_nil
60
- expect(@result.last).to be_nil
61
- expect(@result.jobs).to be_nil
62
- end
63
-
64
- xit '#page' do
65
- validate_result(@result, @query_api)
66
- page_result = HawatelSearchJobs::Api::Careerbuilder.page({
67
- :settings => HawatelSearchJobs.careerbuilder,
68
- :query_key => @result.key,
69
- :page => 1})
70
- expect(page_result.key).to match(/&PageNumber=2/)
71
- expect(@result.totalResults).to eq(0)
72
- expect(@result.page).to be_nil
73
- expect(@result.last).to be_nil
74
- expect(@result.jobs).to be_nil
75
- end
76
- end
77
-
78
- private
79
-
80
- def validate_result(result, query_api)
81
- expect(result.code).to eq(200)
82
- expect(result.msg).to eq('OK')
83
- expect(result.totalResults).to be >= 0
84
- expect(result.key).to match("Location=#{query_api[:location]}")
85
- expect(result.key).to match("Keywords=#{query_api[:keywords]}")
86
- end
1
+ require 'spec_helper'
2
+
3
+ describe HawatelSearchJobs::Api::Careerbuilder do
4
+ context 'APIs returned jobs' do
5
+ before(:each) do
6
+ HawatelSearchJobs.configure do |config|
7
+ config.careerbuilder[:api] = 'api.careerbuilder.com'
8
+ config.careerbuilder[:version] = 'v2'
9
+ config.careerbuilder[:clientid] = ''
10
+ end
11
+
12
+ @query_api = {:keywords => 'ruby', :location => ''}
13
+ @result = HawatelSearchJobs::Api::Careerbuilder.search(
14
+ :settings => HawatelSearchJobs.careerbuilder,
15
+ :query => {
16
+ :keywords => @query_api[:keywords],
17
+ :location => @query_api[:location]
18
+ })
19
+ end
20
+
21
+ xit '#search' do
22
+ validate_result(@result, @query_api)
23
+ expect(@result.page).to be >= 0
24
+ expect(@result.last).to be >= 0
25
+ end
26
+
27
+ xit '#page' do
28
+ validate_result(@result, @query_api)
29
+ page_result = HawatelSearchJobs::Api::Careerbuilder.page({
30
+ :settings => HawatelSearchJobs.careerbuilder,
31
+ :query_key => @result.key,
32
+ :page => 1})
33
+ expect(page_result.key).to match(/&PageNumber=2/)
34
+ expect(page_result.page).to be == 1
35
+ expect(page_result.last).to be >= 0
36
+ end
37
+ end
38
+
39
+ context 'APIs returned empty table' do
40
+ before(:each) do
41
+ HawatelSearchJobs.configure do |config|
42
+ config.careerbuilder[:api] = 'api.careerbuilder.com'
43
+ config.careerbuilder[:version] = 'v2'
44
+ config.careerbuilder[:clientid] = ''
45
+ end
46
+
47
+ @query_api = {:keywords => 'job-not-found-zero-records', :location => 'London'}
48
+ @result = HawatelSearchJobs::Api::Careerbuilder.search(
49
+ :settings => HawatelSearchJobs.careerbuilder,
50
+ :query => {
51
+ :keywords => @query_api[:keywords],
52
+ :location => @query_api[:location]
53
+ })
54
+ end
55
+
56
+ xit '#search' do
57
+ validate_result(@result, @query_api)
58
+ expect(@result.totalResults).to eq(0)
59
+ expect(@result.page).to be_nil
60
+ expect(@result.last).to be_nil
61
+ expect(@result.jobs).to be_nil
62
+ end
63
+
64
+ xit '#page' do
65
+ validate_result(@result, @query_api)
66
+ page_result = HawatelSearchJobs::Api::Careerbuilder.page({
67
+ :settings => HawatelSearchJobs.careerbuilder,
68
+ :query_key => @result.key,
69
+ :page => 1})
70
+ expect(page_result.key).to match(/&PageNumber=2/)
71
+ expect(@result.totalResults).to eq(0)
72
+ expect(@result.page).to be_nil
73
+ expect(@result.last).to be_nil
74
+ expect(@result.jobs).to be_nil
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def validate_result(result, query_api)
81
+ expect(result.code).to eq(200)
82
+ expect(result.msg).to eq('OK')
83
+ expect(result.totalResults).to be >= 0
84
+ expect(result.key).to match("Location=#{query_api[:location]}")
85
+ expect(result.key).to match("Keywords=#{query_api[:keywords]}")
86
+ end
87
87
  end