Class: Pdfserve::Stamp
- Inherits:
-
Object
- Object
- Pdfserve::Stamp
- Defined in:
- lib/pdfserve/stamp.rb
Constant Summary collapse
- PATH =
"/api/v1/pdf/stamp"
Instance Method Summary collapse
- #call(file_url, stamp_text) ⇒ Object
-
#initialize(api_endpoint:, api_token: nil) ⇒ Stamp
constructor
A new instance of Stamp.
Constructor Details
Instance Method Details
#call(file_url, stamp_text) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pdfserve/stamp.rb', line 19 def call(file_url, stamp_text) uri = URI(api_endpoint) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" request = Net::HTTP::Post.new(uri.request_uri) request["token"] = api_token unless api_token.nil? form_data = [ ["files", file_url], ["stamp_text", { "text" => stamp_text, "color" => "0,0,0", "position_name" => "tr", "over" => "true" }.to_json] ] request.set_form form_data, "multipart/form-data" response = http.request(request) if response.is_a?(Net::HTTPSuccess) puts "Successful stamp!" OpenStruct.new( success: true, response: response.body, errors: "" ) else puts "Failed!" OpenStruct.new( success: false, response: response.body, errors: response. ) end end |