Class: SVNCampfireNotifier::GoogleImage
- Inherits:
-
Object
- Object
- SVNCampfireNotifier::GoogleImage
- Defined in:
- lib/svn_campfire_notifier/google_image.rb
Constant Summary collapse
- URL =
'http://images.google.com/images?safe=active'
- RESULTS_REGEXP =
/setResults\((\[\[.+\]\])\);/
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
Instance Method Summary collapse
- #extra_options ⇒ Object
- #feeling_lucky ⇒ Object
-
#initialize(project) ⇒ GoogleImage
constructor
A new instance of GoogleImage.
- #query ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(project) ⇒ GoogleImage
Returns a new instance of GoogleImage.
8 9 10 |
# File 'lib/svn_campfire_notifier/google_image.rb', line 8 def initialize(project) @project = project end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/svn_campfire_notifier/google_image.rb', line 6 def project @project end |
Class Method Details
.feeling_lucky(query) ⇒ Object
43 44 45 |
# File 'lib/svn_campfire_notifier/google_image.rb', line 43 def self.feeling_lucky(query) new(query).feeling_lucky end |
Instance Method Details
#extra_options ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/svn_campfire_notifier/google_image.rb', line 12 def { 'isch' => '1', 'itp' => project.image_type, 'ic' => 'specific', 'ics' => project.color }.inject([]) do |serialized, (key, value)| serialized << "#{key}:#{value}" end.join(',') end |
#feeling_lucky ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/svn_campfire_notifier/google_image.rb', line 31 def feeling_lucky puts url response = REST.get(url) if response.ok? and match = RESULTS_REGEXP.match(response.body) data = JSON.parse(match[1]).first image_url = data[3] token = data[2] image_host = data[14] "#{image_host}?q=tbn:#{token}#{image_url}" end end |
#query ⇒ Object
23 24 25 |
# File 'lib/svn_campfire_notifier/google_image.rb', line 23 def query "#{project.subject}+#{project.revision}" end |
#url ⇒ Object
27 28 29 |
# File 'lib/svn_campfire_notifier/google_image.rb', line 27 def url "#{URL}&q=#{query}&tbs=#{}" end |