Created
December 30, 2016 16:14
-
-
Save therealjasonkenney/e919ca15611af2400e0570dab5217f20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Etl | |
module CasUrl | |
class UnsuccessfulResponseError < ::StandardError; end | |
class Base | |
private_class_method :new | |
private | |
attr_reader :applicant_id, :cas_id, :response | |
def initialize(applicant_id, cas_id) | |
@applicant_id = applicant_id | |
@cas_id = cas_id | |
end | |
def response_dump | |
[response.body, response.code, response.message, response.headers.inspect].join("\n") | |
end | |
def request_etl | |
@response = self.class.post("#{applicant_id}/#{cas_id}") | |
raise UnsuccessfulResponseError, response_dump unless success? | |
end | |
def success? | |
response.body == 'SUCCESS' | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Etl.configure do |c| | |
old_url = CasUrl::Factory.build(ENV.fetch('CAS3_0_ONE_BUTTON', 'default_url')) | |
new_url = CasUrl::Factory.build(ENV.fetch('CAS3_1_ONE_BUTTON', 'default_url')) | |
c.cas_url = { | |
1121: old_url, | |
1116: old_url, | |
1122: old_url, | |
1117: old_url, | |
1: old_url, | |
default: new_url | |
} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Etl | |
module CasUrl | |
class Factory | |
private_class_method :new | |
def self.build(base_url) | |
Class.new(CasUrl::Base) do | |
include HTTParty | |
base_uri("#{base_url}/generateXMLAndPushToMQL2") | |
define_singleton_method :request_etl! do |applicant_id:, cas_id:| | |
new(applicant_id, cas_id).send(:request_etl) | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Etl | |
class RequeueApplicantJob | |
include Resque::Plugins::Status | |
def self.perform | |
at(1,2,'Requesting from CAS Server') | |
cas_url_for(cas_id).request_etl!(applicant_id: applicant_id, cas_id: cas_id) | |
at(2,2, 'Applicant is back on the queue.') | |
end | |
private | |
def applicant_id | |
options.fetch('applicant_id') | |
end | |
def cas_id | |
options.fetch('cas_id') | |
end | |
def cas_url_for(cas_id) | |
Etl.configuration.cas_url[cas_id.to_sym] || Etl.configuration.cas_url.fetch(:default) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So you just need to do: