Sha256: 03294565c4e5d70fea612ddf1332e9692e64718db4d36332a0d631c6dd7ccbde

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module ActionNetworkRest
  class Signatures < Base
    class CreateError < StandardError; end

    attr_accessor :petition_id

    def base_path
      "petitions/#{url_escape(petition_id)}/signatures/"
    end

    def create(signature_data, tags: [])
      post_body = signature_data
      post_body['add_tags'] = tags if tags.any?

      response = client.post_request(base_path, post_body)
      new_signature = object_from_response(response)

      # Action Network treats the signature create helper endpoint as an unauthenticated
      # "blind" POST (see https://actionnetwork.org/docs/v2/unauthenticated-post/). For this
      # reason they don't return a status code with error to avoid leaking private data. Instead
      # they return 200 OK with an empty body (vs. the newly created signature's data for successful calls)
      raise CreateError if new_signature.empty?

      new_signature
    end

    def update(id, signature_data)
      response = client.put_request("#{base_path}#{url_escape(id)}", signature_data)
      object_from_response(response)
    end

    private

    def osdi_key
      'osdi:signatures'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
action_network_rest-0.12.0 lib/action_network_rest/signatures.rb
action_network_rest-1.0.1 lib/action_network_rest/signatures.rb
action_network_rest-1.0.0 lib/action_network_rest/signatures.rb
action_network_rest-0.11.0 lib/action_network_rest/signatures.rb
action_network_rest-0.10.0 lib/action_network_rest/signatures.rb
action_network_rest-0.9.0 lib/action_network_rest/signatures.rb