direct_employers 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,9 +18,10 @@ Usage Examples
18
18
  --------------
19
19
  require 'direct_employers'
20
20
 
21
- @client = DirectEmployers.new
21
+ @client = DirectEmployers.new({key: => "abc123"}) #Add your development key
22
22
  @client.search({moc: => ""11b}) # Return an array for all matching job listings for MOC of 11b
23
23
  @client.search.query # => "First-Line Supervisors/Managers of Weapons Specialists/Crew Members, Infantry"
24
+ @client.search.api.jobs.job.first.company # => "Tennessee Employer"
24
25
 
25
26
 
26
27
  Contributing
@@ -1,8 +1,8 @@
1
1
  require 'direct_employers/client'
2
2
 
3
3
  module DirectEmployers
4
- def self.new
5
- DirectEmployers::Client.new
4
+ def self.new(options={})
5
+ DirectEmployers::Client.new(options)
6
6
  end
7
7
 
8
8
  # Delegate to DirectEmployers::Client
@@ -3,9 +3,19 @@ require 'direct_employers/request'
3
3
 
4
4
  module DirectEmployers
5
5
  class Client
6
+ attr_accessor :key
6
7
  include DirectEmployers::Connection
7
8
  include DirectEmployers::Request
8
9
 
10
+ # Set your development key on New
11
+ #
12
+ # @param options [Hash] A customizable set of options.
13
+ # @example
14
+ # DirectEmployers.New({:key => "abc123"})
15
+ def initialize(options={})
16
+ @key = options[:key]
17
+ end
18
+
9
19
  # Get a list of all jobs that match the query string parameters
10
20
  #
11
21
  # @param options [Hash] A customizable set of options.
@@ -1,4 +1,5 @@
1
1
  require 'faraday_middleware'
2
+ require 'faraday/response/parse_error'
2
3
 
3
4
  module DirectEmployers
4
5
  module Connection
@@ -10,8 +11,9 @@ module DirectEmployers
10
11
  connection.use Faraday::Response::RaiseError
11
12
  connection.use Faraday::Response::Rashify
12
13
  connection.use Faraday::Response::ParseXml
14
+ connection.use Faraday::Response::ParseError
13
15
  connection.adapter(Faraday.default_adapter)
14
16
  end
15
17
  end
16
18
  end
17
- end
19
+ end
@@ -8,9 +8,9 @@ module DirectEmployers
8
8
 
9
9
  def request(method, path, options)
10
10
  response = connection.send(method) do |request|
11
- request.url(path, options)
11
+ request.url(path, options.merge(:key => @key))
12
12
  end
13
13
  response.body
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module DirectEmployers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,16 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+ class Response::ParseError < Response::Middleware
5
+ def on_complete(env)
6
+ if 200 == env[:status] && 'unknown site' == env[:body]
7
+ raise Faraday::Error::ParsingError, response_values(env)
8
+ end
9
+ end
10
+
11
+ def response_values(env)
12
+ {:status => env[:status], :headers => env[:response_headers], :body => env[:body]}
13
+ end
14
+ end
15
+ end
16
+
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe DirectEmployers::Client do
4
4
  before do
5
- @client = DirectEmployers::Client.new
5
+ @client = DirectEmployers.new(:key => "abc123")
6
6
  end
7
7
 
8
8
  describe "#search" do
@@ -13,7 +13,7 @@ describe DirectEmployers::Client do
13
13
  end
14
14
 
15
15
  it "should return search to broad" do
16
- search = @client.search(:key => "abc123")
16
+ search = @client.search
17
17
  a_get("api.asp?key=abc123").should have_been_made
18
18
  search.api.error.should == "Search Too Broad"
19
19
  end
@@ -26,9 +26,10 @@ describe DirectEmployers::Client do
26
26
  end
27
27
 
28
28
  it "should return a list of jobs with moc code 11b" do
29
- search = @client.search(:key => "abc123", :moc => "11b")
29
+ search = @client.search(:moc => "11b")
30
30
  a_get("api.asp?key=abc123&moc=11b").should have_been_made
31
31
  search.api.query.should == "First-Line Supervisors/Managers of Weapons Specialists/Crew Members, Infantry"
32
+ search.api.jobs.job.first.company == "Tennessee Employer"
32
33
  end
33
34
  end
34
35
  end
@@ -1,9 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require 'helper'
2
3
 
3
4
  describe DirectEmployers do
5
+
6
+ describe ".respond_to?" do
7
+ it "should be true if method exists" do
8
+ DirectEmployers.respond_to?(:new, true).should be_true
9
+ end
10
+ end
11
+
4
12
  describe ".new" do
5
- it "should return a DirectEmployers::Client" do
13
+ it "should be a DirectEmployers::Client" do
6
14
  DirectEmployers.new.should be_a DirectEmployers::Client
7
15
  end
8
16
  end
9
- end
17
+
18
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ describe Faraday::Response do
4
+ before do
5
+ @client = DirectEmployers::new(:key => "abc123")
6
+ end
7
+
8
+ {
9
+ 400 => Faraday::Error::ClientError,
10
+ 401 => Faraday::Error::ClientError,
11
+ 403 => Faraday::Error::ClientError,
12
+ 404 => Faraday::Error::ResourceNotFound,
13
+ 406 => Faraday::Error::ClientError,
14
+ 500 => Faraday::Error::ClientError,
15
+ 501 => Faraday::Error::ClientError,
16
+ 502 => Faraday::Error::ClientError,
17
+ 503 => Faraday::Error::ClientError,
18
+ }.each do |status, exception|
19
+ context "when HTTP status is #{status}" do
20
+
21
+ before do
22
+ stub_get("api.asp?key=abc123&moc=11b").
23
+ to_return(:status => status, :body => fixture("11bquery.xml"))
24
+ end
25
+
26
+ it "should raise #{exception.name} error" do
27
+ lambda do
28
+ @client.search(:key=> "abc123", :moc => "11b")
29
+ end.should raise_error exception
30
+ end
31
+ end
32
+ end
33
+ context "with no items found in search query" do
34
+ before do
35
+ stub_get("api.asp").
36
+ to_return(:status => 200, :body => '')
37
+ end
38
+
39
+ it "should raise an exception" do
40
+ lambda do
41
+ @client.search
42
+ end.should raise_error
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: direct_employers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-06-06 00:00:00.000000000Z
13
+ date: 2011-06-07 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ZenTest
17
- requirement: &2156115980 !ruby/object:Gem::Requirement
17
+ requirement: &2161326740 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '4.5'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2156115980
25
+ version_requirements: *2161326740
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: maruku
28
- requirement: &2156115200 !ruby/object:Gem::Requirement
28
+ requirement: &2161326180 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0.6'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2156115200
36
+ version_requirements: *2161326180
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rake
39
- requirement: &2156114720 !ruby/object:Gem::Requirement
39
+ requirement: &2161325600 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0.9'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2156114720
47
+ version_requirements: *2161325600
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &2156114220 !ruby/object:Gem::Requirement
50
+ requirement: &2161325120 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '2.6'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2156114220
58
+ version_requirements: *2161325120
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: simplecov
61
- requirement: &2156113580 !ruby/object:Gem::Requirement
61
+ requirement: &2161324540 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0.4'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2156113580
69
+ version_requirements: *2161324540
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: webmock
72
- requirement: &2156112780 !ruby/object:Gem::Requirement
72
+ requirement: &2161324040 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '1.6'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2156112780
80
+ version_requirements: *2161324040
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: yard
83
- requirement: &2156112080 !ruby/object:Gem::Requirement
83
+ requirement: &2161323540 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0.7'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2156112080
91
+ version_requirements: *2161323540
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: faraday
94
- requirement: &2156111320 !ruby/object:Gem::Requirement
94
+ requirement: &2161323080 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 0.6.1
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *2156111320
102
+ version_requirements: *2161323080
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: faraday_middleware
105
- requirement: &2156110600 !ruby/object:Gem::Requirement
105
+ requirement: &2161322620 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 0.6.3
111
111
  type: :runtime
112
112
  prerelease: false
113
- version_requirements: *2156110600
113
+ version_requirements: *2161322620
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: hashie
116
- requirement: &2156109720 !ruby/object:Gem::Requirement
116
+ requirement: &2161312940 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ~>
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: 1.0.0
122
122
  type: :runtime
123
123
  prerelease: false
124
- version_requirements: *2156109720
124
+ version_requirements: *2161312940
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: multi_json
127
- requirement: &2156108960 !ruby/object:Gem::Requirement
127
+ requirement: &2161312360 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ~>
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: 1.0.2
133
133
  type: :runtime
134
134
  prerelease: false
135
- version_requirements: *2156108960
135
+ version_requirements: *2161312360
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: multi_xml
138
- requirement: &2156108160 !ruby/object:Gem::Requirement
138
+ requirement: &2161311760 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ~>
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: 0.2.2
144
144
  type: :runtime
145
145
  prerelease: false
146
- version_requirements: *2156108160
146
+ version_requirements: *2161311760
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: rash
149
- requirement: &2156107440 !ruby/object:Gem::Requirement
149
+ requirement: &2161311180 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ~>
@@ -154,7 +154,7 @@ dependencies:
154
154
  version: 0.3.0
155
155
  type: :runtime
156
156
  prerelease: false
157
- version_requirements: *2156107440
157
+ version_requirements: *2161311180
158
158
  description: Ruby Wrapper for the Direct Employers API
159
159
  email:
160
160
  - erik@codeforamerica.org
@@ -179,8 +179,10 @@ files:
179
179
  - lib/direct_employers/connection.rb
180
180
  - lib/direct_employers/request.rb
181
181
  - lib/direct_employers/version.rb
182
+ - lib/faraday/response/parse_error.rb
182
183
  - spec/direct_employers/client_spec.rb
183
184
  - spec/direct_employers_spec.rb
185
+ - spec/faraday/response_spec.rb
184
186
  - spec/fixtures/11bquery.xml
185
187
  - spec/fixtures/search_to_broad.xml
186
188
  - spec/helper.rb
@@ -211,6 +213,7 @@ summary: ''
211
213
  test_files:
212
214
  - spec/direct_employers/client_spec.rb
213
215
  - spec/direct_employers_spec.rb
216
+ - spec/faraday/response_spec.rb
214
217
  - spec/fixtures/11bquery.xml
215
218
  - spec/fixtures/search_to_broad.xml
216
219
  - spec/helper.rb