jobviter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jobviter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Jared Pace
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ Jobviter
2
+ ========
3
+
4
+ Jobviter is a simple Ruby gem which fetches and parses a given company's
5
+ jobvite.com listing feed.
6
+
7
+
8
+ Installation
9
+ ------------
10
+
11
+ $ gem install jobviter
12
+
13
+
14
+ Dependencies
15
+ ------------
16
+
17
+ Jobviter uses [Typhoeus](https://github.com/dbalatero/typhoeus) to fetch
18
+ and [Nokogiri](https://github.com/tenderlove/nokogiri) to parse the job
19
+ feed. They each have their own dependencies like libcurl and libxml2.
20
+ Installation instructions are given on their respective sites.
21
+
22
+
23
+ Usage
24
+ -----
25
+
26
+ Below is an example of using Jobviter to pull down a list of Twitter
27
+ job listings.
28
+
29
+ ruby > require 'jobviter'
30
+ ruby > Jobviter.configure do |config|
31
+ ruby > config.company_id = 'q8X9VfwT'
32
+ ruby > end
33
+ ruby > jobs = Jobviter::Job.all
34
+ => 71
35
+ ruby > job = jobs.first
36
+ => #<Jobviter::Job:0x00000100a85600>
37
+ ruby > job.title
38
+ => "Software Engineer - Tools"
39
+ ruby > job.apply_url
40
+ => "http://hire.jobvite.com/CompanyJobs/Apply.aspx?c=q8X9VfwT&j=oSbdVfwV"
41
+
42
+
43
+ Contributing
44
+ ------------
45
+
46
+ * Fork the project.
47
+ * Setup your development environment with: gem install bundler; bundle install
48
+ * Make your feature addition or bug fix.
49
+ * Add tests for it. This is important so I don't break it in a
50
+ future version unintentionally.
51
+ * Commit, do not mess with rakefile, version, or history.
52
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
53
+ * Send me a pull request. Bonus points for topic branches.
54
+
55
+
56
+ Copyright
57
+ ---------
58
+
59
+ Copyright (c) 2011 Jared Pace. See LICENSE for details.
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jobviter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jobviter"
7
+ s.version = Jobviter::VERSION
8
+ s.authors = ["Jared Pace"]
9
+ s.email = ["jared@codeword.io"]
10
+ s.homepage = ""
11
+ s.summary = %q{Jobvite job feed parser}
12
+ s.description = %q{Simple ruby wrapper for pasing job feeds from Jobvite.com}
13
+
14
+ s.rubyforge_project = "jobviter"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # Dependencies
22
+ s.add_dependency 'typhoeus', ['~> 0.2.4']
23
+ s.add_dependency 'nokogiri', ['~> 1.4.6']
24
+
25
+ # Developmnet Dependencies
26
+ s.add_development_dependency 'rspec', ['~> 2.6']
27
+ s.add_development_dependency 'mocha', ['~> 0.9.12']
28
+ end
@@ -0,0 +1,4 @@
1
+ require "jobviter/version"
2
+ require "jobviter/exception"
3
+ require "jobviter/config"
4
+ require "jobviter/job"
@@ -0,0 +1,30 @@
1
+ module Jobviter
2
+ class Config
3
+ attr_accessor :base_jobs_url, :company_id
4
+
5
+ def initialize
6
+ self.base_jobs_url = "http://www.jobvite.com/CompanyJobs/Xml.aspx?c="
7
+ end
8
+
9
+ def jobs_url
10
+ unless company_id
11
+ raise Jobviter::Exception::InvalidConfiguration.new('company_id is required')
12
+ end
13
+
14
+ base_jobs_url + company_id
15
+ end
16
+ end
17
+
18
+ class << self
19
+ attr_accessor :config
20
+ end
21
+
22
+ def self.config
23
+ @config ||= Config.new
24
+ end
25
+
26
+ def self.configure
27
+ yield(config)
28
+ end
29
+ end
30
+
@@ -0,0 +1,17 @@
1
+ module Jobviter
2
+ module Exception
3
+
4
+ class BadResponse < StandardError
5
+ def initialize(message)
6
+ super "Error Fetching Data from Jobvite: #{message}"
7
+ end
8
+ end
9
+
10
+ class InvalidConfiguration < StandardError
11
+ def initialize(message)
12
+ super "Invalid Configuration: #{message}"
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,100 @@
1
+ require 'typhoeus'
2
+ require 'nokogiri'
3
+
4
+ module Jobviter
5
+ class Job
6
+
7
+ attr_accessor :attributes
8
+
9
+ def initialize(attrs)
10
+ attrs.each {|k,v| attrs[k] = v.strip}
11
+ self.attributes = attrs
12
+ end
13
+
14
+ def date
15
+ return @date if defined?(@date)
16
+
17
+ match = attributes[:date].match /(\d{1,2})\/(\d{1,2})\/(\d{4})/
18
+ month, day, year = match[1], match[2], match[3]
19
+
20
+ @date = Date.civil year.to_i, month.to_i, day.to_i
21
+ end
22
+
23
+ def [](attr)
24
+ attributes[attr.to_sym]
25
+ end
26
+
27
+ def []=(attr, value)
28
+ attributes[attr.to_sym] = value
29
+ end
30
+
31
+ def self.all
32
+ fetch_and_parse.map do |job_node|
33
+ job_attrs = node_to_attrs(job_node)
34
+ self.new job_attrs
35
+ end
36
+ end
37
+
38
+ def self.first(limit = nil)
39
+ limit ? all.first(limit) : all.first
40
+ end
41
+
42
+ def self.find(id)
43
+ all.detect {|job| job.id == id}
44
+ end
45
+
46
+ def method_missing(method, *args, &block)
47
+ if attributes.has_key?(method) && args.empty?
48
+ return self[method]
49
+ else
50
+ super
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def self.fetch_and_parse
57
+ return unless raw_result = fetch
58
+ parse raw_result
59
+ end
60
+
61
+ def self.fetch
62
+ response = Typhoeus::Request.get Jobviter.config.jobs_url
63
+
64
+ if response.success?
65
+ return response.body
66
+ else
67
+ handle_bad_response response
68
+ end
69
+ end
70
+
71
+ def self.parse(result)
72
+ parsed_document = Nokogiri::XML(result)
73
+ parsed_document.css 'job'
74
+ end
75
+
76
+ def self.handle_bad_response(response)
77
+ error_message = response.code.to_i > 0 ?
78
+ response.code :
79
+ response.curl_error_message
80
+ raise Jobviter::Exception::BadResponse.new error_message
81
+ end
82
+
83
+ def self.node_to_attrs(node)
84
+ {
85
+ :id => node.at_css('id').content,
86
+ :requisition_id => node.at_css('requisitionid').content,
87
+ :title => node.at_css('title').content,
88
+ :category => node.at_css('category').content,
89
+ :type => node.at_css('jobtype').content,
90
+ :location => node.at_css('location').content,
91
+ :date => node.at_css('date').content,
92
+ :detail_url => node.at_css('detail-url').content,
93
+ :apply_url => node.at_css('apply-url').content,
94
+ :description => node.at_css('description').content,
95
+ :brief_description => node.at_css('briefdescription').content
96
+ }
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module Jobviter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,72 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <result>
3
+ <job>
4
+ <id>omglol42</id>
5
+ <title>Senior Trouble Maker</title>
6
+ <requisitionid>req1</requisitionid>
7
+ <category>Roflmao</category>
8
+ <jobtype>Full-Time</jobtype>
9
+ <location>New York, NY</location>
10
+ <date>7/04/2011</date>
11
+ <detail-url>
12
+ <![CDATA[http://hire.jobvite.com/CompanyJobs/Job.aspx?c=funcorp1&j=omglol42]]>
13
+ </detail-url>
14
+ <apply-url>
15
+ <![CDATA[http://hire.jobvite.com/CompanyJobs/Apply.aspx?c=funcorp1&j=omglol42]]>
16
+ </apply-url>
17
+ <description>
18
+ We're looking for serious trouble makers. Only apply if you have the following applies:
19
+
20
+ &lt;ul&gt;
21
+ &lt;li&gt;You're comfortable not getting any real work done.&lt;/li&gt;
22
+ &lt;li&gt;You'll go to any length for a laugh&lt;/li&gt;
23
+ &lt;li&gt;You'd prank the pope himself&lt;/li&gt;
24
+ &lt;/ul&gt;
25
+ </description>
26
+ <briefdescription>Come make a mockery of us and our employees.</briefdescription>
27
+ </job>
28
+ <job>
29
+ <id>roflcptr</id>
30
+ <title>Lead Shenanigan Engineer</title>
31
+ <requisitionid>req2</requisitionid>
32
+ <category>Roflmao</category>
33
+ <jobtype>Full-Time</jobtype>
34
+ <location>San Francisco, CA</location>
35
+ <date>7/15/2011</date>
36
+ <detail-url>
37
+ <![CDATA[http://hire.jobvite.com/CompanyJobs/Job.aspx?c=funcorp1&j=roflcptr]]>
38
+ </detail-url>
39
+ <apply-url>
40
+ <![CDATA[http://hire.jobvite.com/CompanyJobs/Apply.aspx?c=funcorp1&j=roflcptr]]>
41
+ </apply-url>
42
+ <description>
43
+ Do you consider yourself the king of shenanigans? We want to hear from you if:
44
+
45
+ &lt;ul&gt;
46
+ &lt;li&gt;You can create shenanigans on the spot&lt;/li&gt;
47
+ &lt;li&gt;You don't take anything seriously including scary stuff like spiders&lt;/li&gt;
48
+ &lt;li&gt;That's pretty much it LOL&lt;/li&gt;
49
+ &lt;/ul&gt;
50
+ </description>
51
+ <briefdescription>Shenanigans, Roflcopters, Troll faces OMGLOL</briefdescription>
52
+ </job>
53
+ <job>
54
+ <id>lolcat99</id>
55
+ <title>Executive LOL Cat Photographer</title>
56
+ <requisitionid>req3</requisitionid>
57
+ <category>LOL Cats</category>
58
+ <jobtype>Part-Time</jobtype>
59
+ <location>Washington, DC</location>
60
+ <date>7/01/2011</date>
61
+ <detail-url>
62
+ <![CDATA[http://hire.jobvite.com/CompanyJobs/Job.aspx?c=funcorp1&j=lolcat99]]>
63
+ </detail-url>
64
+ <apply-url>
65
+ <![CDATA[http://hire.jobvite.com/CompanyJobs/Apply.aspx?c=funcorp1&j=lolcat99]]>
66
+ </apply-url>
67
+ <description>
68
+ Is your favorite day &lt;strong&gt;Caturday&lt;/strong&gt;? Then we want to hear from you!
69
+ </description>
70
+ <briefdescription>Ceiling cat is watching you apply for jobs</briefdescription>
71
+ </job>
72
+ </result>
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jobviter::Config do
4
+
5
+ context "#configure" do
6
+ it "saves config values" do
7
+ Jobviter.configure do |config|
8
+ config.company_id = 'abcd1234'
9
+ end
10
+
11
+ Jobviter.config.company_id.should == 'abcd1234'
12
+ end
13
+
14
+ it "has default values" do
15
+ Jobviter.config.base_jobs_url.should == "http://www.jobvite.com/CompanyJobs/Xml.aspx?c="
16
+ end
17
+ end
18
+
19
+ context "jobs_url" do
20
+ it 'returns the full url for the job feed' do
21
+ Jobviter.configure do |config|
22
+ config.company_id = 'abcd1234'
23
+ end
24
+
25
+ expected_jobs_url = Jobviter.config.base_jobs_url + 'abcd1234'
26
+ Jobviter.config.jobs_url.should == expected_jobs_url
27
+ end
28
+
29
+ it 'raises an error if the company_id is not configured' do
30
+ Jobviter.configure do |config|
31
+ config.company_id = nil
32
+ end
33
+
34
+ expect do
35
+ Jobviter.config.jobs_url
36
+ end.should raise_exception(Jobviter::Exception::InvalidConfiguration)
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jobviter::Job do
4
+
5
+ context "fetching trouble makers" do
6
+ before do
7
+ jobs_xml = SpecRoot.join('fixtures', 'jobs.xml').read
8
+ Jobviter::Job.stubs(:fetch).returns(jobs_xml)
9
+ end
10
+
11
+ context '#all' do
12
+ it 'should return all of the jobs' do
13
+ jobs = Jobviter::Job.all
14
+
15
+ jobs.count.should == 3
16
+ jobs[0].title.should == "Senior Trouble Maker"
17
+ jobs[1].title.should == "Lead Shenanigan Engineer"
18
+ jobs[2].title.should == "Executive LOL Cat Photographer"
19
+ end
20
+ end
21
+
22
+ context '#first' do
23
+ it 'returns the first job found if given no arguments' do
24
+ job = Jobviter::Job.first
25
+ job.title.should == "Senior Trouble Maker"
26
+ end
27
+
28
+ it 'returns the first n items if given a limit' do
29
+ jobs = Jobviter::Job.first(2)
30
+ jobs.count.should == 2
31
+ jobs[0].title.should == "Senior Trouble Maker"
32
+ jobs[1].title.should == "Lead Shenanigan Engineer"
33
+ end
34
+ end
35
+
36
+ context '#find' do
37
+ it 'returns a job by its id' do
38
+ job = Jobviter::Job.find 'roflcptr'
39
+ job.should_not be_nil
40
+ job.title.should == "Lead Shenanigan Engineer"
41
+ end
42
+ end
43
+
44
+ context 'being parsed' do
45
+ it 'assigns its attributes appropriately' do
46
+ photographer = Jobviter::Job.find 'lolcat99'
47
+
48
+ photographer.id.should == 'lolcat99'
49
+ photographer.title.should == 'Executive LOL Cat Photographer'
50
+ photographer.requisition_id.should == 'req3'
51
+ photographer.category.should == 'LOL Cats'
52
+ photographer.type.should == 'Part-Time'
53
+ photographer.location.should == 'Washington, DC'
54
+ photographer.date.should == Date.parse('July, 1st 2011')
55
+ photographer.detail_url.should == 'http://hire.jobvite.com/CompanyJobs/Job.aspx?c=funcorp1&j=lolcat99'
56
+ photographer.apply_url.should == 'http://hire.jobvite.com/CompanyJobs/Apply.aspx?c=funcorp1&j=lolcat99'
57
+ photographer.description.should == "Is your favorite day <strong>Caturday</strong>? Then we want to hear from you!"
58
+ photographer.brief_description.should == "Ceiling cat is watching you apply for jobs"
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'error handling' do
64
+ before do
65
+ Jobviter.configure {|c| c.company_id = 'corp1234'}
66
+ end
67
+
68
+ it 'raises an error if unsuccessful response is returned' do
69
+ bad_response = stub 'response', :success? => false, :code => 500
70
+ Typhoeus::Request.expects(:get).returns(bad_response)
71
+
72
+ expect do
73
+ Jobviter::Job.all
74
+ end.should raise_exception(Jobviter::Exception::BadResponse)
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,20 @@
1
+ require 'pathname'
2
+ require 'rspec'
3
+ require 'rspec/autorun'
4
+ require 'mocha'
5
+
6
+ SpecRoot = Pathname.new File.expand_path('..', __FILE__)
7
+ $LOAD_PATH.unshift(SpecRoot)
8
+ $LOAD_PATH.unshift(File.join(SpecRoot, '..', 'lib'))
9
+
10
+ require 'jobviter'
11
+
12
+ RSpec.configure do |config|
13
+ config.color_enabled = true
14
+ config.filter_run :focused => true
15
+ config.run_all_when_everything_filtered = true
16
+ config.alias_example_to :fit, :focused => true
17
+ config.alias_example_to :they
18
+
19
+ config.mock_with :mocha
20
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jobviter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jared Pace
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-22 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: typhoeus
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.2.4
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 1.4.6
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: "2.6"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: mocha
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 0.9.12
58
+ type: :development
59
+ version_requirements: *id004
60
+ description: Simple ruby wrapper for pasing job feeds from Jobvite.com
61
+ email:
62
+ - jared@codeword.io
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - jobviter.gemspec
76
+ - lib/jobviter.rb
77
+ - lib/jobviter/config.rb
78
+ - lib/jobviter/exception.rb
79
+ - lib/jobviter/job.rb
80
+ - lib/jobviter/version.rb
81
+ - spec/fixtures/jobs.xml
82
+ - spec/jobviter/config_spec.rb
83
+ - spec/jobviter/job_spec.rb
84
+ - spec/spec_helper.rb
85
+ has_rdoc: true
86
+ homepage: ""
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: jobviter
109
+ rubygems_version: 1.6.2
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Jobvite job feed parser
113
+ test_files:
114
+ - spec/fixtures/jobs.xml
115
+ - spec/jobviter/config_spec.rb
116
+ - spec/jobviter/job_spec.rb
117
+ - spec/spec_helper.rb