blekko-search 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+ gem.add_dependency "activesupport"
19
20
  end
@@ -2,8 +2,13 @@ require 'cgi'
2
2
  require 'open-uri'
3
3
  require 'json'
4
4
  require 'net/http'
5
+ require 'active_support/all'
5
6
  require "blekko-search/version"
6
7
  require "blekko-search/blekko"
7
8
  require "blekko-search/search"
8
9
  require "blekko-search/search_result"
9
- require "blekko-search/slashtag"
10
+ require "blekko-search/slashtag"
11
+
12
+ module BlekkoSearch
13
+ mattr_accessor :http_class
14
+ end
@@ -38,10 +38,18 @@ class Blekko
38
38
  Blekko::Slashtag.new(self, name, args)
39
39
  end
40
40
 
41
- def request(url)
41
+ def http_class
42
+ BlekkoSearch.http_class || Net::HTTP
43
+ end
44
+
45
+ def request(path)
42
46
  sleep(seconds_until_next_request)
43
47
  self.last_request_at = Time.now
44
- open(url, headers)
48
+ http_class.start("blekko.com", 80) do |http|
49
+ request = Net::HTTP::Get.new path
50
+ headers.each { |key, value| request[key] = value }
51
+ http.request(request).body
52
+ end
45
53
  end
46
54
 
47
55
  def login_uri
@@ -24,7 +24,7 @@ class Blekko
24
24
  def search
25
25
  page_number = 0
26
26
  number_of_searches.times do
27
- response = JSON.load(blekko.request(url(page_number)))
27
+ response = JSON.load(blekko.request(path(page_number)))
28
28
  if response['RESULT']
29
29
  self.results += response['RESULT'].collect { |r| Blekko::SearchResult.new(r) }
30
30
  else
@@ -60,7 +60,11 @@ class Blekko
60
60
  end
61
61
 
62
62
  def url(page_number)
63
- blekko.protocol + blekko.host + PREFIX + escaped_query + RESPONSE_FORMAT + params(page_number)
63
+ blekko.protocol + blekko.host + path(page_number)
64
+ end
65
+
66
+ def path(page_number)
67
+ PREFIX + escaped_query + RESPONSE_FORMAT + params(page_number)
64
68
  end
65
69
 
66
70
  def web_url
@@ -1,3 +1,3 @@
1
1
  module BlekkoSearch
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-19 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: Search and manage slashtags for blekko.com
15
31
  email:
16
32
  - barelyknown@icloud.com