i_heart_quotes 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,6 +8,10 @@ This is a ruby client to interact with the [I <3 Quotes](http://iheartquotes.com
8
8
 
9
9
  (Working on Ruby 1.9.X - Let me know if you need the 1.8.X version)
10
10
 
11
+ ## Full Documentation
12
+
13
+ http://rdoc.info/gems/i_heart_quotes/frames
14
+
11
15
  ## Authors
12
16
 
13
17
  Roberto Decurnex (nex.development@gmail.com)
@@ -42,4 +46,24 @@ You can also clone the project with Git by running:
42
46
  fortune.tags #=> ["hitchhiker"]
43
47
 
44
48
  fortune.link #=> "http://iheartquotes.com/fortune/show/7934"
49
+
50
+ ### Using filters
51
+
52
+ require 'i_heart_quotes'
45
53
 
54
+ # Returns a quote from the hitchhiker that has a single line.
55
+ IHeartQuotes::Client.where(:source => "hitchhiker", :max_lines => 1).random
56
+
57
+ # Returns a quote from the either hitchhiker or cryptonomicon that has at most 2 lines.
58
+ # Note that you can chain as many where s as you want.
59
+ IHeartQuotes::Client.where(:source => "hitchhiker+cryptonomicon").where(:max_lines => 2).random
60
+
61
+ ## Supported Filters
62
+
63
+ * **:source** ("+" separated list of desired sources. Available sources at http://iheartquotes.com/api)
64
+ * **:max_lines** (maximum number of lines in the quote)
65
+ * **:min_lines** (minumum number of lines in the quote)
66
+ * **:max_characters** (maximum number of characters in the quote)
67
+ * **:min_characters** (minimum number of characters in the quote)
68
+
69
+
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'i_heart_quotes'
3
- s.version = '0.1.0'
4
- s.date = '2012-03-06'
3
+ s.version = '0.2.0'
4
+ s.date = '2012-03-14'
5
5
  s.summary = 'I <3 Quotes Client'
6
6
  s.authors = ['Roberto Decurnex']
7
7
  s.email = 'nex.development@gmail.com'
@@ -2,17 +2,58 @@ module IHeartQuotes
2
2
 
3
3
  # I <3 Quotes Client
4
4
  class Client
5
-
5
+
6
6
  # Random call API path
7
- RANDOM_PATH = '/api/v1/random?format=json'
7
+ RANDOM_PATH = '/api/v1/random'
8
8
 
9
9
  include HTTParty
10
10
 
11
11
  self.base_uri 'http://iheartquotes.com'
12
12
  self.format :json
13
13
 
14
+ def initialize
15
+ @options = {:format => 'json'}
16
+ end
17
+
18
+ # Instanciates an IHeartQuotes::Client object and
19
+ # return a randome IHeartQuotes::Fortune
20
+ #
21
+ # @return <IHeartQuotes::Fortune>
14
22
  def self.random
15
- return Fortune.new(self.get(RANDOM_PATH))
23
+ Client.new.random
24
+ end
25
+
26
+ # Instantiates an IHeartQuotes::Client object and
27
+ # set the given options via the where method
28
+ #
29
+ # @return <IHeartQuotes::Client>
30
+ def self.where(opts)
31
+ Client.new.where(opts)
32
+ end
33
+
34
+ # Gets a random fortune
35
+ #
36
+ # @return <IHeartQuotes::Fortune>
37
+ def random
38
+ return Fortune.new(self.class.get(RANDOM_PATH, :query => @options))
39
+ end
40
+
41
+
42
+ # Sets filters for the fortunes search
43
+ #
44
+ # Filters Supported:
45
+ # * :source ("+" separated list of desired sources - available sources at http://iheartquotes.com/api)
46
+ # * :max_lines (maximum number of lines in the quote)
47
+ # * :min_lines (minumum number of lines in the quote)
48
+ # * :max_characters (maximum number of characters in the quote)
49
+ # * :min_characters (minimum number of characters in the quote)
50
+ #
51
+ # @param {Symbol => String,Number} opts filters to be set
52
+ # @return <IHeartQuotes::Client>
53
+ def where(opts)
54
+ opts.delete(:format)
55
+ @options.merge!(opts)
56
+ self
16
57
  end
17
58
 
18
59
  end
@@ -1,5 +1,7 @@
1
1
  require 'httparty'
2
2
 
3
+ require_relative 'fortune'
4
+
3
5
  require_relative 'i_heart_quotes/fortune'
4
6
  require_relative 'i_heart_quotes/client'
5
7
 
@@ -1,9 +1,27 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe IHeartQuotes::Client do
4
-
4
+
5
5
  it 'should return a random Fortune when requested' do
6
6
  IHeartQuotes::Client.random.should be_an_instance_of IHeartQuotes::Fortune
7
+ IHeartQuotes::Client.new.random.should be_an_instance_of IHeartQuotes::Fortune
8
+ end
9
+
10
+ describe 'filtered by source' do
11
+
12
+ it 'should return only quotes from the target source' do
13
+ IHeartQuotes::Client.where({:source => 'hitchhiker'}).random.source.should == 'hitchhiker'
14
+ IHeartQuotes::Client.where({:source => 'cryptonomicon'}).random.should be_an_instance_of IHeartQuotes::Fortune
15
+ end
16
+
17
+ end
18
+
19
+ describe 'with valid filters' do
20
+
21
+ it 'should return a valid quote' do
22
+ IHeartQuotes::Client.where({:source => 'hitchhiker+cryptonomicon'}).where(:max_lines => 1).random.should be_an_instance_of IHeartQuotes::Fortune
23
+ end
24
+
7
25
  end
8
26
 
9
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i_heart_quotes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000Z
12
+ date: 2012-03-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &22770300 !ruby/object:Gem::Requirement
16
+ requirement: &23137980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *22770300
24
+ version_requirements: *23137980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &22769860 !ruby/object:Gem::Requirement
27
+ requirement: &23137540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *22769860
35
+ version_requirements: *23137540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: httparty
38
- requirement: &22805000 !ruby/object:Gem::Requirement
38
+ requirement: &23137120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *22805000
46
+ version_requirements: *23137120
47
47
  description:
48
48
  email: nex.development@gmail.com
49
49
  executables: []
@@ -90,3 +90,4 @@ signing_key:
90
90
  specification_version: 3
91
91
  summary: I <3 Quotes Client
92
92
  test_files: []
93
+ has_rdoc: