Class: MoreappAPI::RegistrationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/moreapp_api/registration_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(customer) ⇒ RegistrationFile

Returns a new instance of RegistrationFile.



5
6
7
# File 'lib/moreapp_api/registration_file.rb', line 5

def initialize(customer)
  @customer = customer
end

Instance Method Details

#post(filename, content_type = 'image/png') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/moreapp_api/registration_file.rb', line 9

def post(filename, content_type = 'image/png')
  # !!! Undocumented more-app API

  image_data = Base64.encode64(File.open(filename, "rb").read)

  response = @customer.moreapp_api.request(:post, "/api/v1.0/client/registrations/files/base64", nil, {},
                              {
                                  customerNumber: customer.id,
                                  base64FileContent: "data:#{content_type};base64," + image_data,
                                  filename: File.basename(filename)
                              }.to_json,
                              { 'Content-Type' => 'application/json' } )

  # returns a body containing the location of the image. Looks something like "gridfs://registrationFiles/#{image_location_id}"
  # which can then be used as a value for a "photo" - field
  response.body
end