Class: VastApi
- Inherits:
-
Object
show all
- Defined in:
- lib/vast_api.rb,
lib/vast_api/listings.rb,
lib/vast_api/attributes.rb,
lib/vast_api/categories.rb,
lib/vast_api/listings/entry.rb,
lib/vast_api/attributes/entry.rb,
lib/vast_api/categories/category.rb
Defined Under Namespace
Classes: Attributes, Categories, Listings
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(apikey = nil, cat = nil, opts = {}) ⇒ VastApi
Returns a new instance of VastApi.
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/vast_api.rb', line 22
def initialize(apikey=nil, cat=nil, opts = {})
@api_url = opts[:api_url] || 'http://data.vast.com/'
@light = opts[:light] || false
@category = cat
@query = { }
@query['apikey'] = apikey if apikey
@categories = {}
@attributes = {}
@listings = {}
end
|
Instance Attribute Details
#api_url ⇒ Object
Returns the value of attribute api_url.
20
21
22
|
# File 'lib/vast_api.rb', line 20
def api_url
@api_url
end
|
#light ⇒ Object
Returns the value of attribute light.
20
21
22
|
# File 'lib/vast_api.rb', line 20
def light
@light
end
|
Class Method Details
.find(id, cat) ⇒ Object
108
109
110
|
# File 'lib/vast_api.rb', line 108
def self.find(id, cat)
Listings.get(self, "#{api_url}listings/#{id}/-/#{cat}?#{api_query}")
end
|
.find_by_url(url) ⇒ Object
112
113
114
|
# File 'lib/vast_api.rb', line 112
def self.find_by_url(url)
Listings.get(self, url)
end
|
Instance Method Details
#api_key ⇒ Object
55
56
57
|
# File 'lib/vast_api.rb', line 55
def api_key
@query['apikey']
end
|
#api_key=(key) ⇒ Object
59
60
61
|
# File 'lib/vast_api.rb', line 59
def api_key=(key)
@query['apikey'] = key
end
|
#api_query ⇒ Object
73
74
75
76
77
78
|
# File 'lib/vast_api.rb', line 73
def api_query
q = {}
q['apikey'] = api_key if api_key
q['light'] = 'yes' if light
q.to_query
end
|
#attributes ⇒ Object
85
86
87
88
|
# File 'lib/vast_api.rb', line 85
def attributes
raise ArgumentError, "No category was entered" if @category.nil? || @category.empty?
@attributes[opt_hash] ||= Attributes.new(self)
end
|
#categories ⇒ Object
90
91
92
|
# File 'lib/vast_api.rb', line 90
def categories
@categories[@api_key] ||= Categories.new(self)
end
|
#category(cat = nil) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/vast_api.rb', line 38
def category(cat=nil)
if cat.nil?
@category
else
self.clone.category!(cat)
end
end
|
#category!(cat) ⇒ Object
33
34
35
36
|
# File 'lib/vast_api.rb', line 33
def category!(cat)
@category = cat
self
end
|
#create_entry(entry) ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/vast_api.rb', line 116
def create_entry(entry)
if entry.at_xpath('v:attribute')
Attributes::Entry.new(self,entry)
else
Listings::Entry.new(self,entry)
end
end
|
#find(id) ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/vast_api.rb', line 94
def find(id)
raise ArgumentError, "No category was entered" if @category.nil? || @category.empty?
if id.nil? || id.empty?
nil
else
Listings.get(self, "#{api_url}listings/#{id}/-/#{@category}?#{api_query}")
end
end
|
#find!(id) ⇒ Object
103
104
105
106
|
# File 'lib/vast_api.rb', line 103
def find!(id)
raise ArgumentError, "No id was entered" if id.nil? || id.empty?
self.find(id)
end
|
#listings ⇒ Object
80
81
82
83
|
# File 'lib/vast_api.rb', line 80
def listings
raise ArgumentError, "No category was entered" if @category.nil? || @category.empty?
@listings[opt_hash] ||= Listings.new(self)
end
|
#opt_hash ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/vast_api.rb', line 124
def opt_hash
str = ''
str << @category if @category
str << @api_key if @api_key
str << @query.hash.to_s if @query
str.hash
end
|
#query ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/vast_api.rb', line 63
def query
q = @query.dup
if light
q['light'] = 'yes'
else
q.delete('light')
end
q.to_query
end
|
#where(options) ⇒ Object
51
52
53
|
# File 'lib/vast_api.rb', line 51
def where(options)
self.clone.where!(options)
end
|
#where!(options) ⇒ Object
46
47
48
49
|
# File 'lib/vast_api.rb', line 46
def where!(options)
@query = @query.merge(options)
self
end
|