indeed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :gemcutter
2
+
3
+ gem "rake"
4
+ gem 'yajl-ruby'
5
+ gem "jeweler"
6
+ group :test do
7
+ gem 'rspec', "1.3.0"
8
+ gem "mocha", "0.9.8"
9
+ end # do
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mocha (0.9.8)
10
+ rake
11
+ rake (0.8.7)
12
+ rspec (1.3.0)
13
+ yajl-ruby (0.7.8)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ jeweler
20
+ mocha (= 0.9.8)
21
+ rake
22
+ rspec (= 1.3.0)
23
+ yajl-ruby
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require "bundler"
3
+ Bundler.setup
4
+
5
+ require 'rake'
6
+ require 'spec/rake/spectask'
7
+ require 'jeweler'
8
+
9
+ Jeweler::Tasks.new do |gemspec|
10
+ gemspec.name = "indeed"
11
+ gemspec.summary = "Api wrap from Indeed service http://indeed.com"
12
+ gemspec.description = <<-EOI
13
+ Simple wrapper for JSON api provided by indeed.
14
+ Original documentation at:
15
+ http://www.indeed.com/jsp/apiinfo.jsp (Require authorization)
16
+ Support search jobs API 2.0 and get jobs API
17
+ EOI
18
+ gemspec.email = "agresso@gmail.com"
19
+ gemspec.homepage = "http://github.com/railsware/indeed"
20
+ gemspec.authors = ["Bogdan Gusiev"]
21
+ gemspec.add_dependency "yajl-ruby"
22
+ end
23
+
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
@@ -0,0 +1,19 @@
1
+ h1. Indeed integration plugin
2
+
3
+ Simple integration plugin for Indeed.com XML feed api
4
+
5
+
6
+ h3. Requirements
7
+
8
+ The following gems are required:
9
+
10
+ * yajl-ruby
11
+ * rake
12
+
13
+ h3. Example
14
+
15
+ <pre><code>require 'indeed'
16
+ Indeed.key = &lt;publisher key&gt;
17
+ Indeed.search(:q => "ruby", :l => "Boston")
18
+ Indeed.get('f8abbe5539f14420', '4fb26405a44d7eb8')
19
+ </code></pre>
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,115 @@
1
+ require 'net/http'
2
+ require 'cgi'
3
+ require "uri"
4
+ require "yajl"
5
+
6
+
7
+
8
+ class Indeed
9
+
10
+ SEARCH_URL = URI.parse("http://api.indeed.com/ads/apisearch")
11
+ GET_URL = URI.parse("http://api.indeed.com/ads/apigetjobs")
12
+
13
+ def self.instance
14
+ @instance ||= Indeed.new
15
+ end
16
+
17
+ def self.search(options)
18
+ self.instance.search(options)
19
+ end
20
+
21
+ def self.key=(key)
22
+ self.default_params[:publisher] = key
23
+ end
24
+
25
+ def self.default_params
26
+ self.instance.default_params
27
+ end
28
+
29
+ def self.get(*job_keys)
30
+ self.instance.get(*job_keys)
31
+ end
32
+
33
+ def search(options)
34
+ options = default_params.merge(options)
35
+ http_get(SEARCH_URL.host, SEARCH_URL.path, options)
36
+ end
37
+
38
+ def get(jobkeys)
39
+ jobkeys = Array(jobkeys)
40
+ http_get(
41
+ GET_URL.host,
42
+ GET_URL.path,
43
+ :jobkeys => jobkeys,
44
+ :v => 2,
45
+ :publisher => default_params[:publisher],
46
+ :format => "json"
47
+ )
48
+ end
49
+
50
+ def default_params
51
+ @default_params ||= {
52
+ :v => 2,
53
+ :format => "json",
54
+ :sort => "relevance",
55
+ :radius => 25,
56
+ :st => nil,
57
+ :jt => nil,
58
+ :limit => 30,
59
+ :highlight => 0,
60
+ :filter => 1,
61
+ :fromage => 1,
62
+ :latlong => 1,
63
+ :co => "us",
64
+ :userip => "77.88.216.22",
65
+ :useragent => "Mozilla/4.0 Firefox",
66
+ }
67
+ end
68
+
69
+ protected
70
+ def http_get(domain, path, params = {})
71
+ log("Indeed query", params.inspect)
72
+ query = "#{path}?#{params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')}"
73
+
74
+ data = Yajl::Parser.parse(Net::HTTP.get(domain, query))
75
+ if error = data["error"]
76
+ raise IndeedError, error
77
+ end
78
+ result = IndeedResult.new(data["results"], data["totalResults"])
79
+
80
+ return result
81
+ end
82
+
83
+
84
+ def log(message, dump)
85
+ if defined?(Rails)
86
+ Rails.logger.debug(format_log_entry(message, dump))
87
+ end
88
+ end
89
+
90
+ def format_log_entry(message, dump = nil)
91
+ if ActiveRecord::Base.colorize_logging
92
+ message_color, dump_color = "4;32;1", "0;1"
93
+ log_entry = " \e[#{message_color}m#{message}\e[0m "
94
+ log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
95
+ log_entry
96
+ else
97
+ "%s %s" % [message, dump]
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ class IndeedResult < Array
104
+
105
+ attr_accessor :total
106
+
107
+ def initialize(array, total)
108
+ super(array)
109
+ self.total = total
110
+ end
111
+ end
112
+
113
+ class IndeedError < StandardError
114
+
115
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require "net/http"
3
+ require "yajl"
4
+
5
+ describe Indeed do
6
+ before(:each) do
7
+ Net::HTTP.stubs(:get).returns(Yajl::Encoder.encode({
8
+
9
+ "version" => 2,
10
+ "query" => "java",
11
+ "location" => "Boston",
12
+ "dupefilter" => true,
13
+ "highlight" => true,
14
+
15
+ "radius" => 25,
16
+
17
+ "start" => 1,
18
+ "end" => 10,
19
+ "totalResults" => 822,
20
+ "pageNumber" => 0,
21
+ "results" => [{
22
+ "jobtitle" => "Java/JEE Software Developers",
23
+ "company" => "360 Training",
24
+ "city" => "Austin",
25
+ "state" => "TX",
26
+ "country" => "US",
27
+ "formattedLocation" => "Austin, TX",
28
+ "source" => "360 Training",
29
+ "date" => "Sun, 24 Oct 2010 15=>49=>31 GMT",
30
+ "snippet" => "multiple positions for <b>Java</b>/JEE developers. We are looking for well-rounded developers with several years of experience in the <b>Java</b>/JEE platform, and who are...",
31
+ "url" => "http=>//www.indeed.com/viewjob?jk=456064eba76fd546&indpubnum=7570038743238473&atk=15fh6j9pl0k106a9",
32
+ "onmousedown" => "indeed_clk(this, '6386');",
33
+ "latitude" => 30.266483,
34
+ "longitude" => -97.74176,
35
+ "jobkey" => "456064eba76fd546",
36
+ "sponsored" => false,
37
+ "expired" => false,
38
+ "formattedLocationFull" => "Austin, TX",
39
+ "formattedRelativeTime" => "16 hours ago"
40
+ }]
41
+ }))
42
+ end
43
+
44
+
45
+ describe ".search" do
46
+ subject { Indeed.search(:q => "Java", :l => "Boston") }
47
+
48
+ it { should be_a(Array) }
49
+
50
+ it {should_not be_empty }
51
+ it "should get total number of results from indeed" do
52
+ subject.total.should == 822
53
+ end
54
+ end
55
+
56
+ describe ".get" do
57
+ subject { Indeed.get(123) }
58
+ it { should be_a(Array) }
59
+ it {should_not be_empty }
60
+ end
61
+ end
@@ -0,0 +1,4 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require 'indeed'
4
+ require "mocha"
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: indeed
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Bogdan Gusiev
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-28 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: yajl-ruby
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: yajl-ruby
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: *id004
77
+ description: |
78
+ Simple wrapper for JSON api provided by indeed.
79
+ Original documentation at:
80
+ http://www.indeed.com/jsp/apiinfo.jsp (Require authorization)
81
+ Support search jobs API 2.0 and get jobs API
82
+
83
+ email: agresso@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - Rakefile
94
+ - Readme.textile
95
+ - VERSION
96
+ - lib/indeed.rb
97
+ - spec/indeed_spec.rb
98
+ - spec/spec_helper.rb
99
+ has_rdoc: true
100
+ homepage: http://github.com/railsware/indeed
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options: []
105
+
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.3.7
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Api wrap from Indeed service http://indeed.com
133
+ test_files:
134
+ - spec/indeed_spec.rb
135
+ - spec/spec_helper.rb