Skip to content

Commit

Permalink
Browse status.rubygems.org when there's a network error.
Browse files Browse the repository at this point in the history
  • Loading branch information
attilagyorffy committed Aug 27, 2013
1 parent 8525391 commit 47ecfb9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<key>plusspaces</key>
<false/>
<key>url</key>
<string>http://rubygems.org/gems/{query}</string>
<string>{query}</string>
<key>utf8</key>
<true/>
</dict>
Expand Down
3 changes: 2 additions & 1 deletion lib/alfred_feedback_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize(title, options = {})
@title = title
@subtitle = options[:subtitle]
@valid = options[:valid].nil? ? true : !!options[:valid]
@arg = options[:arg] || @title
end

def valid?
Expand All @@ -17,7 +18,7 @@ def to_xml
REXML::Element.new('item').tap do |xml_item|
xml_item.add_attributes({
'uid' => @title,
'arg' => @title,
'arg' => @arg,
'valid' => valid? ? 'yes' : 'no'
})

Expand Down
27 changes: 17 additions & 10 deletions rubygems-search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@
query = ARGV[0]

feedback = AlfredFeedback.new
gem_results = Gems.search(query)

if gem_results.any?
begin
gem_results = Gems.search(query)

gem_results.each do |gem_data|
name = gem_data['name']
info = gem_data['info']
version = gem_data['version']
subtitle = "#{version} - #{info}"
if gem_results.any?

feedback << AlfredFeedBackItem.new(name, :subtitle => subtitle)
gem_results.each do |gem_data|
name = gem_data['name']
info = gem_data['info']
version = gem_data['version']
arg = ""
subtitle = "#{version} - #{info}"

feedback << AlfredFeedBackItem.new(name, :subtitle => subtitle, :arg => "http://rubygems.org/gems/#{name}")
end
else
feedback << AlfredFeedBackItem.new("No gems found for '#{query}'.", :subtitle => "Are you sure you're looking for the right thing?", :valid => false)
end
else
feedback << AlfredFeedBackItem.new("No gems found for '#{query}'.", :subtitle => "Are you sure you're looking for the right thing?", :valid => false)
rescue SocketError => e
rubygems_status_url = 'http://status.rubygems.org'
feedback << AlfredFeedBackItem.new("Error: RubyGems seems unavailable.", :subtitle => "SocketError occurred: #{e}", :arg => rubygems_status_url)
end

puts feedback

0 comments on commit 47ecfb9

Please sign in to comment.