odata 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/odata.rb +2 -0
- data/lib/odata/entity.rb +1 -1
- data/lib/odata/entity_set.rb +42 -3
- data/lib/odata/properties/binary.rb +6 -0
- data/lib/odata/properties/boolean.rb +1 -0
- data/lib/odata/properties/date_time.rb +6 -0
- data/lib/odata/properties/date_time_offset.rb +6 -0
- data/lib/odata/properties/decimal.rb +6 -0
- data/lib/odata/properties/float.rb +9 -0
- data/lib/odata/properties/guid.rb +2 -0
- data/lib/odata/properties/integer.rb +15 -0
- data/lib/odata/properties/number.rb +1 -0
- data/lib/odata/properties/string.rb +9 -0
- data/lib/odata/properties/time.rb +6 -0
- data/lib/odata/query.rb +82 -0
- data/lib/odata/query/criteria.rb +75 -0
- data/lib/odata/service.rb +2 -2
- data/lib/odata/version.rb +1 -1
- data/spec/fixtures/sample_service/product_filter_many.xml +234 -0
- data/spec/fixtures/sample_service/product_filter_one.xml +42 -0
- data/spec/fixtures/sample_service/product_not_found.xml +5 -0
- data/spec/odata/entity_set_spec.rb +33 -3
- data/spec/odata/query/criteria_spec.rb +36 -0
- data/spec/odata/query_spec.rb +58 -0
- data/spec/spec_helper.rb +9 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1ee4f9637afcfe8f3b9e088e14056e3bff1a90a
|
4
|
+
data.tar.gz: b1821379f53b957eb494930b0700ddaa99f20004
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1844be486c58326b07a7415c1e9dd0d98a92eb505459f678ff7adacfa5812331a488885989f6dc30b37aa2552103a4dec39a76091e6be3850d53809addf99f3b
|
7
|
+
data.tar.gz: 6a86353c36caf8aeb84aff2711b3967247c8c0d6a91fe2036c42a644b41114a3d8d53cc362a89633dfad31df9580d0395403f563708d0b31ffaee303472cb3dc
|
data/.travis.yml
CHANGED
data/lib/odata.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'backports/2.1.0/enumerable/to_h'
|
2
2
|
|
3
|
+
require 'uri'
|
3
4
|
require 'date'
|
4
5
|
require 'nokogiri'
|
5
6
|
require 'typhoeus'
|
@@ -13,6 +14,7 @@ require 'odata/property'
|
|
13
14
|
require 'odata/properties'
|
14
15
|
require 'odata/entity'
|
15
16
|
require 'odata/entity_set'
|
17
|
+
require 'odata/query'
|
16
18
|
require 'odata/service'
|
17
19
|
require 'odata/service_registry'
|
18
20
|
|
data/lib/odata/entity.rb
CHANGED
@@ -30,7 +30,6 @@ module OData
|
|
30
30
|
def self.with_properties(new_properties = {}, options = {})
|
31
31
|
entity = OData::Entity.new(options)
|
32
32
|
entity.instance_eval do
|
33
|
-
# TODO Define the properties
|
34
33
|
service.properties_for(name).each do |name, instance|
|
35
34
|
set_property(name, instance)
|
36
35
|
end
|
@@ -43,6 +42,7 @@ module OData
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def self.from_xml(xml_doc, options = {})
|
45
|
+
return nil if xml_doc.nil?
|
46
46
|
entity = OData::Entity.new(options)
|
47
47
|
entity.instance_eval do
|
48
48
|
xml_doc.xpath('//content/properties/*').each do |property_xml|
|
data/lib/odata/entity_set.rb
CHANGED
@@ -47,21 +47,56 @@ module OData
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
# Return the first Entity for the set.
|
51
|
+
# @return [OData::EntitySet]
|
50
52
|
def first
|
51
|
-
|
53
|
+
query = OData::Query.new(name)
|
54
|
+
query << OData::Query::Criteria.new(operation: 'skip', argument: 0)
|
55
|
+
query << OData::Query::Criteria.new(operation: 'top', argument: 1)
|
56
|
+
result = service.execute(query)
|
52
57
|
entities = service.find_entities(result)
|
53
58
|
OData::Entity.from_xml(entities[0], entity_options)
|
54
59
|
end
|
55
60
|
|
56
|
-
# Returns the number of entities within the set
|
61
|
+
# Returns the number of entities within the set.
|
62
|
+
# @return [Integer]
|
57
63
|
def count
|
58
64
|
service.execute("#{name}/$count").body.to_i
|
59
65
|
end
|
60
66
|
|
67
|
+
# Create a new Entity for this set with the given properties.
|
68
|
+
# @param properties [Hash] property name as key and it's initial value
|
69
|
+
# @return [OData::Entity]
|
61
70
|
def new_entity(properties = {})
|
62
71
|
OData::Entity.with_properties(properties, entity_options)
|
63
72
|
end
|
64
73
|
|
74
|
+
# Find Entities with the supplied filter applied.
|
75
|
+
# @param filter [to_s] filter to apply
|
76
|
+
# @return [Array<OData::Entity>]
|
77
|
+
def filter(filter)
|
78
|
+
entities = []
|
79
|
+
result = service.execute("#{name}?$filter=#{filter}")
|
80
|
+
|
81
|
+
service.find_entities(result).each do |entity_xml|
|
82
|
+
entities << OData::Entity.from_xml(entity_xml, entity_options)
|
83
|
+
end
|
84
|
+
|
85
|
+
entities
|
86
|
+
end
|
87
|
+
|
88
|
+
# Find the Entity with the supplied key value.
|
89
|
+
# @param key [to_s] primary key to lookup
|
90
|
+
# @return [OData::Entity,nil]
|
91
|
+
def [](key)
|
92
|
+
result = service.execute("#{name}(#{key})")
|
93
|
+
entities = service.find_entities(result)
|
94
|
+
OData::Entity.from_xml(entities[0], entity_options)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Write supplied entity back to the service.
|
98
|
+
# @param entity [OData::Entity] entity to save or update in the service
|
99
|
+
# @return [OData::Entity]
|
65
100
|
def <<(entity)
|
66
101
|
new_entity = entity[entity.primary_key].nil?
|
67
102
|
|
@@ -103,7 +138,11 @@ module OData
|
|
103
138
|
end
|
104
139
|
|
105
140
|
def get_paginated_entities(per_page, page)
|
106
|
-
|
141
|
+
query = OData::Query.new(name)
|
142
|
+
query << OData::Query::Criteria.new(operation: 'inline_count', argument: 'allpages')
|
143
|
+
query << OData::Query::Criteria.new(operation: 'skip', argument: (per_page * page))
|
144
|
+
query << OData::Query::Criteria.new(operation: 'top', argument: per_page)
|
145
|
+
result = service.execute(query)
|
107
146
|
entities = service.find_entities(result)
|
108
147
|
total = service.find_node(result, 'count').content.to_i
|
109
148
|
return total, entities
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the Binary OData type.
|
3
4
|
class Binary < OData::Property
|
5
|
+
# Returns the property value, properly typecast
|
6
|
+
# @return [Integer,nil]
|
4
7
|
def value
|
5
8
|
if @value.nil? && allows_nil?
|
6
9
|
nil
|
@@ -9,11 +12,14 @@ module OData
|
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
# Sets the property value
|
16
|
+
# @params new_value [0,1,Boolean]
|
12
17
|
def value=(new_value)
|
13
18
|
validate(new_value)
|
14
19
|
@value = parse_value(new_value)
|
15
20
|
end
|
16
21
|
|
22
|
+
# The OData type name
|
17
23
|
def type
|
18
24
|
'Edm.Binary'
|
19
25
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the DateTime OData type.
|
3
4
|
class DateTime < OData::Property
|
5
|
+
# Returns the property value, properly typecast
|
6
|
+
# @return [DateTime, nil]
|
4
7
|
def value
|
5
8
|
if @value.nil? && allows_nil?
|
6
9
|
nil
|
@@ -13,11 +16,14 @@ module OData
|
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
19
|
+
# Sets the property value
|
20
|
+
# @params new_value [DateTime]
|
16
21
|
def value=(new_value)
|
17
22
|
validate(new_value)
|
18
23
|
@value = parse_value(new_value)
|
19
24
|
end
|
20
25
|
|
26
|
+
# The OData type name
|
21
27
|
def type
|
22
28
|
'Edm.DateTime'
|
23
29
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the DateTimeOffset OData type.
|
3
4
|
class DateTimeOffset < OData::Property
|
5
|
+
# Returns the property value, properly typecast
|
6
|
+
# @return [DateTime,nil]
|
4
7
|
def value
|
5
8
|
if @value.nil? && allow_nil?
|
6
9
|
nil
|
@@ -9,11 +12,14 @@ module OData
|
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
# Sets the property value
|
16
|
+
# @params new_value [DateTime]
|
12
17
|
def value=(new_value)
|
13
18
|
validate(new_value)
|
14
19
|
@value = parse_value(new_value)
|
15
20
|
end
|
16
21
|
|
22
|
+
# The OData type name
|
17
23
|
def type
|
18
24
|
'Edm.DateTimeOffset'
|
19
25
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the Decimal OData type.
|
3
4
|
class Decimal < OData::Property
|
5
|
+
# Returns the property value, properly typecast
|
6
|
+
# @return [BigDecimal,nil]
|
4
7
|
def value
|
5
8
|
if @value.nil? && allows_nil?
|
6
9
|
nil
|
@@ -9,11 +12,14 @@ module OData
|
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
# Sets the property value
|
16
|
+
# @params new_value something BigDecimal() can parse
|
12
17
|
def value=(new_value)
|
13
18
|
validate(BigDecimal(new_value))
|
14
19
|
@value = new_value.to_s
|
15
20
|
end
|
16
21
|
|
22
|
+
# The OData type name
|
17
23
|
def type
|
18
24
|
'Edm.Decimal'
|
19
25
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the Float OData type.
|
3
4
|
class Float < OData::Property
|
4
5
|
include OData::Properties::Number
|
5
6
|
|
7
|
+
# Returns the property value, properly typecast
|
8
|
+
# @return [Float,nil]
|
6
9
|
def value
|
7
10
|
if @value.nil? && allows_nil?
|
8
11
|
nil
|
@@ -11,11 +14,14 @@ module OData
|
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
17
|
+
# Sets the property value
|
18
|
+
# @params new_value [to_f]
|
14
19
|
def value=(new_value)
|
15
20
|
validate(new_value.to_f)
|
16
21
|
@value = new_value.to_f.to_s
|
17
22
|
end
|
18
23
|
|
24
|
+
# The OData type name
|
19
25
|
def type
|
20
26
|
'Edm.Double'
|
21
27
|
end
|
@@ -31,9 +37,12 @@ module OData
|
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
40
|
+
# Defines the Double (Float) OData type.
|
34
41
|
class Double < OData::Properties::Float; end
|
35
42
|
|
43
|
+
# Defines the Single (Float) OData type.
|
36
44
|
class Single < OData::Properties::Float
|
45
|
+
# The OData type name
|
37
46
|
def type
|
38
47
|
'Edm.Single'
|
39
48
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the Integer OData type.
|
3
4
|
class Integer < OData::Property
|
4
5
|
include OData::Properties::Number
|
5
6
|
|
7
|
+
# Returns the property value, properly typecast
|
8
|
+
# @return [Integer,nil]
|
6
9
|
def value
|
7
10
|
if @value.nil? && allows_nil?
|
8
11
|
nil
|
@@ -11,11 +14,14 @@ module OData
|
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
17
|
+
# Sets the property value
|
18
|
+
# @params new_value [to_i]
|
14
19
|
def value=(new_value)
|
15
20
|
validate(new_value.to_i)
|
16
21
|
@value = new_value.to_i.to_s
|
17
22
|
end
|
18
23
|
|
24
|
+
# The OData type name
|
19
25
|
def type
|
20
26
|
'Edm.Int64'
|
21
27
|
end
|
@@ -31,7 +37,9 @@ module OData
|
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
40
|
+
# Defines the Integer (16 bit) OData type.
|
34
41
|
class Int16 < Integer
|
42
|
+
# The OData type name
|
35
43
|
def type
|
36
44
|
'Edm.Int16'
|
37
45
|
end
|
@@ -47,7 +55,9 @@ module OData
|
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
58
|
+
# Defines the Integer (32 bit) OData type.
|
50
59
|
class Int32 < Integer
|
60
|
+
# The OData type name
|
51
61
|
def type
|
52
62
|
'Edm.Int32'
|
53
63
|
end
|
@@ -63,9 +73,12 @@ module OData
|
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
76
|
+
# Defines the Integer (64 bit) OData type.
|
66
77
|
class Int64 < Integer; end
|
67
78
|
|
79
|
+
# Defines the Byte OData type.
|
68
80
|
class Byte < Integer
|
81
|
+
# The OData type name
|
69
82
|
def type
|
70
83
|
'Edm.Byte'
|
71
84
|
end
|
@@ -81,7 +94,9 @@ module OData
|
|
81
94
|
end
|
82
95
|
end
|
83
96
|
|
97
|
+
# Defines the Signed Byte OData type.
|
84
98
|
class SByte < Integer
|
99
|
+
# The OData type name
|
85
100
|
def type
|
86
101
|
'Edm.SByte'
|
87
102
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the String OData type.
|
3
4
|
class String < OData::Property
|
5
|
+
# Returns the property value, properly typecast
|
6
|
+
# @return [String,nil]
|
4
7
|
def value
|
5
8
|
if @value.nil? && allows_nil?
|
6
9
|
nil
|
@@ -9,23 +12,29 @@ module OData
|
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
# Sets the property value
|
16
|
+
# @params new_value [to_s,nil]
|
12
17
|
def value=(new_value)
|
13
18
|
validate(new_value)
|
14
19
|
@value = new_value.nil? ? nil : encode_value(new_value.to_s)
|
15
20
|
end
|
16
21
|
|
22
|
+
# The OData type name
|
17
23
|
def type
|
18
24
|
'Edm.String'
|
19
25
|
end
|
20
26
|
|
27
|
+
# Is the property value Unicode encoded
|
21
28
|
def is_unicode?
|
22
29
|
options[:unicode]
|
23
30
|
end
|
24
31
|
|
32
|
+
# Does the property have a default value
|
25
33
|
def has_default_value?
|
26
34
|
not(options[:default_value].nil?)
|
27
35
|
end
|
28
36
|
|
37
|
+
# The default value for the property
|
29
38
|
def default_value
|
30
39
|
options[:default_value]
|
31
40
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module OData
|
2
2
|
module Properties
|
3
|
+
# Defines the Time OData type.
|
3
4
|
class Time < OData::Property
|
5
|
+
# Returns the property value, properly typecast
|
6
|
+
# @return [Time,nil]
|
4
7
|
def value
|
5
8
|
if @value.nil? && allow_nil?
|
6
9
|
nil
|
@@ -9,11 +12,14 @@ module OData
|
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
15
|
+
# Sets the property value
|
16
|
+
# @params new_value [Time]
|
12
17
|
def value=(new_value)
|
13
18
|
validate(new_value)
|
14
19
|
@value = parse_value(new_value)
|
15
20
|
end
|
16
21
|
|
22
|
+
# The OData type name
|
17
23
|
def type
|
18
24
|
'Edm.Time'
|
19
25
|
end
|
data/lib/odata/query.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'odata/query/criteria'
|
2
|
+
|
3
|
+
module OData
|
4
|
+
class Query
|
5
|
+
# Defines the operations the OData gem knows how to support.
|
6
|
+
SUPPORTED_OPERATIONS = [
|
7
|
+
:filter, :order_by, :skip, :top, :select, :expand, :inline_count
|
8
|
+
]
|
9
|
+
|
10
|
+
def initialize(collection)
|
11
|
+
@collection = collection.to_s
|
12
|
+
setup_empty_criteria_set
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(criteria)
|
16
|
+
criteria_set[criteria.operation] << criteria.argument
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
[collection,assemble_criteria].compact.join('?')
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def collection
|
26
|
+
@collection
|
27
|
+
end
|
28
|
+
|
29
|
+
def criteria_set
|
30
|
+
@criteria_set
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_empty_criteria_set
|
34
|
+
criteria_set = SUPPORTED_OPERATIONS.map do |operation|
|
35
|
+
[operation, []]
|
36
|
+
end
|
37
|
+
@criteria_set = Hash[criteria_set]
|
38
|
+
end
|
39
|
+
|
40
|
+
def assemble_criteria
|
41
|
+
criteria = [
|
42
|
+
filter_criteria,
|
43
|
+
order_by_criteria,
|
44
|
+
expand_criteria,
|
45
|
+
select_criteria,
|
46
|
+
inline_count_criteria,
|
47
|
+
skip_criteria,
|
48
|
+
top_criteria
|
49
|
+
].compact!
|
50
|
+
|
51
|
+
criteria.empty? ? nil : criteria.join('&')
|
52
|
+
end
|
53
|
+
|
54
|
+
def filter_criteria
|
55
|
+
criteria_set[:filter].empty? ? nil : "$filter=#{criteria_set[:filter].join(' and ')}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def order_by_criteria
|
59
|
+
criteria_set[:order_by].empty? ? nil : "$orderby=#{criteria_set[:order_by].join(',')}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def expand_criteria
|
63
|
+
criteria_set[:expand].empty? ? nil : "$expand=#{criteria_set[:expand].join(',')}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def select_criteria
|
67
|
+
criteria_set[:select].empty? ? nil : "$select=#{criteria_set[:select].join(',')}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def inline_count_criteria
|
71
|
+
criteria_set[:inline_count].empty? ? nil : "$inlinecount=#{criteria_set[:inline_count].last}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def skip_criteria
|
75
|
+
criteria_set[:skip].empty? ? nil : "$skip=#{criteria_set[:skip].last}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def top_criteria
|
79
|
+
criteria_set[:top].empty? ? nil : "$top=#{criteria_set[:top].last}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module OData
|
2
|
+
class Query
|
3
|
+
# Represents a discreet detail about an OData query. It also validates
|
4
|
+
# the criteria based on what the gem knows how to support.
|
5
|
+
class Criteria
|
6
|
+
# Defines the options required to create a new OData::Query::Criteria.
|
7
|
+
REQUIRED_OPTIONS = [:operation, :argument]
|
8
|
+
|
9
|
+
# Defines the operations the OData gem knows how to support.
|
10
|
+
SUPPORTED_OPERATIONS = [
|
11
|
+
:filter, :order_by, :skip, :top, :select, :expand, :inline_count
|
12
|
+
]
|
13
|
+
|
14
|
+
# Creates a new OData::Query::Criteria with the supplied options.
|
15
|
+
# @param options [Hash]
|
16
|
+
def initialize(options = {})
|
17
|
+
@options = process_options(options)
|
18
|
+
validate_required_options
|
19
|
+
validate_supported_operation
|
20
|
+
end
|
21
|
+
|
22
|
+
# The query operation of a particular criteria.
|
23
|
+
# @return [Symbol]
|
24
|
+
def operation
|
25
|
+
options[:operation]
|
26
|
+
end
|
27
|
+
|
28
|
+
# The query argument of a particular criteria.
|
29
|
+
# @return [String]
|
30
|
+
def argument
|
31
|
+
options[:argument]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def options
|
37
|
+
@options
|
38
|
+
end
|
39
|
+
|
40
|
+
def process_options(passed_options)
|
41
|
+
new_options = passed_options.map do |key, value|
|
42
|
+
if key.to_sym == :operation
|
43
|
+
value = value.to_sym
|
44
|
+
end
|
45
|
+
|
46
|
+
[key.to_sym, value]
|
47
|
+
end
|
48
|
+
|
49
|
+
Hash[new_options]
|
50
|
+
end
|
51
|
+
|
52
|
+
def required_options
|
53
|
+
REQUIRED_OPTIONS
|
54
|
+
end
|
55
|
+
|
56
|
+
def supported_operations
|
57
|
+
SUPPORTED_OPERATIONS
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_required_options
|
61
|
+
required_options.each do |required_option|
|
62
|
+
unless options.key?(required_option)
|
63
|
+
raise ArgumentError, "Missing required option: #{required_option}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def validate_supported_operation
|
69
|
+
unless supported_operations.include?(options[:operation])
|
70
|
+
raise ArgumentError, "Operation not supported: #{options[:operation]}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/odata/service.rb
CHANGED
@@ -84,7 +84,7 @@ module OData
|
|
84
84
|
# @return [Typhoeus::Response]
|
85
85
|
def execute(url_chunk, additional_options = {})
|
86
86
|
request = ::Typhoeus::Request.new(
|
87
|
-
"#{service_url}/#{url_chunk}",
|
87
|
+
URI.escape("#{service_url}/#{url_chunk}"),
|
88
88
|
options[:typhoeus].merge({
|
89
89
|
method: :get
|
90
90
|
}).merge(additional_options)
|
@@ -168,7 +168,7 @@ module OData
|
|
168
168
|
def metadata
|
169
169
|
@metadata ||= lambda {
|
170
170
|
request = ::Typhoeus::Request.new(
|
171
|
-
"#{service_url}/$metadata",
|
171
|
+
URI.escape("#{service_url}/$metadata"),
|
172
172
|
options[:typhoeus].merge({
|
173
173
|
method: :get
|
174
174
|
})
|
data/lib/odata/version.rb
CHANGED
@@ -0,0 +1,234 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<feed xml:base="http://services.odata.org/OData/OData.svc/" xmlns="http://www.w3.org/2005/Atom"
|
3
|
+
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
|
4
|
+
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
|
5
|
+
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
|
6
|
+
<id>http://services.odata.org/OData/OData.svc/Products</id>
|
7
|
+
<title type="text">Products</title>
|
8
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
9
|
+
<link rel="self" title="Products" href="Products"/>
|
10
|
+
<entry>
|
11
|
+
<id>http://services.odata.org/OData/OData.svc/Products(1)</id>
|
12
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
13
|
+
<link rel="edit" title="Product" href="Products(1)"/>
|
14
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
15
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(1)/Categories"/>
|
16
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
17
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(1)/Supplier"/>
|
18
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
19
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(1)/ProductDetail"/>
|
20
|
+
<title type="text">Milk</title>
|
21
|
+
<summary type="text">Low fat milk</summary>
|
22
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
23
|
+
<author>
|
24
|
+
<name/>
|
25
|
+
</author>
|
26
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
27
|
+
title="Categories" href="Products(1)/$links/Categories"/>
|
28
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
29
|
+
title="Supplier" href="Products(1)/$links/Supplier"/>
|
30
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
31
|
+
title="ProductDetail" href="Products(1)/$links/ProductDetail"/>
|
32
|
+
<content type="application/xml">
|
33
|
+
<m:properties>
|
34
|
+
<d:ID m:type="Edm.Int32">1</d:ID>
|
35
|
+
<d:ReleaseDate m:type="Edm.DateTime">1995-10-01T00:00:00</d:ReleaseDate>
|
36
|
+
<d:DiscontinuedDate m:null="true"/>
|
37
|
+
<d:Rating m:type="Edm.Int16">3</d:Rating>
|
38
|
+
<d:Price m:type="Edm.Double">3.5</d:Price>
|
39
|
+
</m:properties>
|
40
|
+
</content>
|
41
|
+
</entry>
|
42
|
+
<entry>
|
43
|
+
<id>http://services.odata.org/OData/OData.svc/Products(2)</id>
|
44
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
45
|
+
<link rel="edit" title="Product" href="Products(2)"/>
|
46
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
47
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(2)/Categories"/>
|
48
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
49
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(2)/Supplier"/>
|
50
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
51
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(2)/ProductDetail"/>
|
52
|
+
<title type="text">Vint soda</title>
|
53
|
+
<summary type="text">Americana Variety - Mix of 6 flavors</summary>
|
54
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
55
|
+
<author>
|
56
|
+
<name/>
|
57
|
+
</author>
|
58
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
59
|
+
title="Categories" href="Products(2)/$links/Categories"/>
|
60
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
61
|
+
title="Supplier" href="Products(2)/$links/Supplier"/>
|
62
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
63
|
+
title="ProductDetail" href="Products(2)/$links/ProductDetail"/>
|
64
|
+
<content type="application/xml">
|
65
|
+
<m:properties>
|
66
|
+
<d:ID m:type="Edm.Int32">2</d:ID>
|
67
|
+
<d:ReleaseDate m:type="Edm.DateTime">2000-10-01T00:00:00</d:ReleaseDate>
|
68
|
+
<d:DiscontinuedDate m:null="true"/>
|
69
|
+
<d:Rating m:type="Edm.Int16">3</d:Rating>
|
70
|
+
<d:Price m:type="Edm.Double">20.9</d:Price>
|
71
|
+
</m:properties>
|
72
|
+
</content>
|
73
|
+
</entry>
|
74
|
+
<entry>
|
75
|
+
<id>http://services.odata.org/OData/OData.svc/Products(3)</id>
|
76
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
77
|
+
<link rel="edit" title="Product" href="Products(3)"/>
|
78
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
79
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(3)/Categories"/>
|
80
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
81
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(3)/Supplier"/>
|
82
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
83
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(3)/ProductDetail"/>
|
84
|
+
<title type="text">Havina Cola</title>
|
85
|
+
<summary type="text">The Original Key Lime Cola</summary>
|
86
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
87
|
+
<author>
|
88
|
+
<name/>
|
89
|
+
</author>
|
90
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
91
|
+
title="Categories" href="Products(3)/$links/Categories"/>
|
92
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
93
|
+
title="Supplier" href="Products(3)/$links/Supplier"/>
|
94
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
95
|
+
title="ProductDetail" href="Products(3)/$links/ProductDetail"/>
|
96
|
+
<content type="application/xml">
|
97
|
+
<m:properties>
|
98
|
+
<d:ID m:type="Edm.Int32">3</d:ID>
|
99
|
+
<d:ReleaseDate m:type="Edm.DateTime">2005-10-01T00:00:00</d:ReleaseDate>
|
100
|
+
<d:DiscontinuedDate m:type="Edm.DateTime">2006-10-01T00:00:00</d:DiscontinuedDate>
|
101
|
+
<d:Rating m:type="Edm.Int16">3</d:Rating>
|
102
|
+
<d:Price m:type="Edm.Double">19.9</d:Price>
|
103
|
+
</m:properties>
|
104
|
+
</content>
|
105
|
+
</entry>
|
106
|
+
<entry>
|
107
|
+
<id>http://services.odata.org/OData/OData.svc/Products(4)</id>
|
108
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
109
|
+
<link rel="edit" title="Product" href="Products(4)"/>
|
110
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
111
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(4)/Categories"/>
|
112
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
113
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(4)/Supplier"/>
|
114
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
115
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(4)/ProductDetail"/>
|
116
|
+
<title type="text">Fruit Punch</title>
|
117
|
+
<summary type="text">Mango flavor, 8.3 Ounce Cans (Pack of 24)</summary>
|
118
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
119
|
+
<author>
|
120
|
+
<name/>
|
121
|
+
</author>
|
122
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
123
|
+
title="Categories" href="Products(4)/$links/Categories"/>
|
124
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
125
|
+
title="Supplier" href="Products(4)/$links/Supplier"/>
|
126
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
127
|
+
title="ProductDetail" href="Products(4)/$links/ProductDetail"/>
|
128
|
+
<content type="application/xml">
|
129
|
+
<m:properties>
|
130
|
+
<d:ID m:type="Edm.Int32">4</d:ID>
|
131
|
+
<d:ReleaseDate m:type="Edm.DateTime">2003-01-05T00:00:00</d:ReleaseDate>
|
132
|
+
<d:DiscontinuedDate m:null="true"/>
|
133
|
+
<d:Rating m:type="Edm.Int16">3</d:Rating>
|
134
|
+
<d:Price m:type="Edm.Double">22.99</d:Price>
|
135
|
+
</m:properties>
|
136
|
+
</content>
|
137
|
+
</entry>
|
138
|
+
<entry>
|
139
|
+
<id>http://services.odata.org/OData/OData.svc/Products(5)</id>
|
140
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
141
|
+
<link rel="edit" title="Product" href="Products(5)"/>
|
142
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
143
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(5)/Categories"/>
|
144
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
145
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(5)/Supplier"/>
|
146
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
147
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(5)/ProductDetail"/>
|
148
|
+
<title type="text">Cranberry Juice</title>
|
149
|
+
<summary type="text">16-Ounce Plastic Bottles (Pack of 12)</summary>
|
150
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
151
|
+
<author>
|
152
|
+
<name/>
|
153
|
+
</author>
|
154
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
155
|
+
title="Categories" href="Products(5)/$links/Categories"/>
|
156
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
157
|
+
title="Supplier" href="Products(5)/$links/Supplier"/>
|
158
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
159
|
+
title="ProductDetail" href="Products(5)/$links/ProductDetail"/>
|
160
|
+
<content type="application/xml">
|
161
|
+
<m:properties>
|
162
|
+
<d:ID m:type="Edm.Int32">5</d:ID>
|
163
|
+
<d:ReleaseDate m:type="Edm.DateTime">2006-08-04T00:00:00</d:ReleaseDate>
|
164
|
+
<d:DiscontinuedDate m:null="true"/>
|
165
|
+
<d:Rating m:type="Edm.Int16">3</d:Rating>
|
166
|
+
<d:Price m:type="Edm.Double">22.8</d:Price>
|
167
|
+
</m:properties>
|
168
|
+
</content>
|
169
|
+
</entry>
|
170
|
+
<entry>
|
171
|
+
<id>http://services.odata.org/OData/OData.svc/Products(6)</id>
|
172
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
173
|
+
<link rel="edit" title="Product" href="Products(6)"/>
|
174
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
175
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(6)/Categories"/>
|
176
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
177
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(6)/Supplier"/>
|
178
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
179
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(6)/ProductDetail"/>
|
180
|
+
<title type="text">Pink Lemonade</title>
|
181
|
+
<summary type="text">36 Ounce Cans (Pack of 3)</summary>
|
182
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
183
|
+
<author>
|
184
|
+
<name/>
|
185
|
+
</author>
|
186
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
187
|
+
title="Categories" href="Products(6)/$links/Categories"/>
|
188
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
189
|
+
title="Supplier" href="Products(6)/$links/Supplier"/>
|
190
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
191
|
+
title="ProductDetail" href="Products(6)/$links/ProductDetail"/>
|
192
|
+
<content type="application/xml">
|
193
|
+
<m:properties>
|
194
|
+
<d:ID m:type="Edm.Int32">6</d:ID>
|
195
|
+
<d:ReleaseDate m:type="Edm.DateTime">2006-11-05T00:00:00</d:ReleaseDate>
|
196
|
+
<d:DiscontinuedDate m:null="true"/>
|
197
|
+
<d:Rating m:type="Edm.Int16">3</d:Rating>
|
198
|
+
<d:Price m:type="Edm.Double">18.8</d:Price>
|
199
|
+
</m:properties>
|
200
|
+
</content>
|
201
|
+
</entry>
|
202
|
+
<entry>
|
203
|
+
<id>http://services.odata.org/OData/OData.svc/Products(8)</id>
|
204
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
205
|
+
<link rel="edit" title="Product" href="Products(8)"/>
|
206
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
207
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(8)/Categories"/>
|
208
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
209
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(8)/Supplier"/>
|
210
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
211
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(8)/ProductDetail"/>
|
212
|
+
<title type="text">LCD HDTV</title>
|
213
|
+
<summary type="text">42 inch 1080p LCD with Built-in Blu-ray Disc Player</summary>
|
214
|
+
<updated>2014-07-11T19:22:18Z</updated>
|
215
|
+
<author>
|
216
|
+
<name/>
|
217
|
+
</author>
|
218
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
219
|
+
title="Categories" href="Products(8)/$links/Categories"/>
|
220
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
221
|
+
title="Supplier" href="Products(8)/$links/Supplier"/>
|
222
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
223
|
+
title="ProductDetail" href="Products(8)/$links/ProductDetail"/>
|
224
|
+
<content type="application/xml">
|
225
|
+
<m:properties>
|
226
|
+
<d:ID m:type="Edm.Int32">8</d:ID>
|
227
|
+
<d:ReleaseDate m:type="Edm.DateTime">2008-05-08T00:00:00</d:ReleaseDate>
|
228
|
+
<d:DiscontinuedDate m:null="true"/>
|
229
|
+
<d:Rating m:type="Edm.Int16">3</d:Rating>
|
230
|
+
<d:Price m:type="Edm.Double">1088.8</d:Price>
|
231
|
+
</m:properties>
|
232
|
+
</content>
|
233
|
+
</entry>
|
234
|
+
</feed>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<feed xml:base="http://services.odata.org/OData/OData.svc/" xmlns="http://www.w3.org/2005/Atom"
|
3
|
+
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
|
4
|
+
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
|
5
|
+
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
|
6
|
+
<id>http://services.odata.org/OData/OData.svc/Products</id>
|
7
|
+
<title type="text">Products</title>
|
8
|
+
<updated>2014-07-11T19:20:06Z</updated>
|
9
|
+
<link rel="self" title="Products" href="Products"/>
|
10
|
+
<entry>
|
11
|
+
<id>http://services.odata.org/OData/OData.svc/Products(0)</id>
|
12
|
+
<category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
13
|
+
<link rel="edit" title="Product" href="Products(0)"/>
|
14
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
|
15
|
+
type="application/atom+xml;type=feed" title="Categories" href="Products(0)/Categories"/>
|
16
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier"
|
17
|
+
type="application/atom+xml;type=entry" title="Supplier" href="Products(0)/Supplier"/>
|
18
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
|
19
|
+
type="application/atom+xml;type=entry" title="ProductDetail" href="Products(0)/ProductDetail"/>
|
20
|
+
<title type="text">Bread</title>
|
21
|
+
<summary type="text">Whole grain bread</summary>
|
22
|
+
<updated>2014-07-11T19:20:06Z</updated>
|
23
|
+
<author>
|
24
|
+
<name/>
|
25
|
+
</author>
|
26
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml"
|
27
|
+
title="Categories" href="Products(0)/$links/Categories"/>
|
28
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml"
|
29
|
+
title="Supplier" href="Products(0)/$links/Supplier"/>
|
30
|
+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml"
|
31
|
+
title="ProductDetail" href="Products(0)/$links/ProductDetail"/>
|
32
|
+
<content type="application/xml">
|
33
|
+
<m:properties>
|
34
|
+
<d:ID m:type="Edm.Int32">0</d:ID>
|
35
|
+
<d:ReleaseDate m:type="Edm.DateTime">1992-01-01T00:00:00</d:ReleaseDate>
|
36
|
+
<d:DiscontinuedDate m:null="true"/>
|
37
|
+
<d:Rating m:type="Edm.Int16">4</d:Rating>
|
38
|
+
<d:Price m:type="Edm.Double">2.5</d:Price>
|
39
|
+
</m:properties>
|
40
|
+
</content>
|
41
|
+
</entry>
|
42
|
+
</feed>
|
@@ -11,7 +11,14 @@ describe OData::EntitySet do
|
|
11
11
|
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
12
12
|
end
|
13
13
|
|
14
|
-
it { expect(subject).to respond_to(:name
|
14
|
+
it { expect(subject).to respond_to(:name) }
|
15
|
+
it { expect(subject).to respond_to(:type) }
|
16
|
+
it { expect(subject).to respond_to(:container) }
|
17
|
+
it { expect(subject).to respond_to(:namespace) }
|
18
|
+
it { expect(subject).to respond_to(:new_entity) }
|
19
|
+
it { expect(subject).to respond_to(:filter) }
|
20
|
+
it { expect(subject).to respond_to(:[]) }
|
21
|
+
it { expect(subject).to respond_to(:<<) }
|
15
22
|
|
16
23
|
it { expect(subject.name).to eq('Products') }
|
17
24
|
it { expect(subject.container).to eq('DemoService') }
|
@@ -58,6 +65,31 @@ describe OData::EntitySet do
|
|
58
65
|
it { expect(new_entity['Price']).to eq(3.5) }
|
59
66
|
end
|
60
67
|
|
68
|
+
describe '#filter' do
|
69
|
+
let(:one_entity) { "Name eq 'Bread'" }
|
70
|
+
let(:many_entities) { 'Rating eq 3' }
|
71
|
+
|
72
|
+
it { expect(subject.filter(one_entity)).to be_a(Array) }
|
73
|
+
it { expect(subject.filter(one_entity).first).to be_a(OData::Entity) }
|
74
|
+
|
75
|
+
it { expect(subject.filter(many_entities)).to be_a(Array) }
|
76
|
+
it do
|
77
|
+
subject.filter(one_entity).each do |entity|
|
78
|
+
expect(entity).to be_a(OData::Entity)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#[]' do
|
84
|
+
let(:existing_entity) { subject[0] }
|
85
|
+
let(:nonexistant_entity) { subject[99] }
|
86
|
+
|
87
|
+
it { expect(existing_entity).to be_a(OData::Entity) }
|
88
|
+
it { expect(existing_entity['ID']).to eq(0) }
|
89
|
+
|
90
|
+
it { expect(nonexistant_entity).to be_nil }
|
91
|
+
end
|
92
|
+
|
61
93
|
describe '#<<' do
|
62
94
|
let(:new_entity) { subject.new_entity(properties) }
|
63
95
|
let(:bad_entity) { subject.new_entity }
|
@@ -71,8 +103,6 @@ describe OData::EntitySet do
|
|
71
103
|
Price: 3.5
|
72
104
|
} }
|
73
105
|
|
74
|
-
it { expect(subject).to respond_to(:<<) }
|
75
|
-
|
76
106
|
it 'with an existing entity' do
|
77
107
|
WebMock.stub_request(:post, 'http://services.odata.org/OData/OData.svc/Products(0)').
|
78
108
|
to_return(status: 200, body: File.open('spec/fixtures/sample_service/product_0.xml'))
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Query::Criteria do
|
4
|
+
let(:subject) { OData::Query::Criteria.new(operation: 'filter', argument: "Name eq 'Bread'") }
|
5
|
+
let(:valid_operations) { [:filter, :order_by, :skip, :top, :select, :expand, :inline_count] }
|
6
|
+
|
7
|
+
it { expect(subject).to respond_to(:operation) }
|
8
|
+
it { expect(subject).to respond_to(:argument) }
|
9
|
+
|
10
|
+
it { expect(subject.operation).to eq(:filter) }
|
11
|
+
it { expect(subject.argument).to eq("Name eq 'Bread'")}
|
12
|
+
|
13
|
+
it 'should require operation option' do
|
14
|
+
expect {
|
15
|
+
OData::Query::Criteria.new(argument: 'test')
|
16
|
+
}.to raise_error(ArgumentError, 'Missing required option: operation')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should require argument option' do
|
20
|
+
expect {
|
21
|
+
OData::Query::Criteria.new(operation: 'filter')
|
22
|
+
}.to raise_error(ArgumentError, 'Missing required option: argument')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should validate operation option' do
|
26
|
+
valid_operations.each do |operation|
|
27
|
+
expect {
|
28
|
+
OData::Query::Criteria.new(operation: operation, argument: 'test')
|
29
|
+
}.to_not raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
expect {
|
33
|
+
OData::Query::Criteria.new(operation: 'invalid', argument: 'test')
|
34
|
+
}.to raise_error(ArgumentError, 'Operation not supported: invalid')
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OData::Query do
|
4
|
+
let(:subject) { OData::Query.new('Products') }
|
5
|
+
|
6
|
+
it { expect(subject).to respond_to(:<<) }
|
7
|
+
it { expect(subject).to respond_to(:to_s) }
|
8
|
+
|
9
|
+
it { expect(subject.to_s).to eq('Products')}
|
10
|
+
|
11
|
+
it 'handles pagination operations' do
|
12
|
+
skip_criteria = OData::Query::Criteria.new(operation: 'skip', argument: 5)
|
13
|
+
top_criteria = OData::Query::Criteria.new(operation: 'top', argument: 5)
|
14
|
+
subject << top_criteria
|
15
|
+
subject << skip_criteria
|
16
|
+
expect(subject.to_s).to eq('Products?$skip=5&$top=5')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'handles inline_count operations' do
|
20
|
+
criteria = OData::Query::Criteria.new(operation: 'inline_count', argument: 'allpages')
|
21
|
+
subject << criteria
|
22
|
+
expect(subject.to_s).to eq('Products?$inlinecount=allpages')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'handles select operations' do
|
26
|
+
criteria1 = OData::Query::Criteria.new(operation: 'select', argument: 'Name')
|
27
|
+
criteria2 = OData::Query::Criteria.new(operation: 'select', argument: 'Rating')
|
28
|
+
criteria3 = OData::Query::Criteria.new(operation: 'select', argument: 'Price')
|
29
|
+
subject << criteria1
|
30
|
+
subject << criteria2
|
31
|
+
subject << criteria3
|
32
|
+
expect(subject.to_s).to eq('Products?$select=Name,Rating,Price')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'handles expand operations' do
|
36
|
+
criteria1 = OData::Query::Criteria.new(operation: 'expand', argument: 'Supplier')
|
37
|
+
criteria2 = OData::Query::Criteria.new(operation: 'expand', argument: 'ProductDetail')
|
38
|
+
subject << criteria1
|
39
|
+
subject << criteria2
|
40
|
+
expect(subject.to_s).to eq('Products?$expand=Supplier,ProductDetail')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'handles order_by operations' do
|
44
|
+
criteria1 = OData::Query::Criteria.new(operation: 'order_by', argument: 'Price')
|
45
|
+
criteria2 = OData::Query::Criteria.new(operation: 'order_by', argument: 'Rating desc')
|
46
|
+
subject << criteria1
|
47
|
+
subject << criteria2
|
48
|
+
expect(subject.to_s).to eq('Products?$orderby=Price,Rating desc')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'handles filter operations' do
|
52
|
+
criteria1 = OData::Query::Criteria.new(operation: 'filter', argument: 'Rating gt 2')
|
53
|
+
criteria2 = OData::Query::Criteria.new(operation: 'filter', argument: 'Price lt 15')
|
54
|
+
subject << criteria1
|
55
|
+
subject << criteria2
|
56
|
+
expect(subject.to_s).to eq('Products?$filter=Rating gt 2 and Price lt 15')
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -62,6 +62,15 @@ RSpec.configure do |config|
|
|
62
62
|
|
63
63
|
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products(0)').
|
64
64
|
to_return(status: 200, body: File.open('spec/fixtures/sample_service/product_0.xml'))
|
65
|
+
|
66
|
+
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products(99)').
|
67
|
+
to_return(status: 404, body: File.open('spec/fixtures/sample_service/product_not_found.xml'))
|
68
|
+
|
69
|
+
WebMock.stub_request(:get, "http://services.odata.org/OData/OData.svc/Products?$filter=Name eq 'Bread'").
|
70
|
+
to_return(status: 200, body: File.open('spec/fixtures/sample_service/product_filter_one.xml'))
|
71
|
+
|
72
|
+
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products?$filter=Rating%20eq%203').
|
73
|
+
to_return(status: 200, body: File.open('spec/fixtures/sample_service/product_filter_many.xml'))
|
65
74
|
end
|
66
75
|
end
|
67
76
|
|
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.2.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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -196,6 +196,8 @@ files:
|
|
196
196
|
- lib/odata/properties/string.rb
|
197
197
|
- lib/odata/properties/time.rb
|
198
198
|
- lib/odata/property.rb
|
199
|
+
- lib/odata/query.rb
|
200
|
+
- lib/odata/query/criteria.rb
|
199
201
|
- lib/odata/railtie.rb
|
200
202
|
- lib/odata/service.rb
|
201
203
|
- lib/odata/service_registry.rb
|
@@ -205,6 +207,9 @@ files:
|
|
205
207
|
- spec/fixtures/sample_service/metadata.xml
|
206
208
|
- spec/fixtures/sample_service/product_0.xml
|
207
209
|
- spec/fixtures/sample_service/product_9999.xml
|
210
|
+
- spec/fixtures/sample_service/product_filter_many.xml
|
211
|
+
- spec/fixtures/sample_service/product_filter_one.xml
|
212
|
+
- spec/fixtures/sample_service/product_not_found.xml
|
208
213
|
- spec/fixtures/sample_service/products.xml
|
209
214
|
- spec/fixtures/sample_service/products_skip0_top5.xml
|
210
215
|
- spec/fixtures/sample_service/products_skip10_top5.xml
|
@@ -222,6 +227,8 @@ files:
|
|
222
227
|
- spec/odata/properties/string_spec.rb
|
223
228
|
- spec/odata/properties/time_spec.rb
|
224
229
|
- spec/odata/property_spec.rb
|
230
|
+
- spec/odata/query/criteria_spec.rb
|
231
|
+
- spec/odata/query_spec.rb
|
225
232
|
- spec/odata/service_registry_spec.rb
|
226
233
|
- spec/odata/service_spec.rb
|
227
234
|
- spec/spec_helper.rb
|
@@ -254,6 +261,9 @@ test_files:
|
|
254
261
|
- spec/fixtures/sample_service/metadata.xml
|
255
262
|
- spec/fixtures/sample_service/product_0.xml
|
256
263
|
- spec/fixtures/sample_service/product_9999.xml
|
264
|
+
- spec/fixtures/sample_service/product_filter_many.xml
|
265
|
+
- spec/fixtures/sample_service/product_filter_one.xml
|
266
|
+
- spec/fixtures/sample_service/product_not_found.xml
|
257
267
|
- spec/fixtures/sample_service/products.xml
|
258
268
|
- spec/fixtures/sample_service/products_skip0_top5.xml
|
259
269
|
- spec/fixtures/sample_service/products_skip10_top5.xml
|
@@ -271,6 +281,8 @@ test_files:
|
|
271
281
|
- spec/odata/properties/string_spec.rb
|
272
282
|
- spec/odata/properties/time_spec.rb
|
273
283
|
- spec/odata/property_spec.rb
|
284
|
+
- spec/odata/query/criteria_spec.rb
|
285
|
+
- spec/odata/query_spec.rb
|
274
286
|
- spec/odata/service_registry_spec.rb
|
275
287
|
- spec/odata/service_spec.rb
|
276
288
|
- spec/spec_helper.rb
|