odata 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -5
- data/lib/odata/entity.rb +4 -1
- data/lib/odata/entity_set.rb +12 -9
- data/lib/odata/service.rb +8 -2
- data/lib/odata/service_registry.rb +6 -6
- data/lib/odata/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/service_registry_specs.yml +2 -2
- data/spec/odata/entity_set_spec.rb +4 -2
- data/spec/odata/entity_spec.rb +7 -4
- data/spec/odata/query/result_spec.rb +1 -1
- data/spec/odata/query_spec.rb +5 -5
- data/spec/odata/service_registry_spec.rb +4 -4
- data/spec/odata/service_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44a27c048ec4706996d0eccc9aff655a5c60be94
|
4
|
+
data.tar.gz: de691ae9f3cb75ab544642f9826521cfc3bb09e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdaae668ecb311bbb45f7abd54b116c9576d6c158c86968379405890aafad70bd14b0deda585c8f7e0cdbe9cb50e258d2590ccec2e3f78561ea851e58cc7a096
|
7
|
+
data.tar.gz: 84222c7cf63702ccc0f6073962a3ce3317cfb32507560dc49ada9c6ac6fb676cf66061a264fba8fa72849638448739d03c2a47bccdd684097499e1cf473a3cc2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -43,22 +43,28 @@ to it like this:
|
|
43
43
|
|
44
44
|
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
45
45
|
|
46
|
+
You may also provide an options hash after the URL. It is suggested that you
|
47
|
+
supply a name for the service via this hash like so:
|
48
|
+
|
49
|
+
OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
|
50
|
+
|
46
51
|
This one call will setup the service and allow for the discovery of everything
|
47
52
|
the other parts of the OData gem need to function. The two methods you will
|
48
|
-
want to remember from `OData::Service` are `#service_url` and `#
|
53
|
+
want to remember from `OData::Service` are `#service_url` and `#name`. Both
|
49
54
|
of these methods are available on instances and will allow for lookup in the
|
50
55
|
`OData::ServiceRegistry`, should you need it.
|
51
56
|
|
52
|
-
Using either the service URL or the
|
53
|
-
|
57
|
+
Using either the service URL or the name provided as an option when creating an
|
58
|
+
`OData::Service` will allow for quick lookup in the `OData::ServiceRegistry`
|
59
|
+
like such:
|
54
60
|
|
55
61
|
OData::ServiceRegistry['http://services.odata.org/OData/OData.svc']
|
56
62
|
OData::ServiceRegistry['ODataDemo']
|
57
63
|
|
58
64
|
Both of the above calls would retrieve the same service from the registry. At
|
59
|
-
the moment there is no protection against
|
65
|
+
the moment there is no protection against name collisions provided in
|
60
66
|
`OData::ServiceRegistry`. So, looking up services by their service URL is the
|
61
|
-
most exact method, but lookup by
|
67
|
+
most exact method, but lookup by name is provided for convenience.
|
62
68
|
|
63
69
|
### Entity Sets
|
64
70
|
|
data/lib/odata/entity.rb
CHANGED
@@ -7,14 +7,17 @@ module OData
|
|
7
7
|
class Entity
|
8
8
|
# The Entity type name
|
9
9
|
attr_reader :type
|
10
|
-
# The OData::Service namespace
|
10
|
+
# The OData::Service's namespace
|
11
11
|
attr_reader :namespace
|
12
|
+
# The OData::Service's identifying name
|
13
|
+
attr_reader :service_name
|
12
14
|
|
13
15
|
# Initializes a bare Entity
|
14
16
|
# @param options [Hash]
|
15
17
|
def initialize(options = {})
|
16
18
|
@type = options[:type]
|
17
19
|
@namespace = options[:namespace]
|
20
|
+
@service_name = options[:service_name]
|
18
21
|
end
|
19
22
|
|
20
23
|
# Returns name of Entity from Service specified type.
|
data/lib/odata/entity_set.rb
CHANGED
@@ -14,8 +14,10 @@ module OData
|
|
14
14
|
attr_reader :name
|
15
15
|
# The Entity type for the EntitySet
|
16
16
|
attr_reader :type
|
17
|
-
# The OData::Service namespace
|
17
|
+
# The OData::Service's namespace
|
18
18
|
attr_reader :namespace
|
19
|
+
# The OData::Service's identifiable name
|
20
|
+
attr_reader :service_name
|
19
21
|
# The EntitySet's container name
|
20
22
|
attr_reader :container
|
21
23
|
|
@@ -24,11 +26,11 @@ module OData
|
|
24
26
|
# @param options [Hash] the options to setup the EntitySet
|
25
27
|
# @return [OData::EntitySet] an instance of the EntitySet
|
26
28
|
def initialize(options = {})
|
27
|
-
@name
|
28
|
-
@type
|
29
|
-
@namespace
|
30
|
-
@
|
31
|
-
|
29
|
+
@name = options[:name]
|
30
|
+
@type = options[:type]
|
31
|
+
@namespace = options[:namespace]
|
32
|
+
@service_name = options[:service_name]
|
33
|
+
@container = options[:container]
|
32
34
|
end
|
33
35
|
|
34
36
|
# Provided for Enumerable functionality
|
@@ -108,7 +110,7 @@ module OData
|
|
108
110
|
# @return [OData::Service]
|
109
111
|
# @api private
|
110
112
|
def service
|
111
|
-
@service ||= OData::ServiceRegistry[
|
113
|
+
@service ||= OData::ServiceRegistry[service_name]
|
112
114
|
end
|
113
115
|
|
114
116
|
# Options used for instantiating a new OData::Entity for this set.
|
@@ -116,8 +118,9 @@ module OData
|
|
116
118
|
# @api private
|
117
119
|
def entity_options
|
118
120
|
{
|
119
|
-
namespace:
|
120
|
-
|
121
|
+
namespace: namespace,
|
122
|
+
service_name: service_name,
|
123
|
+
type: type
|
121
124
|
}
|
122
125
|
end
|
123
126
|
|
data/lib/odata/service.rb
CHANGED
@@ -4,7 +4,6 @@ module OData
|
|
4
4
|
class Service
|
5
5
|
# The OData Service's URL
|
6
6
|
attr_reader :service_url
|
7
|
-
|
8
7
|
# Options to pass around
|
9
8
|
attr_reader :options
|
10
9
|
|
@@ -31,6 +30,12 @@ module OData
|
|
31
30
|
Service.new(service_url, options)
|
32
31
|
end
|
33
32
|
|
33
|
+
# Returns user supplied name for service, or its URL
|
34
|
+
# @return [String]
|
35
|
+
def name
|
36
|
+
@name ||= options[:name] || service_url
|
37
|
+
end
|
38
|
+
|
34
39
|
# Returns a list of entities exposed by the service
|
35
40
|
def entity_types
|
36
41
|
@entity_types ||= metadata.xpath('//EntityType').collect {|entity| entity.attributes['Name'].value}
|
@@ -58,7 +63,7 @@ module OData
|
|
58
63
|
|
59
64
|
# Returns a more compact inspection of the service object
|
60
65
|
def inspect
|
61
|
-
"#<#{self.class.name}:#{self.object_id}
|
66
|
+
"#<#{self.class.name}:#{self.object_id} name='#{name}' service_url='#{self.service_url}'>"
|
62
67
|
end
|
63
68
|
|
64
69
|
# Retrieves the EntitySet associated with a specific EntityType by name
|
@@ -74,6 +79,7 @@ module OData
|
|
74
79
|
OData::EntitySet.new(name: entity_set_name,
|
75
80
|
namespace: namespace,
|
76
81
|
type: entity_type_name.to_s,
|
82
|
+
service_name: name,
|
77
83
|
container: container_name)
|
78
84
|
end
|
79
85
|
|
@@ -11,17 +11,17 @@ module OData
|
|
11
11
|
def add(service)
|
12
12
|
initialize_instance_variables
|
13
13
|
@services << service if service.is_a?(OData::Service) && !@services.include?(service)
|
14
|
-
@
|
14
|
+
@services_by_name[service.name] = @services.find_index(service)
|
15
15
|
@services_by_url[service.service_url] = @services.find_index(service)
|
16
16
|
end
|
17
17
|
|
18
|
-
# Lookup a service by URL or
|
18
|
+
# Lookup a service by URL or name
|
19
19
|
#
|
20
|
-
# @param lookup_key [String] the URL or
|
20
|
+
# @param lookup_key [String] the URL or name to lookup
|
21
21
|
# @return [OData::Service, nil] the OData::Service or nil
|
22
22
|
def [](lookup_key)
|
23
23
|
initialize_instance_variables
|
24
|
-
index = @
|
24
|
+
index = @services_by_name[lookup_key] || @services_by_url[lookup_key]
|
25
25
|
index.nil? ? nil : @services[index]
|
26
26
|
end
|
27
27
|
|
@@ -39,13 +39,13 @@ module OData
|
|
39
39
|
|
40
40
|
def initialize_instance_variables
|
41
41
|
@services ||= []
|
42
|
-
@
|
42
|
+
@services_by_name ||= {}
|
43
43
|
@services_by_url ||= {}
|
44
44
|
end
|
45
45
|
|
46
46
|
def flush
|
47
47
|
@services = []
|
48
|
-
@
|
48
|
+
@services_by_name = {}
|
49
49
|
@services_by_url = {}
|
50
50
|
end
|
51
51
|
end
|
data/lib/odata/version.rb
CHANGED
@@ -41,7 +41,7 @@ http_interactions:
|
|
41
41
|
Set-Cookie:
|
42
42
|
- ARRAffinity=a9aad020fb0149d28d0efdb1e8bab24ad3481a904c8fb94abced8813c01ee265;Path=/;Domain=services.odata.org
|
43
43
|
Date:
|
44
|
-
-
|
44
|
+
- Mon, 21 Jul 2014 17:13:14 GMT
|
45
45
|
body:
|
46
46
|
encoding: UTF-8
|
47
47
|
string: <?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"><edmx:DataServices
|
@@ -160,5 +160,5 @@ http_interactions:
|
|
160
160
|
http_version: '1.1'
|
161
161
|
adapter_metadata:
|
162
162
|
effective_url: http://services.odata.org/OData/OData.svc/$metadata
|
163
|
-
recorded_at:
|
163
|
+
recorded_at: Mon, 21 Jul 2014 17:13:14 GMT
|
164
164
|
recorded_with: VCR 2.9.2
|
@@ -2,19 +2,20 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe OData::EntitySet, vcr: {cassette_name: 'entity_set_specs'} do
|
4
4
|
before(:example) do
|
5
|
-
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
5
|
+
OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:subject) { OData::EntitySet.new(options) }
|
9
9
|
let(:options) { {
|
10
10
|
container: 'DemoService', namespace: 'ODataDemo', name: 'Products',
|
11
|
-
type: 'Product'
|
11
|
+
type: 'Product', service_name: 'ODataDemo'
|
12
12
|
} }
|
13
13
|
|
14
14
|
it { expect(subject).to respond_to(:name) }
|
15
15
|
it { expect(subject).to respond_to(:type) }
|
16
16
|
it { expect(subject).to respond_to(:container) }
|
17
17
|
it { expect(subject).to respond_to(:namespace) }
|
18
|
+
it { expect(subject).to respond_to(:service_name) }
|
18
19
|
it { expect(subject).to respond_to(:new_entity) }
|
19
20
|
it { expect(subject).to respond_to(:[]) }
|
20
21
|
it { expect(subject).to respond_to(:<<) }
|
@@ -22,6 +23,7 @@ describe OData::EntitySet, vcr: {cassette_name: 'entity_set_specs'} do
|
|
22
23
|
it { expect(subject.name).to eq('Products') }
|
23
24
|
it { expect(subject.container).to eq('DemoService') }
|
24
25
|
it { expect(subject.namespace).to eq('ODataDemo') }
|
26
|
+
it { expect(subject.service_name).to eq('ODataDemo') }
|
25
27
|
it { expect(subject.type).to eq('Product') }
|
26
28
|
|
27
29
|
describe '#each' do
|
data/spec/odata/entity_spec.rb
CHANGED
@@ -2,20 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe OData::Entity, vcr: {cassette_name: 'entity_specs'} do
|
4
4
|
before(:example) do
|
5
|
-
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
5
|
+
OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:subject) { OData::Entity.new(options) }
|
9
9
|
let(:options) { {
|
10
|
-
type:
|
11
|
-
namespace:
|
10
|
+
type: 'ODataDemo.Product',
|
11
|
+
namespace: 'ODataDemo',
|
12
|
+
service_name: 'ODataDemo'
|
12
13
|
} }
|
13
14
|
|
14
|
-
it { expect(subject).to respond_to(:name, :type, :namespace) }
|
15
|
+
it { expect(subject).to respond_to(:name, :type, :namespace, :service_name) }
|
15
16
|
|
16
17
|
it { expect(subject.name).to eq('Product') }
|
17
18
|
it { expect(subject.type).to eq('ODataDemo.Product') }
|
18
19
|
it { expect(subject.namespace).to eq('ODataDemo') }
|
20
|
+
it { expect(subject.service_name).to eq('ODataDemo') }
|
19
21
|
|
20
22
|
describe '.from_xml' do
|
21
23
|
let(:subject) { OData::Entity.from_xml(product_xml, options) }
|
@@ -31,6 +33,7 @@ describe OData::Entity, vcr: {cassette_name: 'entity_specs'} do
|
|
31
33
|
it { expect(subject.name).to eq('Product') }
|
32
34
|
it { expect(subject.type).to eq('ODataDemo.Product') }
|
33
35
|
it { expect(subject.namespace).to eq('ODataDemo') }
|
36
|
+
it { expect(subject.service_name).to eq('ODataDemo') }
|
34
37
|
|
35
38
|
it { expect(subject['ID']).to eq(0) }
|
36
39
|
it { expect(subject['Name']).to eq('Bread') }
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe OData::Query::Result, vcr: {cassette_name: 'query/result_specs'} do
|
4
4
|
before(:example) do
|
5
|
-
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
5
|
+
OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:subject) { query.execute }
|
data/spec/odata/query_spec.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OData::Query, vcr: {cassette_name: 'query_specs'} do
|
4
|
+
before(:example) do
|
5
|
+
OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
|
6
|
+
end
|
7
|
+
|
4
8
|
let(:subject) { OData::Query.new(entity_set) }
|
5
9
|
let(:entity_set) { OData::EntitySet.new(options) }
|
6
10
|
let(:options) { {
|
7
11
|
container: 'DemoService', namespace: 'ODataDemo', name: 'Products',
|
8
|
-
type: 'Product'
|
12
|
+
service_name: 'ODataDemo', type: 'Product'
|
9
13
|
} }
|
10
14
|
|
11
|
-
before(:example) do
|
12
|
-
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
13
|
-
end
|
14
|
-
|
15
15
|
it { expect(subject).to respond_to(:to_s) }
|
16
16
|
it { expect(subject.to_s).to eq('Products')}
|
17
17
|
|
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe OData::ServiceRegistry, vcr: {cassette_name: 'service_registry_specs'} do
|
4
4
|
let(:subject) { OData::ServiceRegistry }
|
5
|
-
let(:sample_service) { OData::Service.open('http://services.odata.org/OData/OData.svc') }
|
5
|
+
let(:sample_service) { OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'demoService') }
|
6
6
|
|
7
7
|
it { expect(subject).to respond_to(:add) }
|
8
8
|
it { expect(subject).to respond_to(:[]) }
|
9
9
|
|
10
10
|
describe '#add' do
|
11
|
-
before
|
11
|
+
before(:example) do
|
12
12
|
subject.add(sample_service)
|
13
13
|
end
|
14
14
|
|
15
|
-
it { expect(subject[
|
16
|
-
it { expect(subject[
|
15
|
+
it { expect(subject['demoService']).to eq(sample_service) }
|
16
|
+
it { expect(subject['http://services.odata.org/OData/OData.svc']).to eq(sample_service) }
|
17
17
|
end
|
18
18
|
end
|
data/spec/odata/service_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OData::Service, vcr: {cassette_name: 'service_specs'} do
|
4
|
-
let(:subject) { OData::Service.open('http://services.odata.org/OData/OData.svc') }
|
4
|
+
let(:subject) { OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo') }
|
5
5
|
let(:entity_types) { %w{Product FeaturedProduct ProductDetail Category Supplier Person Customer Employee PersonDetail Advertisement} }
|
6
6
|
let(:entity_sets) { %w{Products ProductDetails Categories Suppliers Persons PersonDetails Advertisements} }
|
7
7
|
let(:entity_set_types) { %w{Product ProductDetail Category Supplier Person PersonDetail Advertisement} }
|
@@ -15,7 +15,7 @@ describe OData::Service, vcr: {cassette_name: 'service_specs'} do
|
|
15
15
|
expect(OData::ServiceRegistry['ODataDemo']).to be_nil
|
16
16
|
expect(OData::ServiceRegistry['http://services.odata.org/OData/OData.svc']).to be_nil
|
17
17
|
|
18
|
-
service = OData::Service.open('http://services.odata.org/OData/OData.svc')
|
18
|
+
service = OData::Service.open('http://services.odata.org/OData/OData.svc', name: 'ODataDemo')
|
19
19
|
|
20
20
|
expect(OData::ServiceRegistry['ODataDemo']).to eq(service)
|
21
21
|
expect(OData::ServiceRegistry['http://services.odata.org/OData/OData.svc']).to eq(service)
|
data/spec/spec_helper.rb
CHANGED
@@ -17,7 +17,8 @@ require 'vcr'
|
|
17
17
|
VCR.configure do |c|
|
18
18
|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
19
19
|
c.hook_into :typhoeus
|
20
|
-
c.default_cassette_options = { record: :new_episodes
|
20
|
+
c.default_cassette_options = { record: :new_episodes }
|
21
|
+
c.debug_logger = File.open(ENV['VCR_LOG'], 'w') if ENV['VCR_LOG']
|
21
22
|
c.configure_rspec_metadata!
|
22
23
|
end
|
23
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|