restful_resource 0.8.0 → 0.8.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.
- checksums.yaml +4 -4
- data/lib/restful_resource.rb +1 -0
- data/lib/restful_resource/authorization.rb +7 -0
- data/lib/restful_resource/base.rb +5 -1
- data/lib/restful_resource/http_client.rb +6 -2
- data/lib/restful_resource/response.rb +3 -3
- data/lib/restful_resource/version.rb +1 -1
- data/spec/restful_resource/base_spec.rb +0 -4
- data/spec/restful_resource/http_client_spec.rb +15 -0
- data/spec/spec_helper.rb +5 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cf54b8d96b7d6394c4c7bcd6e50d4fd0affbf71
|
4
|
+
data.tar.gz: 817417b57ea34cb79b0bae515677c6c238dd60d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea58b5641a2971b5d9538eaec970e2957bb00136d1b47305fdd5e2c69bf7120daf115c238be881e8afde5de93d1ff030494037908fbf9f0609313ab6be3669de
|
7
|
+
data.tar.gz: 14e7d26efc07d50c61a3b638cedd5c986e830d6937ecab455b1952900fdbb168bfbc2d4bad6194e1f70a0192acf32d40a53e934dc1d09e069ef87ab490f87e90
|
data/lib/restful_resource.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative "restful_resource/paginated_array"
|
|
9
9
|
require_relative "restful_resource/parameter_missing_error"
|
10
10
|
require_relative "restful_resource/open_object"
|
11
11
|
require_relative 'restful_resource/response'
|
12
|
+
require_relative 'restful_resource/authorization'
|
12
13
|
require_relative 'restful_resource/http_client'
|
13
14
|
require_relative "restful_resource/associations"
|
14
15
|
require_relative "restful_resource/base"
|
@@ -7,7 +7,11 @@ module RestfulResource
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.http
|
10
|
-
@@http ||= RestfulResource::HttpClient.new()
|
10
|
+
@@http ||= RestfulResource::HttpClient.new(authorization: @base_authorization)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.http_authorization(user, password)
|
14
|
+
@base_authorization = RestfulResource::Authorization.http_authorization(user, password)
|
11
15
|
end
|
12
16
|
|
13
17
|
def self.base_url=(url)
|
@@ -1,8 +1,12 @@
|
|
1
1
|
module RestfulResource
|
2
2
|
class HttpClient
|
3
|
+
def initialize(authorization: nil)
|
4
|
+
@authorization = authorization
|
5
|
+
end
|
6
|
+
|
3
7
|
def get(url)
|
4
|
-
response = RestClient.get(url, :accept => :json)
|
5
|
-
Response.new(body: response.body, headers: response.headers)
|
8
|
+
response = RestClient.get(url, :accept => :json, authorization: @authorization)
|
9
|
+
Response.new(body: response.body, headers: response.headers, status: response.code)
|
6
10
|
end
|
7
11
|
end
|
8
12
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RestfulResource
|
2
2
|
class Response
|
3
|
-
attr_reader :body, :headers
|
3
|
+
attr_reader :body, :headers, :status
|
4
4
|
|
5
|
-
def initialize(body: "{}", headers: {})
|
6
|
-
@body, @headers = body, headers
|
5
|
+
def initialize(body: "{}", headers: {}, status: nil)
|
6
|
+
@body, @headers, @status = body, headers, status
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -136,10 +136,6 @@ describe RestfulResource::Base do
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
def expect_get(url, response)
|
140
|
-
expect(@mock_http).to receive(:get).with(url).and_return(response)
|
141
|
-
end
|
142
|
-
|
143
139
|
def response_with_page_information
|
144
140
|
RestfulResource::Response.new(body: [{ id: 1, name: 'Golf'}, { id: 2, name: 'Polo' }].to_json,
|
145
141
|
headers: { links: '<http://api.carwow.co.uk/makes/Volkswagen/models.json?page=6>;rel="last",<http://api.carwow.co.uk/makes/Volkswagen/models.json?page=2>;rel="next"'})
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe RestfulResource::HttpClient do
|
4
|
+
describe 'Authentication' do
|
5
|
+
before :each do
|
6
|
+
auth = RestfulResource::Authorization.http_authorization('user', 'passwd')
|
7
|
+
@http_client = RestfulResource::HttpClient.new(authorization: auth)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should get authenticated get' do
|
11
|
+
response = @http_client.get('http://httpbin.org/basic-auth/user/passwd')
|
12
|
+
expect(response.status).to eq 200
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Santoro
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- Rakefile
|
124
124
|
- lib/restful_resource.rb
|
125
125
|
- lib/restful_resource/associations.rb
|
126
|
+
- lib/restful_resource/authorization.rb
|
126
127
|
- lib/restful_resource/base.rb
|
127
128
|
- lib/restful_resource/http_client.rb
|
128
129
|
- lib/restful_resource/old_base.rb
|
@@ -135,6 +136,7 @@ files:
|
|
135
136
|
- spec/fixtures.rb
|
136
137
|
- spec/restful_resource/associations_spec.rb
|
137
138
|
- spec/restful_resource/base_spec.rb
|
139
|
+
- spec/restful_resource/http_client_spec.rb
|
138
140
|
- spec/restful_resource/old_base_spec.rb
|
139
141
|
- spec/restful_resource/open_object_spec.rb
|
140
142
|
- spec/restful_resource/rest_client_spec.rb
|
@@ -159,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
161
|
version: '0'
|
160
162
|
requirements: []
|
161
163
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.0.14
|
163
165
|
signing_key:
|
164
166
|
specification_version: 4
|
165
167
|
summary: A simple activerecord inspired rest resource base class implemented using
|
@@ -168,6 +170,7 @@ test_files:
|
|
168
170
|
- spec/fixtures.rb
|
169
171
|
- spec/restful_resource/associations_spec.rb
|
170
172
|
- spec/restful_resource/base_spec.rb
|
173
|
+
- spec/restful_resource/http_client_spec.rb
|
171
174
|
- spec/restful_resource/old_base_spec.rb
|
172
175
|
- spec/restful_resource/open_object_spec.rb
|
173
176
|
- spec/restful_resource/rest_client_spec.rb
|