Sha256: 91b26f1c1d155c50c4c02971bf0037955630af3ef581e011030d961fa52446f9

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# 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.
#
# @example
#   Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
# @example
#   Yummly::Api.search('Onion soup')

module Yummly
  class Api

    # Retrieves a single recipe.
    #
    # @param [String] id The yummly recipe identifier.
    # @return [Yummly::Recipe] a instance of a recipe object
    # @example
    #   recipe = Yummly::Api.find('French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364')
    def self.find(id)
      recipe_json = Yummly::Connection.get("recipe/#{id}")
      Yummly::Recipe.new(recipe_json)
    end

    # Searches for recipes that match the supplied search terms.
    #
    # @param [String] terms A string of terms used to search API
    # @param [Hash] params Additional options to pass to the search API
    # @return [Array] a collection of recipe objects
    # @example
    #   recipes = Yummly::Api.search('Onion soup')
    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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yummly-0.0.9 lib/yummly/api.rb
yummly-0.0.8 lib/yummly/api.rb
yummly-0.0.7 lib/yummly/api.rb
yummly-0.0.6 lib/yummly/api.rb
yummly-0.0.5 lib/yummly/api.rb
yummly-0.0.4 lib/yummly/api.rb