Class: Punchr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/punchr/client.rb

Instance Method Summary collapse

Instance Method Details

#diet_index(ingredients) ⇒ Object

Generate an array of diet terms describing which diets are safe for the input recipe ingredients.

Parameters:

  • ingredients (String)

    Recipe ingredients, as a newline-separated list. Also see punchfork.com/api.

Returns:

  • An array of diet terms describing which diets are safe for the input recipe ingredients.



44
45
46
47
48
49
50
# File 'lib/punchr/client.rb', line 44

def diet_index(ingredients)
  JSON.parse(Typhoeus::Request.post(
    api_url('diet_index'),
    :headers => {'User-Agent' => Punchr::USER_AGENT_HEADER},
    :params => {:key => Punchr.api_key, :ingredients => ingredients}
  ).body)
end

#publishersObject

Retrieve all recipe publishers on Punchfork.

Returns:

  • All recipe publishers on Punchfork.



32
33
34
35
36
37
38
# File 'lib/punchr/client.rb', line 32

def publishers
  JSON.parse(Typhoeus::Request.get(
    api_url('publishers'),
    :headers => {'User-Agent' => Punchr::USER_AGENT_HEADER},
    :params => {:key => Punchr.api_key}
  ).body)
end

#random_recipeObject

Retrieve a single recipe selected at random from the Punchfork database.

Returns:

  • A single recipe selected at random from the Punchfork database.



21
22
23
24
25
26
27
# File 'lib/punchr/client.rb', line 21

def random_recipe
  JSON.parse(Typhoeus::Request.get(
    api_url('random_recipe'),
    :headers => {'User-Agent' => Punchr::USER_AGENT_HEADER},
    :params => {:key => Punchr.api_key}
  ).body)
end

#rate_limit_statusObject

Retrieve the number of remaining API calls allowed today for the given API key.

Returns:

  • The number of remaining API calls allowed today for the given API key.



68
69
70
71
72
73
74
# File 'lib/punchr/client.rb', line 68

def rate_limit_status
  JSON.parse(Typhoeus::Request.get(
    api_url('rate_limit_status'),
    :headers => {'User-Agent' => Punchr::USER_AGENT_HEADER},
    :params => {:key => Punchr.api_key}
  ).body)
end

#recipes(options = {}) ⇒ Object

Recipe search.

Parameters:

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

    For details on valid options see punchfork.com/api.

Returns:

  • Search results matching the input options.



10
11
12
13
14
15
16
# File 'lib/punchr/client.rb', line 10

def recipes(options = {})
  JSON.parse(Typhoeus::Request.get(
    api_url('recipes'),
    :headers => {'User-Agent' => Punchr::USER_AGENT_HEADER},
    :params => options.dup.merge({:key => Punchr.api_key})
  ).body)
end

#search_index(title, ingredients) ⇒ Object

Generate search index terms for the input recipe. Also see punchfork.com/api.

Parameters:

  • title (String)

    Recipe title.

  • ingredients (String)

    Recipe ingredients, as a newline-separated list.

Returns:

  • Search index terms for the input recipe.



57
58
59
60
61
62
63
# File 'lib/punchr/client.rb', line 57

def search_index(title, ingredients)
  JSON.parse(Typhoeus::Request.post(
    api_url('search_index'),
    :headers => {'User-Agent' => Punchr::USER_AGENT_HEADER},
    :params => {:key => Punchr.api_key, :title => title, :ingredients => ingredients}
  ).body)
end