Module: HawatelSearchJobs::Api::Upwork

Extended by:
Helpers::Base
Defined in:
lib/hawatel_search_jobs/api/upwork.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.page(args) ⇒ Hash<OpenStruct>

Show next page of results

Examples:

page({:query_key => result.key, :page => 2}

Parameters:

  • args (Hash)
  • page (Hash)

    a customizable set of options

  • query_key (Hash)

    a customizable set of options

Returns:

  • (Hash<OpenStruct>)


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hawatel_search_jobs/api/upwork.rb', line 56

def page(args)
  args[:page] = 0 if args[:page].nil?
  page_size = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
  page_size = RESULT_LIMIT if page_size <= 0 || page_size > 100

  result = send_request({:keywords => args[:query_key], :offset => args[:page]*page_size, :settings => args[:settings], :page_size => page_size})

  if result['error']
    error_handling(result)
  else
    set_attributes({:result => result, :page => args[:page], :keywords => args[:query_key], :page_size => page_size})
  end
end

.search(args) ⇒ Hash<OpenStruct>

Search jobs based on specified keywords

Examples:

search(:settings => HawatelSearchJobs.upwork,:query => {:keywords => 'ruby'})

Parameters:

  • args (Hash)

Options Hash (args):

Returns:

  • (Hash<OpenStruct>)

See Also:



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

def search(args)
  args[:query] = DEFAULT.merge(args[:query]) if args[:query]
  keywords = args[:query][:keywords]
  page_size = args[:settings][:page_size].to_s.empty? ? RESULT_LIMIT : args[:settings][:page_size].to_i
  page_size = RESULT_LIMIT if page_size <= 0 || page_size > 100

  result = send_request({:keywords => keywords, :offset => 0, :settings => args[:settings], :page_size => page_size})

  if result['error']
    error_handling(result)
  else
    set_attributes({:result => result, :page => 0, :keywords => keywords, :page_size => page_size})
  end
end