Class: IHeartQuotes::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/i_heart_quotes/client.rb

Overview

I <3 Quotes Client

Constant Summary collapse

RANDOM_PATH =

Random call API path

'/api/v1/random'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



14
15
16
# File 'lib/i_heart_quotes/client.rb', line 14

def initialize
  @options = {:format => 'json'}
end

Class Method Details

.randomIHeartQuotes::Fortune

Instanciates an IHeartQuotes::Client object and return a randome IHeartQuotes::Fortune



22
23
24
# File 'lib/i_heart_quotes/client.rb', line 22

def self.random
  Client.new.random
end

.where(opts) ⇒ IHeartQuotes::Client

Instantiates an IHeartQuotes::Client object and set the given options via the where method



30
31
32
# File 'lib/i_heart_quotes/client.rb', line 30

def self.where(opts)
  Client.new.where(opts)
end

Instance Method Details

#randomIHeartQuotes::Fortune

Gets a random fortune



37
38
39
# File 'lib/i_heart_quotes/client.rb', line 37

def random
  return Fortune.new(self.class.get(RANDOM_PATH, :query => @options))
end

#where(opts) ⇒ IHeartQuotes::Client

Sets filters for the fortunes search

Filters Supported:

  • :source (“+” separated list of desired sources - available sources at iheartquotes.com/api)

  • :max_lines (maximum number of lines in the quote)

  • :min_lines (minumum number of lines in the quote)

  • :max_characters (maximum number of characters in the quote)

  • :min_characters (minimum number of characters in the quote)

Parameters:

  • opts (Symbol => String, Number)

    filters to be set

Returns:



53
54
55
56
57
# File 'lib/i_heart_quotes/client.rb', line 53

def where(opts)
  opts.delete(:format)
  @options.merge!(opts)
  self
end