Class: IHeartQuotes::Client
- Inherits:
-
Object
- Object
- IHeartQuotes::Client
- 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
-
.random ⇒ IHeartQuotes::Fortune
Instanciates an IHeartQuotes::Client object and return a randome IHeartQuotes::Fortune.
-
.where(opts) ⇒ IHeartQuotes::Client
Instantiates an IHeartQuotes::Client object and set the given options via the where method.
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#random ⇒ IHeartQuotes::Fortune
Gets a random fortune.
-
#where(opts) ⇒ IHeartQuotes::Client
Sets filters for the fortunes search.
Constructor Details
#initialize ⇒ Client
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
.random ⇒ IHeartQuotes::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
#random ⇒ IHeartQuotes::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)
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 |