Class: Kuler
- Inherits:
-
Object
- Object
- Kuler
- Defined in:
- lib/kuler.rb,
lib/kuler/theme.rb,
lib/kuler/swatch.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
:nodoc:
'0.1.0'
- BASE_URL =
:nodoc:
"http://kuler-api.adobe.com"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
the key required to access the kuler API.
Instance Method Summary collapse
-
#build_url(args = {}) ⇒ Object
Build the appropriate URL for a request to the Kuler API.
-
#fetch_random_theme ⇒ Object
fetch a single random color theme.
-
#initialize(api_key) ⇒ Kuler
constructor
Create a new Kuler object.
Constructor Details
#initialize(api_key) ⇒ Kuler
Create a new Kuler object. Accepts a single argument, the api_key
.
16 17 18 |
# File 'lib/kuler.rb', line 16 def initialize( api_key ) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
the key required to access the kuler API
12 13 14 |
# File 'lib/kuler.rb', line 12 def api_key @api_key end |
Instance Method Details
#build_url(args = {}) ⇒ Object
Build the appropriate URL for a request to the Kuler API.
Parameters:
type
-
the type of API call to make. Options are
recent
,popular
,rating
, orrandom
. limit
-
the number of themes to return. Valid range is 1 to 100.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kuler.rb', line 27 def build_url( args = {} ) # default options opts = { :type => :recent, :limit => 20 }.merge( args ) unless [ :recent, :popular, :rating, :random ].include? opts[:type] raise ArgumentError, "unknown feed type '#{opts[:type]}'. Valid options are recent, popular, rating, or random" end unless (1..100).include? opts[:limit] raise ArgumentError, "invalid limit: #{opts[:limit]}. Valid options are 1-100" end = { :key => self.api_key, :itemsPerPage => opts[:limit], :listType => opts[:type], } get_args = . sort_by {|k,v| k.to_s }. map {|k,v| "#{k}=#{v}" }. join( "&" ) return "#{BASE_URL}/rss/get.cfm?#{get_args}" end |