Class: UnifiedDB::Backend::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/unified_db/backend/base.rb

Direct Known Subclasses

IMDB, TVDB

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.


11
12
13
# File 'lib/unified_db/backend/base.rb', line 11

def initialize
  @result = []
end

Instance Attribute Details

#idObject

Returns the value of attribute id


5
6
7
# File 'lib/unified_db/backend/base.rb', line 5

def id
  @id
end

#titleObject

Returns the value of attribute title


5
6
7
# File 'lib/unified_db/backend/base.rb', line 5

def title
  @title
end

Class Method Details

.find(params) ⇒ Object


7
8
9
# File 'lib/unified_db/backend/base.rb', line 7

def self.find(params)
  new.find(params)
end

Instance Method Details

#find(params) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/unified_db/backend/base.rb', line 15

def find(params)
  if params[:id]
    find_by_id params[:id]
  elsif params[:t] || params[:title]
    find_by_title(params[:t] || params[:title])
  else
    raise ApiError, 'no search criteria specified'
  end

  result
rescue ApiError => e
  {
    :status => 'error',
    :reason => e.message
  }
end

#find_by_id(id) ⇒ Object

Raises:


32
33
34
# File 'lib/unified_db/backend/base.rb', line 32

def find_by_id(id)
  raise ApiError, 'not implemented'
end

#find_by_title(title) ⇒ Object

Raises:


36
37
38
# File 'lib/unified_db/backend/base.rb', line 36

def find_by_title(title)
  raise ApiError, 'not implemented'
end

#resultObject


40
41
42
43
44
45
46
# File 'lib/unified_db/backend/base.rb', line 40

def result
  {
    :status => 'success',
    :service => service,
    :result => @result
  }
end