Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
clean code and added more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
soleo committed Oct 14, 2015
1 parent 14ecb1b commit 9bfb410
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
12 changes: 3 additions & 9 deletions lib/DDG/Spice/Cocoapods.pm
@@ -1,34 +1,28 @@
package DDG::Spice::Cocoapods;
# ABSTRACT: Write an abstract here
# Start at https://duck.co/duckduckhack/spice_overview if you are new
# to instant answer development

use DDG::Spice;

spice is_cached => 1;

# Metadata. See https://duck.co/duckduckhack/metadata for help in filling out this section.
name "Cocoapods";
source "https://cocoapods.org";
icon_url "https://cocoapods.org/favicons/favicon.ico";
description "Search Pod Info from Cocoapods";
primary_example_queries "cocoapods AFNetworking", "cocoapods SVProgressHUD";
secondary_example_queries "cocoapods AFNetworking for ios";
# Uncomment and complete: https://duck.co/duckduckhack/metadata#category

category "programming";
# Uncomment and complete: https://duck.co/duckduckhack/metadata#topics

topics "computing", "programming";
code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Cocoapods.pm";
attribution github => ["https://github.com/soleo", "Xinjiang Shao"],
twitter => ['https://twitter.com/soleoshao', 'Xinjiang Shao'];

# Triggers
#triggers any => "cocoapods", "trigger phrase";
triggers startend => 'cocoapods';

spice to => 'http://search.cocoapods.org/api/v1/pods.flat.hash.json?query=$1';
spice wrap_jsonp_callback => 1;
# Handle statement

handle remainder => sub {
return lc $_ if $_;
return;
Expand Down
9 changes: 3 additions & 6 deletions share/spice/cocoapods/cocoapods.js
Expand Up @@ -2,20 +2,17 @@
"use strict";
env.ddg_spice_cocoapods = function(api_result){

// Validate the response (customize for your Spice)

if (!api_result || api_result.error) {
return Spice.failed('cocoapods');
}

// Get the original query.
var script = $('[src*="/js/spice/cocoapods/"]')[0];
var source = $(script).attr("src");
var query = source.match(/cocoapods\/([^\/]*)/)[1];
var query = DDG.get_query().replace("cocoapods", "");

// Render the response
Spice.add({
id: "cocoapods",
// Customize these properties
name: "Software",
data: api_result,
meta: {
Expand All @@ -28,7 +25,7 @@
normalize: function(item) {
return {
title: item.id + ' ' + item.version,
subtitle: item.platforms,
subtitle: item.platforms.join(', ').toUpperCase(),
url: item.link,
description: item.summary
}
Expand Down
19 changes: 16 additions & 3 deletions t/Cocoapods.t
Expand Up @@ -9,14 +9,27 @@ spice is_cached => 1;

ddg_spice_test(
[qw( DDG::Spice::Cocoapods)],
# At a minimum, be sure to include tests for all:
# - primary_example_queries
# - secondary_example_queries

'cocoapods test' => test_spice(
'/js/spice/cocoapods/test',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),
'cocoapods afnetworking' => test_spice(
'/js/spice/cocoapods/afnetworking',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),
'cocoapods SVProgressHUD' => test_spice(
'/js/spice/cocoapods/svprogresshud',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),
'cocoapods AFNetworking for ios' => test_spice(
'/js/spice/cocoapods/afnetworking%20for%20ios',
call_type => 'include',
caller => 'DDG::Spice::Cocoapods'
),

# Try to include some examples of queries on which it might
# appear that your answer will trigger, but does not.
Expand Down

0 comments on commit 9bfb410

Please sign in to comment.