Module: Immobilienscout24::Api::Attachment

Included in:
Immobilienscout24::Api
Defined in:
lib/immobilienscout24/api/attachment.rb

Overview

Methods for the Attachment API

For all methods you must provide the immoscout estate id in the options hash.

Per default the client will use the current user (‘me`). If you want to use an other user then you have to provide the id in the options hash.

Examples:

client.attachment(663515214, estate: estate_id)
client.attachment(663515214, estate: estate_id, user: immoscout_user_id)

See Also:

Instance Method Summary collapse

Instance Method Details

#attachment(id, options = {}) ⇒ Hashie::Mash

Get an attachment by id

Examples:

client.attachment(663515214, estate: 62412598)

Parameters:

  • id (String, Integer)

    Attachment id

  • options (Hash) (defaults to: {})

    Additional options

Returns:

  • (Hashie::Mash)

    Immobilienscout24 response

See Also:



40
41
42
# File 'lib/immobilienscout24/api/attachment.rb', line 40

def attachment(id, options = {})
  get attachment_endpoint("/attachment/#{id}", options)
end

#attachment_endpoint(resource, options = {}) ⇒ String

Generates the attachment endpoint

Parameters:

  • resource (String, Integer)

    In most cases the id of the attachment

  • options (Hash) (defaults to: {})

    Additional options

Returns:

  • (String)

    The url to the attachment resource



94
95
96
97
# File 'lib/immobilienscout24/api/attachment.rb', line 94

def attachment_endpoint(resource, options = {})
  estate = options.fetch(:estate)
  estate_attachment_endpoint(estate, resource, options)
end

#attachments(options = {}) ⇒ Hashie::Mash

Get a list of all attachments

Examples:

client.attachments(estate: 62412598)

Parameters:

  • options (Hash) (defaults to: {})

    Additional options

Returns:

  • (Hashie::Mash)

    Immobilienscout24 response

See Also:



28
29
30
# File 'lib/immobilienscout24/api/attachment.rb', line 28

def attachments(options = {})
  get attachment_endpoint("/attachment", options)
end

#create_attachment(metadata, attachment, options = {}) ⇒ Hashie::Mash

Create an attachment

Examples:

client.create_attachment(matadata, 'path/to/attachment.jpg', estate: 62412598)

Parameters:

  • metadata (Hash)

    Object that contains the information about the attachment (title etc.)

  • attachment (String, Hash, Array, Attachment, File)

    Contains the file information

  • options (Hash) (defaults to: {})

    Additional options

Returns:

  • (Hashie::Mash)

    Immobilienscout24 response

See Also:



53
54
55
56
57
58
59
60
# File 'lib/immobilienscout24/api/attachment.rb', line 53

def create_attachment(, attachment, options = {})
  attachment = ::Immobilienscout24::Helper::Attachment.new(attachment)
  multipart  = {metadata: , attachment: attachment.build}

  with_request_options(multipart: true) do |client|
    client.post attachment_endpoint("/attachment", options), multipart
  end
end

#delete_attachment(id, options = {}) ⇒ Hashie::Mash

Delete an attachment

Examples:

client.delete_attachment(663515214, estate: 62412598)

Parameters:

  • id (String, Integer)

    Attachment id

  • options (Hash) (defaults to: {})

    Additional options

Returns:

  • (Hashie::Mash)

    Immobilienscout24 response

See Also:



83
84
85
# File 'lib/immobilienscout24/api/attachment.rb', line 83

def delete_attachment(id, options = {})
  delete attachment_endpoint("/attachment/#{id}", options)
end

#estate_attachment_endpoint(estate, resource, options = {}) ⇒ Object



99
100
101
# File 'lib/immobilienscout24/api/attachment.rb', line 99

def estate_attachment_endpoint(estate, resource, options = {})
  [real_estate_endpoint("/realestate/#{estate}", options), resource].join
end

#update_attachment(id, attachment, options = {}) ⇒ Hashie::Mash

Update an attachment

Examples:

client.update_attachment(663515214, attachment, estate: 62412598)

Parameters:

  • id (String, Integer)

    Attachment id

  • attachment (Hash)

    Attachment meta data to be updated (title etc.). You can’t upload a new file.

  • options (Hash) (defaults to: {})

    Additional options

Returns:

  • (Hashie::Mash)

    Immobilienscout24 response

See Also:



71
72
73
# File 'lib/immobilienscout24/api/attachment.rb', line 71

def update_attachment(id, attachment, options = {})
  put attachment_endpoint("/attachment/#{id}", options), attachment
end