Class: Yummly::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/yummly/api.rb

Overview

This class is the primary mechanism to execute Yummly API calls.

Currently Yummly only has two public API calls: one for searching recipes and the other to retrieve a specific recipe.

Examples:

Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
Yummly::Api.search('Onion soup')

Class Method Summary collapse

Class Method Details

.find(id) ⇒ Yummly::Recipe

Retrieves a single recipe.

Examples:

recipe = Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')

Parameters:

  • id (String)

    The yummly recipe identifier.

Returns:



17
18
19
20
# File 'lib/yummly/api.rb', line 17

def self.find(id)
  recipe_json = Yummly::Connection.get("recipe/#{id}")
  Yummly::Recipe.new(recipe_json)
end

.search(terms, params = {}) ⇒ Array

Searches for recipes that match the supplied search terms.

Examples:

recipes = Yummly::Api.search('Onion soup')

Parameters:

  • terms (String)

    A string of terms used to search API

  • params (Hash) (defaults to: {})

    Additional options to pass to the search API

Returns:

  • (Array)

    a collection of recipe objects



29
30
31
32
33
# File 'lib/yummly/api.rb', line 29

def self.search(terms, params = {})
  params[:q] = terms unless params.has_key?(:q)
  result = Yummly::Connection.get(:recipes, params)
  result["matches"].collect { |recipe_json| Yummly::Recipe.new(recipe_json) }
end