poxy_client 0.0.1.pre.1 → 0.0.1.pre.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/poxy_client.rb +5 -8
- data/lib/poxy_client/configuration.rb +3 -3
- data/lib/poxy_client/connector.rb +17 -0
- data/lib/poxy_client/processor.rb +4 -1
- data/lib/poxy_client/retriever.rb +1 -1
- data/lib/poxy_client/version.rb +1 -1
- data/poxy_client.gemspec +2 -1
- data/test/test_poxy_client.rb +2 -2
- data/test/test_poxy_processor.rb +1 -1
- data/test/test_poxy_repeater.rb +4 -2
- metadata +17 -6
data/lib/poxy_client.rb
CHANGED
@@ -11,9 +11,6 @@ module PoxyClient
|
|
11
11
|
|
12
12
|
class << self
|
13
13
|
|
14
|
-
#attr_reader :configuration
|
15
|
-
|
16
|
-
|
17
14
|
def configure
|
18
15
|
yield(configuration)
|
19
16
|
end
|
@@ -35,15 +32,15 @@ module PoxyClient
|
|
35
32
|
end
|
36
33
|
|
37
34
|
def connector
|
38
|
-
@connector ||=
|
35
|
+
@connector ||= PoxyClien::Connector.new(configuration)
|
39
36
|
end
|
40
37
|
|
41
38
|
# Encapsulates the three important operations. Retrieve, Process and Repeat
|
42
39
|
#
|
43
|
-
# @
|
44
|
-
# Options are :all, :first, :last, :starred, :unstarred, :archived
|
45
|
-
# @
|
46
|
-
def perform(howmany = :
|
40
|
+
# @param [Symbol] howmany which requests to retrieve from the API.
|
41
|
+
# Options are :new, :all, :first, :last, :starred, :unstarred, :archived
|
42
|
+
# @return [Array] With the responses received in the destination server.
|
43
|
+
def perform(howmany = :new)
|
47
44
|
# Retrieve all the available requests from the site API
|
48
45
|
requests = PoxyClient.retriever.get(howmany)
|
49
46
|
# Parse those requests to JSON.
|
@@ -13,9 +13,9 @@ module PoxyClient
|
|
13
13
|
|
14
14
|
def initialize
|
15
15
|
@origin = 'http://poxy.porta.sh'
|
16
|
-
@destination = 'http://localhost'
|
16
|
+
@destination = 'http://localhost:9292'
|
17
17
|
@mode = 'development'
|
18
|
-
@method =
|
18
|
+
@method = 'post'
|
19
19
|
@retriever_version = VERSION
|
20
20
|
end
|
21
21
|
|
@@ -35,4 +35,4 @@ module PoxyClient
|
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
38
|
-
end
|
38
|
+
end
|
@@ -19,8 +19,25 @@ module PoxyClient
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def response
|
22
|
+
downcase_headers
|
23
|
+
replace_host_from_headers
|
22
24
|
@response = HTTPI.send(method, @request)
|
23
25
|
end
|
24
26
|
|
27
|
+
private
|
28
|
+
|
29
|
+
def downcase_headers
|
30
|
+
@replace = {}
|
31
|
+
@request.headers.each_pair do |k,v|
|
32
|
+
@replace.merge!({k.downcase => v})
|
33
|
+
end
|
34
|
+
@request.headers = @replace
|
35
|
+
end
|
36
|
+
|
37
|
+
def replace_host_from_headers
|
38
|
+
@request.headers['host'] = @request.url.host
|
39
|
+
end
|
40
|
+
|
25
41
|
end
|
42
|
+
|
26
43
|
end
|
@@ -6,12 +6,15 @@ module PoxyClient
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def parse(content)
|
9
|
-
@response =
|
9
|
+
@response = ""
|
10
10
|
if ( content.respond_to?(:body) )
|
11
11
|
@response = JSON.parse(content.body)
|
12
12
|
else
|
13
13
|
@response = JSON.parse(content)
|
14
14
|
end
|
15
|
+
@response.each_with_index do |head, i|
|
16
|
+
@response[i]['headers']['X-FORWARDED-FOR'] = @response[i]['headers']['HOST']
|
17
|
+
end
|
15
18
|
@response
|
16
19
|
end
|
17
20
|
|
data/lib/poxy_client/version.rb
CHANGED
data/poxy_client.gemspec
CHANGED
@@ -11,7 +11,8 @@ Gem::Specification.new do |gem|
|
|
11
11
|
|
12
12
|
gem.add_runtime_dependency "httpi", [">= 1.0.0"]
|
13
13
|
gem.add_runtime_dependency "clap", [">= 0.0.2"]
|
14
|
-
|
14
|
+
gem.add_development_dependency "test-unit"
|
15
|
+
|
15
16
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
17
|
gem.files = `git ls-files`.split("\n")
|
17
18
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/test/test_poxy_client.rb
CHANGED
@@ -5,7 +5,7 @@ require 'json'
|
|
5
5
|
class PoxyClientTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def test_version
|
8
|
-
assert_equal PoxyClient::VERSION, '0.0.1.pre.
|
8
|
+
assert_equal PoxyClient::VERSION, '0.0.1.pre.2'
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_config_version
|
@@ -24,7 +24,7 @@ class PoxyClientTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal @client.configuration.api_key, "test"
|
25
25
|
assert_equal @client.configuration.bucket_key, "test"
|
26
26
|
#params by default
|
27
|
-
assert_equal @client.configuration.destination, "http://localhost"
|
27
|
+
assert_equal @client.configuration.destination, "http://localhost:9292"
|
28
28
|
end
|
29
29
|
|
30
30
|
|
data/test/test_poxy_processor.rb
CHANGED
data/test/test_poxy_repeater.rb
CHANGED
@@ -9,6 +9,8 @@ class PoxyRepeaterTest < Test::Unit::TestCase
|
|
9
9
|
config.destination = "http://poxy.porta.sh/collector/test"
|
10
10
|
end
|
11
11
|
@repeater = PoxyClient.repeater
|
12
|
+
|
13
|
+
#make sure the HOST header is set to the destination host, or the request willl be rejected
|
12
14
|
@raw_request = "[{\"method\":\"POST\",\"headers\":{\"HOST\":\"localhost:9393\",\"CONNECTION\":\"keep-alive\",\"ORIGIN\":\"localhost:9393\",\"USER_AGENT\":\"Don Gato y su Pandilla\",\"ACCEPT\":\"*/*\",\"ACCEPT_ENCODING\":\"gzip,deflate,sdch\",\"ACCEPT_LANGUAGE\":\"en-US,en;q=0.8\",\"ACCEPT_CHARSET\":\"ISO-8859-1,utf-8;q=0.7,*;q=0.3\",\"COOKIE\":\"rumba\",\"VERSION\":\"HTTP/1.1\"},\"query_string\":\"urlparam=1&url_param=2\",\"params\":{\"postparam\":\"uno\",\"post_param\":\"dos\"},\"body\":\"\"}]"
|
13
15
|
@json_request = JSON.parse(@raw_request)
|
14
16
|
end
|
@@ -19,9 +21,9 @@ class PoxyRepeaterTest < Test::Unit::TestCase
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def test_repeater_set
|
22
|
-
|
23
|
-
puts response.inspect
|
24
|
+
response = @repeater.set(@json_request)
|
24
25
|
assert_equal response[0].class, HTTPI::Response
|
26
|
+
assert_equal response[0].code, 200 #poxy will respond with a 200, since it's a "receive" bucket
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poxy_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httpi
|
16
|
-
requirement: &
|
16
|
+
requirement: &23073740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *23073740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: clap
|
27
|
-
requirement: &
|
27
|
+
requirement: &23073220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: 0.0.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *23073220
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: test-unit
|
38
|
+
requirement: &23072840 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *23072840
|
36
47
|
description: Client for Poxy (the awesome app)
|
37
48
|
email:
|
38
49
|
- julian@porta.sh
|