Sha256: bb5f906df5cca9da9747b321fecbbaaf7772572066871c7ba1a8fb7c4506577d

Contents?: true

Size: 1.98 KB

Versions: 12

Compression:

Stored size: 1.98 KB

Contents

<div class="container">
  <% if @error.present? %>
    <h3><%= @error.message %></h3>
  <% else %>
    <h3 class="text-center">Select File</h3>
    <p>You can take an example of file <%= link_to "here", download_path, target: "_blank"%>.</p>
    <% if flash[:notice] %>
      <div class="notice"><%= flash[:notice] %></div>
    <% end %>
    <%= form_tag('/imports', method: 'post', multipart: true) do %>
      <%= file_field_tag(:file) %>
      <%= submit_tag("Upload") %>
    <% end %>

    <pre>
module Services
  module Hubspot
    module Imports
      class Create
        def initialize(uploaded_file:)
          @file = copy_file_to_uploads(uploaded_file)
          @filename = uploaded_file.original_filename
        end

        def call
          core_api = ::Hubspot::Crm::Imports::CoreApi.new
          core_api.create(import_request: import_request(@filename), files: @file, auth_names: 'oauth2')
        end

        private

        def import_request(filename)
          {
            "name": "test_import",
            "files": [
              {
                "fileName": filename,
                "fileImportPage": {
                  "hasHeader": true,
                  "columnMappings": [
                    {
                      "columnName": "First Name",
                      "propertyName": "firstname",
                      "columnObjectType": "CONTACT",
                    },
                    {
                      "columnName": "Email",
                      "propertyName": "email",
                      "columnObjectType": "CONTACT",
                    },
                  ]
                }
              }
            ]
          }.to_json
        end

        def copy_file_to_uploads(uploaded_file)
          tmp = uploaded_file.tempfile
          destiny_file = File.join('public', 'uploads', uploaded_file.original_filename)
          FileUtils.cp tmp.path, destiny_file
          File.open(destiny_file)
        end
      end
    end
  end
end
    </pre>
  <% end %>
</div>

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-8.0.1 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-8.0.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-7.3.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-7.2.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-7.1.1 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-7.1.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-7.0.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-6.0.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-5.0.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-4.0.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb
hubspot-api-client-3.3.0 sample-apps/imports-contacts-app/app/views/imports/index.html.erb