Skip to content

hausgold/immoscout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Immoscout

Continuous Integration Gem Version Test Coverage Test Ratio API docs

This gem provides an API wrapper for the Immobilienscout24 REST API. It provides the well known ActiveRecord-like model methods.

Installation

Add this line to your application's Gemfile:

gem 'immoscout'

And then execute:

$ bundle

Or install it yourself as:

$ gem install immoscout

Usage

Configuration

Immoscout.configure do |config|
  config.consumer_key = "key"
  config.consumer_secret = "secret"
  config.oauth_token = "token"
  config.oauth_token_secret = "token_secret"
  config.use_sandbox = true # default: false
  config.user_name = "immoscout-user-name" # default: 'me'
end

Models

Real Estates

Currently supported: ApartmentBuy, HouseBuy

Overview supported actions
  • .find(id)
  • .all
  • .first
  • .last
  • .new(hash)
  • .from_raw(remote_hash_or_json)
  • .create(hash)
  • #save
  • #destroy
  • #publish
  • #unpublish
  • #place(placement_type)
  • #unplace(placement_type)
Initialize
# initialize with hash
house = Immoscout::Models::HouseBuy.new(title: "test", address: {street: "thestreet"})
# => #<Immoscout::Models::HouseBuy:0x0055c9fbbc6ea0 @address=#<Immoscout::Models::Parts::Address:0x0055c9fbbc6888 @street="thestreet">, @title="test">

# initialize with attribute writers
house = Immoscout::Models::HouseBuy.new
# => #<Immoscout::Models::HouseBuy:0x0055d31f734838>
house.title = "another title"
# => "another title"

# access nested attributes
house.build_address
# => #<Immoscout::Models::Parts::Address:0x0055c9fbc77d18>
house.address.street = "another street"

# lookup all allowed first-level attributes
house.attributes
# => [:address, :api_search_data, :building_energy_rating_type, ...]
house.address.attributes
# => [:city, :house_number, :postcode, :street, ...]
Find
apartment = Immoscout::Models::ApartmentBuy.find('ID')
# => #<Immoscout::Models::ApartmentBuy:0x0055c9fbfa0648>
apartment.address.street
# => 'Orig street name'
Create & Update & Destroy
apartment = Immoscout::Models::ApartmentBuy.find('ID')
apartment.address.street = "Changed street"
apartment.save
# => #<Immoscout::Models::ApartmentBuy:0x0055c9fbfa0648>

house = Immoscout::Models::HouseBuy.find('9473634')
house.destroy
# => #<Immoscout::Models::HouseBuy:0x0055d31f734838>
Publish & Unpublish
apartment = Immoscout::Models::ApartmentBuy.find('ID')
# => #<Immoscout::Models::ApartmentBuy:0x0055c9fbfa0648>
apartment.publish
# => #<Immoscout::Models::Publish:0x0085a2fbfa0688>
apartment.unpublish
# => #<Immoscout::Models::Publish:0x00831b2fbfc1234>
Ontop-Placement
# allowed placement types: showcaseplacement, premiumplacement, topplacement
apartment = Immoscout::Models::ApartmentBuy.find('ID')
# add premiumplacement
apartment.place(:premiumplacement)
# => #<Immoscout::Models::ApartmentBuy:0x0055c9fbfa0648>
# remove premiumplacement
apartment.unplace(:premiumplacement)
# => #<Immoscout::Models::ApartmentBuy:0x0055c9fbfa0648>

Contact

Overview supported actions
  • .find(id)
  • .all
  • .first
  • .last
  • .new(hash)
  • .from_raw(remote_hash_or_json)
  • .create(hash)
  • #save
  • #destroy
contact = Immoscout::Models::Contact.new firstname: "John", lastname: "Doe"
# => #<Immoscout::Models::Contact:0x0055c9fb889878 @firstname="John", @lastname="Doe">
contact.email = "john.doe@example.com"
contact.salutation = "MALE"
contact.save
# => #<Immoscout::Models::Contact:0x0055c9fb889878 @email="john.doe@example.com", @firstname="John", @lastname="Doe", @salutation="MALE">

Publish

If you don't like or can't use the #publish and #unpublish methods defined for realestate models, you can create the Publish instance yourself.

Overview supported actions
  • .new(hash)
  • .from_raw(remote_hash_or_json)
  • #save
  • #destroy
# NOTE: publish_channel#id = 10000 => publish on immobilienscout24
publish = Immoscout::Models::Publish.new real_estate: { id: "ID" }, publish_channel: {id: 10_000}

publish.save # published!
# => #<Immoscout::Models::Publish:0x0055c9faea1fb8>
publish.destroy # unpublished!
# => #<Immoscout::Models::Publish:0x0055c9faea1fb8>

Attachment (Picture & Document)

Overview supported actions
  • .new(hash)
  • .from_raw(remote_hash_or_json)
  • #save
  • #destroy
picture = Immoscout::Models::Picture.new title: "Badezimmer", title_picture: true, floor_plan: false
picture.file = File.open("the/path/to/the/file.jpg") #
picture.attachable = Immoscout::Models::HouseBuy.last # you can also pass the ID

picture.save # attachment upload!
# => #<Immoscout::Models::Picture:0x0055c9faea1fb8>

picture.destroy # attachment destroy!
# => #<Immoscout::Models::Picture:0x0055c9faea1fb8>

Development

After checking out the repo, run make install to install dependencies. Then, run make test to run the tests. You can also run make shell-irb for an interactive prompt that will allow you to experiment.

To run specs against the immobilienscout24 sandbox api, you need to create some keys and tokens. Copy the spec/test_config.yml.example to spec/test_config.yml and fill in your generated values.

Code of Conduct

Everyone interacting in the project codebase, issue tracker, chat rooms and mailing lists is expected to follow the code of conduct.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hausgold/immoscout. Make sure that every pull request adds a bullet point to the changelog file with a reference to the actual pull request.

Releasing

The release process of this Gem is fully automated. You just need to open the Github Actions Release Workflow and trigger a new run via the Run workflow button. Insert the new version number (check the changelog first for the latest release) and you're done.