policymap_wrap 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/policymap_wrap/connection.rb +14 -39
  3. metadata +10 -10
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -17,11 +17,7 @@ module PolicyMap
17
17
  request :get, endpoint, data
18
18
  end
19
19
 
20
- class Response
21
-
22
- attr_reader :code, :header, :body, :message
23
-
24
- HTTP_RESPONSES = { '100' => 'Continue', '101' => 'SwitchProtocol', '200' => 'OK', '201' => 'Created', '202' => 'Accepted', '203' => 'NonAuthoritativeInformation',
20
+ HTTP_RESPONSES = { '100' => 'Continue', '101' => 'SwitchProtocol', '200' => 'OK', '201' => 'Created', '202' => 'Accepted', '203' => 'NonAuthoritativeInformation',
25
21
  '204' => 'NoContent', '205' => 'ResetContent', '206' => 'PartialContent', '300' => 'MultipleChoice', '301' => 'MovedPermanently',
26
22
  '302' => 'Found', '303' => 'SeeOther', '304' => 'NotModified', '305' => 'UseProxy', '307' => 'TemporaryRedirect', '400' => 'BadRequest',
27
23
  '401' => 'Unauthorized', '402' => 'PaymentRequired', '403' => 'Forbidden', '404' => 'NotFound', '405' => 'MethodNotAllowed',
@@ -30,27 +26,6 @@ module PolicyMap
30
26
  '415' => 'UnsupportedMediaType', '416' => 'RequestedRangeNotSatisfiable', '417' => 'ExpectationFailed', '500' => 'InternalServerError',
31
27
  '501' => 'NotImplemented', '502' => 'BadGateway', '503' => 'ServiceUnavailable', '504' => 'GatewayTimeOut', '505' => 'VersionNotSupported' }
32
28
 
33
- def initialize(http_client)
34
- @code = http_client.response_code
35
- @header = http_client.header_str.is_a?(String) ? parse_headers(http_client.header_str) : http_client.header_str
36
- @body = http_client.body_str
37
- @message = HTTP_RESPONSES[@code.to_s]
38
- end
39
-
40
- private
41
-
42
- def parse_headers(header_string)
43
- header_lines = header_string.split($/)
44
- header_lines.shift
45
- header_lines.inject({}) do |hsh, line|
46
- whole_enchillada, key, value = /^(.*?):\s*(.*)$/.match(line.chomp).to_a
47
- hsh[key] = value unless whole_enchillada.nil?
48
- hsh
49
- end
50
- end
51
-
52
- end
53
-
54
29
  private
55
30
 
56
31
  def request(method, endpoint, data)
@@ -68,7 +43,7 @@ module PolicyMap
68
43
  end
69
44
  end
70
45
 
71
- response = send_request(method, endpoint, headers)
46
+ response = send_request(method, endpoint, headers, data)
72
47
 
73
48
  if debug
74
49
  puts "\nresponse: #{response.code}"
@@ -102,23 +77,23 @@ module PolicyMap
102
77
  end.join('&')
103
78
  end
104
79
 
105
- def send_request(method, endpoint, headers)
106
- if method == :get
107
- @http_client = Curl::Easy.new(endpoint) do |c|
108
- c.headers = headers
109
- end
80
+ def send_request(method, endpoint, headers, data)
81
+ RestClient.proxy = @proxy_url unless @proxy_url.nil?
82
+ begin
83
+ response = RestClient::Request.execute(:method => method,
84
+ :url => endpoint,
85
+ :headers => headers,
86
+ :user => @username,
87
+ :password => @password)
88
+ rescue => e
89
+ raise_errors(e.response)
110
90
  end
111
91
 
112
- @http_client.userpwd = [@username, @password].join(':')
113
- @http_client.proxy_url = @proxy_url unless @proxy_url.nil?
114
-
115
- @http_client.perform
116
-
117
- Response.new(@http_client)
92
+ response
118
93
  end
119
94
 
120
95
  def raise_errors(response)
121
- response_description = "(#{response.code}): #{response.message}"
96
+ response_description = "(#{response.code}): #{HTTP_RESPONSES[response.code.to_s]}"
122
97
  response_description += " - #{response.body}" unless response.body.empty?
123
98
 
124
99
  case response.code.to_i
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: policymap_wrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
16
- requirement: &70213337199520 !ruby/object:Gem::Requirement
16
+ requirement: &70278446457560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 0.7.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70213337199520
24
+ version_requirements: *70278446457560
25
25
  - !ruby/object:Gem::Dependency
26
- name: curb
27
- requirement: &70213337198580 !ruby/object:Gem::Requirement
26
+ name: rest-client
27
+ requirement: &70278446456760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ! '>='
30
+ - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 0.7.7.1
32
+ version: 1.6.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70213337198580
35
+ version_requirements: *70278446456760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70213337024520 !ruby/object:Gem::Requirement
38
+ requirement: &70278446455540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.2.9
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70213337024520
46
+ version_requirements: *70278446455540
47
47
  description: Ruby wrapper around the PolicyMap API. Your API may vary.
48
48
  email: mauricio@geminisbs.com
49
49
  executables: []