This gem provides an API wrapper for the Immobilienscout24 REST API. It provides the well known ActiveRecord-like model methods.
Add this line to your application's Gemfile:
gem 'immoscout'
And then execute:
$ bundle
Or install it yourself as:
$ gem install immoscout
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
Currently supported: ApartmentBuy
, HouseBuy
- .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 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, ...]
apartment = Immoscout::Models::ApartmentBuy.find('ID')
# => #<Immoscout::Models::ApartmentBuy:0x0055c9fbfa0648>
apartment.address.street
# => 'Orig street name'
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>
apartment = Immoscout::Models::ApartmentBuy.find('ID')
# => #<Immoscout::Models::ApartmentBuy:0x0055c9fbfa0648>
apartment.publish
# => #<Immoscout::Models::Publish:0x0085a2fbfa0688>
apartment.unpublish
# => #<Immoscout::Models::Publish:0x00831b2fbfc1234>
# 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>
- .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 = "[email protected]"
contact.salutation = "MALE"
contact.save
# => #<Immoscout::Models::Contact:0x0055c9fb889878 @email="[email protected]", @firstname="John", @lastname="Doe", @salutation="MALE">
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.
- .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>
- .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>
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.
Everyone interacting in the project codebase, issue tracker, chat rooms and mailing lists is expected to follow the code of conduct.
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.
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.