Ver Fonte

add jpg as renderType to phantomjscloud setting

convexshiba há 6 anos atrás
pai
commit
8fb396fd30

+ 2 - 2
app/models/agents/phantom_js_cloud_agent.rb

@@ -26,7 +26,7 @@ module Agents
       * `Api key` - PhantomJs Cloud API Key credential stored in Huginn
       * `Url` - The url to render
       * `Mode` - Create a new `clean` event or `merge` old payload with new values (default: `clean`)
-      * `Render type` - Render as html or plain text without html tags (default: `html`)
+      * `Render type` - Render as html, plain text without html tags, or jpg as screenshot of the page (default: `html`)
       * `Output as json` - Return the page conents and metadata as a JSON object (default: `false`)
       * `Ignore images` - Skip loading of inlined images (default: `false`)
       * `Url agent` - A custom User-Agent name (default: `#{default_user_agent}`)
@@ -59,7 +59,7 @@ module Agents
     form_configurable :mode, type: :array, values: ['clean', 'merge']
     form_configurable :api_key, roles: :completable
     form_configurable :url
-    form_configurable :render_type, type: :array, values: ['html', 'plainText']
+    form_configurable :render_type, type: :array, values: ['html', 'plainText', 'jpg']
     form_configurable :output_as_json, type: :boolean
     form_configurable :ignore_images, type: :boolean
     form_configurable :user_agent, type: :text

+ 11 - 0
spec/models/agents/phantom_js_cloud_agent_spec.rb

@@ -55,6 +55,17 @@ describe Agents::PhantomJsCloudAgent do
       expect(item.payload['url']).to eq("https://phantomjscloud.com/api/browser/v2/1234567890/?request=%7B%22url%22%3A%22http%3A%2F%2Fxkcd.com%22%2C%22renderType%22%3A%22plainText%22%2C%22requestSettings%22%3A%7B%22userAgent%22%3A%22Huginn%20-%20https%3A%2F%2Fgithub.com%2Fhuginn%2Fhuginn%22%7D%7D")
     end
 
+    it "should set render type as jpg" do
+      @checker.options['render_type'] = 'jpg'
+
+      expect {
+        @checker.check
+      }.to change { @checker.events.count }.by(1)
+
+      item,* = @checker.events.last(1)
+      expect(item.payload['url']).to eq("https://phantomjscloud.com/api/browser/v2/1234567890/?request=%7B%22url%22%3A%22http%3A%2F%2Fxkcd.com%22%2C%22renderType%22%3A%22jpg%22%2C%22requestSettings%22%3A%7B%22userAgent%22%3A%22Huginn%20-%20https%3A%2F%2Fgithub.com%2Fhuginn%2Fhuginn%22%7D%7D")
+    end
+
     it "should set output as json" do
       @checker.options['output_as_json'] = true