Class: Cornerstore::Search
- Inherits:
-
Object
- Object
- Cornerstore::Search
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/cornerstore/api/search.rb
Instance Attribute Summary collapse
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#products ⇒ Object
(also: #results)
Returns the value of attribute products.
-
#scores ⇒ Object
Returns the value of attribute scores.
Instance Method Summary collapse
-
#initialize(keywords = nil) ⇒ Search
constructor
A new instance of Search.
- #persisted? ⇒ Boolean
- #results? ⇒ Boolean
- #run ⇒ Object
- #to_key ⇒ Object
Constructor Details
#initialize(keywords = nil) ⇒ Search
Returns a new instance of Search.
7 8 9 |
# File 'lib/cornerstore/api/search.rb', line 7 def initialize(keywords = nil) @keywords, @scores, @products = keywords, Array.new, Cornerstore::Product::Resource.new end |
Instance Attribute Details
#keywords ⇒ Object
Returns the value of attribute keywords.
4 5 6 |
# File 'lib/cornerstore/api/search.rb', line 4 def keywords @keywords end |
#products ⇒ Object Also known as: results
Returns the value of attribute products.
4 5 6 |
# File 'lib/cornerstore/api/search.rb', line 4 def products @products end |
#scores ⇒ Object
Returns the value of attribute scores.
4 5 6 |
# File 'lib/cornerstore/api/search.rb', line 4 def scores @scores end |
Instance Method Details
#persisted? ⇒ Boolean
19 20 21 |
# File 'lib/cornerstore/api/search.rb', line 19 def persisted? false end |
#results? ⇒ Boolean
11 12 13 |
# File 'lib/cornerstore/api/search.rb', line 11 def results? !@products.empty? end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cornerstore/api/search.rb', line 23 def run return false unless @keywords RestClient.get("#{Cornerstore.root_url}/products/search?keywords=#{URI::encode(@keywords)}", Cornerstore.headers) do |response, request, result, &block| if response.code == 200 data = ActiveSupport::JSON.decode(response) @scores = data['scores'] @products = Cornerstore::Product::Resource.new(nil, data['products']) return true end end end |
#to_key ⇒ Object
15 16 17 |
# File 'lib/cornerstore/api/search.rb', line 15 def to_key [''] end |