colourlovers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in colourlovers.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Chris Masters
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # Colourlovers
2
+
3
+ A simple gem to use to make it easy to use the COLOURlovers API.
4
+
5
+ http://www.colourlovers.com/api
6
+
7
+ This is my first gem and there are currently no tests, bt I am working on it.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'colourlovers'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install colourlovers
22
+
23
+ ## Usage
24
+
25
+
26
+ ```ruby
27
+
28
+ cl = Colourlovers::Client.new
29
+
30
+ # for colors (parameters supported)
31
+ colors = cl.colors({:numResults => 3, :lover => 'COLOURlover'})
32
+ top_colors = cl.top_colors({:numResults => 3})
33
+ new_colors = cl.new_colors({:numResults => 3})
34
+ random_color = cl.random_color
35
+ color = cl.color('FFFFFF')
36
+
37
+ p "colors"
38
+ p colors
39
+ p "top_colors"
40
+ p top_colors
41
+ p "new_colors"
42
+ p new_colors
43
+ p "random_color"
44
+ p random_color
45
+ p "color"
46
+ p color
47
+
48
+ # for palettes (parameters supported)
49
+ palettes = cl.palettes({:numResults => 5})
50
+ top_palettes = cl.top_palettes({:numResults => 3})
51
+ new_palettes = cl.new_palettes({:numResults => 3})
52
+ random_palette = cl.random_palette
53
+ palette = cl.palette('113451')
54
+
55
+ p "palettes"
56
+ p palettes
57
+ p "top_palettes"
58
+ p top_palettes
59
+ p "new_palettes"
60
+ p new_palettes
61
+ p "random_palette"
62
+ p random_palette
63
+ p "palette"
64
+ p palette
65
+
66
+ # for patterns (parameters supported)
67
+ patterns = cl.patterns({:numResults => 5})
68
+ top_patterns = cl.top_patterns({:numResults => 3})
69
+ new_patterns = cl.new_patterns({:numResults => 3})
70
+ random_pattern = cl.random_pattern
71
+ pattern = cl.pattern('1451')
72
+
73
+ p "patterns"
74
+ p patterns
75
+ p "top_patterns"
76
+ p top_patterns
77
+ p "new_patterns"
78
+ p new_patterns
79
+ p "random_pattern"
80
+ p random_pattern
81
+ p "pattern"
82
+ p pattern
83
+
84
+ # for lovers (parameters supported)
85
+ lovers = cl.lovers({:numResults => 5})
86
+ top_lovers = cl.top_lovers({:numResults => 3})
87
+ new_lovers = cl.new_lovers({:numResults => 3})
88
+ lover = cl.lover('COLOURlover')
89
+
90
+ p "lovers"
91
+ p lovers
92
+ p "top_lovers"
93
+ p top_lovers
94
+ p "new_lovers"
95
+ p new_lovers
96
+ p "lover"
97
+ p lover
98
+
99
+
100
+
101
+ ```
102
+
103
+
104
+
105
+ ## Contributing
106
+
107
+ 1. Fork it
108
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
109
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
110
+ 4. Push to the branch (`git push origin my-new-feature`)
111
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/colourlovers/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Chris Masters"]
6
+ gem.email = ["chrismasters@gmail.com"]
7
+ gem.description = %q{A simple gem to use to make it easy to use the COLOURlovers API http://www.colourlovers.com/api. This is my first gem and there are currently no tests, bt I am working on it.}
8
+ gem.summary = %q{A ruby wrapper for the COLOURlovers API}
9
+ gem.homepage = "https://github.com/chrism/COLOURlovers"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "colourlovers"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Colourlovers::VERSION
17
+
18
+ gem.add_dependency "httparty"
19
+ gem.add_development_dependency "rake"
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'httparty'
2
+
3
+ require "colourlovers/version"
4
+ require 'colourlovers/client'
5
+ require 'colourlovers/color'
6
+ require 'colourlovers/palette'
7
+ require 'colourlovers/pattern'
8
+ require 'colourlovers/lover'
@@ -0,0 +1,186 @@
1
+ module Colourlovers
2
+
3
+ class Client
4
+
5
+ include HTTParty
6
+ default_params :format => 'json'
7
+ base_uri 'http://www.colourlovers.com/api'
8
+
9
+ # Rather than making laborious calls to `Colourlovers::Client.colors` you can create an instance
10
+ # of the {Colourlovers::Client} and call methods on it. Instance methods will be defined for
11
+ # class methods on their first utilization.
12
+ # @example
13
+ # cl = Colourlovers::Client.new
14
+ # cl.colors #=> [...]
15
+ def method_missing(method, *args, &block)
16
+ super unless self.class.respond_to? method
17
+ self.class.class_eval do
18
+ define_method method do |*args, &block|
19
+ self.class.send(method, *args, &block)
20
+ end
21
+ end
22
+ self.class.send(method, *args, &block)
23
+ end
24
+
25
+ class << self
26
+
27
+
28
+ # Handle responses from HTTParty calls to the COLOURlovers API with
29
+ # some generic response interpretation and manipulation.
30
+ # @todo Add individual errors for various HTTP Status codes
31
+ def handle_response(response)
32
+ status = response.code
33
+
34
+ case status
35
+ when 404 then STDERR.puts "404 - maybe COLOURlovers down? #{$!}"
36
+ when 400..499 then STDERR.puts "400-499 - maybe COLOURlovers down? #{$!}"
37
+ when 500..599 then STDERR.puts "500-599 - maybe COLOURlovers down? #{$!}"
38
+ else response.first
39
+ end
40
+
41
+ end
42
+ private :handle_response
43
+
44
+ # Handle all HTTParty responses with some error handling so that our
45
+ # individual methods don't have to worry about it at all (although they)
46
+ # can (and should where relevant) rescue from errors when they are able to.
47
+ [:get, :head, :post, :put, :delete].each do |http_verb|
48
+ define_method http_verb do |*args|
49
+ begin
50
+ handle_response super(*args)
51
+ rescue Exception
52
+ STDERR.puts "socketerror - maybe no connection? #{$!}"
53
+ exit
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+
60
+ ## COLORS ##
61
+
62
+ # List colors
63
+ # @see Colourlovers::Color.all
64
+ def colors(options={})
65
+ Color.all(options)
66
+ end
67
+
68
+ # List top colors
69
+ # @see Colourlovers::Color.top
70
+ def top_colors(options={})
71
+ Color.top(options)
72
+ end
73
+
74
+ # List new colors
75
+ # @see Colourlovers::Color.new
76
+ def new_colors(options={})
77
+ Color.new(options)
78
+ end
79
+
80
+ # Retrieve random color
81
+ # @see Colourlovers::Color.random
82
+ def random_color
83
+ Color.random
84
+ end
85
+
86
+ # Retrieve color from hex value
87
+ # @see Colourlovers::Color.find
88
+ def color(hex)
89
+ Color.find(hex)
90
+ end
91
+
92
+ ## PALETTES ##
93
+
94
+ # List palettes
95
+ # @see Colourlovers::Palette.all
96
+ def palettes(options={})
97
+ Palette.all(options)
98
+ end
99
+
100
+ # List top palettes
101
+ # @see Colourlovers::Palette.top
102
+ def top_palettes(options={})
103
+ Palette.top(options)
104
+ end
105
+
106
+ # List new palettes
107
+ # @see Colourlovers::Palette.new
108
+ def new_palettes(options={})
109
+ Palette.new(options)
110
+ end
111
+
112
+ # Retrieve random palette
113
+ # @see Colourlovers::Palette.random
114
+ def random_palette
115
+ Palette.random
116
+ end
117
+
118
+ # Retrieve palette from paletteID
119
+ # @see Colourlovers::Palette.find
120
+ def palette(paletteID)
121
+ Palette.find(paletteID)
122
+ end
123
+
124
+ ## PATTERNS ##
125
+
126
+ # List patterns
127
+ # @see Colourlovers::Pattern.all
128
+ def patterns(options={})
129
+ Pattern.all(options)
130
+ end
131
+
132
+ # List top patterns
133
+ # @see Colourlovers::Pattern.top
134
+ def top_patterns(options={})
135
+ Pattern.top(options)
136
+ end
137
+
138
+ # List new patterns
139
+ # @see Colourlovers::Pattern.new
140
+ def new_patterns(options={})
141
+ Pattern.new(options)
142
+ end
143
+
144
+ # Retrieve random pattern
145
+ # @see Colourlovers::Pattern.random
146
+ def random_pattern
147
+ Pattern.random
148
+ end
149
+
150
+ # Retrieve pattern from patternID
151
+ # @see Colourlovers::Pattern.find
152
+ def pattern(patternID)
153
+ Pattern.find(patternID)
154
+ end
155
+
156
+ ## LOVERS ##
157
+
158
+ # List lovers
159
+ # @see Colourlovers::Lover.all
160
+ def lovers(options={})
161
+ Lover.all(options)
162
+ end
163
+
164
+ # List top lovers
165
+ # @see Colourlovers::Lover.top
166
+ def top_lovers(options={})
167
+ Lover.top(options)
168
+ end
169
+
170
+ # List new lovers
171
+ # @see Colourlovers::Lover.new
172
+ def new_lovers(options={})
173
+ Lover.new(options)
174
+ end
175
+
176
+ # Retrieve lover from username
177
+ # @see Colourlovers::Lover.find
178
+ def lover(username)
179
+ Lover.find(username)
180
+ end
181
+
182
+ end
183
+
184
+ end
185
+
186
+ end
@@ -0,0 +1,46 @@
1
+ module Colourlovers
2
+
3
+ class Color
4
+
5
+ class << self
6
+
7
+ # Retrieve colors as an array of hashes with options available from Colourlovers API
8
+ # see documentation here: http://www.colourlovers.com/api#colors
9
+ # lover = COLOURlover
10
+ # hueRange = 12,68 [values must be 0>value<359, and the left value must be less than the right value]
11
+ # briRange = 2,88 [values must be 0>value<99, and the left value must be less than the right value]
12
+ # keywords = search+term
13
+ # keywordExact = 0 or 1 [Perform an exact search for the keywords passed. Default 0]
14
+ # orderCol = X [Where X can be: dateCreated, score, name, numVotes, or numViews]
15
+ # sortBy = X [Where X can be: ASC or DESC. Default ASC]
16
+ # numResults = 20 [Number of results to return, maximum of 100. Default 20]
17
+ # resultOffset = 5 [Result offset, for paging. Default 0]
18
+ def all(options)
19
+ Client.get("/colors", :query => options)
20
+ end
21
+
22
+ # Retrives colors as an array of hashes, same options as all but ordered by popularity
23
+ def top(options)
24
+ Client.get("/colors/top", :query => options)
25
+ end
26
+
27
+ # Retrives colors as an array of hashes, same options as all but ordered by dateCreated
28
+ def new(options)
29
+ Client.get("/colors/new", :query => options)
30
+ end
31
+
32
+ # Retrieve random color as an array with one hash, no parameters allowed
33
+ def random
34
+ Client.get("/colors/random")
35
+ end
36
+
37
+ # Retrieve color details from hex value as an array with one hash
38
+ def find(hex)
39
+ Client.get("/color/#{hex}")
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,36 @@
1
+ module Colourlovers
2
+
3
+ class Lover
4
+
5
+ class << self
6
+
7
+ # Retrieve lovers as an array of hashes with options available from Colourlovers API
8
+ # see documentation here: http://www.colourlovers.com/api#lovers
9
+ # orderCol = X [Where X can be: dateCreated, score, name, numVotes, or numViews]
10
+ # sortBy = X [Where X can be: ASC or DESC. Default ASC]
11
+ # numResults = 20 [Number of results to return, maximum of 100. Default 20]
12
+ # resultOffset = 5 [Result offset, for paging. Default 0]
13
+ def all(options)
14
+ Client.get("/lovers", :query => options)
15
+ end
16
+
17
+ # Retrives lovers as an array of hashes, same options as all but ordered by popularity
18
+ def top(options)
19
+ Client.get("/lovers/top", :query => options)
20
+ end
21
+
22
+ # Retrives lovers as an array of hashes, same options as all but ordered by dateCreated
23
+ def new(options)
24
+ Client.get("/lovers/new", :query => options)
25
+ end
26
+
27
+ # Retrieve lover details from username as an array with one hash
28
+ def find(username)
29
+ Client.get("/lover/#{username}")
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,50 @@
1
+ module Colourlovers
2
+
3
+ class Palette
4
+
5
+ class << self
6
+
7
+ # Retrieve palettes as an array of hashes with options available from Colourlovers API
8
+ # see documentation here: http://www.colourlovers.com/api#palettes
9
+ # lover = COLOURlover
10
+ # hueOption = yellow,orange,red or green,violet or blue
11
+ # [Possible Values can be a combination of: red, orange, yellow, green, aqua, blue, violet, and / or fuchsia]
12
+ # hex = 00FF33 [Possible Values: any valid 6-char hex value]
13
+ # keywords = search+term
14
+ # keywordExact = 0 or 1 [Perform an exact search for the keywords passed. Default 0]
15
+ # orderCol = X [Where X can be: dateCreated, score, name, numVotes, or numViews]
16
+ # sortBy = X [Where X can be: ASC or DESC. Default ASC]
17
+ # numResults = 20 [Number of results to return, maximum of 100. Default 20]
18
+ # resultOffset = 5 [Result offset, for paging. Default 0]
19
+ # format = json or xml [Result format. Default is xml]
20
+ # jsonCallback = yourCallbackFunction [Adds a callback to JSON format. Assumes format=json]
21
+ # showPaletteWidths = 0 or 1 [Shows palette's color's widths. Default 0]
22
+ def all(options)
23
+ Client.get("/palettes", :query => options)
24
+ end
25
+
26
+ # Retrives palettes as an array of hashes, same options as all but ordered by popularity
27
+ def top(options)
28
+ Client.get("/palettes/top", :query => options)
29
+ end
30
+
31
+ # Retrives palettes as an array of hashes, same options as all but ordered by dateCreated
32
+ def new(options)
33
+ Client.get("/palettes/new", :query => options)
34
+ end
35
+
36
+ # Retrieve random palette as an array with one hash, no parameters allowed
37
+ def random
38
+ Client.get("/palettes/random")
39
+ end
40
+
41
+ # Retrieve palette details from paletteID as an array with one hash
42
+ def find(paletteID)
43
+ Client.get("/palette/#{paletteID}")
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,47 @@
1
+ module Colourlovers
2
+
3
+ class Pattern
4
+
5
+ class << self
6
+
7
+ # Retrieve patterns as an array of hashes with options available from Colourlovers API
8
+ # see documentation here: http://www.colourlovers.com/api#patterns
9
+ # lover = COLOURlover
10
+ # hueOption = yellow,orange,red or green,violet or blue
11
+ # [Possible Values can be a combination of: red, orange, yellow, green, aqua, blue, violet, and / or fuchsia]
12
+ # hex = 00FF33 [Possible Values: any valid 6-char hex value]
13
+ # keywords = search+term
14
+ # keywordExact = 0 or 1 [Perform an exact search for the keywords passed. Default 0]
15
+ # orderCol = X [Where X can be: dateCreated, score, name, numVotes, or numViews]
16
+ # sortBy = X [Where X can be: ASC or DESC. Default ASC]
17
+ # numResults = 20 [Number of results to return, maximum of 100. Default 20]
18
+ # resultOffset = 5 [Result offset, for paging. Default 0]
19
+ def all(options)
20
+ Client.get("/patterns", :query => options)
21
+ end
22
+
23
+ # Retrives patterns as an array of hashes, same options as all but ordered by popularity
24
+ def top(options)
25
+ Client.get("/patterns/top", :query => options)
26
+ end
27
+
28
+ # Retrives patterns as an array of hashes, same options as all but ordered by dateCreated
29
+ def new(options)
30
+ Client.get("/patterns/new", :query => options)
31
+ end
32
+
33
+ # Retrieve random pattern as an array with one hash, no parameters allowed
34
+ def random
35
+ Client.get("/patterns/random")
36
+ end
37
+
38
+ # Retrieve pattern details from patternID
39
+ def find(patternID)
40
+ Client.get("/pattern/#{patternID}")
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,3 @@
1
+ module Colourlovers
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colourlovers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Masters
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70281982366840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70281982366840
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70281982366420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70281982366420
36
+ description: A simple gem to use to make it easy to use the COLOURlovers API http://www.colourlovers.com/api.
37
+ This is my first gem and there are currently no tests, bt I am working on it.
38
+ email:
39
+ - chrismasters@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - colourlovers.gemspec
50
+ - lib/colourlovers.rb
51
+ - lib/colourlovers/client.rb
52
+ - lib/colourlovers/color.rb
53
+ - lib/colourlovers/lover.rb
54
+ - lib/colourlovers/palette.rb
55
+ - lib/colourlovers/pattern.rb
56
+ - lib/colourlovers/version.rb
57
+ homepage: https://github.com/chrism/COLOURlovers
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ segments:
70
+ - 0
71
+ hash: 4566665335935066597
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 4566665335935066597
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.17
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: A ruby wrapper for the COLOURlovers API
87
+ test_files: []