frodata 0.9.1 → 0.9.2b
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +9 -0
- data/CHANGELOG.md +12 -0
- data/README.md +10 -33
- data/lib/frodata/errors.rb +1 -0
- data/lib/frodata/service.rb +13 -3
- data/lib/frodata/service/request.rb +6 -11
- data/lib/frodata/service/response.rb +1 -6
- data/lib/frodata/version.rb +1 -1
- data/spec/frodata/service_spec.rb +11 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dedcb00937ab1990ed95efd42b3e8642cf5455b
|
4
|
+
data.tar.gz: 9bb87a5f001789cf7faab8601890b46a61af8145
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef9e60b6641d846ce4fff2eb0a8f942ed059034f963c78517a6d506aad2116f50bbd7567a0dd4f8e35c2cc87c189399686870fc1a76d386f2697f46947fbb98b
|
7
|
+
data.tar.gz: d013d2fff11d0134354583fe232cbc10c3bff5b3fe885b25951e48ee1f1415157ad475c6879f122ddd2a5d4b3452615e3334ce982b6c3f5a23eb7cf70fd50379
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
rspec:
|
2
|
+
image: ruby:2.2
|
3
|
+
script:
|
4
|
+
- bundle install --path /cache --jobs $(nproc)
|
5
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
6
|
+
- chmod +x ./cc-test-reporter
|
7
|
+
- ./cc-test-reporter before-build
|
8
|
+
- bundle exec rspec
|
9
|
+
- ./cc-test-reporter after-build --exit-code $?
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.9.2b
|
4
|
+
|
5
|
+
* Fix broken stack traces in response errors
|
6
|
+
* Ensure that `Service#service_url` always returns a string
|
7
|
+
|
8
|
+
## 0.9.2
|
9
|
+
|
10
|
+
* Ignore connection options when connection object is passed in
|
11
|
+
* Don't send `Accept` header unless explicitly configured
|
12
|
+
* Use middleware for request/response logging
|
13
|
+
* Specifying an adapter is no longer necessary when passing a block to the constructor
|
14
|
+
|
3
15
|
## 0.9.1
|
4
16
|
|
5
17
|
* [New] Raising specific error classes instead of `RuntimeError` when request fails
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# FrOData
|
1
|
+
# FrOData - Free OData V4.0 library for Ruby
|
2
2
|
|
3
3
|
The FrOData gem provides a simple wrapper around the OData Version 4.0 API protocol.
|
4
4
|
It has the ability to automatically inspect compliant APIs and expose the relevant Ruby objects dynamically.
|
@@ -8,12 +8,11 @@ It also provides a set of code generation tools for quickly bootstrapping more c
|
|
8
8
|
|
9
9
|
If you need a gem to integration with OData Version 3, you can use James Thompson's [original OData gem][ruby-odata], upon which this gem is based.
|
10
10
|
|
11
|
+
[![Gem Version](https://badge.fury.io/rb/frodata.svg)](https://badge.fury.io/rb/frodata)
|
11
12
|
[![Build Status](https://app.codeship.com/projects/da1eb540-ce3f-0135-2ddc-161d5c3cc5fd/status?branch=master)](https://app.codeship.com/projects/262148)
|
12
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
13
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/
|
14
|
-
[![Dependency Status](https://gemnasium.com/badges/github.com/wrstudios/frodata.svg)](https://gemnasium.com/github.com/wrstudios/frodata)
|
13
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/2425311d859408ef8798/maintainability)](https://codeclimate.com/github/wrstudios/frodata/maintainability)
|
14
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/2425311d859408ef8798/test_coverage)](https://codeclimate.com/github/wrstudios/frodata/test_coverage)
|
15
15
|
[![Documentation](http://inch-ci.org/github/wrstudios/frodata.png?branch=master)](http://www.rubydoc.info/github/wrstudios/frodata/master)
|
16
|
-
[![Gem Version](https://badge.fury.io/rb/frodata.svg)](https://badge.fury.io/rb/frodata)
|
17
16
|
|
18
17
|
## Installation
|
19
18
|
|
@@ -106,7 +105,7 @@ This allows you to e.g. set custom headers (such as `Authorization`) that may be
|
|
106
105
|
|
107
106
|
##### Using Authentication Helpers
|
108
107
|
|
109
|
-
You may also set up authorization by directly accessing the underlying `Faraday::Connection` object (as explained in [Advanced Customization](#advanced-connection-customization) below).
|
108
|
+
You may also set up authorization by directly accessing the underlying `Faraday::Connection` object `yield`ed to the constructor (as explained in [Advanced Customization](#advanced-connection-customization) below).
|
110
109
|
This allows you to make use of Faraday's [authentication helpers][faraday-auth], such as `basic_auth` or `token_auth`.
|
111
110
|
|
112
111
|
For instance, if your service requires HTTP basic authentication:
|
@@ -114,12 +113,11 @@ For instance, if your service requires HTTP basic authentication:
|
|
114
113
|
```ruby
|
115
114
|
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', {
|
116
115
|
name: 'ODataDemo'
|
117
|
-
})
|
118
|
-
|
116
|
+
}) do |conn|
|
117
|
+
conn.basic_auth('username', 'password')
|
118
|
+
end
|
119
119
|
```
|
120
120
|
|
121
|
-
You may also use these helpers when passing a block to the constructor (see second example [below](#passing-a-block-to-the-constructor)).
|
122
|
-
|
123
121
|
[http-auth]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
|
124
122
|
[faraday]: https://github.com/lostisland/faraday
|
125
123
|
[faraday-auth]: https://github.com/lostisland/faraday#authentication
|
@@ -144,6 +142,8 @@ In this case, you'll be setting the service URL on the connection object, as sho
|
|
144
142
|
service = FrOData::Service.new(conn, name: 'ODataDemo')
|
145
143
|
```
|
146
144
|
|
145
|
+
**NOTE**: if you use this method, any options set via the `:connection` options key will be ignored.
|
146
|
+
|
147
147
|
##### Passing a block to the constructor
|
148
148
|
|
149
149
|
Alternatively, the connection object is also `yield`ed by the constructor, so you may customize it by passing a block argument.
|
@@ -157,21 +157,6 @@ For instance, if you wanted to use [Typhoeus][typhoeus] as your HTTP library:
|
|
157
157
|
end
|
158
158
|
```
|
159
159
|
|
160
|
-
**IMPORTANT**
|
161
|
-
|
162
|
-
Please be aware that if you use this method to customize the connection, you must ALWAYS specify an adapter:
|
163
|
-
|
164
|
-
```ruby
|
165
|
-
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', {
|
166
|
-
name: 'ODataDemo'
|
167
|
-
}) do |conn|
|
168
|
-
conn.basic_auth('username', 'password')
|
169
|
-
conn.adapter Faraday.default_adapter
|
170
|
-
end
|
171
|
-
```
|
172
|
-
|
173
|
-
Otherwise, your requests WILL fail!
|
174
|
-
|
175
160
|
[typhoeus]: https://github.com/typhoeus/typhoeus
|
176
161
|
|
177
162
|
### Exploring a Service
|
@@ -395,14 +380,6 @@ You should refer to the published RubyDocs for full details on the various capab
|
|
395
380
|
* [FrOData::Query](http://rubydoc.info/github/wrstudios/frodata/master/FrOData/Query)
|
396
381
|
* [FrOData::Query::Criteria](http://rubydoc.info/github/wrstudios/frodata/master/FrOData/Query/Criteria)
|
397
382
|
|
398
|
-
## To Do
|
399
|
-
|
400
|
-
[x] ~Lenient property validation~
|
401
|
-
[ ] Write support (create/update/delete)
|
402
|
-
[ ] Support for invoking [Operations][odata-ops] (Functions/Actions)
|
403
|
-
[ ] [Property facets][odata-facets]
|
404
|
-
[ ] Annotations
|
405
|
-
|
406
383
|
[odata-facets]: http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part3-csdl/odata-v4.0-errata03-os-part3-csdl-complete.html#_Toc453752528
|
407
384
|
[odata-ops]: http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.html#_Toc453752307
|
408
385
|
|
data/lib/frodata/errors.rb
CHANGED
data/lib/frodata/service.rb
CHANGED
@@ -31,14 +31,14 @@ module FrOData
|
|
31
31
|
# @param options [Hash] options to pass to the service
|
32
32
|
# @return [FrOData::Service] an instance of the service
|
33
33
|
def initialize(service_url, options = {}, &block)
|
34
|
+
@options = default_options.merge(options)
|
34
35
|
if service_url.is_a? Faraday::Connection
|
35
36
|
@connection = service_url
|
36
|
-
@service_url = connection.url_prefix
|
37
|
+
@service_url = connection.url_prefix.to_s
|
37
38
|
else
|
38
39
|
@service_url = service_url
|
39
|
-
@connection =
|
40
|
+
@connection = default_connection(&block)
|
40
41
|
end
|
41
|
-
@options = default_options.merge(options)
|
42
42
|
FrOData::ServiceRegistry.add(self)
|
43
43
|
register_custom_types
|
44
44
|
end
|
@@ -151,6 +151,7 @@ module FrOData
|
|
151
151
|
# @param options [Hash] additional request options
|
152
152
|
# @return [FrOData::Service::Response]
|
153
153
|
def execute(url_chunk, options = {})
|
154
|
+
options = (@options[:request] || {}).merge(options)
|
154
155
|
Request.new(self, url_chunk, options).execute
|
155
156
|
end
|
156
157
|
|
@@ -225,6 +226,15 @@ module FrOData
|
|
225
226
|
end
|
226
227
|
end
|
227
228
|
|
229
|
+
def default_connection(&block)
|
230
|
+
Faraday.new(service_url, options[:connection]) do |conn|
|
231
|
+
conn.request :url_encoded
|
232
|
+
conn.response :logger, logger
|
233
|
+
yield conn if block_given?
|
234
|
+
conn.adapter Faraday.default_adapter unless conn.builder.send(:adapter_set?)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
228
238
|
def read_metadata
|
229
239
|
# From file, good for debugging
|
230
240
|
if options[:metadata_file]
|
@@ -44,12 +44,9 @@ module FrOData
|
|
44
44
|
|
45
45
|
# Execute the request
|
46
46
|
#
|
47
|
-
# @param
|
47
|
+
# @param request_options [Hash] Request options to pass to Faraday
|
48
48
|
# @return [FrOData::Service::Response]
|
49
|
-
def execute(
|
50
|
-
request_options = service.options[:request].merge(additional_options)
|
51
|
-
|
52
|
-
logger.info "Requesting #{method.to_s.upcase} #{url}..."
|
49
|
+
def execute(request_options = {})
|
53
50
|
Response.new(service, query) do
|
54
51
|
connection.run_request(method, url_chunk, nil, headers) do |conn|
|
55
52
|
conn.options.merge! request_options
|
@@ -61,14 +58,8 @@ module FrOData
|
|
61
58
|
|
62
59
|
attr_reader :url_chunk
|
63
60
|
|
64
|
-
def connection
|
65
|
-
service.connection
|
66
|
-
end
|
67
|
-
|
68
61
|
def default_headers
|
69
62
|
{
|
70
|
-
'Accept' => content_type,
|
71
|
-
'Content-Type' => content_type,
|
72
63
|
'OData-Version' => '4.0'
|
73
64
|
}
|
74
65
|
end
|
@@ -77,6 +68,10 @@ module FrOData
|
|
77
68
|
default_headers.merge(@options[:headers] || {})
|
78
69
|
end
|
79
70
|
|
71
|
+
def connection
|
72
|
+
service.connection
|
73
|
+
end
|
74
|
+
|
80
75
|
def logger
|
81
76
|
service.logger
|
82
77
|
end
|
@@ -96,7 +96,7 @@ module FrOData
|
|
96
96
|
# @return [self]
|
97
97
|
def validate_response!
|
98
98
|
if error = FrOData::Errors::ERROR_MAP[status]
|
99
|
-
raise error
|
99
|
+
raise error.new(response, error_message)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -104,11 +104,6 @@ module FrOData
|
|
104
104
|
|
105
105
|
def execute(&block)
|
106
106
|
@response = block.call
|
107
|
-
logger.debug <<-EOS
|
108
|
-
[FrOData: #{service.name}] Received response:
|
109
|
-
Headers: #{response.headers}
|
110
|
-
Body: #{response.body}
|
111
|
-
EOS
|
112
107
|
check_content_type
|
113
108
|
validate_response!
|
114
109
|
rescue Faraday::TimeoutError
|
data/lib/frodata/version.rb
CHANGED
@@ -27,6 +27,7 @@ describe FrOData::Service, vcr: {cassette_name: 'service_specs'} do
|
|
27
27
|
connection = Faraday.new(service_url)
|
28
28
|
service = FrOData::Service.new(connection)
|
29
29
|
expect(service.connection).to eq(connection)
|
30
|
+
expect(service.service_url).to eq(service_url)
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'allows connection to be customized via options hash' do
|
@@ -36,10 +37,19 @@ describe FrOData::Service, vcr: {cassette_name: 'service_specs'} do
|
|
36
37
|
expect(service.connection.headers).to include('X-Custom-Header' => 'foo')
|
37
38
|
end
|
38
39
|
|
40
|
+
it 'ignores connection options when connetion is passed in' do
|
41
|
+
connection = Faraday.new(service_url, {
|
42
|
+
headers: { 'X-Custom-Header' => 'foo' }
|
43
|
+
})
|
44
|
+
service = FrOData::Service.new(connection, connection: {
|
45
|
+
headers: { 'X-Custom-Header' => 'bar' }
|
46
|
+
})
|
47
|
+
expect(service.connection.headers).to include('X-Custom-Header' => 'foo')
|
48
|
+
end
|
49
|
+
|
39
50
|
it 'allows connection to be customized via block argument' do
|
40
51
|
service = FrOData::Service.new(service_url) do |conn|
|
41
52
|
conn.headers['X-Custom-Header'] = 'foo'
|
42
|
-
conn.adapter Faraday.default_adapter
|
43
53
|
end
|
44
54
|
expect(service.connection.headers).to include('X-Custom-Header' => 'foo')
|
45
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frodata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2b
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Wagner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-05-
|
12
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -189,6 +189,7 @@ extra_rdoc_files: []
|
|
189
189
|
files:
|
190
190
|
- ".autotest"
|
191
191
|
- ".gitignore"
|
192
|
+
- ".gitlab-ci.yml"
|
192
193
|
- ".rspec"
|
193
194
|
- ".ruby-gemset"
|
194
195
|
- ".ruby-version"
|
@@ -328,9 +329,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
328
329
|
version: '0'
|
329
330
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
330
331
|
requirements:
|
331
|
-
- - "
|
332
|
+
- - ">"
|
332
333
|
- !ruby/object:Gem::Version
|
333
|
-
version:
|
334
|
+
version: 1.3.1
|
334
335
|
requirements: []
|
335
336
|
rubyforge_project:
|
336
337
|
rubygems_version: 2.6.14
|