alovak-network 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,6 +49,8 @@ module Network
49
49
 
50
50
  def post(data)
51
51
  try_request do
52
+ data = post_data(data)
53
+
52
54
  log_request(data, "POST")
53
55
  response = nil
54
56
  ms = Benchmark.realtime do
@@ -61,9 +63,11 @@ module Network
61
63
 
62
64
  def get(data)
63
65
  try_request do
66
+ data = post_data(data)
67
+
64
68
  log_request(data, "GET")
65
69
  response = nil
66
- query_string = uri.path + data
70
+ query_string = uri.path + "?" + data
67
71
  ms = Benchmark.realtime do
68
72
  response = http.get(query_string)
69
73
  end
@@ -111,6 +115,10 @@ module Network
111
115
  @headers
112
116
  end
113
117
 
118
+ def post_data(data)
119
+ uri.query ? [data, uri.query].join("&") : data
120
+ end
121
+
114
122
  def configure_ssl(http)
115
123
  http.use_ssl = true
116
124
 
@@ -57,6 +57,40 @@ class TestConnectionLogging < Test::Unit::TestCase
57
57
  end
58
58
  end
59
59
 
60
+ class TestConnectionWithParamsInURI < Test::Unit::TestCase
61
+ def setup
62
+ @connection = Network::Connection.new("http://example.com/path?route=some/where/else")
63
+ @http = mock('http')
64
+ end
65
+
66
+ def test_post_methods
67
+ sec = sequence('order')
68
+
69
+ default_headers = { 'Content-Type' => 'application/x-www-form-urlencoded',
70
+ 'Content-Length' => 'hello&route=some/where/else'.bytesize.to_s }
71
+
72
+ @http.expects(:post).with('/path', 'hello&route=some/where/else', default_headers)
73
+
74
+ @connection.expects(:log_request).in_sequence(sec)
75
+ @connection.expects(:http).in_sequence(sec).returns(@http)
76
+ @connection.expects(:log_response).in_sequence(sec)
77
+
78
+ @connection.post("hello")
79
+ end
80
+
81
+ def test_get_methods
82
+ sec = sequence('order')
83
+
84
+ @http.expects(:get).with('/path?query=hello&route=some/where/else')
85
+
86
+ @connection.expects(:log_request).in_sequence(sec)
87
+ @connection.expects(:http).in_sequence(sec).returns(@http)
88
+ @connection.expects(:log_response).in_sequence(sec)
89
+
90
+ @connection.get("query=hello")
91
+ end
92
+ end
93
+
60
94
  class TestConnection < Test::Unit::TestCase
61
95
 
62
96
  def setup
@@ -82,8 +116,14 @@ class TestConnection < Test::Unit::TestCase
82
116
 
83
117
  def test_post_methods
84
118
  sec = sequence('order')
119
+
120
+ default_headers = { 'Content-Type' => 'application/x-www-form-urlencoded',
121
+ 'Content-Length' => 'hello'.bytesize.to_s }
122
+
123
+ @http.expects(:post).with('/path', 'hello', default_headers)
124
+
85
125
  @connection.expects(:log_request).in_sequence(sec)
86
- @connection.expects(:http).in_sequence(sec).returns(stub('http', :post => true))
126
+ @connection.expects(:http).in_sequence(sec).returns(@http)
87
127
  @connection.expects(:log_response).in_sequence(sec)
88
128
 
89
129
  @connection.post("hello")
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alovak-network
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 2
9
- - 0
10
- version: 1.2.0
4
+ version: 1.2.1
11
5
  platform: ruby
12
6
  authors:
13
7
  - Pavel Gabriel
@@ -15,25 +9,19 @@ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
11
 
18
- date: 2010-09-06 00:00:00 +03:00
12
+ date: 2012-05-10 00:00:00 +03:00
19
13
  default_executable:
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: mocha
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
26
20
  requirements:
27
21
  - - ">="
28
22
  - !ruby/object:Gem::Version
29
- hash: 53
30
- segments:
31
- - 0
32
- - 9
33
- - 7
34
23
  version: 0.9.7
35
- type: :runtime
36
- version_requirements: *id001
24
+ version:
37
25
  description: HTTP/HTTPS communication module with logging, filtering and easy SSL configuration
38
26
  email: alovak@gmail.com
39
27
  executables: []
@@ -45,9 +33,6 @@ extra_rdoc_files: []
45
33
  files:
46
34
  - lib/network/connection.rb
47
35
  - lib/network.rb
48
- - test/network/test_network.rb
49
- - test/network/test_connection.rb
50
- - test/test_helper.rb
51
36
  has_rdoc: true
52
37
  homepage: http://github.com/alovak/network/
53
38
  licenses: []
@@ -58,27 +43,21 @@ rdoc_options: []
58
43
  require_paths:
59
44
  - lib
60
45
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
46
  requirements:
63
47
  - - ">="
64
48
  - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
49
  version: "0"
50
+ version:
69
51
  required_rubygems_version: !ruby/object:Gem::Requirement
70
- none: false
71
52
  requirements:
72
53
  - - ">="
73
54
  - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
55
  version: "0"
56
+ version:
78
57
  requirements: []
79
58
 
80
59
  rubyforge_project:
81
- rubygems_version: 1.3.7
60
+ rubygems_version: 1.3.5
82
61
  signing_key:
83
62
  specification_version: 3
84
63
  summary: HTTP/HTTPS communication module based on ruby net/http, net/https modules