cb-api 6.3.3 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cb.rb CHANGED
@@ -3,13 +3,15 @@ require 'cb/models/implementations/branding/styles/base'
3
3
  require 'cb/models/implementations/branding/styles/css_adapter'
4
4
  require 'cb/exceptions'
5
5
  require 'cb/convenience'
6
+ require 'cb/client'
6
7
 
7
8
  def require_directory(relative_path)
8
9
  Dir[File.dirname(__FILE__) + relative_path].each { |file| require file }
9
10
  end
10
11
 
11
12
  %w(/cb/utils/*.rb /cb/clients/**/*.rb /cb/criteria/**/*.rb /cb/models/**.rb
12
- /cb/models/**/*.rb /cb/responses/*.rb /cb/responses/**/*.rb).each { |path| require_directory path }
13
+ /cb/models/**/*.rb /cb/responses/*.rb /cb/responses/**/*.rb
14
+ /cb/requests/*.rb /cb/requests/**/*.rb).each { |path| require_directory path }
13
15
 
14
16
  module Cb
15
17
  extend Convenience::ClassMethods
@@ -0,0 +1,32 @@
1
+ module Cb
2
+ class Client
3
+ attr_reader :callback_block
4
+
5
+ def initialize(&block)
6
+ @callback_block = block
7
+ end
8
+
9
+ def execute(request)
10
+ api_response = call_api(request)
11
+ response_class = Cb::Utils::ResponseMap.response_for(request.class)
12
+ response_class.new api_response
13
+ end
14
+
15
+ private
16
+
17
+ def call_api(request)
18
+ cb_client.method(:"cb_#{request.http_method}").call(
19
+ request.endpoint_uri,
20
+ {
21
+ query: request.query,
22
+ headers: request.headers,
23
+ body: request.body
24
+ },
25
+ &@callback_block)
26
+ end
27
+
28
+ def cb_client
29
+ Cb::Utils::Api.instance
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Cb
2
+ module Requests
3
+ class Base
4
+
5
+ def initialize(argument_hash)
6
+ @args = argument_hash || {}
7
+ end
8
+
9
+ def endpoint_uri
10
+ raise NotImplementedError.new __method__
11
+ end
12
+
13
+ def http_method
14
+ raise NotImplementedError.new __method__
15
+ end
16
+
17
+ def query
18
+ nil
19
+ end
20
+
21
+ def headers
22
+ nil
23
+ end
24
+
25
+ def body
26
+ nil
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../base'
2
+
3
+ module Cb
4
+ module Requests
5
+ module User
6
+ class ChangePassword < Base
7
+
8
+ def endpoint_uri
9
+ Cb.configuration.uri_user_change_password
10
+ end
11
+
12
+ def http_method
13
+ :post
14
+ end
15
+
16
+ def body
17
+ <<-eos
18
+ <Request>
19
+ <DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>
20
+ <ExternalID>#{@args[:external_id]}</ExternalID>
21
+ <Test>#{(@args[:test] || false).to_s}</Test>
22
+ <OldPassword>#{@args[:old_password]}</OldPassword>
23
+ <NewPassword>#{@args[:new_password]}</NewPassword>
24
+ </Request>
25
+ eos
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require_relative '../base'
2
+
3
+ module Cb
4
+ module Requests
5
+ module User
6
+ class CheckExisting < Base
7
+
8
+ def endpoint_uri
9
+ Cb.configuration.uri_user_check_existing
10
+ end
11
+
12
+ def http_method
13
+ :post
14
+ end
15
+
16
+ def body
17
+ <<-eos
18
+ <Request>
19
+ <DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>
20
+ <Email>#{@args[:email]}</Email>
21
+ <Password>#{@args[:password]}</Password>
22
+ <Test>#{(@args[:test] || false).to_s}</Test>
23
+ </Request>
24
+ eos
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require_relative '../base'
2
+
3
+ module Cb
4
+ module Requests
5
+ module User
6
+ class Delete < Base
7
+
8
+ def endpoint_uri
9
+ Cb.configuration.uri_user_delete
10
+ end
11
+
12
+ def http_method
13
+ :post
14
+ end
15
+
16
+ def body
17
+ <<-eos
18
+ <Request>
19
+ <DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>
20
+ <ExternalID>#{@args[:external_id]}</ExternalID>
21
+ <Test>#{(@args[:test] || false).to_s}</Test>
22
+ <Password>#{@args[:password]}</Password>
23
+ </Request>
24
+ eos
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../base'
2
+
3
+ module Cb
4
+ module Requests
5
+ module User
6
+ class Retrieve < Base
7
+
8
+ def endpoint_uri
9
+ Cb.configuration.uri_user_retrieve
10
+ end
11
+
12
+ def http_method
13
+ :post
14
+ end
15
+
16
+ def body
17
+ <<-eos
18
+ <Request>
19
+ <DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>
20
+ <ExternalID>#{@args[:external_id]}</ExternalID>
21
+ <Test>#{(@args[:test] || false).to_s}</Test>
22
+ </Request>
23
+ eos
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../base'
2
+
3
+ module Cb
4
+ module Requests
5
+ module User
6
+ class TemporaryPassword < Base
7
+
8
+ def endpoint_uri
9
+ Cb.configuration.uri_user_temp_password
10
+ end
11
+
12
+ def http_method
13
+ :get
14
+ end
15
+
16
+ def query
17
+ {
18
+ 'ExternalID' => @args[:external_id]
19
+ }
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ module Cb
2
+ module Responses
3
+ module User
4
+
5
+ class ChangePassword < ApiResponse
6
+ class Model < Struct.new(:status) ; end
7
+
8
+ protected
9
+
10
+ def validate_api_hash
11
+ required_response_field(root_node, response)
12
+ required_response_field(request_node, response[root_node])
13
+ end
14
+
15
+ def extract_models
16
+ model = Model.new()
17
+ model.status = response[root_node][status_node]
18
+ model
19
+ end
20
+
21
+ def metadata_containing_node
22
+ response[root_node]
23
+ end
24
+
25
+ def hash_containing_metadata
26
+ response
27
+ end
28
+
29
+ private
30
+
31
+ def root_node
32
+ 'ResponseUserChangePW'
33
+ end
34
+
35
+ def request_node
36
+ 'Request'
37
+ end
38
+
39
+ def status_node
40
+ 'Status'
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ module Cb
2
+ module Responses
3
+ module User
4
+
5
+ class Delete < ApiResponse
6
+ class Model < Struct.new(:status) ; end
7
+
8
+ protected
9
+
10
+ def validate_api_hash
11
+ required_response_field(root_node, response)
12
+ required_response_field(request_node, response[root_node])
13
+ end
14
+
15
+ def extract_models
16
+ model = Model.new
17
+ model.status = response[root_node][status_node]
18
+ model
19
+ end
20
+
21
+ def metadata_containing_node
22
+ response[root_node]
23
+ end
24
+
25
+ def hash_containing_metadata
26
+ response
27
+ end
28
+
29
+ private
30
+
31
+ def root_node
32
+ 'ResponseUserDelete'
33
+ end
34
+
35
+ def request_node
36
+ 'Request'
37
+ end
38
+
39
+ def status_node
40
+ 'Status'
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ module Cb
2
+ module Responses
3
+ module User
4
+
5
+ class Retrieve < ApiResponse
6
+
7
+ protected
8
+
9
+ def validate_api_hash
10
+ required_response_field(root_node, response)
11
+ required_response_field(request_node, response[root_node])
12
+ end
13
+
14
+ def extract_models
15
+ Models::User.new response[root_node][user_info_node]
16
+ end
17
+
18
+ def metadata_containing_node
19
+ response[root_node]
20
+ end
21
+
22
+ def hash_containing_metadata
23
+ response
24
+ end
25
+
26
+ private
27
+
28
+ def root_node
29
+ 'ResponseUserInfo'
30
+ end
31
+
32
+ def request_node
33
+ 'Request'
34
+ end
35
+
36
+ def user_info_node
37
+ 'UserInfo'
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -28,27 +28,27 @@ module Cb
28
28
  self.class.headers.merge! ({'accept-encoding' => 'deflate, gzip'}) unless Cb.configuration.debug_api
29
29
  end
30
30
 
31
- def cb_get(path, options={})
31
+ def cb_get(path, options={}, &block)
32
32
  self.class.base_uri Cb.configuration.base_uri
33
- cb_event(:cb_get_before, path, options, nil)
33
+ cb_event(:cb_get_before, path, options, nil, &block)
34
34
  response = self.class.get(path, options)
35
- cb_event(:cb_get_after, path, options, response)
35
+ cb_event(:cb_get_after, path, options, response, &block)
36
36
  validate_response(response)
37
37
  end
38
38
 
39
- def cb_post(path, options={})
39
+ def cb_post(path, options={}, &block)
40
40
  self.class.base_uri Cb.configuration.base_uri
41
- cb_event(:cb_post_before, path, options, nil)
41
+ cb_event(:cb_post_before, path, options, nil, &block)
42
42
  response = self.class.post(path, options)
43
- cb_event(:cb_post_after, path, options, response)
43
+ cb_event(:cb_post_after, path, options, response, &block)
44
44
  validate_response(response)
45
45
  end
46
46
 
47
- def cb_put(path, options={})
47
+ def cb_put(path, options={}, &block)
48
48
  self.class.base_uri Cb.configuration.base_uri
49
- cb_event(:cb_put_before, path, options, nil)
49
+ cb_event(:cb_put_before, path, options, nil, &block)
50
50
  response = self.class.put(path, options)
51
- cb_event(:cb_put_after, path, options, response)
51
+ cb_event(:cb_put_after, path, options, response, &block)
52
52
  validate_response(response)
53
53
  end
54
54
 
@@ -110,9 +110,11 @@ module Cb
110
110
  Cb::Models::ApiCall.new(api_call_type, path, options, response)
111
111
  end
112
112
 
113
- def cb_event(api_call_type, path, options, response)
113
+ def cb_event(api_call_type, path, options, response, &block)
114
+ call_model = api_call_model(api_call_type, path, options, response)
115
+ block.call(call_model) if block_given?
114
116
  changed(true)
115
- notify_observers(api_call_model(api_call_type, path, options, response))
117
+ notify_observers(call_model)
116
118
  end
117
119
 
118
120
  def ensure_non_nil_metavalues(obj)
@@ -0,0 +1,31 @@
1
+ module Cb
2
+ module Utils
3
+ class ResponseMap
4
+ class << self
5
+ def response_for request_class
6
+ response_class = response_hash[request_class]
7
+ return response_class unless response_class.nil?
8
+ raise ResponseNotFoundError.new request_class
9
+ end
10
+
11
+ private
12
+
13
+ def response_hash
14
+ {
15
+ Cb::Requests::User::ChangePassword => Cb::Responses::User::ChangePassword,
16
+ Cb::Requests::User::CheckExisting => Cb::Responses::User::CheckExisting,
17
+ Cb::Requests::User::Delete => Cb::Responses::User::Delete,
18
+ Cb::Requests::User::Retrieve => Cb::Responses::User::Retrieve,
19
+ Cb::Requests::User::TemporaryPassword => Cb::Responses::User::TemporaryPassword
20
+ }
21
+ end
22
+
23
+ end
24
+ end
25
+ class ResponseNotFoundError < StandardError
26
+ def initialize(args)
27
+ super(args)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Cb
2
- VERSION = '6.3.3'
2
+ VERSION = '6.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cb-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.3
4
+ version: 6.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-07 00:00:00.000000000 Z
12
+ date: 2014-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -220,7 +220,10 @@ files:
220
220
  - lib/cb/responses/industry/search.rb
221
221
  - lib/cb/responses/api_response.rb
222
222
  - lib/cb/responses/user/check_existing.rb
223
+ - lib/cb/responses/user/delete.rb
224
+ - lib/cb/responses/user/change_password.rb
223
225
  - lib/cb/responses/user/temporary_password.rb
226
+ - lib/cb/responses/user/retrieve.rb
224
227
  - lib/cb/responses/timing.rb
225
228
  - lib/cb/responses/saved_search/list.rb
226
229
  - lib/cb/responses/saved_search/singular.rb
@@ -265,6 +268,12 @@ files:
265
268
  - lib/cb/models/implementations/spot.rb
266
269
  - lib/cb/models/implementations/email_subscription.rb
267
270
  - lib/cb/models/api_call_model.rb
271
+ - lib/cb/requests/user/check_existing.rb
272
+ - lib/cb/requests/user/delete.rb
273
+ - lib/cb/requests/user/change_password.rb
274
+ - lib/cb/requests/user/temporary_password.rb
275
+ - lib/cb/requests/user/retrieve.rb
276
+ - lib/cb/requests/base.rb
268
277
  - lib/cb/convenience.rb
269
278
  - lib/cb/clients/job_branding.rb
270
279
  - lib/cb/clients/recommendation.rb
@@ -282,12 +291,14 @@ files:
282
291
  - lib/cb/clients/anon_saved_search.rb
283
292
  - lib/cb/clients/spot.rb
284
293
  - lib/cb/clients/email_subscription.rb
294
+ - lib/cb/client.rb
285
295
  - lib/cb/utils/response_array_extractor.rb
286
296
  - lib/cb/utils/country.rb
287
297
  - lib/cb/utils/validator.rb
288
298
  - lib/cb/utils/meta_values.rb
289
299
  - lib/cb/utils/console_observer.rb
290
300
  - lib/cb/utils/api.rb
301
+ - lib/cb/utils/response_map.rb
291
302
  - lib/cb/utils/fluid_attributes.rb
292
303
  - README.md
293
304
  homepage: http://api.careerbuilder.com