Class: VastApi::Listings

Inherits:
Array
  • Object
show all
Defined in:
lib/vast_api/listings.rb,
lib/vast_api/listings/entry.rb

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vast) ⇒ Listings

Returns a new instance of Listings.



7
8
9
10
11
12
13
# File 'lib/vast_api/listings.rb', line 7

def initialize(vast)
  @vast = vast
  @url = "#{@vast.api_url}listings/-/#{@vast.category}?#{@vast.query}"
  @response = Typhoeus::Request.get(@url)
  @xml = Nokogiri::XML(@response.body)
  populate
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/vast_api/listings.rb', line 3

def attributes
  @attributes
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/vast_api/listings.rb', line 3

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/vast_api/listings.rb', line 3

def url
  @url
end

#vastObject (readonly)

Returns the value of attribute vast.



3
4
5
# File 'lib/vast_api/listings.rb', line 3

def vast
  @vast
end

#xmlObject (readonly)

Returns the value of attribute xml.



3
4
5
# File 'lib/vast_api/listings.rb', line 3

def xml
  @xml
end

Class Method Details

.get(vast, url) ⇒ Object



37
38
39
40
# File 'lib/vast_api/listings.rb', line 37

def self.get(vast,url)
  response = Typhoeus::Request.get(url)
  Entry.new(vast, Nokogiri::XML(response.body).at('entry'))
end

Instance Method Details

#attr(var_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vast_api/listings.rb', line 15

def attr(var_name)
  if var = @xml.at(var_name)
    var.text
  elsif var = @xml.at('//v:'+var_name)
    var.text
  elsif var = @xml.at('//o:'+var_name)
    var.text
  else
    nil
  end
end

#queryObject



27
28
29
30
31
32
33
34
35
# File 'lib/vast_api/listings.rb', line 27

def query
  if @query.nil?
    @query = {}
    @xml.at('//o:Query').attributes.each do |name,value|
      @query[name] = value.value
    end
  end
  @query
end