Class: Colourlovers::Client
- Inherits:
-
Object
- Object
- Colourlovers::Client
- Includes:
- HTTParty
- Defined in:
- lib/colourlovers/client.rb
Class Method Summary collapse
-
.color(hex) ⇒ Object
Retrieve color from hex value.
-
.colors(options = {}) ⇒ Object
List colors.
-
.handle_response(response) ⇒ Object
Handle responses from HTTParty calls to the COLOURlovers API with some generic response interpretation and manipulation.
-
.lover(username) ⇒ Object
Retrieve lover from username.
-
.lovers(options = {}) ⇒ Object
List lovers.
-
.new_colors(options = {}) ⇒ Object
List new colors.
-
.new_lovers(options = {}) ⇒ Object
List new lovers.
-
.new_palettes(options = {}) ⇒ Object
List new palettes.
-
.new_patterns(options = {}) ⇒ Object
List new patterns.
-
.palette(paletteID) ⇒ Object
Retrieve palette from paletteID.
-
.palettes(options = {}) ⇒ Object
List palettes.
-
.pattern(patternID) ⇒ Object
Retrieve pattern from patternID.
-
.patterns(options = {}) ⇒ Object
List patterns.
-
.random_color ⇒ Object
Retrieve random color.
-
.random_palette ⇒ Object
Retrieve random palette.
-
.random_pattern ⇒ Object
Retrieve random pattern.
-
.top_colors(options = {}) ⇒ Object
List top colors.
-
.top_lovers(options = {}) ⇒ Object
List top lovers.
-
.top_palettes(options = {}) ⇒ Object
List top palettes.
-
.top_patterns(options = {}) ⇒ Object
List top patterns.
Instance Method Summary collapse
-
#method_missing(method, *args, &block) ⇒ Object
Rather than making laborious calls to ‘Colourlovers::Client.colors` you can create an instance of the Client and call methods on it.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Rather than making laborious calls to ‘Colourlovers::Client.colors` you can create an instance of the Colourlovers::Client and call methods on it. Instance methods will be defined for class methods on their first utilization.
15 16 17 18 19 20 21 22 23 |
# File 'lib/colourlovers/client.rb', line 15 def method_missing(method, *args, &block) super unless self.class.respond_to? method self.class.class_eval do define_method method do |*args, &block| self.class.send(method, *args, &block) end end self.class.send(method, *args, &block) end |
Class Method Details
.color(hex) ⇒ Object
Retrieve color from hex value
88 89 90 |
# File 'lib/colourlovers/client.rb', line 88 def color(hex) Color.find(hex) end |
.colors(options = {}) ⇒ Object
List colors
64 65 66 |
# File 'lib/colourlovers/client.rb', line 64 def colors(={}) Color.all() end |
.handle_response(response) ⇒ Object
Add individual errors for various HTTP Status codes
Handle responses from HTTParty calls to the COLOURlovers API with some generic response interpretation and manipulation.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/colourlovers/client.rb', line 31 def handle_response(response) status = response.code case status when 404 then STDERR.puts "404 - maybe COLOURlovers down? #{$!}" when 400..499 then STDERR.puts "400-499 - maybe COLOURlovers down? #{$!}" when 500..599 then STDERR.puts "500-599 - maybe COLOURlovers down? #{$!}" else response.first end end |
.lover(username) ⇒ Object
Retrieve lover from username
178 179 180 |
# File 'lib/colourlovers/client.rb', line 178 def lover(username) Lover.find(username) end |
.lovers(options = {}) ⇒ Object
List lovers
160 161 162 |
# File 'lib/colourlovers/client.rb', line 160 def lovers(={}) Lover.all() end |
.new_colors(options = {}) ⇒ Object
List new colors
76 77 78 |
# File 'lib/colourlovers/client.rb', line 76 def new_colors(={}) Color.new() end |
.new_lovers(options = {}) ⇒ Object
List new lovers
172 173 174 |
# File 'lib/colourlovers/client.rb', line 172 def new_lovers(={}) Lover.new() end |
.new_palettes(options = {}) ⇒ Object
List new palettes
108 109 110 |
# File 'lib/colourlovers/client.rb', line 108 def new_palettes(={}) Palette.new() end |
.new_patterns(options = {}) ⇒ Object
List new patterns
140 141 142 |
# File 'lib/colourlovers/client.rb', line 140 def new_patterns(={}) Pattern.new() end |
.palette(paletteID) ⇒ Object
Retrieve palette from paletteID
120 121 122 |
# File 'lib/colourlovers/client.rb', line 120 def palette(paletteID) Palette.find(paletteID) end |
.palettes(options = {}) ⇒ Object
List palettes
96 97 98 |
# File 'lib/colourlovers/client.rb', line 96 def palettes(={}) Palette.all() end |
.pattern(patternID) ⇒ Object
Retrieve pattern from patternID
152 153 154 |
# File 'lib/colourlovers/client.rb', line 152 def pattern(patternID) Pattern.find(patternID) end |
.patterns(options = {}) ⇒ Object
List patterns
128 129 130 |
# File 'lib/colourlovers/client.rb', line 128 def patterns(={}) Pattern.all() end |
.random_color ⇒ Object
Retrieve random color
82 83 84 |
# File 'lib/colourlovers/client.rb', line 82 def random_color Color.random end |
.random_palette ⇒ Object
Retrieve random palette
114 115 116 |
# File 'lib/colourlovers/client.rb', line 114 def random_palette Palette.random end |
.random_pattern ⇒ Object
Retrieve random pattern
146 147 148 |
# File 'lib/colourlovers/client.rb', line 146 def random_pattern Pattern.random end |
.top_colors(options = {}) ⇒ Object
List top colors
70 71 72 |
# File 'lib/colourlovers/client.rb', line 70 def top_colors(={}) Color.top() end |
.top_lovers(options = {}) ⇒ Object
List top lovers
166 167 168 |
# File 'lib/colourlovers/client.rb', line 166 def top_lovers(={}) Lover.top() end |