zip_recruiter 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .rvmrc
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zip_recruiter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Adam Dunson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # ZipRecruiter
2
+
3
+ Provides a CLI and ruby interface to the ZipRecruiter Job Alerts API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'zip_recruiter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install zip_recruiter
18
+
19
+ ## Usage
20
+
21
+ Run the following to display CLI usage:
22
+
23
+ $ ziprecruiter
24
+
25
+ Additionally, you may use the ZipRecruiter::API class directly in a ruby
26
+ script.
27
+
28
+ require 'zip_recruiter'
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
37
+
38
+ ## Notes
39
+
40
+ There is a bug in Thor (see
41
+ [issue 261](https://github.com/wycats/thor/issues/261)) where the help command
42
+ for a subcommand will display the wrong name for the subcommand due to the way
43
+ it generates the help output. E.g., `$ ziprecruiter jobalerts` shows
44
+ `ziprecruiter c_l_i` in the output.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/ziprecruiter ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'zip_recruiter/cli'
3
+ ZipRecruiter::CLI.start
@@ -0,0 +1,4 @@
1
+ require 'zip_recruiter/version'
2
+
3
+ module ZipRecruiter
4
+ end
@@ -0,0 +1,17 @@
1
+ module ZipRecruiter
2
+ class API
3
+ ##
4
+ # Sets the API key
5
+ #
6
+ def self.api_key=(api_key)
7
+ @@api_key = api_key
8
+ end
9
+
10
+ ##
11
+ # Gets the API key
12
+ #
13
+ def self.api_key
14
+ @@api_key || ''
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'thor'
2
+ require 'zip_recruiter/job_alerts/cli'
3
+
4
+ module ZipRecruiter
5
+ class CLI < Thor
6
+ register ZipRecruiter::JobAlerts::CLI, 'jobalerts', 'jobalerts [COMMAND]', 'Type ziprecruiter jobalerts for more help.'
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module ZipRecruiter
2
+ module JobAlerts
3
+ end
4
+ end
@@ -0,0 +1,71 @@
1
+ require 'curb'
2
+ require 'zip_recruiter/api'
3
+
4
+ module ZipRecruiter
5
+ module JobAlerts
6
+ class API < ZipRecruiter::API
7
+ ##
8
+ # Performs the specified API action.
9
+ #
10
+ # This will perform the specified API action. The action must be one of:
11
+ #
12
+ # * +subscribe+
13
+ # * +unsubscribe+
14
+ # * +status+
15
+ #
16
+ # The +subscribe+ and +unsubscribe+ actions require an argument that is the
17
+ # path to a CSV file. The +status+ action requires an argument that is the
18
+ # task ID of a previously submitted API request.
19
+ #
20
+ # You should not call this method directly, but instead use one of the
21
+ # helper methods below.
22
+ #
23
+ def self.perform_action(action, arg)
24
+ c = Curl::Easy.new("https://api.ziprecruiter.com/job-alerts/v1/#{action.to_s}")
25
+ c.http_auth_types = :basic
26
+ c.userpwd = "#{api_key}:"
27
+
28
+ case action
29
+ when :subscribe, :unsubscribe
30
+ path = File.expand_path(arg.to_s)
31
+ if !File.exists?(path)
32
+ raise "File \"#{path}\" does not exist."
33
+ end
34
+
35
+ c.multipart_form_post = true
36
+ c.http_post(Curl::PostField.file('content', path.to_s)) # http_post calls perform
37
+
38
+ when :status
39
+ c.url += "/#{arg.to_s}"
40
+ c.perform
41
+
42
+ else
43
+ raise "Unknown action \"#{action.to_s}\"."
44
+ end
45
+
46
+ c.body_str
47
+ end
48
+
49
+ ##
50
+ # A Subscribe action is used to upload a collection of job seekers to subscribe to our job alerts program.
51
+ #
52
+ def self.subscribe(path)
53
+ ZipRecruiter::JobAlerts::API.perform_action :subscribe, path
54
+ end
55
+
56
+ ##
57
+ # An Unsubscribe action is used to upload a collection of job seekers to unsubscribe from our job alerts program.
58
+ #
59
+ def self.unsubscribe(path)
60
+ ZipRecruiter::JobAlerts::API.perform_action :unsubscribe, path
61
+ end
62
+
63
+ ##
64
+ # A Status action returns the current status of a previously-submitted request.
65
+ #
66
+ def self.status(task_id)
67
+ ZipRecruiter::JobAlerts::API.perform_action :status, task_id
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,38 @@
1
+ require 'thor'
2
+ require 'thor/group'
3
+ require 'zip_recruiter/api'
4
+ require 'zip_recruiter/job_alerts/api'
5
+
6
+ module ZipRecruiter
7
+ module JobAlerts
8
+ class CLI < Thor
9
+ class_option :api_key, :aliases => "-k", :desc => "Specify your ZipRecruiter Job Alerts API key."
10
+
11
+ desc "subscribe [PATH]", "A Subscribe action is used to upload a collection of job seekers to subscribe to the ZipRecruiter job alerts program."
12
+ def subscribe(path)
13
+ ZipRecruiter::API.api_key = options[:api_key] unless options[:api_key].nil?
14
+ if File.exists?(path)
15
+ p ZipRecruiter::JobAlerts::API.subscribe(path)
16
+ else
17
+ puts "File \"#{path}\" does not exist."
18
+ end
19
+ end
20
+
21
+ desc "unsubscribe [PATH]", "An Unsubscribe action is used to upload a collection of job seekers to unsubscribe from the ZipRecruiter job alerts program."
22
+ def unsubscribe(path)
23
+ ZipRecruiter::API.api_key = options[:api_key] unless options[:api_key].nil?
24
+ if File.exists?(path)
25
+ p ZipRecruiter::JobAlerts::API.unsubscribe(path)
26
+ else
27
+ puts "File \"#{path}\" does not exist."
28
+ end
29
+ end
30
+
31
+ desc "status [TASK_ID]", "A Status action returns the current status of a previously-submitted request."
32
+ def status(task_id)
33
+ ZipRecruiter::API.api_key = options[:api_key] unless options[:api_key].nil?
34
+ p ZipRecruiter::JobAlerts::API.status(task_id)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module ZipRecruiter
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require 'zip_recruiter/job_alerts'
3
+ require 'zip_recruiter/job_alerts/api'
4
+
5
+ describe ZipRecruiter::JobAlerts::API do
6
+ before :each do
7
+ ZipRecruiter::API.api_key = '' # might not need this?
8
+ @curl_easy = mock Curl::Easy
9
+ Curl::Easy.stub(:new).and_return(@curl_easy)
10
+ Curl::PostField.stub(:file)
11
+ @curl_easy.stub(:http_auth_types=)
12
+ @curl_easy.stub(:userpwd=)
13
+ @curl_easy.stub(:url).and_return("")
14
+ @curl_easy.stub(:url=)
15
+ @curl_easy.stub(:multipart_form_post=)
16
+ @curl_easy.stub(:http_post)
17
+ @curl_easy.stub(:perform)
18
+ @curl_easy.stub(:body_str)
19
+ end
20
+
21
+ describe "#perform_action" do
22
+ it "raises an exception when called with an unknown action" do
23
+ lambda { ZipRecruiter::JobAlerts::API.perform_action(:unknown_action, nil) }.should raise_error
24
+ end
25
+
26
+ it "works when called with subscribe and a good file path" do
27
+ File.stub(:exists?).and_return(true) # pretend the file exists
28
+ @curl_easy.should_receive(:http_post)
29
+ @curl_easy.should_receive(:body_str)
30
+ ZipRecruiter::JobAlerts::API.perform_action(:subscribe, '/path/to/good/file.csv')
31
+ end
32
+
33
+ it "raises an exception when called with subscribe and a bad file path" do
34
+ File.stub(:exists?).and_return(false) # pretend the file does not exist
35
+ lambda { ZipRecruiter::JobAlerts::API.perform_action(:subscribe, "/path/to/bad/file.csv") }.should raise_error
36
+ end
37
+
38
+ it "works when called with unsubscribe and a good file path" do
39
+ File.stub(:exists?).and_return(true) # pretend the file exists
40
+ @curl_easy.should_receive(:http_post)
41
+ @curl_easy.should_receive(:body_str)
42
+ ZipRecruiter::JobAlerts::API.perform_action(:unsubscribe, '/path/to/good/file.csv')
43
+ end
44
+
45
+ it "raises an exception when called with unsubscribe and a bad file path" do
46
+ File.stub(:exists?).and_return(false) # pretend the file does not exist
47
+ lambda { ZipRecruiter::JobAlerts::API.perform_action(:unsubscribe, "/path/to/bad/file.csv") }.should raise_error
48
+ end
49
+
50
+ it "works when called with status and a string argument" do
51
+ @curl_easy.should_receive(:perform)
52
+ @curl_easy.should_receive(:body_str)
53
+ ZipRecruiter::JobAlerts::API.perform_action(:status, "foobar")
54
+ end
55
+ end
56
+
57
+ describe "#subscribe" do
58
+ it "calls perform_action subscribe with the correct argument" do
59
+ ZipRecruiter::JobAlerts::API.should_receive(:perform_action).with(:subscribe, "the path")
60
+ ZipRecruiter::JobAlerts::API.subscribe("the path")
61
+ end
62
+ end
63
+
64
+ describe "#unsubscribe" do
65
+ it "calls perform_action unsubscribe with the correct argument" do
66
+ ZipRecruiter::JobAlerts::API.should_receive(:perform_action).with(:unsubscribe, "the path")
67
+ ZipRecruiter::JobAlerts::API.unsubscribe("the path")
68
+ end
69
+ end
70
+
71
+ describe "#status" do
72
+ it "calls perform_action status with the correct argument" do
73
+ ZipRecruiter::JobAlerts::API.should_receive(:perform_action).with(:status, "the task id")
74
+ ZipRecruiter::JobAlerts::API.status("the task id")
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,48 @@
1
+ require 'stringio'
2
+ require 'spec_helper'
3
+ require 'zip_recruiter/job_alerts'
4
+ require 'zip_recruiter/job_alerts/cli'
5
+
6
+ describe ZipRecruiter::JobAlerts::CLI do
7
+ before :each do
8
+ $stdout = StringIO.new # redirect stdout
9
+ ZipRecruiter::API.api_key = '' # might not need this?
10
+ @jobalerts_cli = ZipRecruiter::JobAlerts::CLI.new
11
+ ZipRecruiter::JobAlerts::API.stub(:subscribe)
12
+ ZipRecruiter::JobAlerts::API.stub(:unsubscribe)
13
+ ZipRecruiter::JobAlerts::API.stub(:status)
14
+ end
15
+
16
+ describe "#subscribe" do
17
+ it "raises an exception when called with a bad file path" do
18
+ $stdout.should_receive(:puts).with("File \"/path/to/bad/file.csv\" does not exist.")
19
+ @jobalerts_cli.subscribe("/path/to/bad/file.csv")
20
+ end
21
+
22
+ it "calls the subscribe api method when given a good file path" do
23
+ File.stub(:exists?).and_return(true) # pretend the file exists
24
+ ZipRecruiter::JobAlerts::API.should_receive(:subscribe).with("/path/to/good/file.csv")
25
+ @jobalerts_cli.subscribe("/path/to/good/file.csv")
26
+ end
27
+ end
28
+
29
+ describe "#unsubscribe" do
30
+ it "raises an exception when called with a bad file path" do
31
+ $stdout.should_receive(:puts).with("File \"/path/to/bad/file.csv\" does not exist.")
32
+ @jobalerts_cli.unsubscribe("/path/to/bad/file.csv")
33
+ end
34
+
35
+ it "calls the unsubscribe api method when given a good file path" do
36
+ File.stub(:exists?).and_return(true) # pretend the file exists
37
+ ZipRecruiter::JobAlerts::API.should_receive(:unsubscribe).with("/path/to/good/file.csv")
38
+ @jobalerts_cli.unsubscribe("/path/to/good/file.csv")
39
+ end
40
+ end
41
+
42
+ describe "#status" do
43
+ it "calls the status api method" do
44
+ ZipRecruiter::JobAlerts::API.should_receive(:status).with("foobar")
45
+ @jobalerts_cli.status("foobar")
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zip_recruiter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "zip_recruiter"
8
+ gem.version = ZipRecruiter::VERSION
9
+ gem.authors = ["Adam Dunson"]
10
+ gem.email = ["adam@cloudspace.com"]
11
+ gem.description = %q{Provides a ruby interface to the ZipRecruiter Job Alerts API.}
12
+ gem.summary = %q{Ruby ZipRecruiter Job Alerts API interface}
13
+ gem.homepage = "https://github.com/adamdunson/zip_recruiter/"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "curb"
21
+ gem.add_dependency "thor"
22
+ gem.add_development_dependency "rspec"
23
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zip_recruiter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Dunson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: curb
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Provides a ruby interface to the ZipRecruiter Job Alerts API.
63
+ email:
64
+ - adam@cloudspace.com
65
+ executables:
66
+ - ziprecruiter
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/ziprecruiter
77
+ - lib/zip_recruiter.rb
78
+ - lib/zip_recruiter/api.rb
79
+ - lib/zip_recruiter/cli.rb
80
+ - lib/zip_recruiter/job_alerts.rb
81
+ - lib/zip_recruiter/job_alerts/api.rb
82
+ - lib/zip_recruiter/job_alerts/cli.rb
83
+ - lib/zip_recruiter/version.rb
84
+ - spec/spec_helper.rb
85
+ - spec/zip_recruiter/job_alerts/api_spec.rb
86
+ - spec/zip_recruiter/job_alerts/cli_spec.rb
87
+ - zip_recruiter.gemspec
88
+ homepage: https://github.com/adamdunson/zip_recruiter/
89
+ licenses: []
90
+ post_install_message:
91
+ rdoc_options: []
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
+ rubyforge_project:
108
+ rubygems_version: 1.8.24
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Ruby ZipRecruiter Job Alerts API interface
112
+ test_files:
113
+ - spec/spec_helper.rb
114
+ - spec/zip_recruiter/job_alerts/api_spec.rb
115
+ - spec/zip_recruiter/job_alerts/cli_spec.rb