Sha256: 94f8e0f6efd385d96437d8ef135b94352cb8d79c4ee5dfec491f18dc8696928d

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module RDStation
  # More info: https://developers.rdstation.com/pt-BR/reference/fields
  class Fields
    include HTTParty
    include ::RDStation::RetryableRequest

    def initialize(authorization:)
      @authorization = authorization
    end

    def all
      retryable_request(@authorization) do |authorization|
        response = self.class.get(base_url, headers: authorization.headers)
        ApiResponse.build(response)
      end
    end

    def create(payload)
      retryable_request(@authorization) do |authorization|
        response = self.class.post(base_url, headers: authorization.headers, body: payload.to_json)
        ApiResponse.build(response)
      end
    end

    def update(uuid, payload)
      retryable_request(@authorization) do |authorization|
        response = self.class.patch(base_url(uuid), headers: authorization.headers, body: payload.to_json)
        ApiResponse.build(response)
      end
    end

    def delete(uuid)
      retryable_request(@authorization) do |authorization|
        response = self.class.delete(base_url(uuid), headers: authorization.headers)
        ApiResponse.build(response)
      end
    end

    private

    def base_url(path = '')
      "#{RDStation.host}/platform/contacts/fields/#{path}"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rdstation-ruby-client-2.9.0 lib/rdstation/fields.rb
rdstation-ruby-client-2.8.2 lib/rdstation/fields.rb
rdstation-ruby-client-2.8.1 lib/rdstation/fields.rb
rdstation-ruby-client-2.8.0 lib/rdstation/fields.rb
rdstation-ruby-client-2.7.0 lib/rdstation/fields.rb
rdstation-ruby-client-2.6.0 lib/rdstation/fields.rb
rdstation-ruby-client-2.5.3 lib/rdstation/fields.rb