Sha256: c68eb306346c054403bd1d94cfe0fc0d25e7da6b44c2bff71251bd28f147a9c9

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

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

    BASE_URL = 'https://api.rd.services/platform/contacts/fields'.freeze

    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 = '')
      "#{BASE_URL}/#{path}"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rdstation-ruby-client-2.5.1 lib/rdstation/fields.rb
rdstation-ruby-client-2.5.0 lib/rdstation/fields.rb
rdstation-ruby-client-2.4.0 lib/rdstation/fields.rb
rdstation-ruby-client-2.3.1 lib/rdstation/fields.rb
rdstation-ruby-client-2.3.0 lib/rdstation/fields.rb