cm-httpclient 1.0.0 → 1.0.1

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/httpclient.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{httpclient}
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["pedro gutierrez"]
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.files = %w[
14
14
  README.md
15
15
  httpclient.gemspec
16
- lib/httpclient.rb
16
+ lib/cm-httpclient.rb
17
17
  lib/httpclient/multipart.rb
18
18
  lib/httpclient/httpclient.rb
19
19
  ]
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
25
25
  s.require_paths = ["lib"]
26
26
  s.rubyforge_project = %q{cm-httpclient}
27
- s.rubygems_version = %q{1.0.0}
27
+ s.rubygems_version = %q{1.0.1}
28
28
  s.summary = %q{a simple httpclient}
29
29
 
30
30
  #if s.respond_to? :specification_version then
@@ -4,4 +4,4 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
4
  require 'httpclient/multipart'
5
5
  require 'httpclient/httpclient'
6
6
 
7
- include HttpClient
7
+ include CodeMutiny::HttpClient
@@ -1,7 +1,6 @@
1
1
  require 'net/https'
2
2
  require 'uri'
3
3
  require 'rexml/document'
4
- require 'helpers/multipart'
5
4
 
6
5
  class Hash
7
6
  def to_s
@@ -45,49 +44,48 @@ class String
45
44
 
46
45
  end
47
46
 
48
- module HttpClient
47
+ module CodeMutiny
48
+
49
+ module HttpClient
49
50
 
50
- def host( host )
51
- @@host = host
52
- end
51
+ def host( host )
52
+ @@host = host
53
+ end
53
54
 
54
- def connect( &block )
55
- uri = URI.parse( @@host )
56
- h = Net::HTTP.new( uri.host, uri.port )
57
- if( uri.scheme == 'https' )
58
- h.use_ssl = uri.scheme
59
- h.verify_mode = OpenSSL::SSL::VERIFY_NONE
60
- end
61
- headers = {}
62
- headers.merge!( @auth ) if @auth
63
- headers.desym!
64
-
65
- block.call( h, headers )
66
- end
55
+ def connect( &block )
56
+ uri = URI.parse( @@host )
57
+ h = Net::HTTP.new( uri.host, uri.port )
58
+ if( uri.scheme == 'https' )
59
+ h.use_ssl = uri.scheme
60
+ h.verify_mode = OpenSSL::SSL::VERIFY_NONE
61
+ end
62
+ headers = {}
63
+ headers.merge!( @auth ) if @auth
64
+ headers.desym!
65
+ block.call( h, headers )
66
+ end
67
67
 
68
- def debug( &block )
69
- @debug = true
70
- instance_eval( &block )
71
- @debug = false
72
- end
68
+ def debug( &block )
69
+ @debug = true
70
+ instance_eval( &block )
71
+ @debug = false
72
+ end
73
73
 
74
+ def debug_request( http_method, path, headers, form = nil )
75
+ if @debug
76
+ puts ""
77
+ puts "Request"
78
+ puts "==========================="
79
+ puts "method: #{http_method}"
80
+ puts "path: #{path}"
81
+ puts "headers: #{headers}"
82
+ puts "form: #{form}" if form
83
+ puts ""
84
+ end
85
+ end
74
86
 
75
-
76
- def debug_request( http_method, path, headers, form = nil )
77
- if @debug
78
- puts ""
79
- puts "Request"
80
- puts "==========================="
81
- puts "method: #{http_method}"
82
- puts "path: #{path}"
83
- puts "headers: #{headers}"
84
- puts "form: #{form}" if form
85
- puts ""
86
- end
87
- end
88
-
89
- def debug_response( code, headers, body )
90
- if @debug
87
+ def debug_response( code, headers, body )
88
+ if @debug
91
89
  puts ""
92
90
  puts "Response"
93
91
  puts "==========================="
@@ -95,87 +93,87 @@ module HttpClient
95
93
  puts "headers: #{headers}"
96
94
  puts "body: #{body}"
97
95
  puts ""
98
- end
99
- end
96
+ end
97
+ end
100
98
 
101
- def retrieve( path, &block )
102
- connect do |http, headers|
103
- debug_request( :get, path, headers )
104
- res = http.get path, headers
105
- handle_response( res, block )
106
- end
107
- end
99
+ def retrieve( path, &block )
100
+ connect do |http, headers|
101
+ debug_request( :get, path, headers )
102
+ res = http.get path, headers
103
+ handle_response( res, block )
104
+ end
105
+ end
108
106
 
109
- def remove( path, &block )
110
- connect do |http, headers|
111
- debug_request( :delete, path, headers )
112
- res = http.delete path, headers
113
- handle_response( res, block )
114
- end
115
- end
107
+ def remove( path, &block )
108
+ connect do |http, headers|
109
+ debug_request( :delete, path, headers )
110
+ res = http.delete path, headers
111
+ handle_response( res, block )
112
+ end
113
+ end
116
114
 
117
115
 
118
- def create( path, form = nil, &block )
119
- connect do |http, headers|
120
- data = nil
121
- headers[ 'Content-Length' ] = '0'
116
+ def create( path, form = nil, &block )
117
+ connect do |http, headers|
118
+ data = nil
119
+ headers[ 'Content-Length' ] = '0'
122
120
 
123
- if form
124
- data, extra_headers = Multipart::Post.prepare_query( form )
125
- headers.merge!( extra_headers )
126
- headers[ 'Content-Length' ] = data.length.to_s
127
- end
121
+ if form
122
+ data, extra_headers = Multipart::Post.prepare_query( form )
123
+ headers.merge!( extra_headers )
124
+ headers[ 'Content-Length' ] = data.length.to_s
125
+ end
128
126
 
129
- debug_request( :post, path, headers, form )
127
+ debug_request( :post, path, headers, form )
130
128
 
131
- res = http.post path, data, headers
132
- handle_response( res, block )
133
- end
134
- end
129
+ res = http.post path, data, headers
130
+ handle_response( res, block )
131
+ end
132
+ end
135
133
 
136
- alias :update :create
134
+ alias :update :create
137
135
 
138
136
 
139
- def handle_response( res, block = nil )
140
- code = res.code.to_i
141
- headers = res.to_hash
142
- body = res.body
143
-
144
- debug_response( code, headers, body )
145
-
146
- if res[ 'Content-Type' ] == 'text/xml'
147
- body = REXML::Document.new( body )
148
- end
149
- if block
150
- block.call( code, body, headers )
151
- else
152
- @obtained_code = code
153
- @obtained_body = body
154
- @obtained_headers = headers
155
- end
156
- end
137
+ def handle_response( res, block = nil )
138
+ code = res.code.to_i
139
+ headers = res.to_hash
140
+ body = res.body
141
+ debug_response( code, headers, body )
142
+ if res[ 'Content-Type' ] == 'text/xml'
143
+ body = REXML::Document.new( body )
144
+ end
145
+ if block
146
+ block.call( code, body, headers )
147
+ else
148
+ @obtained_code = code
149
+ @obtained_body = body
150
+ @obtained_headers = headers
151
+ end
152
+ end
157
153
 
158
- attr_reader :obtained_code, :obtained_body, :obtained_headers
154
+ attr_reader :obtained_code, :obtained_body, :obtained_headers
159
155
 
160
- def admin( key, &block )
161
- if key == nil
162
- anonymous( &block )
163
- else
164
- @auth = { :cmuser => key }
165
- instance_eval( &block )
166
- end
167
- end
156
+ def admin( key, &block )
157
+ if key == nil
158
+ anonymous( &block )
159
+ else
160
+ @auth = { :cmuser => key }
161
+ instance_eval( &block )
162
+ end
163
+ end
168
164
 
169
- def user( username, password = nil, &block )
170
- @auth = { :cmuser => username }
171
- @auth[ :cmpasswd ] = password if password
172
- instance_eval( &block )
173
- end
165
+ def user( username, password = nil, &block )
166
+ @auth = { :cmuser => username }
167
+ @auth[ :cmpasswd ] = password if password
168
+ instance_eval( &block )
169
+ end
174
170
 
175
- def anonymous( &block )
176
- @auth = { :cmuser => 'anonymous' }
177
- instance_eval( &block )
178
- end
171
+ def anonymous( &block )
172
+ @auth = { :cmuser => 'anonymous' }
173
+ instance_eval( &block )
174
+ end
179
175
 
180
- end
181
176
 
177
+ end
178
+
179
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-httpclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pedro gutierrez
@@ -24,7 +24,7 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - README.md
26
26
  - httpclient.gemspec
27
- - lib/httpclient.rb
27
+ - lib/cm-httpclient.rb
28
28
  - lib/httpclient/multipart.rb
29
29
  - lib/httpclient/httpclient.rb
30
30
  has_rdoc: true