Class: HawatelSearchJobs::Client

Inherits:
Object
  • Object
show all
Includes:
Api
Defined in:
lib/hawatel_search_jobs/client.rb

Overview

Client for a jobs search engine

Constant Summary collapse

APIS =

Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::)

['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet', 'Upwork']
DEFAULT =
{
    :keywords => '',
    :location => '',
    :company  => '',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hawatel_search_jobs/client.rb', line 31

def initialize
  APIS.each do |api|
    metaclasses.send(:attr_reader, api.downcase.to_sym)
    api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)

    if api_conf.nil?
      HawatelSearchJobs.configure
      api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
    end

    instance_variable_set("@#{api.downcase}", api_conf.dup)
  end
end

Instance Attribute Details

#careerbuilderHash

Returns settings of API.

Returns:

  • (Hash)

    settings of API



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/hawatel_search_jobs/client.rb', line 17

class Client
  include HawatelSearchJobs::Api

  # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
  APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet', 'Upwork']

  attr_reader :jobs_table

  DEFAULT = {
      :keywords => '',
      :location => '',
      :company  => '',
  }

  def initialize
    APIS.each do |api|
      metaclasses.send(:attr_reader, api.downcase.to_sym)
      api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)

      if api_conf.nil?
        HawatelSearchJobs.configure
        api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
      end

      instance_variable_set("@#{api.downcase}", api_conf.dup)
    end
  end

  def metaclasses
    class << self; self; end
  end

  # Search Jobs by specific criteria
  # @param query [Hash]
  # @option query [String] :keywords
  # @option query [String] :location not working in Xing API
  # @option query [String] :company not working in Reed API
  # @example
  #       HawatelSearchJobs.configure do |config|
  #           config.indeed[:activated] = true
  #           config.indeed[:api]       = 'api.indeed.com'
  #           config.indeed[:version]   = '2'
  #           config.indeed[:publisher] = 'secret-key'
  #           config.indeed[:page_size] = 25 # allowed range <1,25>
  #
  #           config.xing[:activated]           = true
  #           config.xing[:consumer_key]        = 'secret-key'
  #           config.xing[:consumer_secret]     = 'secret-key'
  #           config.xing[:oauth_token]         = 'secret-key'
  #           config.xing[:oauth_token_secret]  = 'secret-key'
  #           config.xing[:page_size]           = 25 # allowed range <1,100>
  #
  #           config.reed[:activated] = true
  #           config.reed[:api]       = 'reed.co.uk/api'
  #           config.reed[:clientid]  = 'secret-key'
  #           config.reed[:version]   = '1.0'
  #           config.reed[:page_size] = 25 # allowed range <1,100>
  #
  #           config.careerbuilder[:activated]  = true
  #           config.careerbuilder[:api]        = 'api.careerbuilder.com'
  #           config.careerbuilder[:clientid]   = 'secret-key'
  #           config.careerbuilder[:version]    = 'v2'
  #           config.careerbuilder[:page_size]  = 25 # allowed range <1,100>
  #
  #           config.careerjet[:activated]   = true
  #           config.careerjet[:api]         = 'public.api.careerjet.net'
  #           config.careerjet[:page_size]   = 25 # allowed range <1,99>
  #
  #           config.upwork[:activated]           = true
  #           config.upwork[:consumer_key]        = 'secret-key'
  #           config.upwork[:consumer_secret]     = 'secret-key'
  #           config.upwork[:page_size]           = 25 # allowed range <1,100>
  #         end
  #
  #       client = HawatelSearchJobs::Client.new
  #       client.search_jobs({:keywords => 'ruby'})
  #
  #       p client.jobs_table[:indeed]
  #       p client.jobs_table[:xing]
  #       p client.jobs_table[:reed]
  #       p client.jobs_table[:careerbuilder]
  #       p client.jobs_table[:careerjet]
  #       p client.jobs_table[:upwork]
  #
  #       client.next
  # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
  def search_jobs(query = {})
    query = DEFAULT.merge(query)

    @jobs_table = Hash.new

    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
    end

    @jobs_table
  end

  # Get next page of result
  # @example
  #   p client.next
  #   p client.jobs_table
  # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
  def next
    next_result = Hash.new
    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      api_sym_name = api.downcase.to_sym

      if api_inst_var[:activated] && next_result?(api_sym_name)
        next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
                                                          :page => @jobs_table[api_sym_name].page + 1,
                                                          :query_key => @jobs_table[api_sym_name].key})
      end
    end

    return nil if next_result.empty?

    @jobs_table = next_result
  end


  # Sum jobs offers from specified api or count all
  #
  # @param api [String] api name
  # @example
  #   p client.count
  #   p client.count('indeed')
  #
  # @return [Integer]
  def count(api = nil)
    sum = 0

    if api
      api = api.downcase
      api_inst_var = instance_variable_get("@"+api)
      if api_inst_var[:activated]
        sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
      end
    else
      APIS.each do |provider|
        api_inst_var = instance_variable_get("@"+provider.downcase)
        if api_inst_var[:activated]
          provider = provider.downcase
          sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
        end
      end
    end
    return sum
  end

  private
  def next_result?(provider)
    if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
        @jobs_table[provider].page < @jobs_table[provider].last
      true
    else
      false
    end

  end

end

#careerjetHash

Returns settings of API.

Returns:

  • (Hash)

    settings of API



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/hawatel_search_jobs/client.rb', line 17

class Client
  include HawatelSearchJobs::Api

  # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
  APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet', 'Upwork']

  attr_reader :jobs_table

  DEFAULT = {
      :keywords => '',
      :location => '',
      :company  => '',
  }

  def initialize
    APIS.each do |api|
      metaclasses.send(:attr_reader, api.downcase.to_sym)
      api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)

      if api_conf.nil?
        HawatelSearchJobs.configure
        api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
      end

      instance_variable_set("@#{api.downcase}", api_conf.dup)
    end
  end

  def metaclasses
    class << self; self; end
  end

  # Search Jobs by specific criteria
  # @param query [Hash]
  # @option query [String] :keywords
  # @option query [String] :location not working in Xing API
  # @option query [String] :company not working in Reed API
  # @example
  #       HawatelSearchJobs.configure do |config|
  #           config.indeed[:activated] = true
  #           config.indeed[:api]       = 'api.indeed.com'
  #           config.indeed[:version]   = '2'
  #           config.indeed[:publisher] = 'secret-key'
  #           config.indeed[:page_size] = 25 # allowed range <1,25>
  #
  #           config.xing[:activated]           = true
  #           config.xing[:consumer_key]        = 'secret-key'
  #           config.xing[:consumer_secret]     = 'secret-key'
  #           config.xing[:oauth_token]         = 'secret-key'
  #           config.xing[:oauth_token_secret]  = 'secret-key'
  #           config.xing[:page_size]           = 25 # allowed range <1,100>
  #
  #           config.reed[:activated] = true
  #           config.reed[:api]       = 'reed.co.uk/api'
  #           config.reed[:clientid]  = 'secret-key'
  #           config.reed[:version]   = '1.0'
  #           config.reed[:page_size] = 25 # allowed range <1,100>
  #
  #           config.careerbuilder[:activated]  = true
  #           config.careerbuilder[:api]        = 'api.careerbuilder.com'
  #           config.careerbuilder[:clientid]   = 'secret-key'
  #           config.careerbuilder[:version]    = 'v2'
  #           config.careerbuilder[:page_size]  = 25 # allowed range <1,100>
  #
  #           config.careerjet[:activated]   = true
  #           config.careerjet[:api]         = 'public.api.careerjet.net'
  #           config.careerjet[:page_size]   = 25 # allowed range <1,99>
  #
  #           config.upwork[:activated]           = true
  #           config.upwork[:consumer_key]        = 'secret-key'
  #           config.upwork[:consumer_secret]     = 'secret-key'
  #           config.upwork[:page_size]           = 25 # allowed range <1,100>
  #         end
  #
  #       client = HawatelSearchJobs::Client.new
  #       client.search_jobs({:keywords => 'ruby'})
  #
  #       p client.jobs_table[:indeed]
  #       p client.jobs_table[:xing]
  #       p client.jobs_table[:reed]
  #       p client.jobs_table[:careerbuilder]
  #       p client.jobs_table[:careerjet]
  #       p client.jobs_table[:upwork]
  #
  #       client.next
  # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
  def search_jobs(query = {})
    query = DEFAULT.merge(query)

    @jobs_table = Hash.new

    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
    end

    @jobs_table
  end

  # Get next page of result
  # @example
  #   p client.next
  #   p client.jobs_table
  # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
  def next
    next_result = Hash.new
    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      api_sym_name = api.downcase.to_sym

      if api_inst_var[:activated] && next_result?(api_sym_name)
        next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
                                                          :page => @jobs_table[api_sym_name].page + 1,
                                                          :query_key => @jobs_table[api_sym_name].key})
      end
    end

    return nil if next_result.empty?

    @jobs_table = next_result
  end


  # Sum jobs offers from specified api or count all
  #
  # @param api [String] api name
  # @example
  #   p client.count
  #   p client.count('indeed')
  #
  # @return [Integer]
  def count(api = nil)
    sum = 0

    if api
      api = api.downcase
      api_inst_var = instance_variable_get("@"+api)
      if api_inst_var[:activated]
        sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
      end
    else
      APIS.each do |provider|
        api_inst_var = instance_variable_get("@"+provider.downcase)
        if api_inst_var[:activated]
          provider = provider.downcase
          sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
        end
      end
    end
    return sum
  end

  private
  def next_result?(provider)
    if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
        @jobs_table[provider].page < @jobs_table[provider].last
      true
    else
      false
    end

  end

end

#indeedHash

Returns settings of API.

Returns:

  • (Hash)

    settings of API



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/hawatel_search_jobs/client.rb', line 17

class Client
  include HawatelSearchJobs::Api

  # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
  APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet', 'Upwork']

  attr_reader :jobs_table

  DEFAULT = {
      :keywords => '',
      :location => '',
      :company  => '',
  }

  def initialize
    APIS.each do |api|
      metaclasses.send(:attr_reader, api.downcase.to_sym)
      api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)

      if api_conf.nil?
        HawatelSearchJobs.configure
        api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
      end

      instance_variable_set("@#{api.downcase}", api_conf.dup)
    end
  end

  def metaclasses
    class << self; self; end
  end

  # Search Jobs by specific criteria
  # @param query [Hash]
  # @option query [String] :keywords
  # @option query [String] :location not working in Xing API
  # @option query [String] :company not working in Reed API
  # @example
  #       HawatelSearchJobs.configure do |config|
  #           config.indeed[:activated] = true
  #           config.indeed[:api]       = 'api.indeed.com'
  #           config.indeed[:version]   = '2'
  #           config.indeed[:publisher] = 'secret-key'
  #           config.indeed[:page_size] = 25 # allowed range <1,25>
  #
  #           config.xing[:activated]           = true
  #           config.xing[:consumer_key]        = 'secret-key'
  #           config.xing[:consumer_secret]     = 'secret-key'
  #           config.xing[:oauth_token]         = 'secret-key'
  #           config.xing[:oauth_token_secret]  = 'secret-key'
  #           config.xing[:page_size]           = 25 # allowed range <1,100>
  #
  #           config.reed[:activated] = true
  #           config.reed[:api]       = 'reed.co.uk/api'
  #           config.reed[:clientid]  = 'secret-key'
  #           config.reed[:version]   = '1.0'
  #           config.reed[:page_size] = 25 # allowed range <1,100>
  #
  #           config.careerbuilder[:activated]  = true
  #           config.careerbuilder[:api]        = 'api.careerbuilder.com'
  #           config.careerbuilder[:clientid]   = 'secret-key'
  #           config.careerbuilder[:version]    = 'v2'
  #           config.careerbuilder[:page_size]  = 25 # allowed range <1,100>
  #
  #           config.careerjet[:activated]   = true
  #           config.careerjet[:api]         = 'public.api.careerjet.net'
  #           config.careerjet[:page_size]   = 25 # allowed range <1,99>
  #
  #           config.upwork[:activated]           = true
  #           config.upwork[:consumer_key]        = 'secret-key'
  #           config.upwork[:consumer_secret]     = 'secret-key'
  #           config.upwork[:page_size]           = 25 # allowed range <1,100>
  #         end
  #
  #       client = HawatelSearchJobs::Client.new
  #       client.search_jobs({:keywords => 'ruby'})
  #
  #       p client.jobs_table[:indeed]
  #       p client.jobs_table[:xing]
  #       p client.jobs_table[:reed]
  #       p client.jobs_table[:careerbuilder]
  #       p client.jobs_table[:careerjet]
  #       p client.jobs_table[:upwork]
  #
  #       client.next
  # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
  def search_jobs(query = {})
    query = DEFAULT.merge(query)

    @jobs_table = Hash.new

    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
    end

    @jobs_table
  end

  # Get next page of result
  # @example
  #   p client.next
  #   p client.jobs_table
  # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
  def next
    next_result = Hash.new
    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      api_sym_name = api.downcase.to_sym

      if api_inst_var[:activated] && next_result?(api_sym_name)
        next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
                                                          :page => @jobs_table[api_sym_name].page + 1,
                                                          :query_key => @jobs_table[api_sym_name].key})
      end
    end

    return nil if next_result.empty?

    @jobs_table = next_result
  end


  # Sum jobs offers from specified api or count all
  #
  # @param api [String] api name
  # @example
  #   p client.count
  #   p client.count('indeed')
  #
  # @return [Integer]
  def count(api = nil)
    sum = 0

    if api
      api = api.downcase
      api_inst_var = instance_variable_get("@"+api)
      if api_inst_var[:activated]
        sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
      end
    else
      APIS.each do |provider|
        api_inst_var = instance_variable_get("@"+provider.downcase)
        if api_inst_var[:activated]
          provider = provider.downcase
          sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
        end
      end
    end
    return sum
  end

  private
  def next_result?(provider)
    if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
        @jobs_table[provider].page < @jobs_table[provider].last
      true
    else
      false
    end

  end

end

#jobs_tableObject (readonly)

Returns the value of attribute jobs_table.



23
24
25
# File 'lib/hawatel_search_jobs/client.rb', line 23

def jobs_table
  @jobs_table
end

#reedHash

Returns settings of API.

Returns:

  • (Hash)

    settings of API



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/hawatel_search_jobs/client.rb', line 17

class Client
  include HawatelSearchJobs::Api

  # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
  APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet', 'Upwork']

  attr_reader :jobs_table

  DEFAULT = {
      :keywords => '',
      :location => '',
      :company  => '',
  }

  def initialize
    APIS.each do |api|
      metaclasses.send(:attr_reader, api.downcase.to_sym)
      api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)

      if api_conf.nil?
        HawatelSearchJobs.configure
        api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
      end

      instance_variable_set("@#{api.downcase}", api_conf.dup)
    end
  end

  def metaclasses
    class << self; self; end
  end

  # Search Jobs by specific criteria
  # @param query [Hash]
  # @option query [String] :keywords
  # @option query [String] :location not working in Xing API
  # @option query [String] :company not working in Reed API
  # @example
  #       HawatelSearchJobs.configure do |config|
  #           config.indeed[:activated] = true
  #           config.indeed[:api]       = 'api.indeed.com'
  #           config.indeed[:version]   = '2'
  #           config.indeed[:publisher] = 'secret-key'
  #           config.indeed[:page_size] = 25 # allowed range <1,25>
  #
  #           config.xing[:activated]           = true
  #           config.xing[:consumer_key]        = 'secret-key'
  #           config.xing[:consumer_secret]     = 'secret-key'
  #           config.xing[:oauth_token]         = 'secret-key'
  #           config.xing[:oauth_token_secret]  = 'secret-key'
  #           config.xing[:page_size]           = 25 # allowed range <1,100>
  #
  #           config.reed[:activated] = true
  #           config.reed[:api]       = 'reed.co.uk/api'
  #           config.reed[:clientid]  = 'secret-key'
  #           config.reed[:version]   = '1.0'
  #           config.reed[:page_size] = 25 # allowed range <1,100>
  #
  #           config.careerbuilder[:activated]  = true
  #           config.careerbuilder[:api]        = 'api.careerbuilder.com'
  #           config.careerbuilder[:clientid]   = 'secret-key'
  #           config.careerbuilder[:version]    = 'v2'
  #           config.careerbuilder[:page_size]  = 25 # allowed range <1,100>
  #
  #           config.careerjet[:activated]   = true
  #           config.careerjet[:api]         = 'public.api.careerjet.net'
  #           config.careerjet[:page_size]   = 25 # allowed range <1,99>
  #
  #           config.upwork[:activated]           = true
  #           config.upwork[:consumer_key]        = 'secret-key'
  #           config.upwork[:consumer_secret]     = 'secret-key'
  #           config.upwork[:page_size]           = 25 # allowed range <1,100>
  #         end
  #
  #       client = HawatelSearchJobs::Client.new
  #       client.search_jobs({:keywords => 'ruby'})
  #
  #       p client.jobs_table[:indeed]
  #       p client.jobs_table[:xing]
  #       p client.jobs_table[:reed]
  #       p client.jobs_table[:careerbuilder]
  #       p client.jobs_table[:careerjet]
  #       p client.jobs_table[:upwork]
  #
  #       client.next
  # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
  def search_jobs(query = {})
    query = DEFAULT.merge(query)

    @jobs_table = Hash.new

    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
    end

    @jobs_table
  end

  # Get next page of result
  # @example
  #   p client.next
  #   p client.jobs_table
  # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
  def next
    next_result = Hash.new
    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      api_sym_name = api.downcase.to_sym

      if api_inst_var[:activated] && next_result?(api_sym_name)
        next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
                                                          :page => @jobs_table[api_sym_name].page + 1,
                                                          :query_key => @jobs_table[api_sym_name].key})
      end
    end

    return nil if next_result.empty?

    @jobs_table = next_result
  end


  # Sum jobs offers from specified api or count all
  #
  # @param api [String] api name
  # @example
  #   p client.count
  #   p client.count('indeed')
  #
  # @return [Integer]
  def count(api = nil)
    sum = 0

    if api
      api = api.downcase
      api_inst_var = instance_variable_get("@"+api)
      if api_inst_var[:activated]
        sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
      end
    else
      APIS.each do |provider|
        api_inst_var = instance_variable_get("@"+provider.downcase)
        if api_inst_var[:activated]
          provider = provider.downcase
          sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
        end
      end
    end
    return sum
  end

  private
  def next_result?(provider)
    if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
        @jobs_table[provider].page < @jobs_table[provider].last
      true
    else
      false
    end

  end

end

#upworkHash

Returns settings of API.

Returns:

  • (Hash)

    settings of API



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/hawatel_search_jobs/client.rb', line 17

class Client
  include HawatelSearchJobs::Api

  # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
  APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet', 'Upwork']

  attr_reader :jobs_table

  DEFAULT = {
      :keywords => '',
      :location => '',
      :company  => '',
  }

  def initialize
    APIS.each do |api|
      metaclasses.send(:attr_reader, api.downcase.to_sym)
      api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)

      if api_conf.nil?
        HawatelSearchJobs.configure
        api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
      end

      instance_variable_set("@#{api.downcase}", api_conf.dup)
    end
  end

  def metaclasses
    class << self; self; end
  end

  # Search Jobs by specific criteria
  # @param query [Hash]
  # @option query [String] :keywords
  # @option query [String] :location not working in Xing API
  # @option query [String] :company not working in Reed API
  # @example
  #       HawatelSearchJobs.configure do |config|
  #           config.indeed[:activated] = true
  #           config.indeed[:api]       = 'api.indeed.com'
  #           config.indeed[:version]   = '2'
  #           config.indeed[:publisher] = 'secret-key'
  #           config.indeed[:page_size] = 25 # allowed range <1,25>
  #
  #           config.xing[:activated]           = true
  #           config.xing[:consumer_key]        = 'secret-key'
  #           config.xing[:consumer_secret]     = 'secret-key'
  #           config.xing[:oauth_token]         = 'secret-key'
  #           config.xing[:oauth_token_secret]  = 'secret-key'
  #           config.xing[:page_size]           = 25 # allowed range <1,100>
  #
  #           config.reed[:activated] = true
  #           config.reed[:api]       = 'reed.co.uk/api'
  #           config.reed[:clientid]  = 'secret-key'
  #           config.reed[:version]   = '1.0'
  #           config.reed[:page_size] = 25 # allowed range <1,100>
  #
  #           config.careerbuilder[:activated]  = true
  #           config.careerbuilder[:api]        = 'api.careerbuilder.com'
  #           config.careerbuilder[:clientid]   = 'secret-key'
  #           config.careerbuilder[:version]    = 'v2'
  #           config.careerbuilder[:page_size]  = 25 # allowed range <1,100>
  #
  #           config.careerjet[:activated]   = true
  #           config.careerjet[:api]         = 'public.api.careerjet.net'
  #           config.careerjet[:page_size]   = 25 # allowed range <1,99>
  #
  #           config.upwork[:activated]           = true
  #           config.upwork[:consumer_key]        = 'secret-key'
  #           config.upwork[:consumer_secret]     = 'secret-key'
  #           config.upwork[:page_size]           = 25 # allowed range <1,100>
  #         end
  #
  #       client = HawatelSearchJobs::Client.new
  #       client.search_jobs({:keywords => 'ruby'})
  #
  #       p client.jobs_table[:indeed]
  #       p client.jobs_table[:xing]
  #       p client.jobs_table[:reed]
  #       p client.jobs_table[:careerbuilder]
  #       p client.jobs_table[:careerjet]
  #       p client.jobs_table[:upwork]
  #
  #       client.next
  # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
  def search_jobs(query = {})
    query = DEFAULT.merge(query)

    @jobs_table = Hash.new

    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
    end

    @jobs_table
  end

  # Get next page of result
  # @example
  #   p client.next
  #   p client.jobs_table
  # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
  def next
    next_result = Hash.new
    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      api_sym_name = api.downcase.to_sym

      if api_inst_var[:activated] && next_result?(api_sym_name)
        next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
                                                          :page => @jobs_table[api_sym_name].page + 1,
                                                          :query_key => @jobs_table[api_sym_name].key})
      end
    end

    return nil if next_result.empty?

    @jobs_table = next_result
  end


  # Sum jobs offers from specified api or count all
  #
  # @param api [String] api name
  # @example
  #   p client.count
  #   p client.count('indeed')
  #
  # @return [Integer]
  def count(api = nil)
    sum = 0

    if api
      api = api.downcase
      api_inst_var = instance_variable_get("@"+api)
      if api_inst_var[:activated]
        sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
      end
    else
      APIS.each do |provider|
        api_inst_var = instance_variable_get("@"+provider.downcase)
        if api_inst_var[:activated]
          provider = provider.downcase
          sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
        end
      end
    end
    return sum
  end

  private
  def next_result?(provider)
    if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
        @jobs_table[provider].page < @jobs_table[provider].last
      true
    else
      false
    end

  end

end

#xingHash

Returns settings of API.

Returns:

  • (Hash)

    settings of API



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/hawatel_search_jobs/client.rb', line 17

class Client
  include HawatelSearchJobs::Api

  # Values have to be the same name like module name of usesd APIs (HawatelSearchJobs::Api::[ApiName])
  APIS = ['Indeed', 'Xing', 'Reed', 'Careerbuilder', 'CareerJet', 'Upwork']

  attr_reader :jobs_table

  DEFAULT = {
      :keywords => '',
      :location => '',
      :company  => '',
  }

  def initialize
    APIS.each do |api|
      metaclasses.send(:attr_reader, api.downcase.to_sym)
      api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)

      if api_conf.nil?
        HawatelSearchJobs.configure
        api_conf = HawatelSearchJobs.instance_variable_get("@"+api.downcase)
      end

      instance_variable_set("@#{api.downcase}", api_conf.dup)
    end
  end

  def metaclasses
    class << self; self; end
  end

  # Search Jobs by specific criteria
  # @param query [Hash]
  # @option query [String] :keywords
  # @option query [String] :location not working in Xing API
  # @option query [String] :company not working in Reed API
  # @example
  #       HawatelSearchJobs.configure do |config|
  #           config.indeed[:activated] = true
  #           config.indeed[:api]       = 'api.indeed.com'
  #           config.indeed[:version]   = '2'
  #           config.indeed[:publisher] = 'secret-key'
  #           config.indeed[:page_size] = 25 # allowed range <1,25>
  #
  #           config.xing[:activated]           = true
  #           config.xing[:consumer_key]        = 'secret-key'
  #           config.xing[:consumer_secret]     = 'secret-key'
  #           config.xing[:oauth_token]         = 'secret-key'
  #           config.xing[:oauth_token_secret]  = 'secret-key'
  #           config.xing[:page_size]           = 25 # allowed range <1,100>
  #
  #           config.reed[:activated] = true
  #           config.reed[:api]       = 'reed.co.uk/api'
  #           config.reed[:clientid]  = 'secret-key'
  #           config.reed[:version]   = '1.0'
  #           config.reed[:page_size] = 25 # allowed range <1,100>
  #
  #           config.careerbuilder[:activated]  = true
  #           config.careerbuilder[:api]        = 'api.careerbuilder.com'
  #           config.careerbuilder[:clientid]   = 'secret-key'
  #           config.careerbuilder[:version]    = 'v2'
  #           config.careerbuilder[:page_size]  = 25 # allowed range <1,100>
  #
  #           config.careerjet[:activated]   = true
  #           config.careerjet[:api]         = 'public.api.careerjet.net'
  #           config.careerjet[:page_size]   = 25 # allowed range <1,99>
  #
  #           config.upwork[:activated]           = true
  #           config.upwork[:consumer_key]        = 'secret-key'
  #           config.upwork[:consumer_secret]     = 'secret-key'
  #           config.upwork[:page_size]           = 25 # allowed range <1,100>
  #         end
  #
  #       client = HawatelSearchJobs::Client.new
  #       client.search_jobs({:keywords => 'ruby'})
  #
  #       p client.jobs_table[:indeed]
  #       p client.jobs_table[:xing]
  #       p client.jobs_table[:reed]
  #       p client.jobs_table[:careerbuilder]
  #       p client.jobs_table[:careerjet]
  #       p client.jobs_table[:upwork]
  #
  #       client.next
  # @return [Hash] First page of result for all providers (default maximum 25 records for each page)
  def search_jobs(query = {})
    query = DEFAULT.merge(query)

    @jobs_table = Hash.new

    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
    end

    @jobs_table
  end

  # Get next page of result
  # @example
  #   p client.next
  #   p client.jobs_table
  # @return [Hash] Next page of result for all providers (default maximum 25 records for each)
  def next
    next_result = Hash.new
    APIS.each do |api|
      api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
      api_inst_var = instance_variable_get("@"+api.downcase)
      api_sym_name = api.downcase.to_sym

      if api_inst_var[:activated] && next_result?(api_sym_name)
        next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
                                                          :page => @jobs_table[api_sym_name].page + 1,
                                                          :query_key => @jobs_table[api_sym_name].key})
      end
    end

    return nil if next_result.empty?

    @jobs_table = next_result
  end


  # Sum jobs offers from specified api or count all
  #
  # @param api [String] api name
  # @example
  #   p client.count
  #   p client.count('indeed')
  #
  # @return [Integer]
  def count(api = nil)
    sum = 0

    if api
      api = api.downcase
      api_inst_var = instance_variable_get("@"+api)
      if api_inst_var[:activated]
        sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
      end
    else
      APIS.each do |provider|
        api_inst_var = instance_variable_get("@"+provider.downcase)
        if api_inst_var[:activated]
          provider = provider.downcase
          sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
        end
      end
    end
    return sum
  end

  private
  def next_result?(provider)
    if @jobs_table[provider] && @jobs_table[provider].page && @jobs_table[provider].last &&
        @jobs_table[provider].page < @jobs_table[provider].last
      true
    else
      false
    end

  end

end

Instance Method Details

#count(api = nil) ⇒ Integer

Sum jobs offers from specified api or count all

Examples:

p client.count
p client.count('indeed')

Parameters:

  • api (String) (defaults to: nil)

    api name

Returns:

  • (Integer)


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/hawatel_search_jobs/client.rb', line 150

def count(api = nil)
  sum = 0

  if api
    api = api.downcase
    api_inst_var = instance_variable_get("@"+api)
    if api_inst_var[:activated]
      sum = @jobs_table[:"#{api}"].totalResults if @jobs_table[:"#{api}"].totalResults
    end
  else
    APIS.each do |provider|
      api_inst_var = instance_variable_get("@"+provider.downcase)
      if api_inst_var[:activated]
        provider = provider.downcase
        sum += @jobs_table[:"#{provider}"].totalResults if @jobs_table[:"#{provider}"].totalResults
      end
    end
  end
  return sum
end

#metaclassesObject



45
46
47
# File 'lib/hawatel_search_jobs/client.rb', line 45

def metaclasses
  class << self; self; end
end

#nextHash

Get next page of result

Examples:

p client.next
p client.jobs_table

Returns:

  • (Hash)

    Next page of result for all providers (default maximum 25 records for each)



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/hawatel_search_jobs/client.rb', line 122

def next
  next_result = Hash.new
  APIS.each do |api|
    api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
    api_inst_var = instance_variable_get("@"+api.downcase)
    api_sym_name = api.downcase.to_sym

    if api_inst_var[:activated] && next_result?(api_sym_name)
      next_result[api_sym_name] = api_module_name.page({:settings => api_inst_var,
                                                        :page => @jobs_table[api_sym_name].page + 1,
                                                        :query_key => @jobs_table[api_sym_name].key})
    end
  end

  return nil if next_result.empty?

  @jobs_table = next_result
end

#search_jobs(query = {}) ⇒ Hash

Search Jobs by specific criteria

Examples:

HawatelSearchJobs.configure do |config|
    config.indeed[:activated] = true
    config.indeed[:api]       = 'api.indeed.com'
    config.indeed[:version]   = '2'
    config.indeed[:publisher] = 'secret-key'
    config.indeed[:page_size] = 25 # allowed range <1,25>

    config.xing[:activated]           = true
    config.xing[:consumer_key]        = 'secret-key'
    config.xing[:consumer_secret]     = 'secret-key'
    config.xing[:oauth_token]         = 'secret-key'
    config.xing[:oauth_token_secret]  = 'secret-key'
    config.xing[:page_size]           = 25 # allowed range <1,100>

    config.reed[:activated] = true
    config.reed[:api]       = 'reed.co.uk/api'
    config.reed[:clientid]  = 'secret-key'
    config.reed[:version]   = '1.0'
    config.reed[:page_size] = 25 # allowed range <1,100>

    config.careerbuilder[:activated]  = true
    config.careerbuilder[:api]        = 'api.careerbuilder.com'
    config.careerbuilder[:clientid]   = 'secret-key'
    config.careerbuilder[:version]    = 'v2'
    config.careerbuilder[:page_size]  = 25 # allowed range <1,100>

    config.careerjet[:activated]   = true
    config.careerjet[:api]         = 'public.api.careerjet.net'
    config.careerjet[:page_size]   = 25 # allowed range <1,99>

    config.upwork[:activated]           = true
    config.upwork[:consumer_key]        = 'secret-key'
    config.upwork[:consumer_secret]     = 'secret-key'
    config.upwork[:page_size]           = 25 # allowed range <1,100>
  end

client = HawatelSearchJobs::Client.new
client.search_jobs({:keywords => 'ruby'})

p client.jobs_table[:indeed]
p client.jobs_table[:xing]
p client.jobs_table[:reed]
p client.jobs_table[:careerbuilder]
p client.jobs_table[:careerjet]
p client.jobs_table[:upwork]

client.next

Parameters:

  • query (Hash) (defaults to: {})

Options Hash (query):

  • :keywords (String)
  • :location (String)

    not working in Xing API

  • :company (String)

    not working in Reed API

Returns:

  • (Hash)

    First page of result for all providers (default maximum 25 records for each page)



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/hawatel_search_jobs/client.rb', line 103

def search_jobs(query = {})
  query = DEFAULT.merge(query)

  @jobs_table = Hash.new

  APIS.each do |api|
    api_module_name = Object.const_get('HawatelSearchJobs').const_get('Api').const_get(api)
    api_inst_var = instance_variable_get("@"+api.downcase)
    @jobs_table[api.downcase.to_sym] = api_module_name.search({:settings => api_inst_var, :query => query}) if api_inst_var[:activated]
  end

  @jobs_table
end