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 CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
 
3
3
  require_relative 'scrapinghub/api_method'
4
+ require_relative 'scrapinghub/api_response'
4
5
  require_relative 'scrapinghub/scrapinghub'
5
6
 
6
7
  module Scrapinghub
@@ -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("<- #{uri.request_uri} redirects to")
47
- debug("-> #{new_location.request_uri}")
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(message)
76
- puts message
75
+ def debug(*messages)
76
+ puts messages.join("\n")
77
77
  end
78
78
  end
79
79
  end
@@ -1,3 +1,3 @@
1
1
  module Scrapinghub
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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