Module: Idol::BasicIdolFunctionality

Included in:
Query, Suggest, SuggestOnText
Defined in:
lib/idol-search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



23
24
25
# File 'lib/idol-search.rb', line 23

def action
  @action
end

#filtersObject

Returns the value of attribute filters.



22
23
24
# File 'lib/idol-search.rb', line 22

def filters
  @filters
end

#parametersObject

Returns the value of attribute parameters.



22
23
24
# File 'lib/idol-search.rb', line 22

def parameters
  @parameters
end

#raw_resultsObject

Returns the value of attribute raw_results.



22
23
24
# File 'lib/idol-search.rb', line 22

def raw_results
  @raw_results
end

#urlObject

Returns the value of attribute url.



22
23
24
# File 'lib/idol-search.rb', line 22

def url
  @url
end

Instance Method Details

#executeObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/idol-search.rb', line 40

def execute
  post_fields = generate_post_fields

  status = nil
  body = nil

  request = Curl::Easy.new do |r|
    r.url = "#{@url}/?action=#{@action}"
    r.on_complete do |data|
      status = data.response_code
      body = data.body_str
    end
  end

  request.http_post(*post_fields)
  return body if @raw_results
  results = if @parameters[:abridged]
    AbridgedResultsParser.new(body).parse
  else
    Hash.from_xml(body)
  end
  results
end

#initialize(url, parameters = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/idol-search.rb', line 25

def initialize(url, parameters = {})
  @raw_results = false
  @url = url
  @parameters = parameters
  @filters = FieldTextFilterCollection.new
end

#to_hashObject



32
33
34
# File 'lib/idol-search.rb', line 32

def to_hash
  @parameters
end