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) ⇒ VastApi
Returns a new instance of VastApi.
19
20
21
22
23
24
25
26
27
|
# File 'lib/vast_api.rb', line 19
def initialize(apikey=nil, cat=nil)
@api_url = 'http://data.vast.com/'
@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.
17
18
19
|
# File 'lib/vast_api.rb', line 17
def api_url
@api_url
end
|
Class Method Details
.find(id, cat) ⇒ Object
95
96
97
|
# File 'lib/vast_api.rb', line 95
def self.find(id, cat)
Listings.get("#{api_url}listings/#{id}/-/#{cat}?#{api_query}")
end
|
.find_by_url(url) ⇒ Object
99
100
101
|
# File 'lib/vast_api.rb', line 99
def self.find_by_url(url)
Listings.get(url)
end
|
Instance Method Details
#api_key ⇒ Object
51
52
53
|
# File 'lib/vast_api.rb', line 51
def api_key
@query['apikey']
end
|
#api_key=(key) ⇒ Object
55
56
57
|
# File 'lib/vast_api.rb', line 55
def api_key=(key)
@query['apikey'] = key
end
|
#api_query ⇒ Object
63
64
65
|
# File 'lib/vast_api.rb', line 63
def api_query
(api_key) ? "apikey=#{api_key}" : ''
end
|
#attributes ⇒ Object
72
73
74
75
|
# File 'lib/vast_api.rb', line 72
def attributes
raise ArgumentError, "No category was entered" if @category.nil? || @category.empty?
@attributes[opt_hash] ||= Attributes.new(self)
end
|
#categories ⇒ Object
77
78
79
|
# File 'lib/vast_api.rb', line 77
def categories
@categories[@api_key] ||= Categories.new(self)
end
|
#category(cat = nil) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/vast_api.rb', line 34
def category(cat=nil)
if cat.nil?
@category
else
self.clone.category!(cat)
end
end
|
#category!(cat) ⇒ Object
29
30
31
32
|
# File 'lib/vast_api.rb', line 29
def category!(cat)
@category = cat
self
end
|
#find(id) ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/vast_api.rb', line 81
def find(id)
raise ArgumentError, "No category was entered" if @category.nil? || @category.empty?
if id.nil? || id.empty?
nil
else
Listings.get("#{api_url}listings/#{id}/-/#{@category}?#{api_query}")
end
end
|
#find!(id) ⇒ Object
90
91
92
93
|
# File 'lib/vast_api.rb', line 90
def find!(id)
raise ArgumentError, "No id was entered" if id.nil? || id.empty?
find(id)
end
|
#listings ⇒ Object
67
68
69
70
|
# File 'lib/vast_api.rb', line 67
def listings
raise ArgumentError, "No category was entered" if @category.nil? || @category.empty?
@listings[opt_hash] ||= Listings.new(self)
end
|
#query ⇒ Object
59
60
61
|
# File 'lib/vast_api.rb', line 59
def query
@query.to_query
end
|
#where(options) ⇒ Object
47
48
49
|
# File 'lib/vast_api.rb', line 47
def where(options)
self.clone.where!(options)
end
|
#where!(options) ⇒ Object
42
43
44
45
|
# File 'lib/vast_api.rb', line 42
def where!(options)
@query.merge!(options)
self
end
|