odata 0.0.9 → 0.0.10
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/README.md +48 -8
- data/lib/odata/service.rb +8 -4
- data/lib/odata/version.rb +1 -1
- data/spec/odata/service_spec.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: bcb9a746bd19061bb07c0311b4bdc705c084ad5b
|
4
|
+
data.tar.gz: 1f2c9dae62cbec8852a2f65a29826f3ee5412a33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28a93be11707fe9adcf4aa51af4a0c48d73bce1b680525ac293ceb89c9cb8b11e4045321da62d4a5e280158efb289fcd50325eaf20b1f2b5d6b5bf198ab3480e
|
7
|
+
data.tar.gz: 88b1a0bc6fb085880e20f102bebf8e16aad9a4313641cf1a5b6a5f75fde34caa47bc677ad886a473e843c4e82d04509bfea6351c5a504818e445a3eea130d3e4
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[](https://codeclimate.com/github/plainprogrammer/odata)
|
5
5
|
[](https://codeclimate.com/github/plainprogrammer/odata)
|
6
6
|
[](http://badge.fury.io/rb/odata)
|
7
|
+
[](https://gemnasium.com/plainprogrammer/odata)
|
7
8
|
[](http://rubydoc.info/github/plainprogrammer/odata/master/frames)
|
8
9
|
|
9
10
|
The OData gem provides a simple wrapper around the OData API protocol. It has
|
@@ -27,36 +28,75 @@ Or install it yourself as:
|
|
27
28
|
|
28
29
|
## Usage
|
29
30
|
|
31
|
+
### Services & the Service Registry
|
32
|
+
|
30
33
|
The OData gem provides a number of core classes, the two most basic ones are
|
31
|
-
the OData::Service and the OData::ServiceRegistry
|
32
|
-
to worry about the OData::ServiceRegistry is when you have multiple OData
|
34
|
+
the `OData::Service` and the `OData::ServiceRegistry`. The only time you will need
|
35
|
+
to worry about the `OData::ServiceRegistry` is when you have multiple OData
|
33
36
|
services you are interacting with that you want to keep straight easily. The
|
34
|
-
nice thing about OData::Service is that it automatically registers with the
|
37
|
+
nice thing about `OData::Service` is that it automatically registers with the
|
35
38
|
registry on creation, so there is no manual interaction with the registry
|
36
39
|
necessary.
|
37
40
|
|
38
|
-
To create an OData::Service simply provide the location of a service endpoint
|
41
|
+
To create an `OData::Service` simply provide the location of a service endpoint
|
39
42
|
to it like this:
|
40
43
|
|
41
44
|
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
42
45
|
|
43
46
|
This one call will setup the service and allow for the discovery of everything
|
44
47
|
the other parts of the OData gem need to function. The two methods you will
|
45
|
-
want to remember from OData::Service are `#service_url` and `#namespace`. Both
|
48
|
+
want to remember from `OData::Service` are `#service_url` and `#namespace`. Both
|
46
49
|
of these methods are available on instances and will allow for lookup in the
|
47
|
-
OData::ServiceRegistry
|
50
|
+
`OData::ServiceRegistry`, should you need it.
|
48
51
|
|
49
52
|
Using either the service URL or the namespace provided by a service's CSDL
|
50
|
-
schema will allow for quick lookup in the OData::ServiceRegistry like such:
|
53
|
+
schema will allow for quick lookup in the `OData::ServiceRegistry` like such:
|
51
54
|
|
52
55
|
OData::ServiceRegistry['http://services.odata.org/OData/OData.svc']
|
53
56
|
OData::ServiceRegistry['ODataDemo']
|
54
57
|
|
55
58
|
Both of the above calls would retrieve the same service from the registry. At
|
56
59
|
the moment there is no protection against namespace collisions provided in
|
57
|
-
OData::ServiceRegistry
|
60
|
+
`OData::ServiceRegistry`. So, looking up services by their service URL is the
|
58
61
|
most exact method, but lookup by namespace is provided for convenience.
|
59
62
|
|
63
|
+
### Entity Sets
|
64
|
+
|
65
|
+
When it comes to reading data from an OData service the most typical way will
|
66
|
+
be via `OData::EntitySet` instances. Under normal circumstances you should
|
67
|
+
never need to worry about an `OData::EntitySet` directly. For example, to get
|
68
|
+
an `OData::EntitySet` for the products in the ODataDemo service simply access
|
69
|
+
the entity set through the service like this:
|
70
|
+
|
71
|
+
svc = OData::Service.open('http://services.odata.org/OData/OData.svc')
|
72
|
+
products = svc['Products'] # => OData::EntitySet
|
73
|
+
|
74
|
+
`OData::EntitySet` instances implement the `Enumerable` module, meaning you can
|
75
|
+
work with them very naturally, like this:
|
76
|
+
|
77
|
+
products.each do |entity|
|
78
|
+
entity # => OData::Entity for type Product
|
79
|
+
end
|
80
|
+
|
81
|
+
### Entities
|
82
|
+
|
83
|
+
`OData::Entity` instances represent individual entities, or records, in a given
|
84
|
+
service. They are returned primarily through interaction with instances of
|
85
|
+
`OData::EntitySet`. You can access individual properties on an `OData::Entity`
|
86
|
+
like so:
|
87
|
+
|
88
|
+
product = products.first # => OData::Entity
|
89
|
+
product['Name'] # => 'Bread'
|
90
|
+
product['Price'] # => 2.5 (Float)
|
91
|
+
|
92
|
+
Individual properties on an `OData::Entity` are automatically typecast by the
|
93
|
+
gem, so you don't have to worry about too much when working with entities. The
|
94
|
+
way this is implemented internally guarantees that an `OData::Entity` is always
|
95
|
+
ready to save back to the service or `OData::EntitySet`, which you do like so:
|
96
|
+
|
97
|
+
svc['Products'] << product # Write back to the service
|
98
|
+
products << product # Write back to the Entity Set
|
99
|
+
|
60
100
|
## Contributing
|
61
101
|
|
62
102
|
1. Fork it ( https://github.com/[my-github-username]/odata/fork )
|
data/lib/odata/service.rb
CHANGED
@@ -83,12 +83,16 @@ module OData
|
|
83
83
|
#
|
84
84
|
# @param entity_type_name [to_s] the name of the EntityType you want the EntitySet of
|
85
85
|
# @return [OData::EntitySet] an OData::EntitySet to query
|
86
|
-
def [](
|
87
|
-
xpath_query = "//EntityContainer/EntitySet[@
|
86
|
+
def [](entity_set_name)
|
87
|
+
xpath_query = "//EntityContainer/EntitySet[@Name='#{entity_set_name}']"
|
88
88
|
entity_set_node = metadata.xpath(xpath_query).first
|
89
|
-
|
89
|
+
raise ArgumentError, "Unknown Entity Set: #{entity_set_name}" if entity_set_node.nil?
|
90
90
|
container_name = entity_set_node.parent.attributes['Name'].value
|
91
|
-
|
91
|
+
entity_type_name = entity_set_node.attributes['EntityType'].value.gsub(/#{namespace}\./, '')
|
92
|
+
OData::EntitySet.new(name: entity_set_name,
|
93
|
+
namespace: namespace,
|
94
|
+
type: entity_type_name.to_s,
|
95
|
+
container: container_name)
|
92
96
|
end
|
93
97
|
|
94
98
|
def execute(url_chunk, additional_options = {})
|
data/lib/odata/version.rb
CHANGED
data/spec/odata/service_spec.rb
CHANGED
@@ -81,6 +81,7 @@ describe OData::Service do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
describe '#[]' do
|
84
|
-
it { expect(subject['
|
84
|
+
it { expect(subject['Products']).to be_a(OData::EntitySet) }
|
85
|
+
it { expect {subject['Nonexistant']}.to raise_error(ArgumentError) }
|
85
86
|
end
|
86
87
|
end
|
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.0.
|
4
|
+
version: 0.0.10
|
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-
|
11
|
+
date: 2014-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|