odata 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0999c3b85269d2ad6c9855aa813ed5e6e10a24e
4
- data.tar.gz: ee7cf848b1c47f15375c2e9cbd6e7cb5a2cbc89f
3
+ metadata.gz: bcb9a746bd19061bb07c0311b4bdc705c084ad5b
4
+ data.tar.gz: 1f2c9dae62cbec8852a2f65a29826f3ee5412a33
5
5
  SHA512:
6
- metadata.gz: 516fa042cb00120bd214aeb52e9c12dbede85614562ccd760cbf4b41d1b6aed5571c82589949f795b42a3e9d4d61c687fb485db4f4bafc36d83c3666dfeb5921
7
- data.tar.gz: 0654fbc52376a5446c86fb8303f6b5ca267b7eae694d87f3bcac4644cf824a953b3ed347a0f40864c022039947d312de4b9038a2775679a32140d4a1e1024186
6
+ metadata.gz: 28a93be11707fe9adcf4aa51af4a0c48d73bce1b680525ac293ceb89c9cb8b11e4045321da62d4a5e280158efb289fcd50325eaf20b1f2b5d6b5bf198ab3480e
7
+ data.tar.gz: 88b1a0bc6fb085880e20f102bebf8e16aad9a4313641cf1a5b6a5f75fde34caa47bc677ad886a473e843c4e82d04509bfea6351c5a504818e445a3eea130d3e4
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
  [![Code Climate](https://codeclimate.com/github/plainprogrammer/odata.png)](https://codeclimate.com/github/plainprogrammer/odata)
5
5
  [![Coverage](https://codeclimate.com/github/plainprogrammer/odata/coverage.png)](https://codeclimate.com/github/plainprogrammer/odata)
6
6
  [![Gem Version](https://badge.fury.io/rb/odata.svg)](http://badge.fury.io/rb/odata)
7
+ [![Dependency Status](https://gemnasium.com/plainprogrammer/odata.svg)](https://gemnasium.com/plainprogrammer/odata)
7
8
  [![Documentation](http://inch-ci.org/github/plainprogrammer/odata.png?branch=master)](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. The only time you will need
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, should you need it.
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. So, looking up services by their service URL is the
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 [](entity_type_name)
87
- xpath_query = "//EntityContainer/EntitySet[@EntityType='#{namespace}.#{entity_type_name}']"
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
- set_name = entity_set_node.attributes['Name'].value
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
- OData::EntitySet.new(name: set_name, namespace: namespace, type: entity_type_name.to_s, container: container_name)
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
@@ -1,3 +1,3 @@
1
1
  module OData
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -81,6 +81,7 @@ describe OData::Service do
81
81
  end
82
82
 
83
83
  describe '#[]' do
84
- it { expect(subject['Product']).to be_a(OData::EntitySet) }
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.9
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-06-30 00:00:00.000000000 Z
11
+ date: 2014-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler