hawatel_search_jobs 0.1.2 → 0.1.3

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,126 +1,126 @@
1
- module HawatelSearchJobs
2
- module Api
3
- module CareerJet
4
- class << self
5
- include HawatelSearchJobs::Helpers::Base
6
-
7
- DEFAULT = {
8
- :keywords => '',
9
- :location => '',
10
- :company => ''
11
- }
12
-
13
- # Search jobs based on specified keywords or location
14
- #
15
- # @param args [Hash]
16
- # @option args :query [Hash] search criteria
17
- # - *:keywords*​ (String) - keywords for search
18
- # @option args [Integer] :page page number (default value 0)
19
- # @option args [String] :query_key option provided by page() method
20
- #
21
- # @example
22
- # search(:settings => HawatelSearchJobs.careerjet,:query => {:keywords => 'ruby'})
23
- # search(:query_key => 'http://api.../search?locale_code=US_en&sort=date&keywords=ruby', :page => 0)
24
- #
25
- # @return [Hash<OpenStruct>]
26
- def search(args)
27
- args[:query] = DEFAULT.merge(args[:query]) if args[:query]
28
- args[:page] = 0 if args[:page].nil?
29
-
30
- if args[:query_key].to_s.empty?
31
- url_request = build_url(args)
32
- else
33
- url_request = args[:query_key]
34
- end
35
-
36
- if url_request
37
- attributes = Hash.new
38
- response = send_request(url_request)
39
- result = JSON(response.body)
40
- if response.code == '200' && result['type'] == 'ERROR'
41
- attributes[:code] = 501
42
- attributes[:msg] = result['error']
43
- return OpenStruct.new(attributes)
44
- else
45
- attributes[:code] = response.code
46
- attributes[:msg] = response.message
47
- return OpenStruct.new(attributes) if response.code != '200'
48
- end
49
- attributes[:totalResults] = result['hits']
50
- attributes[:page] = args[:page]
51
- attributes[:last] = result['pages'] - 1
52
- attributes[:key] = url_request
53
- attributes[:jobs] = parse_raw_data(result)
54
- OpenStruct.new(attributes)
55
- else
56
- OpenStruct.new({:code => 501, :msg => 'lack of keywords or api setting'})
57
- end
58
- end
59
-
60
- # Show next page of results
61
- #
62
- # @param args [Hash]
63
- # @option args [Integer] :page specified page number (default 0)
64
- # @option args [String] :query_key full url from last query
65
- #
66
- # @example
67
- # page({:query_key => result.key, :page => 2}
68
- #
69
- # @return [Hash<OpenStrunct>]
70
- def page(args)
71
- args[:page] = 0 if args[:page].nil?
72
- args[:query_key] = args[:query_key].gsub(/&page=.*/, '') << "&page=#{args[:page]+1}"
73
- return search(args)
74
- end
75
-
76
- private
77
-
78
- # Build query URL
79
- #
80
- # @param args [Hash]
81
- # @option args query [Hash] - search criteria
82
- # - *:keywords* (String) - keywords for search
83
- # - *:location* (String) - specified location for search criteria (default: europe)
84
- # @option settings [Hash]
85
- # - *:api* (String) - api ip or domainname
86
- #
87
- # @example
88
- # build_url(:query => {:keywords => 'ruby'}, :settings => {:api => 'http://api...'} }
89
- #
90
- # @return [String] ready to call URL
91
- def build_url(args)
92
- keywords = args[:query][:keywords] if !args[:query][:keywords].to_s.empty?
93
- api_url = args[:settings][:api] if !args[:settings][:api].to_s.empty?
94
- if keywords && api_url
95
- !args[:query][:location].to_s.empty? ? location = args[:query][:location] : location = 'europe'
96
- "http://#{api_url}/search?locale_code=US_en&pagesize=25&sort=date&keywords=#{keywords}&location=#{location}&page=1"
97
- end
98
- end
99
-
100
-
101
- # Build jobs array with specified attributes
102
- #
103
- # @param result [Hash]
104
- # @option result [Hash] :jobs jobs hash array return from API
105
- #
106
- # @return [Array<OpenStruct>]
107
- def parse_raw_data(result)
108
- jobs = Array.new
109
- return jobs if result['jobs'].to_s.empty?
110
- result['jobs'].each do |offer|
111
- job = Hash.new
112
- job[:jobtitle] = offer['title']
113
- job[:location] = offer['locations']
114
- job[:company] = offer['company']
115
- job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
116
- job[:url] = offer['url']
117
- job = convert_empty_to_nil(job)
118
- jobs << OpenStruct.new(job)
119
- end
120
- return jobs
121
- end
122
-
123
- end
124
- end
125
- end
126
- end
1
+ module HawatelSearchJobs
2
+ module Api
3
+ module CareerJet
4
+ class << self
5
+ include HawatelSearchJobs::Helpers::Base
6
+
7
+ DEFAULT = {
8
+ :keywords => '',
9
+ :location => '',
10
+ :company => ''
11
+ }
12
+
13
+ # Search jobs based on specified keywords or location
14
+ #
15
+ # @param args [Hash]
16
+ # @option args :query [Hash] search criteria
17
+ # - *:keywords*​ (String) - keywords for search
18
+ # @option args [Integer] :page page number (default value 0)
19
+ # @option args [String] :query_key option provided by page() method
20
+ #
21
+ # @example
22
+ # search(:settings => HawatelSearchJobs.careerjet,:query => {:keywords => 'ruby'})
23
+ # search(:query_key => 'http://api.../search?locale_code=US_en&sort=date&keywords=ruby', :page => 0)
24
+ #
25
+ # @return [Hash<OpenStruct>]
26
+ def search(args)
27
+ args[:query] = DEFAULT.merge(args[:query]) if args[:query]
28
+ args[:page] = 0 if args[:page].nil?
29
+
30
+ if args[:query_key].to_s.empty?
31
+ url_request = build_url(args)
32
+ else
33
+ url_request = args[:query_key]
34
+ end
35
+
36
+ if url_request
37
+ attributes = Hash.new
38
+ response = send_request(url_request)
39
+ result = JSON(response.body)
40
+ if response.code == '200' && result['type'] == 'ERROR'
41
+ attributes[:code] = 501
42
+ attributes[:msg] = result['error']
43
+ return OpenStruct.new(attributes)
44
+ else
45
+ attributes[:code] = response.code
46
+ attributes[:msg] = response.message
47
+ return OpenStruct.new(attributes) if response.code != '200'
48
+ end
49
+ attributes[:totalResults] = result['hits']
50
+ attributes[:page] = args[:page]
51
+ attributes[:last] = result['pages'] - 1
52
+ attributes[:key] = url_request
53
+ attributes[:jobs] = parse_raw_data(result)
54
+ OpenStruct.new(attributes)
55
+ else
56
+ OpenStruct.new({:code => 501, :msg => 'lack of keywords or api setting'})
57
+ end
58
+ end
59
+
60
+ # Show next page of results
61
+ #
62
+ # @param args [Hash]
63
+ # @option args [Integer] :page specified page number (default 0)
64
+ # @option args [String] :query_key full url from last query
65
+ #
66
+ # @example
67
+ # page({:query_key => result.key, :page => 2}
68
+ #
69
+ # @return [Hash<OpenStrunct>]
70
+ def page(args)
71
+ args[:page] = 0 if args[:page].nil?
72
+ args[:query_key] = args[:query_key].gsub(/&page=.*/, '') << "&page=#{args[:page]+1}"
73
+ return search(args)
74
+ end
75
+
76
+ private
77
+
78
+ # Build query URL
79
+ #
80
+ # @param args [Hash]
81
+ # @option args query [Hash] - search criteria
82
+ # - *:keywords* (String) - keywords for search
83
+ # - *:location* (String) - specified location for search criteria (default: europe)
84
+ # @option settings [Hash]
85
+ # - *:api* (String) - api ip or domainname
86
+ #
87
+ # @example
88
+ # build_url(:query => {:keywords => 'ruby'}, :settings => {:api => 'http://api...'} }
89
+ #
90
+ # @return [String] ready to call URL
91
+ def build_url(args)
92
+ keywords = args[:query][:keywords] if !args[:query][:keywords].to_s.empty?
93
+ api_url = args[:settings][:api] if !args[:settings][:api].to_s.empty?
94
+ if keywords && api_url
95
+ !args[:query][:location].to_s.empty? ? location = args[:query][:location] : location = 'europe'
96
+ "http://#{api_url}/search?locale_code=US_en&pagesize=25&sort=date&keywords=#{keywords}&location=#{location}&page=1"
97
+ end
98
+ end
99
+
100
+
101
+ # Build jobs array with specified attributes
102
+ #
103
+ # @param result [Hash]
104
+ # @option result [Hash] :jobs jobs hash array return from API
105
+ #
106
+ # @return [Array<OpenStruct>]
107
+ def parse_raw_data(result)
108
+ jobs = Array.new
109
+ return jobs if result['jobs'].to_s.empty?
110
+ result['jobs'].each do |offer|
111
+ job = Hash.new
112
+ job[:jobtitle] = offer['title']
113
+ job[:location] = offer['locations']
114
+ job[:company] = offer['company']
115
+ job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
116
+ job[:url] = offer['url']
117
+ job = convert_empty_to_nil(job)
118
+ jobs << OpenStruct.new(job)
119
+ end
120
+ return jobs
121
+ end
122
+
123
+ end
124
+ end
125
+ end
126
+ end
@@ -1,158 +1,158 @@
1
- require 'ostruct'
2
- require 'net/http'
3
- require 'json'
4
-
5
- module HawatelSearchJobs
6
- module Api
7
- module Indeed
8
- class << self
9
- include HawatelSearchJobs::Helpers::Base
10
-
11
- DEFAULT = {
12
- :keywords => '',
13
- :location => '',
14
- :company => ''
15
- }
16
-
17
- # Search jobs based on specified keywords or location
18
- #
19
- # @param args [Hash]
20
- # @option args [String] :query_key full url from last query, option deliverd by page() method
21
- # @option args :query [Hash] search criteria
22
- # - *:keywords* (String) keywords for search
23
- # - *:location* (String) specified location for search criteria (default all countries)
24
- # @option args :settings [Hash]
25
- # - *:api* (String) hostname or ip address api server
26
- # - *:publisher* (String) authentication string
27
- #
28
- # @example
29
- # search(:settings => HawatelSearchJobs.indeed,:query => {:keywords => 'ruby'})
30
- # search(:query_key => 'http://api.../ads/apisearch?publisher=12323&q=ruby')
31
- #
32
- # @return [Hash<OpenStruct>]
33
- def search(args)
34
- args[:query] = DEFAULT.merge(args[:query]) if args[:query]
35
- if args[:query_key].to_s.empty?
36
- url_request = build_url(args)
37
- else
38
- url_request = args[:query_key]
39
- end
40
-
41
- if url_request
42
- attributes = Hash.new
43
- response = send_request(url_request)
44
- result = JSON(response.body)
45
- if response.code == '200' && result['error']
46
- attributes[:code] = 501
47
- attributes[:msg] = result['error']
48
- return OpenStruct.new(attributes)
49
- else
50
- attributes[:code] = response.code
51
- attributes[:msg] = response.message
52
- return OpenStruct.new(attributes) if response.code != '200'
53
- end
54
- attributes[:totalResults] = result['totalResults']
55
- attributes[:page] = result['pageNumber']
56
- #attributes[:last] = (result['totalResults'] / 25) - 1
57
- attributes[:last] = paging_info(25, result['totalResults'])
58
- attributes[:key] = url_request
59
- attributes[:jobs] = parse_raw_data(result)
60
- OpenStruct.new(attributes)
61
- else
62
- OpenStruct.new({:code => 501, :msg => 'lack of api or publisher setting'})
63
- end
64
- end
65
-
66
- # Show next page of results
67
- #
68
- # @param args [Hash]
69
- # @option args [Integer] :page page number (default 0)
70
- # @option args [String] :query_key url from last query
71
- #
72
- # @example
73
- # page({:query_key => result.key, :page => 2}
74
- #
75
- # @return [Hash<OpenStruct>]
76
- def page(args)
77
- args[:page] = 0 if args[:page].nil?
78
- if args[:query_key]
79
- url = args[:query_key].gsub(/&start=.*/, '') << "&start=#{args[:page]*25}"
80
- search({:query_key => url})
81
- end
82
- end
83
-
84
- private
85
- # Build query URL
86
- #
87
- # @param args [Hash]
88
- # option args :query [Hash]
89
- # - *:keywords* (String) keywords for search
90
- # - *:location* (String) search jobs from specified location
91
- # - *:salary* (String) show only position above specified salary
92
- # - *:company* (String) find position from specified company
93
- # @option args :settings [Hash]
94
- # - *:api* (String) hostname or ip address api server
95
- # - *:publisher* (String) authentication string
96
- #
97
- # @example
98
- # build_url(:query => {:keywords => 'ruby'}, :settings => {:api => 'http://api...',:publisher => '23234'}}
99
- #
100
- # @return [String]
101
- def build_url(args)
102
- api_url = args[:settings][:api]
103
- publisher = args[:settings][:publisher]
104
- location = args[:query][:location]
105
- salary = args[:query][:salary]
106
- company = args[:query][:company]
107
- keywords = args[:query][:keywords]
108
-
109
- if !keywords.to_s.empty? && !company.to_s.empty?
110
- keywords = "company:#{company}+#{keywords}"
111
- elsif keywords.to_s.empty? && !company.to_s.empty?
112
- keywords = "company:#{company}"
113
- end
114
- if api_url && publisher
115
- "http://#{api_url}/ads/apisearch?publisher=#{publisher}&q=#{keywords}&salary=#{salary}&l=#{location}"\
116
- "&v=2&format=json&limit=25&start=0"
117
- end
118
- end
119
-
120
- # Build jobs array with specified attributes
121
- #
122
- # @param result [Hash]
123
- # @option result [Hash] :results job attributes
124
- #
125
- # @return [Array<OpenStruct>]
126
- def parse_raw_data(result)
127
- jobs = Array.new
128
- return jobs if result['results'].to_s.empty?
129
- result['results'].each do |offer|
130
- job = Hash.new
131
- job[:jobtitle] = offer['jobtitle'] if offer['jobtitle']
132
- job[:location] = "#{offer['country']}, #{offer['city']}"
133
- job[:company] = offer['company']
134
- job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
135
- job[:url] = offer['url']
136
- job = convert_empty_to_nil(job)
137
- jobs << OpenStruct.new(job)
138
- end
139
- return jobs
140
- end
141
-
142
- def paging_info(limit, total_result)
143
- return nil if total_result == 0
144
-
145
- mod = total_result.to_i % limit.to_i
146
- if mod == 0
147
- last = (total_result.to_i / limit.to_i) - 1
148
- else
149
- last = (total_result.to_i / limit.to_i).to_i
150
- end
151
-
152
- last
153
- end
154
-
155
- end
156
- end
157
- end
1
+ require 'ostruct'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module HawatelSearchJobs
6
+ module Api
7
+ module Indeed
8
+ class << self
9
+ include HawatelSearchJobs::Helpers::Base
10
+
11
+ DEFAULT = {
12
+ :keywords => '',
13
+ :location => '',
14
+ :company => ''
15
+ }
16
+
17
+ # Search jobs based on specified keywords or location
18
+ #
19
+ # @param args [Hash]
20
+ # @option args [String] :query_key full url from last query, option deliverd by page() method
21
+ # @option args :query [Hash] search criteria
22
+ # - *:keywords* (String) keywords for search
23
+ # - *:location* (String) specified location for search criteria (default all countries)
24
+ # @option args :settings [Hash]
25
+ # - *:api* (String) hostname or ip address api server
26
+ # - *:publisher* (String) authentication string
27
+ #
28
+ # @example
29
+ # search(:settings => HawatelSearchJobs.indeed,:query => {:keywords => 'ruby'})
30
+ # search(:query_key => 'http://api.../ads/apisearch?publisher=12323&q=ruby')
31
+ #
32
+ # @return [Hash<OpenStruct>]
33
+ def search(args)
34
+ args[:query] = DEFAULT.merge(args[:query]) if args[:query]
35
+ if args[:query_key].to_s.empty?
36
+ url_request = build_url(args)
37
+ else
38
+ url_request = args[:query_key]
39
+ end
40
+
41
+ if url_request
42
+ attributes = Hash.new
43
+ response = send_request(url_request)
44
+ result = JSON(response.body)
45
+ if response.code == '200' && result['error']
46
+ attributes[:code] = 501
47
+ attributes[:msg] = result['error']
48
+ return OpenStruct.new(attributes)
49
+ else
50
+ attributes[:code] = response.code
51
+ attributes[:msg] = response.message
52
+ return OpenStruct.new(attributes) if response.code != '200'
53
+ end
54
+ attributes[:totalResults] = result['totalResults']
55
+ attributes[:page] = result['pageNumber']
56
+ #attributes[:last] = (result['totalResults'] / 25) - 1
57
+ attributes[:last] = paging_info(25, result['totalResults'])
58
+ attributes[:key] = url_request
59
+ attributes[:jobs] = parse_raw_data(result)
60
+ OpenStruct.new(attributes)
61
+ else
62
+ OpenStruct.new({:code => 501, :msg => 'lack of api or publisher setting'})
63
+ end
64
+ end
65
+
66
+ # Show next page of results
67
+ #
68
+ # @param args [Hash]
69
+ # @option args [Integer] :page page number (default 0)
70
+ # @option args [String] :query_key url from last query
71
+ #
72
+ # @example
73
+ # page({:query_key => result.key, :page => 2}
74
+ #
75
+ # @return [Hash<OpenStruct>]
76
+ def page(args)
77
+ args[:page] = 0 if args[:page].nil?
78
+ if args[:query_key]
79
+ url = args[:query_key].gsub(/&start=.*/, '') << "&start=#{args[:page]*25}"
80
+ search({:query_key => url})
81
+ end
82
+ end
83
+
84
+ private
85
+ # Build query URL
86
+ #
87
+ # @param args [Hash]
88
+ # option args :query [Hash]
89
+ # - *:keywords* (String) keywords for search
90
+ # - *:location* (String) search jobs from specified location
91
+ # - *:salary* (String) show only position above specified salary
92
+ # - *:company* (String) find position from specified company
93
+ # @option args :settings [Hash]
94
+ # - *:api* (String) hostname or ip address api server
95
+ # - *:publisher* (String) authentication string
96
+ #
97
+ # @example
98
+ # build_url(:query => {:keywords => 'ruby'}, :settings => {:api => 'http://api...',:publisher => '23234'}}
99
+ #
100
+ # @return [String]
101
+ def build_url(args)
102
+ api_url = args[:settings][:api]
103
+ publisher = args[:settings][:publisher]
104
+ location = args[:query][:location]
105
+ salary = args[:query][:salary]
106
+ company = args[:query][:company]
107
+ keywords = args[:query][:keywords]
108
+
109
+ if !keywords.to_s.empty? && !company.to_s.empty?
110
+ keywords = "company:#{company}+#{keywords}"
111
+ elsif keywords.to_s.empty? && !company.to_s.empty?
112
+ keywords = "company:#{company}"
113
+ end
114
+ if api_url && publisher
115
+ "http://#{api_url}/ads/apisearch?publisher=#{publisher}&q=#{keywords}&salary=#{salary}&l=#{location}"\
116
+ "&v=2&format=json&limit=25&start=0"
117
+ end
118
+ end
119
+
120
+ # Build jobs array with specified attributes
121
+ #
122
+ # @param result [Hash]
123
+ # @option result [Hash] :results job attributes
124
+ #
125
+ # @return [Array<OpenStruct>]
126
+ def parse_raw_data(result)
127
+ jobs = Array.new
128
+ return jobs if result['results'].to_s.empty?
129
+ result['results'].each do |offer|
130
+ job = Hash.new
131
+ job[:jobtitle] = offer['jobtitle'] if offer['jobtitle']
132
+ job[:location] = "#{offer['country']}, #{offer['city']}"
133
+ job[:company] = offer['company']
134
+ job[:date] = convert_date_to_format(offer['date'],'%d/%m/%y')
135
+ job[:url] = offer['url']
136
+ job = convert_empty_to_nil(job)
137
+ jobs << OpenStruct.new(job)
138
+ end
139
+ return jobs
140
+ end
141
+
142
+ def paging_info(limit, total_result)
143
+ return nil if total_result == 0
144
+
145
+ mod = total_result.to_i % limit.to_i
146
+ if mod == 0
147
+ last = (total_result.to_i / limit.to_i) - 1
148
+ else
149
+ last = (total_result.to_i / limit.to_i).to_i
150
+ end
151
+
152
+ last
153
+ end
154
+
155
+ end
156
+ end
157
+ end
158
158
  end