scrapinghub 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/scrapinghub.rb +1 -0
- data/lib/scrapinghub/api_response.rb +16 -0
- data/lib/scrapinghub/scrapinghub.rb +5 -5
- data/lib/scrapinghub/version.rb +1 -1
- metadata +2 -1
data/lib/scrapinghub.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Scrapinghub
|
2
|
+
class ApiResponse
|
3
|
+
def initialize(net_http_request)
|
4
|
+
case net_http_request
|
5
|
+
when Net::HTTPOK
|
6
|
+
@body = JSON.parse(net_http_request.body)
|
7
|
+
else
|
8
|
+
raise "Invalid Net:HTTP request sent to ApiResponse"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def response
|
13
|
+
@body
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -43,12 +43,12 @@ module Scrapinghub
|
|
43
43
|
when Net::HTTPFound
|
44
44
|
new_location = URI(response['location'])
|
45
45
|
|
46
|
-
debug
|
47
|
-
|
46
|
+
debug "<- #{uri.request_uri} redirects to",
|
47
|
+
"-> #{new_location.request_uri}"
|
48
48
|
|
49
49
|
fetch(new_location, redirect_limit-1)
|
50
50
|
else
|
51
|
-
response
|
51
|
+
ApiResponse.new(response)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -72,8 +72,8 @@ module Scrapinghub
|
|
72
72
|
return build_url(api_method, parameters)
|
73
73
|
end
|
74
74
|
|
75
|
-
def debug(
|
76
|
-
puts
|
75
|
+
def debug(*messages)
|
76
|
+
puts messages.join("\n")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
data/lib/scrapinghub/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrapinghub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- lib/scrapinghub.rb
|
27
27
|
- lib/scrapinghub/api_method.rb
|
28
|
+
- lib/scrapinghub/api_response.rb
|
28
29
|
- lib/scrapinghub/scrapinghub.rb
|
29
30
|
- lib/scrapinghub/version.rb
|
30
31
|
- scrapinghub.gemspec
|