Class: Is24::Api

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/is24.rb

Constant Summary collapse

API_ENDPOINT =
"http://rest.immobilienscout24.de/restapi/api/search/v1.0/"
API_OFFER_ENDPOINT =
"http://rest.immobilienscout24.de/restapi/api/offer/v1.0/"
API_AUTHORIZATION_ENDPOINT =
"http://rest.immobilienscout24.de/restapi/security/"
MARKETING_TYPES =

TODO move in separate module

{
  "PURCHASE" => "Kauf",
  "PURCHASE_PER_SQM" => "Kaufpreis/ Quadratmeter",
  "RENT" => "Miete",
  "RENT_PER_SQM" => "Mietpreis/ Quadratmeter",
  "LEASE" => "Leasing",
  "LEASEHOLD" => "",
  "BUDGET_RENT" => "",
  "RENT_AND_BUY" => ""
}
PRICE_INTERVAL_TYPES =
{
  "DAY" => "Tag",
  "WEEK" => "Woche",
  "MONTH" => "Monat",
  "YEAR" => "Jahr",
  "ONE_TIME_CHARGE" => "einmalig"
}
REAL_ESTATE_TYPES =
{
  "APARTMENT_RENT" => "Wohnung Miete",
  "APARTMENT_BUY" => "Wohnung Kauf",
  "HOUSE_RENT" => "Haus Miete",
  "HOUSE_BUY" => "Haus Kauf",
  "GARAGE_RENT" => "Garage / Stellplatz Miete",
  "GARAGE_BUY" => "Garage / Stellplatz Kauf",
  "LIVING_RENT_SITE" => "Grundstück Wohnen Miete",
  "LIVING_BUY_SITE" => "Grundstück Wohnen Kauf",
  "TRADE_SITE" => "Grundstück Gewerbe",
  "HOUSE_TYPE" => "Typenhäuser",
  "FLAT_SHARE_ROOM" => "WG-Zimmer",
  "SENIOR_CARE" => "Altenpflege",
  "ASSISTED_LIVING" => "Betreutes Wohnen",
  "OFFICE" => "Büro / Praxis",
  "INDUSTRY" => "Hallen / Produktion",
  "STORE" => "Einzelhandel",
  "GASTRONOMY" => "Gastronomie / Hotel",
  "SPECIAL_PURPOSE" => "",
  "INVESTMENT" => "Gewerbeprojekte",
  "COMPULSORY_AUCTION" => "",
  "SHORT_TERM_ACCOMMODATION" => ""
}
XSI_SEARCH_TYPES =

transforms, eg. “SPECIAL_PURPOSE” => “” to “search:SpecialPurpose” => “”

lambda {
  return Hash[*REAL_ESTATE_TYPES.map{ |v|
      [
        "search:"+v.first.downcase.split("_").map!(&:capitalize).join,
        v[1]
      ]
    }.flatten
  ]
}.()

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initialize(options = {}) ⇒ Api

Returns a new instance of Api.



83
84
85
86
87
88
89
90
91
92
# File 'lib/is24.rb', line 83

def initialize( options = {} )
  logger "Initialized b'nerd IS24 with options #{options}"

  @token = options[:token] || nil
  @secret = options[:secret] || nil
  @consumer_secret = options[:consumer_secret] || nil
  @consumer_key = options[:consumer_key] || nil

  raise "Missing Credentials!" if @consumer_secret.nil? || @consumer_key.nil?
end

Class Method Details

.format_marketing_type(marketing_type) ⇒ Object



75
76
77
# File 'lib/is24.rb', line 75

def self.format_marketing_type(marketing_type)
  MARKETING_TYPES[marketing_type] || ""
end

.format_price_interval_type(price_interval_type) ⇒ Object



79
80
81
# File 'lib/is24.rb', line 79

def self.format_price_interval_type(price_interval_type)
  PRICE_INTERVAL_TYPES[price_interval_type] || ""
end

Instance Method Details

#expose(id) ⇒ Object



159
160
161
162
# File 'lib/is24.rb', line 159

def expose(id)
  response = connection.get("expose/#{id}")
  response.body["expose.expose"]
end

#list_exposesObject



164
165
166
167
# File 'lib/is24.rb', line 164

def list_exposes
  response = connection(:offer).get("user/me/realestate?publishchannel=IS24")
  response.body
end

#request_access_token(params = {}) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/is24.rb', line 106

def request_access_token( params = {} )
  # TODO error handling
  @oauth_verifier = params[:oauth_verifier]
  @token = params[:oauth_token]
  @secret = params[:oauth_token_secret]

  response = connection(:authorization).get("oauth/access_token")
  body = response.body.split('&')

  response = {
    :oauth_token => body[0].split('=')[1],
    :oauth_token_secret => CGI::unescape(body[1].split('=')[1]),
  }

  # set credentials in client
  @token = response[:oauth_token]
  @token_secret = response[:oauth_token_secret]

  # return access token and secret
  response
end

#request_token(callback_uri) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/is24.rb', line 94

def request_token( callback_uri )
  # TODO error handling
  response = connection(:authorization, callback_uri).get("oauth/request_token")

  body = response.body.split('&')
  response = {
    :oauth_token => CGI::unescape(body[0].split("=")[1]),
    :oauth_token_secret => CGI::unescape(body[1].split("=")[1]),
    :redirect_uri => "http://rest.immobilienscout24.de/restapi/security/oauth/confirm_access?#{body[0]}"
  }
end

#search(options) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/is24.rb', line 128

def search(options)
  defaults = {
    :channel => "hp",
    :realestatetype => ["housebuy"],
    :geocodes => 1276,
    :username => "me"
  }
  options = defaults.merge(options)
  types = options[:realestatetype]

  case types
    when String
      types = [types]
  end

  objects = []

  types.each do |type|
    options[:realestatetype] = type
    response = connection.get("search/region", options )
    if response.status == 200
      if response.body["resultlist.resultlist"].resultlistEntries[0]['@numberOfHits'] == "0"
        response.body["resultlist.resultlist"].resultlistEntries[0].resultlistEntries = []
      end
      objects.push response.body["resultlist.resultlist"].resultlistEntries[0]
    end
  end

  objects
end

#short_listObject



169
170
171
172
# File 'lib/is24.rb', line 169

def short_list
  response = connection.get("searcher/me/shortlist/0/entry")
  response.body["shortlist.shortlistEntries"].first["shortlistEntry"]
end