Sha256: f7933b289826410808929de91146fa97a92a826a5e3f43386c9ec742586d0166

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module HubSpot
  module HTTPApiCalls
    module Contact
      class CreateOrUpdate
        include ::HubSpot::HTTPApiCalls::Base
        URL = "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/%<email>s"

        def initialize(properties)
          @properties = properties
        end

        private

        attr_reader :properties

        def make_the_call
          response = HubSpot::HTTP.post(url: url, headers: headers, post_body: post_body)
          puts response
          response
        end

        def url
          format(URL, email: email)
        end

        def email
          properties.fetch("email")
        end

        def headers
          default_headers.merge(HubSpot::HTTP::AUTHORIZATION => auth_header_value)
        end

        def auth_header_value
          "Bearer #{HubSpot::OAuth.access_token}"
        end

        def post_body
          { "properties" => properties_array }
        end

        def properties_array
          properties.map { |k, v| { "property" => k.to_s, "value" => v } }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hub_spot-0.2.0 lib/hub_spot/http_api_calls/contact/create_or_update.rb