Class: Razsell::Query
- Inherits:
-
Object
- Object
- Razsell::Query
- Includes:
- ImageSizes, SortMethods
- Defined in:
- lib/razsell/query.rb
Overview
Allows you to specify the result set you would like returned
=== Attributes that you can specify
* keywords
* product_line
* product_type (see Razsell::ProductTypes)
* sort_type (see Razsell::SortMethods)
* sort_period (see Razsell::SortPeriods)
* image_size (see Razsell::ImageSizes)
* image_background_color
Additionally you can use
query = Razsell::Query.new.for_artist('some_zazzle_artist')
to specify the artist. Or if you have a link to a zazzle item you can get the details with:
query = Razsell::Query.new.for_item_url('http://www.zazzle.com/some-item-354678976578865')
Once you have built your query, use Razsell#request(query) to get the results.
Constant Summary
Constants included from ImageSizes
ImageSizes::HUGE, ImageSizes::LARGE, ImageSizes::MEDIUM, ImageSizes::SMALL, ImageSizes::TINY
Constants included from SortMethods
SortMethods::DATE_CREATED, SortMethods::POPULARITY
Instance Attribute Summary collapse
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#page_limit ⇒ Object
Returns the value of attribute page_limit.
Instance Method Summary collapse
- #advance_page ⇒ Object
- #base_url ⇒ Object
- #for_artist(artist) ⇒ Object
- #for_item_url(url) ⇒ Object
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
- #strip_item_number_from(url) ⇒ Object
- #to_querystring ⇒ Object
- #to_url ⇒ Object
Constructor Details
#initialize(*args) ⇒ Query
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/razsell/query.rb', line 34 def initialize *args set_default_page_limit default_criteria @keys = { :keywords => 'qs', :product_line => 'cg', :product_type => 'pt', :sort_type => 'st', :sort_period => 'sp', :page => 'pg', :items_per_page => 'ps', :feed_type => 'ft', :image_size => 'isz', :image_background_color => 'bg', :opensearch => 'opensearch', :source => 'src'} end |
Instance Attribute Details
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
32 33 34 |
# File 'lib/razsell/query.rb', line 32 def artist @artist end |
#page_limit ⇒ Object
Returns the value of attribute page_limit.
31 32 33 |
# File 'lib/razsell/query.rb', line 31 def page_limit @page_limit end |
Instance Method Details
#advance_page ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/razsell/query.rb', line 73 def advance_page cur_page = @querystring[:page] return false if cur_page >= page_limit @querystring[:page] = cur_page + 1 true end |
#base_url ⇒ Object
60 61 62 63 |
# File 'lib/razsell/query.rb', line 60 def base_url return "http://feed.zazzle.com/#{@artist}/rss" if @artist "http://feed.zazzle.com/rss" end |
#for_artist(artist) ⇒ Object
45 46 47 48 |
# File 'lib/razsell/query.rb', line 45 def for_artist artist @artist = artist self end |
#for_item_url(url) ⇒ Object
50 51 52 53 54 |
# File 'lib/razsell/query.rb', line 50 def for_item_url url @item_url = url self.keywords = strip_item_number_from url self end |
#strip_item_number_from(url) ⇒ Object
56 57 58 |
# File 'lib/razsell/query.rb', line 56 def strip_item_number_from url url.scan(/\d*$/)[0] end |
#to_querystring ⇒ Object
65 66 67 |
# File 'lib/razsell/query.rb', line 65 def to_querystring @querystring.to_a.map { |element| build_pair(element) }.sort {|first, second| first <=> second }.delete_if { |pair| pair == "" }.join("&") end |
#to_url ⇒ Object
69 70 71 |
# File 'lib/razsell/query.rb', line 69 def to_url "#{base_url}?#{to_querystring}" end |