Class: Simplprinter::Requester
- Inherits:
-
Object
- Object
- Simplprinter::Requester
- Defined in:
- lib/simplprinter/requester.rb
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#callback_url ⇒ Object
Returns the value of attribute callback_url.
-
#jobs_arr ⇒ Object
Returns the value of attribute jobs_arr.
-
#mandate_id ⇒ Object
Returns the value of attribute mandate_id.
-
#simplprinter_base_url ⇒ Object
Returns the value of attribute simplprinter_base_url.
Instance Method Summary collapse
- #add_job(content, opt = {}) ⇒ Object
-
#initialize(mandate_id, api_token, callback_url, simplprinter_base_url = "http://app.simplprinter.ch") ⇒ Requester
constructor
A new instance of Requester.
- #send_it ⇒ Object
Constructor Details
#initialize(mandate_id, api_token, callback_url, simplprinter_base_url = "http://app.simplprinter.ch") ⇒ Requester
Returns a new instance of Requester.
6 7 8 9 10 11 12 |
# File 'lib/simplprinter/requester.rb', line 6 def initialize(mandate_id, api_token, callback_url, simplprinter_base_url="http://app.simplprinter.ch") self.mandate_id = mandate_id self.api_token = api_token self.callback_url = callback_url self.simplprinter_base_url = simplprinter_base_url self.jobs_arr = [] end |
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
4 5 6 |
# File 'lib/simplprinter/requester.rb', line 4 def api_token @api_token end |
#callback_url ⇒ Object
Returns the value of attribute callback_url.
4 5 6 |
# File 'lib/simplprinter/requester.rb', line 4 def callback_url @callback_url end |
#jobs_arr ⇒ Object
Returns the value of attribute jobs_arr.
4 5 6 |
# File 'lib/simplprinter/requester.rb', line 4 def jobs_arr @jobs_arr end |
#mandate_id ⇒ Object
Returns the value of attribute mandate_id.
4 5 6 |
# File 'lib/simplprinter/requester.rb', line 4 def mandate_id @mandate_id end |
#simplprinter_base_url ⇒ Object
Returns the value of attribute simplprinter_base_url.
4 5 6 |
# File 'lib/simplprinter/requester.rb', line 4 def simplprinter_base_url @simplprinter_base_url end |
Instance Method Details
#add_job(content, opt = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/simplprinter/requester.rb', line 14 def add_job(content, opt={}) require 'ostruct' j = OpenStruct.new j.action = opt.fetch(:action, 'print_pdf') j.template = opt.fetch(:template, 'a4_portrait_standard') j.isdraft = opt.fetch(:isdraft, 'true') j.uuid = opt.fetch(:uuid, '') j.callback_url = opt.fetch(:callback_url, self.callback_url) j.content = content default_keys = ["action", "template", "isdraft", "uuid", "callback_url"] opt.keys.each do |key| j["#{key}"] = opt["#{key}".to_sym()] if !default_keys.include?("#{key}") end job = j.marshal_dump jobs_arr << job job end |
#send_it ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/simplprinter/requester.rb', line 37 def send_it require "uri" require "net/http" u = URI.parse("#{self.simplprinter_base_url}?access_token=#{self.api_token}&mandate_id=#{self.mandate_id}") payload = { 'jobs' => self.jobs_arr.to_json } resp = Net::HTTP.post_form(u, payload) resp end |