ruby_odata 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,4 +7,8 @@ tmp/*
7
7
  test/SampleService/App_Data/TestDB.mdf
8
8
  test/SampleService/App_Data/TestDB_Log.ldf
9
9
  pkg/*
10
- doc/*
10
+ doc/*
11
+ *.gem
12
+ .bundle
13
+ Gemfile.lock
14
+ pkg/*
@@ -1,38 +1,46 @@
1
- = ruby_odata Change Log
2
-
3
- === 0.0.1
4
- * New Features
5
- * Basic CRUD Operations
6
- * Query Enhancement: Filters
7
- * Query Enhancement: Expands
8
-
9
- === 0.0.2
10
- * New Features
11
- * Query Enhancement: Order By (both desc and asc)
12
-
13
- === 0.0.3
14
- * Bug Fixes
15
- * Rearranged code to match the gem name. Things were mismatched between odata_ruby and ruby_odata.
16
-
17
- === 0.0.4
18
- * New Features
19
- * Query Enhancement: skip
20
- * Query Enhancement: top
21
- * Ability to perform paging using skip and top together
22
- * Updated README with examples for order_by, skip, and top
23
-
24
- === 0.0.5
25
- * Bug Fixes
26
- * Works with Ruby 1.9.1
27
- * Works with ActiveSupport 3.0.0.beta4
28
-
29
- === 0.0.6
30
- * New Features
31
- * Ability to batch saves (Adds, Updates, Deletes); this will help save on network chatter
32
-
33
- === 0.0.7
34
- * New Features
35
- * Complex Types are now supported
36
- * Support for Edm.Int16, Edm.Int32, Edm.Int64
37
- * Support for Edm.Decimal
38
- * Support for Edm.DateTime
1
+ = ruby_odata Change Log
2
+
3
+ === 0.0.1
4
+ * New Features
5
+ * Basic CRUD Operations
6
+ * Query Enhancement: Filters
7
+ * Query Enhancement: Expands
8
+
9
+ === 0.0.2
10
+ * New Features
11
+ * Query Enhancement: Order By (both desc and asc)
12
+
13
+ === 0.0.3
14
+ * Bug Fixes
15
+ * Rearranged code to match the gem name. Things were mismatched between odata_ruby and ruby_odata.
16
+
17
+ === 0.0.4
18
+ * New Features
19
+ * Query Enhancement: skip
20
+ * Query Enhancement: top
21
+ * Ability to perform paging using skip and top together
22
+ * Updated README with examples for order_by, skip, and top
23
+
24
+ === 0.0.5
25
+ * Bug Fixes
26
+ * Works with Ruby 1.9.1
27
+ * Works with ActiveSupport 3.0.0.beta4
28
+
29
+ === 0.0.6
30
+ * New Features
31
+ * Ability to batch saves (Adds, Updates, Deletes); this will help save on network chatter
32
+
33
+ === 0.0.7
34
+ * New Features
35
+ * Complex Types are now supported
36
+ * Support for Edm.Int16, Edm.Int32, Edm.Int64
37
+ * Support for Edm.Decimal
38
+ * Support for Edm.DateTime
39
+
40
+ === 0.0.8
41
+ * New Features
42
+ * Basic HTTP Authentication (thanks J.D. Mullin)\
43
+ * Modified cucumber tests to setup the test database so you no longer need to copy them yourself
44
+ * Bug Fixes
45
+ * ActiveSupport 2.3.x (tested 2.3.11) and 3.0.x (tested 3.0.4) are now supported
46
+ * Works with Ruby 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby_odata.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,24 +1,24 @@
1
- Copyright (c) 2010, Visoft, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
- * Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
8
- * Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
11
- * Neither the name of Visoft, Inc. nor the
12
- names of its contributors may be used to endorse or promote products
13
- derived from this software without specific prior written permission.
14
-
15
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
- DISCLAIMED. IN NO EVENT SHALL VISOFT, INC. BE LIABLE FOR ANY
19
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ Copyright (c) 2010, Visoft, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of Visoft, Inc. nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL VISOFT, INC. BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,153 +1,179 @@
1
- = ruby_odata
2
-
3
- The <b>Open Data Protocol</b> (OData) is a fantastic way to query and update data over standard Web technologies. The ruby_odata library acts as a consumer of OData services.
4
-
5
- == Resources
6
-
7
- * Source Code (hosted on GitHub): http://github.com/visoft/ruby_odata
8
- * Documentation (hosted on rdoc.info): http://rdoc.info/projects/visoft/ruby_odata
9
- * Issue tracking (hosted on Lighthouse): http://visoft.lighthouseapp.com/projects/54309/home
10
- * Wiki (hosted on GitHub): http://wiki.github.com/visoft/ruby_odata/
11
- * Gem (hosted on Gemcutter): http://gemcutter.org/gems/ruby_odata
12
- * Blog articles: {Introducing a Ruby OData Client Library}[http://bit.ly/IntroRubyOData]
13
-
14
- == Installation
15
- You can install ruby_odata as a gem using:
16
- gem install ruby_odata
17
-
18
- == Usage
19
- As of version 0.0.5, support has been added for ActiveSupport 3.0.0 beta 4 and Ruby 1.9.1
20
- As of version 0.0.6, support has been added for batch saves
21
-
22
- === Adding
23
- When you point at a service, an AddTo<EntityName> method is created for you. This method takes in the new entity to create. To commit the change, you need to call the save_changes method on the service. To add a new category for example, you would simply do the following:
24
-
25
- require 'lib/ruby_odata'
26
-
27
- svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
28
- new_category = Category.new
29
- new_category.Name = "Sample Category"
30
- svc.AddToCategories(new_category)
31
- category = svc.save_changes
32
- puts category.to_json
33
-
34
- === Updating
35
- To update an object, simply pass the modified object to the update_object method on the service. Updating, like adding requires you to call save_changes in order to persist the change. For example:
36
-
37
- require 'lib/ruby_odata'
38
-
39
- svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
40
- new_category = Category.new
41
- new_category.Name = "Sample Category"
42
- svc.AddToCategories(new_category)
43
- category = svc.save_changes
44
- puts category.to_json
45
-
46
- category.Name = 'Updated Category'
47
- svc.update_object(category)
48
- result = svc.save_changes
49
- puts "Was the category updated? #{result}"
50
-
51
- === Deleting
52
- Deleting an object involves passing the tracked object to the delete_object method on the service. Deleting is another function that involves the save_changes method (to commit the change back to the server). In this example, we'll add a category and then delete it.
53
-
54
- require 'lib/ruby_odata'
55
-
56
- svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
57
- new_category = Category.new
58
- new_category.Name = "Sample Category"
59
- svc.AddToCategories(new_category)
60
- category = svc.save_changes
61
- puts category.to_json
62
-
63
- svc.delete_object(category)
64
- result = svc.save_changes
65
- puts "Was the category deleted? #{result}"
66
-
67
- === Querying
68
- Querying is easy, for example to pull all the categories from the SampleService, you simply can run:
69
-
70
- require 'lib/ruby_odata'
71
-
72
- svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
73
- svc.Categories
74
- categories = svc.execute
75
- puts categories.to_json
76
-
77
- You can also expand, add filters, order, skip records, and take only the top X records to the query before executing it. For example:
78
-
79
- === Expanding
80
- Expanding allows you to eagerly load other objects that are children of the root.
81
- You can use more than one expand on a query.
82
- For expanding grandchild and lower entities, you must pass in the full path from the root, for example +Products.expand('Orders').expand('Orders/LineItems')+
83
-
84
- # Without expanding the query
85
- svc.Products(1)
86
- prod1 = svc.execute
87
- puts "Without expanding the query"
88
- puts "#{prod1.to_json}\n"
89
-
90
- # With expanding the query
91
- svc.Products(1).expand('Category')
92
- prod1 = svc.execute
93
- puts "Without expanding the query"
94
- puts "#{prod1.to_json}\n"
95
-
96
-
97
- === Filtering
98
- The syntax for filtering can be found on the {OData Protocol URI Conventions}[http://www.odata.org/developers/protocols/uri-conventions#FilterSystemQueryOption] page.
99
- You can use more than one filter, if you call the filter method multiple times it will before an AND.
100
-
101
- # You can access by ID (but that isn't is a filter)
102
- # The syntax is just svc.ENTITYNAME(ID) which is shown in the expanding examples above
103
-
104
- svc.Products.filter("Name eq 'Product 2'")
105
- prod = svc.execute
106
- puts "Filtering on Name eq 'Product 2'"
107
- puts "#{prod.to_json}"
108
-
109
- === Combining Expanding and Filtering
110
- The query operations follow a {fluent interface}[http://en.wikipedia.org/wiki/Fluent_interface], although they can be added by themselves as well as chained
111
-
112
- svc.Products.filter("Name eq 'Product 2'").expand("Category")
113
- prod = svc.execute
114
- puts "Filtering on Name eq 'Product 2' and expanding"
115
- puts "#{prod.to_json}"
116
-
117
- === Order By
118
- You can order the results by properties of your choice, either ascending or descending.
119
- Order by are similar to +expand+s in that you can use more than one of them on a query.
120
- For expanding grandchild and lower entities, you must pass in the full path from the root like would do on an +expand+
121
-
122
- svc.Products.order_by("Name")
123
- products = svc.execute
124
-
125
- # Specifically requesting descending
126
- svc.Products.order_by("Name desc")
127
- products = svc.execute
128
-
129
- # Specifically requesting ascending
130
- svc.Products.order_by("Name asc")
131
- products = svc.execute
132
-
133
- === Skip
134
- Skip allows you to skip a number of records when querying. This is often used for paging along with +top+.
135
-
136
- svc.Products.skip(5)
137
- products = svc.execute # => skips the first 5 items
138
-
139
- === Top
140
- Top allows you only retrieve the top X number of records when querying. This is often used for paging along with +skip+.
141
-
142
- svc.Products.top(5)
143
- products = svc.execute # => returns only the first 5 items
144
-
145
- == Tests
146
- ===DATABASE SETUP - DO THIS FIRST
147
- Within /test/SampleService/App_Data/ rename _TestDB*.* to TestDB*.*. This file is just the initial database, and needs to be renamed so that unwanted changes to that DB aren't persisted in source control.
148
-
149
- All of the tests are written using Cucumber going against a sample service (Found in /test/SampleService/*). The SampleService is an ASP.NET Web Site running a SQLEXPRESS 2008 R2 Database (TestDB), as well as the ADO.NET Entity Framework and a WCF Data Service. In order to run the tests, you need to spin up the SampleService and have it running on port 8888 (http://localhost:8888/SampleService).
150
-
151
- One way to do this is to open the SampleService within Visual Studio 2010 and run it from there. Another option is to use Cassini (the built ASP.NET Development server that comes with Visual Studio 2010). There is a batch file found in /test called "Cassini x64.bat", you can run the batch file and just close the command window. There is a also a "Cassini x86.bat" file for those of you running a 32-bit machine, however it hasn't been tested. The only difference is the path to the Program Files directory. Once you run the batch file, the web server will spin up and you can find the instance in your systray just like if Visual Studio ran it for you. To stop the server, right click on the icon in your systray and tell it to stop
152
-
153
-
1
+ = ruby_odata
2
+
3
+ The <b>Open Data Protocol</b> (OData) is a fantastic way to query and update data over standard Web technologies. The ruby_odata library acts as a consumer of OData services.
4
+
5
+ == Resources
6
+
7
+ * Source Code (hosted on GitHub): http://github.com/visoft/ruby_odata
8
+ * Documentation (hosted on rdoc.info): http://rdoc.info/projects/visoft/ruby_odata
9
+ * Issue tracking (hosted on Lighthouse): http://visoft.lighthouseapp.com/projects/54309/home
10
+ * Wiki (hosted on GitHub): http://wiki.github.com/visoft/ruby_odata/
11
+ * Gem (hosted on Gemcutter): http://gemcutter.org/gems/ruby_odata
12
+ * Blog articles: {Introducing a Ruby OData Client Library}[http://bit.ly/IntroRubyOData]
13
+
14
+ == Installation
15
+ You can install ruby_odata as a gem using:
16
+ gem install ruby_odata
17
+
18
+ == Usage
19
+ As of version 0.0.5, support has been added for ActiveSupport 3.0.0 beta 4 and Ruby 1.9.1.
20
+
21
+ As of version 0.0.6, support has been added for batch saves
22
+
23
+ === Adding
24
+ When you point at a service, an AddTo<EntityName> method is created for you. This method takes in the new entity to create. To commit the change, you need to call the save_changes method on the service. To add a new category for example, you would simply do the following:
25
+
26
+ require 'lib/ruby_odata'
27
+
28
+ svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
29
+ new_category = Category.new
30
+ new_category.Name = "Sample Category"
31
+ svc.AddToCategories(new_category)
32
+ category = svc.save_changes
33
+ puts category.to_json
34
+
35
+ === Updating
36
+ To update an object, simply pass the modified object to the update_object method on the service. Updating, like adding requires you to call save_changes in order to persist the change. For example:
37
+
38
+ require 'lib/ruby_odata'
39
+
40
+ svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
41
+ new_category = Category.new
42
+ new_category.Name = "Sample Category"
43
+ svc.AddToCategories(new_category)
44
+ category = svc.save_changes
45
+ puts category.to_json
46
+
47
+ category.Name = 'Updated Category'
48
+ svc.update_object(category)
49
+ result = svc.save_changes
50
+ puts "Was the category updated? #{result}"
51
+
52
+ === Deleting
53
+ Deleting an object involves passing the tracked object to the delete_object method on the service. Deleting is another function that involves the save_changes method (to commit the change back to the server). In this example, we'll add a category and then delete it.
54
+
55
+ require 'lib/ruby_odata'
56
+
57
+ svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
58
+ new_category = Category.new
59
+ new_category.Name = "Sample Category"
60
+ svc.AddToCategories(new_category)
61
+ category = svc.save_changes
62
+ puts category.to_json
63
+
64
+ svc.delete_object(category)
65
+ result = svc.save_changes
66
+ puts "Was the category deleted? #{result}"
67
+
68
+ === Querying
69
+ Querying is easy, for example to pull all the categories from the SampleService, you simply can run:
70
+
71
+ require 'lib/ruby_odata'
72
+
73
+ svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc"
74
+ svc.Categories
75
+ categories = svc.execute
76
+ puts categories.to_json
77
+
78
+ You can also expand, add filters, order, skip records, and take only the top X records to the query before executing it. For example:
79
+
80
+ === Authentication
81
+ Basic HTTP Authentication is supported via sending a username and password as service constructor arguments:
82
+
83
+ require 'lib/ruby_odata'
84
+
85
+ svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc", { :username => "bob", :password=> "12345" }
86
+
87
+ === Expanding
88
+ Expanding allows you to eagerly load other objects that are children of the root.
89
+ You can use more than one expand on a query.
90
+ For expanding grandchild and lower entities, you must pass in the full path from the root, for example +Products.expand('Orders').expand('Orders/LineItems')+
91
+
92
+ # Without expanding the query
93
+ svc.Products(1)
94
+ prod1 = svc.execute
95
+ puts "Without expanding the query"
96
+ puts "#{prod1.to_json}\n"
97
+
98
+ # With expanding the query
99
+ svc.Products(1).expand('Category')
100
+ prod1 = svc.execute
101
+ puts "Without expanding the query"
102
+ puts "#{prod1.to_json}\n"
103
+
104
+
105
+ === Filtering
106
+ The syntax for filtering can be found on the {OData Protocol URI Conventions}[http://www.odata.org/developers/protocols/uri-conventions#FilterSystemQueryOption] page.
107
+ You can use more than one filter, if you call the filter method multiple times it will before an AND.
108
+
109
+ # You can access by ID (but that isn't is a filter)
110
+ # The syntax is just svc.ENTITYNAME(ID) which is shown in the expanding examples above
111
+
112
+ svc.Products.filter("Name eq 'Product 2'")
113
+ prod = svc.execute
114
+ puts "Filtering on Name eq 'Product 2'"
115
+ puts "#{prod.to_json}"
116
+
117
+ Note you can pass more than one filter in the string, for example (querying Netflix):
118
+
119
+ svc.Titles.filter("Rating eq 'PG' and ReleaseYear eq 1980")
120
+
121
+ Filters can also be chained, by doing this you will create an "and" filter (just like the last example) when it is passed to the server.
122
+
123
+ svc.Titles.filter("Rating eq 'PG'").filter("ReleaseYear eq 1980")
124
+
125
+
126
+ === Combining Expanding and Filtering
127
+ The query operations follow a {fluent interface}[http://en.wikipedia.org/wiki/Fluent_interface], although they can be added by themselves as well as chained
128
+
129
+ svc.Products.filter("Name eq 'Product 2'").expand("Category")
130
+ prod = svc.execute
131
+ puts "Filtering on Name eq 'Product 2' and expanding"
132
+ puts "#{prod.to_json}"
133
+
134
+ === Order By
135
+ You can order the results by properties of your choice, either ascending or descending.
136
+ Order by are similar to +expand+s in that you can use more than one of them on a query.
137
+ For expanding grandchild and lower entities, you must pass in the full path from the root like would do on an +expand+
138
+
139
+ svc.Products.order_by("Name")
140
+ products = svc.execute
141
+
142
+ # Specifically requesting descending
143
+ svc.Products.order_by("Name desc")
144
+ products = svc.execute
145
+
146
+ # Specifically requesting ascending
147
+ svc.Products.order_by("Name asc")
148
+ products = svc.execute
149
+
150
+ Like the fiter method, order_by statements can also be chained like so:
151
+
152
+ svc.Products.order_by("Name asc").order_by("Price desc")
153
+
154
+
155
+ === Skip
156
+ Skip allows you to skip a number of records when querying. This is often used for paging along with +top+.
157
+
158
+ svc.Products.skip(5)
159
+ products = svc.execute # => skips the first 5 items
160
+
161
+ === Top
162
+ Top allows you only retrieve the top X number of records when querying. This is often used for paging along with +skip+.
163
+
164
+ svc.Products.top(5)
165
+ products = svc.execute # => returns only the first 5 items
166
+
167
+ == Tests
168
+ All of the tests are written using Cucumber going against a sample service (Found in /test/SampleService/*). The SampleService is an ASP.NET Web Site running a SQLEXPRESS 2008 R2 Database (TestDB), as well as the ADO.NET Entity Framework and a WCF Data Service. In order to run the tests, you need to spin up the SampleService and have it running on port 8888 (http://localhost:8888/SampleService).
169
+
170
+ One way to do this is to open the SampleService within Visual Studio 2010 and run it from there (must use IIS instead of development web server in order for basic auth tests to pass, however). Another option is to use IIS Express. It is a free download from Microsoft. Once installed, there is a batch file found in /test called "iisExpress x64.bat", you can run the batch file and just close the command window. There is a also an "iisExpress x86.bat" file for those of you running a 32-bit machine. The only difference is the path to the Program Files directory. Once you run the batch file, the web server will spin up and you can find the instance in your systray just like if Visual Studio ran it for you. To stop the server, right click on the icon in your systray and tell it to stop.
171
+
172
+ Note there are also Cassini batch files that you can use as well, but the basic auth tests will fail if using this server (which doesn't support basic http authentication).
173
+
174
+ If you are testing on a Windows machine, you may encounter a problem with using cucumber and Ruby 1.9.2. You will get a message when you fire up cucumber about missing msvcrt-ruby18.dll. The fix for this is to make sure you have the {RubyInstaller DevKit}[https://github.com/oneclick/rubyinstaller/wiki/Development-Kit] installed, then do the following:
175
+ gem uninstall json
176
+ gem install json --platform=ruby -v 1.4.6
177
+
178
+ From the BASE ruby_odata directory, run cucumber, which will execute all of the tests.
179
+