class Mobile::Client

Attributes

api_version[RW]
password[RW]
username[RW]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/mobile/client.rb, line 16
def initialize(&block)
  yield(self)
  self.api_version = '1.0.0' if self.api_version.nil?
  self
end

Public Instance Methods

ad(id, options={}) click to toggle source
# File lib/mobile/client.rb, line 27
def ad(id, options={})
  request('get', "/ad/#{id}", options)['ad']
end
ads(options={}) click to toggle source
# File lib/mobile/client.rb, line 23
def ads(options={})
  request('get', '/ad/search', options)['result']
end
configured?() click to toggle source
# File lib/mobile/client.rb, line 31
def configured?
  raise Mobile::MissingConfig, "Either username or password is not set in configuration block. Please fix this." unless !username.nil? && !password.nil?
  !username.nil? && !password.nil?
end

Private Instance Methods

auth() click to toggle source
# File lib/mobile/client.rb, line 50
def auth
  { username: self.username, password: self.password }
end
headers() click to toggle source
# File lib/mobile/client.rb, line 46
def headers
  { "Accept-Language" => "de" }
end
request(method, path, opts={}) click to toggle source
# File lib/mobile/client.rb, line 38
def request(method, path, opts={})
  opts.merge!({ headers: headers, basic_auth: auth })
  response = self.class.get("/#{api_version}#{path}", opts)
  parsed_body = MultiXml.parse(response.body)
  raise Mobile::BadRequest, "Your search query can not be processed. Unfortunately, we can't provide more details but at least we don't reply with an internal server error any more. Maybe it helps to specify a search parameter which is not boolean or numeric. We will improve this in the future." if parsed_body.nil?
  parsed_body
end