Class: ScreenshotScout::Client
- Inherits:
-
Object
- Object
- ScreenshotScout::Client
- Defined in:
- lib/screenshotscout/client.rb,
sig/screenshotscout.rbs
Overview
Reusable blocking client for the inline Screenshot Scout capture operation.
Instance Method Summary collapse
-
#build_capture_url(url, options = nil) ⇒ String
Builds a sensitive GET capture URL without performing network I/O.
-
#capture(url, options = nil, method: CaptureHttpMethod::POST) ⇒ Object
Sends one GET or POST request and waits for the final inline response.
-
#initialize(access_key: MISSING_ACCESS_KEY, secret_key: nil, transport: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(access_key: MISSING_ACCESS_KEY, secret_key: nil, transport: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 |
# File 'lib/screenshotscout/client.rb', line 12 def initialize(access_key: MISSING_ACCESS_KEY, secret_key: nil, transport: nil) validate_access_key(access_key) validate_secret_key(secret_key) validate_transport(transport) @access_key = access_key.dup.freeze @secret_key = secret_key&.dup&.freeze @transport = transport || NetHttpTransport.new end |
Instance Method Details
#build_capture_url(url, options = nil) ⇒ String
Builds a sensitive GET capture URL without performing network I/O.
38 39 40 41 42 43 44 |
# File 'lib/screenshotscout/client.rb', line 38 def build_capture_url(url, = nil) serialized = Internal::Serializer.serialize(url, ) signature = create_signature(serialized.pairs) pairs = [Internal::WirePair.new(name: "access_key", value: @access_key), *serialized.pairs] pairs << Internal::WirePair.new(name: "signature", value: signature) unless signature.nil? "#{CAPTURE_ENDPOINT}?#{Internal::Serializer.encode_query(pairs)}" end |
#capture(url, options = nil, method: CaptureHttpMethod::POST) ⇒ Object
Sends one GET or POST request and waits for the final inline response.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/screenshotscout/client.rb', line 23 def capture(url, = nil, method: CaptureHttpMethod::POST) serialized = Internal::Serializer.serialize(url, ) method = CaptureHttpMethod::POST if method.nil? validate_method(method) expected_kind = expected_response_kind() signature = create_signature(serialized.pairs) request = create_request(serialized, method, signature) raw_response = execute_request(request) raise create_api_error(raw_response) unless raw_response.status.between?(200, 299) decode_success_response(raw_response, expected_kind) end |