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
# File 'lib/vast_api/listings.rb', line 7

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

Instance Attribute Details

#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(url) ⇒ Object



44
45
46
# File 'lib/vast_api/listings.rb', line 44

def self.get(url)
  Entry.new(Nokogiri::XML(open(url)).at('entry'))
end

Instance Method Details

#attr(var_name) ⇒ Object



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

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

#find(id) ⇒ Object



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

def find(id)
  @vast.find(id)
end

#find!(id) ⇒ Object



40
41
42
# File 'lib/vast_api/listings.rb', line 40

def find!(id)
  @vast.find!(id)
end

#queryObject



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

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