Class: Fusion::Client
- Inherits:
-
Object
- Object
- Fusion::Client
- Defined in:
- lib/fusion/client.rb,
lib/fusion/client/version.rb
Constant Summary collapse
- URL =
'https://fusionpro1450.cloudapp.net/FusionProRestService/'- VERSION =
"1.0.0"
Class Attribute Summary collapse
-
.password ⇒ Object
Returns the value of attribute password.
-
.username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #add_job(template:, data:, proof:) ⇒ Object
- #bypass_timer(job_id:) ⇒ Object
- #cancel_job(job_id:) ⇒ Object
- #handle_response(response, request, result) ⇒ Object
-
#initialize(username: nil, password: nil) ⇒ Client
constructor
A new instance of Client.
- #logoff ⇒ Object
-
#logon ⇒ Object
private.
- #request(method, params, path) ⇒ Object
Constructor Details
Class Attribute Details
.password ⇒ Object
Returns the value of attribute password.
11 12 13 |
# File 'lib/fusion/client.rb', line 11 def password @password end |
.username ⇒ Object
Returns the value of attribute username.
11 12 13 |
# File 'lib/fusion/client.rb', line 11 def username @username end |
Class Method Details
.configure {|_self| ... } ⇒ Object
13 14 15 |
# File 'lib/fusion/client.rb', line 13 def configure yield self end |
Instance Method Details
#add_job(template:, data:, proof:) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/fusion/client.rb', line 23 def add_job(template:, data:, proof:) logon path = "addjob?templatename=#{template}&sessionid=#{@session_id}&bReturnSingleProof=#{proof}" params = data response = request(:post, params, path) response['response'] end |
#bypass_timer(job_id:) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/fusion/client.rb', line 40 def bypass_timer(job_id:) logon path = 'bypasstimer' params = { JobID: job_id, SessionID: @session_id } request(:post, params, path) end |
#cancel_job(job_id:) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/fusion/client.rb', line 32 def cancel_job(job_id:) logon path = 'canceljob' params = { JobID: job_id, SessionID: @session_id } request(:post, params, path) end |
#handle_response(response, request, result) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fusion/client.rb', line 67 def handle_response(response, request, result) case response.code when 200..299 JSON.parse(response) when 400 raise RestClient::BadRequest, response when 404 raise RestClient::ResourceNotFound, response when 500 raise RestClient::InternalServerError, response else puts response.inspect puts request.inspect raise result.to_s end end |
#logoff ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fusion/client.rb', line 84 def logoff return unless @session_id.present? path = 'logoff' params = { SessionID: @session_id } begin request(:post, params, path) rescue => e # We don't really care if logoff failed. Log it and move on. Rails.logger.debug(e.) end end |
#logon ⇒ Object
private
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fusion/client.rb', line 100 def logon return if @session_id.present? path = 'logon' params = { UserID: Client.username, Password: Client.password } response = request(:post, params, path) @session_id = response['SessionID'] raise response['Message'].inspect unless @session_id.present? response end |
#request(method, params, path) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fusion/client.rb', line 49 def request(method, params, path) raise 'You need to configure Fusion::Client with your username and password.' unless Client.username && Client.password path ||= default_path url = URL url += path if params.is_a?(Hash) params = params.to_json content_type = 'application/json' else content_type = 'application/octet-stream' end RestClient::Request.execute(:method => method, :url => url, payload: params, :headers => {:accept => :json, content_type: content_type}, :timeout => nil, :verify_ssl => false) { |response, request, result, &block| handle_response(response, request, result) } end |