Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ $ FIELDAGENT_SERVER=https://apistaging.sentera.com ruby upsert_feature_set.rb
| Ruby | `$ ruby import_files.rb` | `FIELDAGENT_ACCESS_TOKEN=PAmnCNUyosKShN9K1AEflLOw6T7bA2fRTWTg-vL3P5Y FIELDAGENT_SERVER=https://api.sentera.com FIELD_SENTERA_ID=agwmnou_AS_lk07AcmeOrg_CV_deve_773b47acb_240514_160730 FILE_PATH="../test_files/test.geojson" CONTENT_TYPE="application/json" ruby import_files.rb` |
| Ruby | `$ ruby upsert_feature_set.rb` | `FIELDAGENT_ACCESS_TOKEN=PAmnCNUyosKShN9K1AEflLOw6T7bA2fRTWTg-vL3P5Y FIELDAGENT_SERVER=https://api.sentera.com SURVEY_SENTERA_ID=mjlmmrw_CO_lk07AcmeOrg_CV_deve_773b47acb_240514_160730 GEOMETRY_PATH="../test_files/test.geojson" FILES_PATH="../test_files" FILE_EXT="*.jpeg" ruby upsert_feature_set.rb` |
| Ruby | `$ ruby upsert_files.rb` | `FIELDAGENT_ACCESS_TOKEN=PAmnCNUyosKShN9K1AEflLOw6T7bA2fRTWTg-vL3P5Y FIELDAGENT_SERVER=https://api.sentera.com FILE_PATH="../test_files/test.geojson" CONTENT_TYPE="application/json" FIELD_SENTERA_ID=agwmnou_AS_lk07AcmeOrg_CV_deve_773b47acb_240514_160730 ORGANIZATION_SENTERA_ID="jiqn6qi_OR_5qytAcmeOrg_CV_deve_0f569249e_250206_162717" ruby upsert_files.rb` |
| Ruby | `$ ruby upsert_images.rb` | `FIELDAGENT_ACCESS_TOKEN=PAmnCNUyosKShN9K1AEflLOw6T7bA2fRTWTg-vL3P5Y FIELDAGENT_SERVER=https://api.sentera.com IMAGES_PATH="../test_files" SURVEY_SENTERA_ID=mjlmmrw_CO_lk07AcmeOrg_CV_deve_773b47acb_240514_160730 FILE_EXT="*.jpeg" SENSOR_TYPE="RGB" ruby upsert_images.rb` |
| Ruby | `$ ruby upsert_mosaics.rb` | `FIELDAGENT_ACCESS_TOKEN=PAmnCNUyosKShN9K1AEflLOw6T7bA2fRTWTg-vL3P5Y FIELDAGENT_SERVER=https://api.sentera.com FILE_PATH="../test_files/test.tif" SURVEY_SENTERA_ID=mjlmmrw_CO_lk07AcmeOrg_CV_deve_773b47acb_240514_160730 ruby upsert_mosaics.rb` |
40 changes: 1 addition & 39 deletions api/import_feature_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'json'
require 'digest'
require '../utils/parallel'
require '../utils/upload'

# If you want to debug this script, run the following gem install
# commands. Then uncomment the require statements below, and put
Expand Down Expand Up @@ -138,45 +139,6 @@ def create_file_uploads(file_paths, survey_sentera_id, feature_set_sentera_id)
json.dig('data', 'create_file_uploads')
end

#
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see that I moved these upload_file and upload_files methods out of the sample scripts into utils/upload.rb.

# This method demonstrates how to upload a file to
# Sentera's cloud storage using the URL and headers
# that were retrieved via the create_file_upload
# GraphQL mutation.
#
# @param [Array[Object]] file_uploads FileUpload GraphQL
# objects created by the
# create_file_uploads mutation
# @param [Array[string]] file_paths Array of paths to
# the files to upload
#
# @return [void]
#
def upload_files(file_uploads, file_paths)
puts 'Upload files'

file_uploads_map = {}
file_uploads.each.with_index do |file_upload, index|
file_path = file_paths[index]
file_uploads_map[file_path] = file_upload
end

Parallel.each(file_paths, in_threads: 6) do |file_path|
file_upload = file_uploads_map[file_path]

uri = URI(file_upload['upload_url'])
file_contents = File.read(file_path)
Net::HTTP.start(uri.host) do |http|
puts "Upload #{file_path} to S3"
response = http.send_request('PUT',
uri,
file_contents,
file_upload['headers'])
puts "Done uploading #{file_path}, response.code = #{response.code}"
end
end
end

#
# This method demonstrates how to use the IDs of the files that
# were previously uploaded to Sentera's cloud storage with the
Expand Down
40 changes: 1 addition & 39 deletions api/import_feature_set_legacy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'json'
require 'digest'
require '../utils/parallel'
require '../utils/upload'

# If you want to debug this script, run the following gem install
# commands. Then uncomment the require statements below, and put
Expand Down Expand Up @@ -116,45 +117,6 @@ def create_file_uploads(file_paths)
json.dig('data', 'create_file_uploads')
end

#
# This method demonstrates how to upload a file to
# Sentera's cloud storage using the URL and headers
# that were retrieved via the create_file_upload
# GraphQL mutation.
#
# @param [Array[Object]] file_uploads FileUpload GraphQL
# objects created by the
# create_file_uploads mutation
# @param [Array[string]] file_paths Array of paths to
# the files to upload
#
# @return [void]
#
def upload_files(file_uploads, file_paths)
puts 'Upload files'

file_uploads_map = {}
file_uploads.each.with_index do |file_upload, index|
file_path = file_paths[index]
file_uploads_map[file_path] = file_upload
end

Parallel.each(file_paths, in_threads: 6) do |file_path|
file_upload = file_uploads_map[file_path]

uri = URI(file_upload['upload_url'])
file_contents = File.read(file_path)
Net::HTTP.start(uri.host) do |http|
puts "Upload #{file_path} to S3"
response = http.send_request('PUT',
uri,
file_contents,
file_upload['headers'])
puts "Done uploading #{file_path}, response.code = #{response.code}"
end
end
end

#
# This method demonstrates how to use the IDs of the files that
# were previously uploaded to Sentera's cloud storage with the
Expand Down
30 changes: 1 addition & 29 deletions api/import_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require 'net/http'
require 'json'
require 'digest'

require '../utils/upload'

# If you want to debug this script, run the following gem install
# commands. Then uncomment the require statements below, and put
Expand Down Expand Up @@ -73,34 +73,6 @@ def create_file_upload(file_path, content_type)
json.dig('data', 'create_file_upload')
end

#
# This method demonstrates how to upload a file to
# Sentera's cloud storage using the URL and headers
# that were retrieved via the create_file_upload
# GraphQL mutation.
#
# @param [Object] file_upload FileUpload GraphQL
# object created by the
# create_file_upload mutation
# @param [string] file_path Path of the file to upload
#
# @return [void]
#
def upload_file(file_upload, file_path)
puts 'Upload file'

uri = URI(file_upload['upload_url'])
file_contents = File.read(file_path)
Net::HTTP.start(uri.host) do |http|
puts "Upload #{file_path} to S3"
response = http.send_request('PUT',
uri,
file_contents,
file_upload['headers'])
puts "Done uploading #{file_path}, response.code = #{response.code}"
end
end

#
# This method demonstrates how to use the ID of the file that
# was previously uploaded to Sentera's cloud storage with the
Expand Down
41 changes: 1 addition & 40 deletions api/upsert_feature_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'json'
require 'digest'
require '../utils/parallel'
require '../utils/upload'

# If you want to debug this script, run the following gem install
# commands. Then uncomment the require statements below, and put
Expand Down Expand Up @@ -130,46 +131,6 @@ def create_file_uploads(file_paths, survey_sentera_id)
json.dig('data', 'create_file_uploads')
end

#
# This method demonstrates how to upload a file to
# Sentera's cloud storage using the URL and headers
# that were retrieved via the create_file_upload
# GraphQL mutation.
#
# @param [Array[Object]] file_uploads FileUpload GraphQL
# objects created by the
# create_file_uploads mutation
# @param [Array[string]] file_paths Array of paths to
# the files to upload
#
# @return [void]
#
def upload_files(file_uploads, file_paths)
puts 'Upload files'

file_uploads_map = file_uploads.each_with_object({}) do |file_upload, map|
s3_url = file_upload['s3_url']
filename = File.basename(s3_url)
map[filename] = file_upload
end

Parallel.each(file_paths, in_threads: 6) do |file_path|
filename = File.basename(file_path)
file_upload = file_uploads_map[filename]

uri = URI(file_upload['upload_url'])
file_contents = File.read(file_path)
Net::HTTP.start(uri.host) do |http|
puts "Upload #{file_path} to S3"
response = http.send_request('PUT',
uri,
file_contents,
file_upload['headers'])
puts "Done uploading #{file_path}, response.code = #{response.code}"
end
end
end

#
# This method demonstrates how to use the IDs of the files that
# were previously uploaded to Sentera's cloud storage with the
Expand Down
30 changes: 1 addition & 29 deletions api/upsert_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require 'net/http'
require 'json'
require 'digest'

require '../utils/upload'

# If you want to debug this script, run the following gem install
# commands. Then uncomment the require statements below, and put
Expand Down Expand Up @@ -87,34 +87,6 @@ def create_file_upload(file_path, content_type, field_sentera_id, organization_s
json.dig('data', 'create_file_upload')
end

#
# This method demonstrates how to upload a file to
# Sentera's cloud storage using the URL and headers
# that were retrieved via the create_file_upload
# GraphQL mutation.
#
# @param [Object] file_upload FileUpload GraphQL
# object created by the
# create_file_upload mutation
# @param [string] file_path Path of the file to upload
#
# @return [void]
#
def upload_file(file_upload, file_path)
puts 'Upload file'

uri = URI(file_upload['upload_url'])
file_contents = File.read(file_path)
Net::HTTP.start(uri.host) do |http|
puts "Upload #{file_path} to S3"
response = http.send_request('PUT',
uri,
file_contents,
file_upload['headers'])
puts "Done uploading #{file_path}, response.code = #{response.code}"
end
end

#
# This method demonstrates how to attach the previously uploaded
# file to a field by using the upsert_files GraphQL mutation.
Expand Down
Loading