binged 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/binged.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{binged}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kevin Faustino"]
12
- s.date = %q{2010-03-07}
12
+ s.date = %q{2010-03-08}
13
13
  s.description = %q{A wrapper for the bing api}
14
14
  s.email = %q{kevin.faustino@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -1,10 +1,12 @@
1
1
  module Binged
2
2
  module Search
3
-
3
+
4
4
  # A class that encapsulated the Bing Web Search source
5
5
  # @todo Add support for adult and market filtering
6
6
  class Web < Base
7
-
7
+
8
+ SEARCH_RESULTS_LIMIT = 1000
9
+
8
10
  SUPPORTED_FILE_TYPES = [:doc, :dwf, :feed, :htm, :html, :pdf, :ppt, :ps, :rtf, :text, :txt, :xls]
9
11
 
10
12
  # @param [Binged::Client] client
@@ -18,7 +20,7 @@ module Binged
18
20
  end
19
21
 
20
22
  # Add query to search
21
- #
23
+ #
22
24
  # @param [String] query The search term to be sent to Bing
23
25
  # @return [self]
24
26
  def containing(query)
@@ -26,36 +28,36 @@ module Binged
26
28
  self
27
29
  end
28
30
 
29
- # Retrieve results of the web search
30
- #
31
+ # Retrieve results of the web search. Limited to first 1000 results.
32
+ #
31
33
  # @return [Hash] A hash of the results returned from Bing
32
34
  def fetch
33
- if @fetch.nil?
35
+ if @fetch.nil?
34
36
  response = perform
35
- @fetch = Hashie::Mash.new(response["SearchResponse"]["Web"]) if response
37
+ @fetch = Hashie::Mash.new(response["SearchResponse"]["Web"])
36
38
  end
37
39
 
38
- @fetch || []
40
+ @fetch
39
41
  end
40
-
42
+
41
43
  # Add filtering based on a file type
42
- #
44
+ #
43
45
  # @example
44
46
  # web_search.file_type(:pdf) # Isolate search to PDF files
45
- #
47
+ #
46
48
  # @param [Symbol] type A symbol of a {SUPPORTED_FILE_TYPES}
47
49
  # @return [self]
48
50
  # @see http://msdn.microsoft.com/en-us/library/dd250876.aspx Description of all supported file types
49
- def file_type(type)
51
+ def file_type(type)
50
52
  @query['Web.FileType'] = type if SUPPORTED_FILE_TYPES.include?(type)
51
53
  self
52
54
  end
53
-
54
- # Isolate search results to a specific site
55
- #
55
+
56
+ # Isolate search results to a specific site
57
+ #
56
58
  # @example
57
59
  # web_search.from_site('www.ruby-lang.org')
58
- #
60
+ #
59
61
  # @param [String] site Web site address to limit search results to
60
62
  # @return [self]
61
63
  def from_site(site)
@@ -64,17 +66,17 @@ module Binged
64
66
  end
65
67
 
66
68
  # Set the page number of the results to display
67
- #
69
+ #
68
70
  # @param [Fixnum] num The page number of the search results
69
71
  # @return [self]
70
72
  def page(num=1)
71
- offset = num - 1
72
- @query['Web.Offset'] = @results_per_page * offset
73
+ @offset = num - 1
74
+ @query['Web.Offset'] = @results_per_page * @offset
73
75
  self
74
76
  end
75
77
 
76
78
  # The amount of results to display per page. Initialized to 20 per page.
77
- #
79
+ #
78
80
  # @param [Fixnum] num The number of results per page
79
81
  # @return [self]
80
82
  def per_page(num)
@@ -83,6 +85,18 @@ module Binged
83
85
  self
84
86
  end
85
87
 
88
+ # The total amount of pages available
89
+ #
90
+ # @return[Fixnum] Amount of pages
91
+ def total_pages
92
+ bing_total = fetch.total.to_i
93
+ if bing_total < SEARCH_RESULTS_LIMIT
94
+ bing_total / @results_per_page
95
+ else
96
+ SEARCH_RESULTS_LIMIT / @results_per_page
97
+ end
98
+ end
99
+
86
100
  end
87
101
  end
88
102
  end
@@ -50,13 +50,28 @@ module Binged
50
50
  it "should return the results of the search" do
51
51
  @response.results.size.should == 20
52
52
  end
53
-
53
+
54
54
  it "should support dot notation" do
55
55
  result = @response.results.first
56
56
  result.title.should == "Ruby Programming Language"
57
57
  result.description.should == "Ruby is… A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is ..."
58
58
  result.url.should == "http://www.ruby-lang.org/en/"
59
59
  end
60
+
61
+ context "total pages" do
62
+
63
+ it "should return of maximum amount of pages that does not exceed the the Bing limit" do
64
+ bing_limit = 1000
65
+ @response.should_receive(:total).and_return(bing_limit + 1)
66
+ @search.total_pages.should == 50
67
+ end
68
+
69
+ it "should calculate the total amount of pages if the Bing results are less than the maximum limit" do
70
+ @response.should_receive(:total).and_return(500)
71
+ @search.total_pages.should == 25
72
+ end
73
+
74
+ end
60
75
 
61
76
  end
62
77
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kevin Faustino
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-07 00:00:00 -05:00
17
+ date: 2010-03-08 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency