Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 116 lines (95 sloc) 3.799 kb
cd85cea initial commit
Wynn Netherland authored
1 require 'hashie'
2 require 'httparty'
3
4 directory = File.expand_path(File.dirname(__FILE__))
5
6 Hash.send :include, Hashie::HashExtensions
7
8 class AuthenticJobsError < StandardError
9 attr_reader :data
10
11 def initialize(data)
12 @data = data
13 super
14 end
15 end
16
17 class AuthenticJobs
18 include HTTParty
19 base_uri 'www.authenticjobs.com/api'
20 format :json
21
d44cc64 @pengwynn updated docs
authored
22 # API key for all requests
23 #
24 # @see http://www.authenticjobs.com/api/ Request your API key here
25 # @param [String] api_key your API key
26 # @return [String] API key
cd85cea initial commit
Wynn Netherland authored
27 attr_accessor :api_key
28
29 def initialize(api_key)
30 self.api_key = api_key
31 end
32
43b2416 @pengwynn Docs, dependencies
authored
33 # List of companies that are currently advertising positions, explicitly refreshing cache
34 #
35 # @return [Array<Hashie::Mash>] list of companies
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
36 def companies!
cd85cea initial commit
Wynn Netherland authored
37 mashup(self.class.get("/", :query => method_params('aj.jobs.getCompanies'))).companies.company
38 end
39
43b2416 @pengwynn Docs, dependencies
authored
40 # List of companies that are currently advertising positions
41 #
42 # @return [Array<Hashie::Mash>] list of companies
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
43 def companies
44 @companies ||= companies!
45 end
46
43b2416 @pengwynn Docs, dependencies
authored
47
48 # List locations for companies that are currently advertising positions, explicitly refreshing cache
49 #
50 # @return [Array<Hashie::Mash>] list of locations
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
51 def locations!
cd85cea initial commit
Wynn Netherland authored
52 mashup(self.class.get("/", :query => method_params('aj.jobs.getLocations'))).locations.location
53 end
54
43b2416 @pengwynn Docs, dependencies
authored
55 # List locations for companies that are currently advertising positions
56 #
57 # @return [Array<Hashie::Mash>] list of locations
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
58 def locations
59 @locations ||= locations!
60 end
61
43b2416 @pengwynn Docs, dependencies
authored
62 # List current positions
63 #
64 # @option options [String] :category The id of a job category to limit to. See aj.categories.getList
65 # @option options [String] :type The id of a job type to limit to. See aj.types.getList
66 # @option options [String] :sort ('date-posted-desc') Accepted values are 'date-posted-desc' and 'date-posted-asc'
67 # @option options [String] :company Free-text matching against company names. Suggested values are the ids from aj.jobs.getCompanies
68 # @option options [String] :location Free-text matching against company location names. Suggested values are the ids from aj.jobs.getLocation
69 # @option options [String] :keywords Keywords to look for in the title or description of the job posting. Separate multiple keywords with commas. Multiple keywords will be treated as an OR
70 # @option options [Integer] :page (1) The page of listings to return. Defaults to 1.
71 # @option options [Integer] :perpage (1) The number of listings per page. The default value is 10. The maximum value is 100.
cd85cea initial commit
Wynn Netherland authored
72 def search(options={})
73 mashup(self.class.get("/", :query => method_params('aj.jobs.search', options))).listings.listing
74 end
75
43b2416 @pengwynn Docs, dependencies
authored
76 # List supported job types, explicitly refreshing cache
77 #
78 # @return [Array<Hashie::Mash>] list of types
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
79 def types!
cd85cea initial commit
Wynn Netherland authored
80 mashup(self.class.get("/", :query => method_params('aj.types.getList'))).types['type']
81 end
82
43b2416 @pengwynn Docs, dependencies
authored
83 # List supported job types
84 #
85 # @return [Array<Hashie::Mash>] list of types
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
86 def types
87 @types ||= types!
88 end
89
43b2416 @pengwynn Docs, dependencies
authored
90 # List supported job categories, explicitly refreshing cache
91 #
92 # @return [Array<Hashie::Mash>] list of categories
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
93 def categories!
cd85cea initial commit
Wynn Netherland authored
94 mashup(self.class.get("/", :query => method_params('aj.categories.getList'))).categories.category
95 end
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
96
43b2416 @pengwynn Docs, dependencies
authored
97 # List supported job categories
98 #
99 # @return [Array<Hashie::Mash>] list of categories
096d602 Added caching for calls that rarely change, updated README
Wynn Netherland authored
100 def categories
101 @categories ||= categories!
102 end
cd85cea initial commit
Wynn Netherland authored
103
104
105 private
106 def mashup(response)
107 response = Hashie::Mash.new(response)
108 raise AuthenticJobsError.new("Code #{response.code} -- #{response.desc}") unless response.stat == 'ok'
109 response
110 end
111
112 def method_params(method, params={})
113 {:method => method, :api_key => self.api_key, :format => 'json'}.merge(params)
114 end
115
116 end
Something went wrong with that request. Please try again.