board-client 0.3.0 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +47 -0
  4. data/Gemfile +1 -7
  5. data/README.md +63 -17
  6. data/Rakefile +4 -44
  7. data/board-client.gemspec +22 -66
  8. data/lib/board/client.rb +41 -22
  9. data/lib/board/client/api.rb +29 -0
  10. data/lib/board/client/candidates.rb +13 -0
  11. data/lib/board/client/organizations.rb +17 -0
  12. data/lib/board/client/request.rb +98 -0
  13. data/lib/board/client/user_organizations.rb +20 -0
  14. data/lib/board/client/users.rb +21 -0
  15. data/lib/board/client/version.rb +5 -0
  16. data/spec/board/client_spec.rb +27 -83
  17. data/spec/cassettes/candidate_exists_with_id.yml +30 -0
  18. data/spec/cassettes/candidate_id_does_not_exist.yml +336 -0
  19. data/spec/cassettes/candidate_invite_email_exists.yml +30 -0
  20. data/spec/cassettes/candidate_invite_when_invalid.yml +30 -0
  21. data/spec/cassettes/candidate_invite_when_valid.yml +32 -0
  22. data/spec/cassettes/list_user_organizations_with_invalid_id.yml +346 -0
  23. data/spec/cassettes/list_user_organizations_with_valid_id.yml +30 -0
  24. data/spec/cassettes/organization_add_user.yml +26 -0
  25. data/spec/cassettes/organization_add_user_-_organization_does_not_exist.yml +356 -0
  26. data/spec/cassettes/organization_add_user_-_user_does_not_exist.yml +348 -0
  27. data/spec/cassettes/organization_create_is_invalid.yml +30 -0
  28. data/spec/cassettes/organization_create_is_valid.yml +32 -0
  29. data/spec/cassettes/organization_exists_with_email.yml +30 -0
  30. data/spec/cassettes/organization_exists_with_id.yml +30 -0
  31. data/spec/cassettes/organization_id_does_not_exist.yml +354 -0
  32. data/spec/cassettes/organization_name_does_not_exist.yml +334 -0
  33. data/spec/cassettes/unsubscribe_email_does_not_exist.yml +340 -0
  34. data/spec/cassettes/unsubscribe_email_exists.yml +30 -0
  35. data/spec/cassettes/user_does_exist.yml +30 -0
  36. data/spec/cassettes/user_does_not_exist.yml +32 -0
  37. data/spec/cassettes/user_email_does_not_exist.yml +334 -0
  38. data/spec/cassettes/user_email_md5_does_not_exist.yml +334 -0
  39. data/spec/cassettes/user_exists_with_email.yml +30 -0
  40. data/spec/cassettes/user_exists_with_email_md5.yml +30 -0
  41. data/spec/cassettes/user_exists_with_id.yml +30 -0
  42. data/spec/cassettes/user_id_does_not_exist.yml +346 -0
  43. data/spec/cassettes/user_missing_attributes.yml +30 -0
  44. data/spec/integration/candidates/find_spec.rb +28 -0
  45. data/spec/integration/candidates/invite_spec.rb +48 -0
  46. data/spec/integration/organizations/add_user_spec.rb +34 -0
  47. data/spec/integration/organizations/create_spec.rb +38 -0
  48. data/spec/integration/organizations/find_spec.rb +50 -0
  49. data/spec/integration/users/create_spec.rb +54 -0
  50. data/spec/integration/users/find_spec.rb +73 -0
  51. data/spec/integration/users/list_organizations_spec.rb +36 -0
  52. data/spec/integration/users/unsubscribe_spec.rb +27 -0
  53. data/spec/spec_helper.rb +6 -5
  54. data/spec/support/integration_helpers.rb +17 -0
  55. data/spec/support/vcr.rb +11 -0
  56. metadata +144 -52
  57. data/Gemfile.lock +0 -22
  58. data/lib/board/candidate_search.rb +0 -45
  59. data/lib/board/request.rb +0 -78
  60. data/spec/board/candidate_search_spec.rb +0 -45
  61. data/spec/spec.opts +0 -1
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ree-1.8.7-2011.03@board-client"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]] ; then
45
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
46
+ # fi
47
+
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rest-client", "~> 1.6.1"
4
- gem "yajl-ruby", "~> 0.7.7"
5
-
6
- group :test do
7
- gem "rspec", "~> 1.3.0"
8
- gem "webmock", "~> 1.3.5"
9
- end
3
+ gemspec
data/README.md CHANGED
@@ -1,30 +1,76 @@
1
- # board-client
1
+ # Board::Client
2
2
 
3
- client = Board::Client.new('YOUR_API_KEY_HERE')
3
+ ## TODO
4
4
 
5
- ## candidate searches
5
+ * Organization / User update add organization to user or add user to organization
6
6
 
7
- search = client.candidate_search(:keywords => "ruby",
8
- :distance => 50,
9
- :location => "Cincinnati, OH")
7
+ ## Usage
10
8
 
11
- iterate through current page of results
9
+ board = Board::Client.new('YOUR_API_KEY_HERE')
12
10
 
13
- search.results.each do |result|
11
+ ### Search
14
12
 
15
- end
13
+ All methods named search return search object that support a few elements of convenience. Each search API returns a similar format and supports similar options.
16
14
 
17
- iterate through all pages and yield result
15
+ search.results # current page of results
16
+ search.each_result { |result| p result } # iterate through all pages of results
17
+ search.total # total number of results
18
+ search.page # current page number
18
19
 
19
- search.each_result do |result|
20
+ ### User Search
20
21
 
21
- end
22
+ # should this mimic candidate search with keywords?
23
+ board.users.search(:email => "foo@bar.com")
22
24
 
23
- ## invitations
25
+ # should this just be a special method?
26
+ board.users.find(42) # by id
27
+ board.users.find(:email => "foo@bar.com")
28
+ board.users.find(:email_md5 => "asdfasdf")
24
29
 
25
- invitation = client.create_invitation(:first_name => "Michael",
26
- :last_name => "Jordan",
27
- :email => "michael.jordan@nike.com")
30
+ ### User Create
31
+
32
+ user = board.users.create(:email => "foo@bar.com",
33
+ :first_name => "Bob",
34
+ :last_name => "Smith")
35
+
36
+ user.email # => "foo@bar.com"
37
+ user.first_name # => "Bob"
38
+ user.last_name # => "Smith"
39
+ user.id # => 42
40
+
41
+ ### Organization Search
42
+
43
+ board.organizations.search(:name => "Nike")
44
+
45
+ ### Organization Create
46
+
47
+ organization = board.organizations.create(:name => "Nike"
48
+ :url => "http://nike.com")
49
+
50
+ organization.name # => "Nike"
51
+ organization.url # => "http://nike.com"
52
+ organization.id # => 9
53
+
54
+ ### Organization Add User
55
+
56
+ board.organizations.add_user(:organization_id => organization.id, :user_id => 42)
57
+
58
+ ### Candidate Search
59
+
60
+ board.candidates.search(:keywords => "ruby",
61
+ :distance => 50,
62
+ :location => "Cincinnati, OH")
63
+
64
+ ### Candidate Invitations
65
+
66
+ invitation = client.candidates.invitation(:first_name => "Michael",
67
+ :last_name => "Jordan",
68
+ :email => "michael.jordan@nike.com")
69
+
70
+ invitation.url # => "https://board.recruitmilitary.com/invitations/abcdefghijklmnopqrstuvwxyz0123456789"
71
+ invitation.first_name # => "Michael"
72
+ invitation.last_name # => "Jordan"
73
+ invitation.email # => "michael.jordan@nike.com"
28
74
 
29
75
  ## Note on Patches/Pull Requests
30
76
 
@@ -38,4 +84,4 @@ iterate through all pages and yield result
38
84
 
39
85
  ## Copyright
40
86
 
41
- Copyright (c) 2010 Michael Guterl. See LICENSE for details.
87
+ Copyright (c) 2011 Michael Guterl. See LICENSE for details
data/Rakefile CHANGED
@@ -1,46 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "board-client"
8
- gem.summary = %Q{A ruby wrapper for the board platform}
9
- gem.description = %Q{A ruby wrapper for the board platform.}
10
- gem.email = "mguterl@gmail.com"
11
- gem.homepage = "http://github.com/mguterl/board-client"
12
- gem.authors = ["Michael Guterl"]
13
- gem.add_dependency "rest-client", "~> 1.6.1"
14
- gem.add_dependency "yajl-ruby", "~> 0.7.7"
15
- gem.add_development_dependency "rspec", "~> 1.3.0"
16
- gem.add_development_dependency "webmock", "~> 1.6.2"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
35
3
 
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
36
6
  task :default => :spec
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "board-client #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
@@ -1,74 +1,30 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "board/client/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{board-client}
8
- s.version = "0.3.0"
6
+ s.name = "board-client"
7
+ s.version = Board::Client::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael Guterl"]
10
+ s.email = ["mguterl@gmail.com"]
11
+ s.homepage = "http://github.com/recruitmilitary/board-client"
12
+ s.summary = %q{A ruby wrapper for the RecruitMilitary Board HTTP API}
13
+ s.description = %q{A ruby wrapper for the RecruitMilitary Board HTTP API}
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Guterl"]
12
- s.date = %q{2011-05-04}
13
- s.description = %q{A ruby wrapper for the board platform.}
14
- s.email = %q{mguterl@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "board-client.gemspec",
28
- "lib/board-client.rb",
29
- "lib/board/candidate_search.rb",
30
- "lib/board/client.rb",
31
- "lib/board/request.rb",
32
- "spec/board/candidate_search_spec.rb",
33
- "spec/board/client_spec.rb",
34
- "spec/spec.opts",
35
- "spec/spec_helper.rb"
36
- ]
37
- s.homepage = %q{http://github.com/mguterl/board-client}
15
+ s.rubyforge_project = "board-client"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
38
20
  s.require_paths = ["lib"]
39
- s.rubygems_version = %q{1.5.2}
40
- s.summary = %q{A ruby wrapper for the board platform}
41
- s.test_files = [
42
- "spec/board/candidate_search_spec.rb",
43
- "spec/board/client_spec.rb",
44
- "spec/spec_helper.rb"
45
- ]
46
21
 
47
- if s.respond_to? :specification_version then
48
- s.specification_version = 3
22
+ s.add_dependency 'rest-client', '~> 1.6.1'
23
+ s.add_dependency 'yajl-ruby', '~> 0.7.7'
24
+ s.add_dependency 'hashie', '~> 1.1.0'
49
25
 
50
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.1"])
52
- s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
53
- s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.1"])
54
- s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
55
- s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
56
- s.add_development_dependency(%q<webmock>, ["~> 1.6.2"])
57
- else
58
- s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
59
- s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
60
- s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
61
- s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
62
- s.add_dependency(%q<rspec>, ["~> 1.3.0"])
63
- s.add_dependency(%q<webmock>, ["~> 1.6.2"])
64
- end
65
- else
66
- s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
67
- s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
68
- s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
69
- s.add_dependency(%q<yajl-ruby>, ["~> 0.7.7"])
70
- s.add_dependency(%q<rspec>, ["~> 1.3.0"])
71
- s.add_dependency(%q<webmock>, ["~> 1.6.2"])
72
- end
26
+ s.add_development_dependency 'rspec', '~> 2.6.0'
27
+ s.add_development_dependency 'vcr', '~> 1.11.1'
28
+ s.add_development_dependency 'webmock', '~> 1.7.4'
29
+ s.add_development_dependency 'ruby-debug'
73
30
  end
74
-
@@ -1,45 +1,64 @@
1
1
  require 'yajl'
2
+ require 'hashie/mash'
2
3
 
3
- require 'board/request'
4
- require 'board/candidate_search'
4
+ require 'board/client/version'
5
+ require 'board/client/request'
5
6
 
6
7
  module Board
7
8
  class Client
8
9
 
9
- include Request
10
+ class Error < StandardError
11
+ attr_reader :response
10
12
 
11
- class << self
12
- attr_accessor :default_url
13
+ def initialize(response)
14
+ @response = response
15
+ end
13
16
  end
14
- self.default_url = 'https://board.recruitmilitary.com/api/v1'
15
17
 
16
- def initialize(api_key, url = Client.default_url)
17
- @api_key = api_key
18
- @url = url
19
- end
18
+ BadRequest = Class.new(Error)
19
+ Unauthorized = Class.new(Error)
20
+ Forbidden = Class.new(Error)
21
+ NotFound = Class.new(Error)
22
+ NotAcceptable = Class.new(Error)
23
+ Conflict = Class.new(Error)
24
+ UnprocessableEntity = Class.new(Error)
25
+ InternalServerError = Class.new(Error)
26
+ NotImplemented = Class.new(Error)
27
+ BadGateway = Class.new(Error)
28
+ ServiceUnavailable = Class.new(Error)
20
29
 
21
- def candidate_searches(params)
22
- get "/candidate_searches", params
30
+ include Request
31
+
32
+ class << self
33
+ attr_accessor :default_endpoint
23
34
  end
35
+ self.default_endpoint = 'https://board.recruitmilitary.com/api/v1'
24
36
 
25
- def find_user(params)
26
- get "/users", params
37
+ def initialize(api_key, endpoint = Client.default_endpoint)
38
+ @api_key = api_key
39
+ @endpoint = endpoint
27
40
  end
28
41
 
29
- def mark_user_invalid(params)
30
- get "/users/invalid", params
42
+ autoload :API, 'board/client/api'
43
+ autoload :Users, 'board/client/users'
44
+ autoload :Candidates, 'board/client/candidates'
45
+ autoload :Organizations, 'board/client/organizations'
46
+ autoload :UserOrganizations, 'board/client/user_organizations'
47
+
48
+ def users
49
+ Users.new(self)
31
50
  end
32
51
 
33
- def unsubscribe(params)
34
- get "/users/unsubscribe", params
52
+ def candidates
53
+ Candidates.new(self)
35
54
  end
36
55
 
37
- def create_candidate_invitation(params)
38
- post "/candidate_invitations", params
56
+ def organizations
57
+ Organizations.new(self)
39
58
  end
40
59
 
41
- def find_candidate(candidate_id)
42
- get "/candidates/#{candidate_id}", {}
60
+ def user_organizations
61
+ UserOrganizations.new(self)
43
62
  end
44
63
 
45
64
  end
@@ -0,0 +1,29 @@
1
+ module Board
2
+ class Client::API
3
+
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def post(path, attributes = {})
9
+ json = @client.post(path, attributes)
10
+
11
+ if json.is_a?(Hash)
12
+ Hashie::Mash.new(json)
13
+ else
14
+ json
15
+ end
16
+ end
17
+
18
+ def get(path, attributes = {})
19
+ json = @client.get(path, attributes)
20
+
21
+ if json.is_a?(Array)
22
+ json.map { |item| Hashie::Mash.new(item) }
23
+ else
24
+ Hashie::Mash.new(json)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Board
2
+ class Client::Candidates < Client::API
3
+
4
+ def find(id)
5
+ get("/candidates/#{id}")
6
+ end
7
+
8
+ def invite(attributes)
9
+ post("/candidate_invitations", attributes)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Board
2
+ class Client::Organizations < Client::API
3
+
4
+ def create(attributes)
5
+ post("/organizations", attributes)
6
+ end
7
+
8
+ def find(id)
9
+ if id.is_a?(Hash)
10
+ get("/organizations", id)
11
+ else
12
+ get("/organizations/#{id}")
13
+ end
14
+ end
15
+
16
+ end
17
+ end