blekko-search 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,6 +30,10 @@ class Blekko
30
30
  Blekko::Search.new(self, query, args).search
31
31
  end
32
32
 
33
+ def web_url(query)
34
+ Blekko::Search.new(self, query).web_url
35
+ end
36
+
33
37
  def slashtag(name, args={})
34
38
  Blekko::Slashtag.new(self, name, args)
35
39
  end
@@ -1,13 +1,13 @@
1
1
  class Blekko
2
2
  class Search
3
-
3
+
4
4
  DEFAULT_PAGE_SIZE = 100
5
5
  DEFAULT_PAGE_NUMBER = 0
6
6
  PREFIX = "/ws/?q="
7
7
  RESPONSE_FORMAT = "/json+/"
8
-
8
+
9
9
  attr_accessor :query, :slashtags, :results, :blekko
10
-
10
+
11
11
  def initialize(blekko, query, args={})
12
12
  args = {page_size: DEFAULT_PAGE_SIZE }.merge(args)
13
13
  @blekko = blekko
@@ -16,11 +16,11 @@ class Blekko
16
16
  @page_size = args[:page_size]
17
17
  @total_size = args[:total_size] || @page_size
18
18
  end
19
-
19
+
20
20
  def results
21
21
  @results ||= []
22
22
  end
23
-
23
+
24
24
  def search
25
25
  page_number = 0
26
26
  number_of_searches.times do
@@ -34,34 +34,38 @@ class Blekko
34
34
  end
35
35
  results[0,@total_size]
36
36
  end
37
-
37
+
38
38
  def number_of_searches
39
39
  @number_of_searches ||= (@total_size.to_f / @page_size).ceil
40
40
  end
41
-
41
+
42
42
  def escaped_query
43
43
  CGI.escape(query + " ") + @slashtags.collect { |s| CGI.escape(s) }.join("+") + "+"
44
44
  end
45
-
45
+
46
46
  def page_size_param
47
47
  "ps=#{@page_size}"
48
48
  end
49
-
49
+
50
50
  def page_number_param(page_number)
51
51
  "p=#{page_number}" if page_number > 0
52
52
  end
53
-
53
+
54
54
  def auth_param
55
55
  blekko.api_key ? "auth=#{blekko.api_key}" : nil
56
56
  end
57
-
57
+
58
58
  def params(page_number)
59
59
  [page_size_param, auth_param, page_number_param(page_number)].compact.join("&")
60
60
  end
61
-
61
+
62
62
  def url(page_number)
63
63
  blekko.protocol + blekko.host + PREFIX + escaped_query + RESPONSE_FORMAT + params(page_number)
64
64
  end
65
-
65
+
66
+ def web_url
67
+ blekko.protocol + blekko.host + PREFIX + escaped_query
68
+ end
69
+
66
70
  end
67
71
  end
@@ -1,3 +1,3 @@
1
1
  module BlekkoSearch
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blekko-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: