Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .autotest

This file was deleted.

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2
3.4.2
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ The nice thing about `FrOData::Service` is that it automatically registers with
To create an `FrOData::Service` simply provide the location of a service endpoint to it like this:

```ruby
FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc')
FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc')
```

You may also provide an options hash after the URL.
It is suggested that you supply a name for the service via this hash like so:

```ruby
FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', name: 'ODataDemo')
FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc', name: 'ODataDemo')
```

For more information regarding available options and how to configure a service instance, refer to [Service Configuration](#service-configuration) below.
Expand All @@ -63,7 +63,7 @@ Both of these methods are available on instances and will allow for lookup in th
Using either the service URL or the name provided as an option when creating an `FrOData::Service` will allow for quick lookup in the `FrOData::ServiceRegistry` like such:

```ruby
FrOData::ServiceRegistry['http://services.odata.org/V4/OData/OData.svc']
FrOData::ServiceRegistry['https://services.odata.org/V4/OData/OData.svc']
FrOData::ServiceRegistry['ODataDemo']
```

Expand All @@ -80,7 +80,7 @@ You can speed your load time by forcing the service to load the metadata from a
This is only recommended for testing purposes, as the metadata file can change.

```ruby
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', {
service = FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc', {
name: 'ODataDemo',
metadata_file: "metadata.xml",
})
Expand All @@ -97,7 +97,7 @@ You can customize request headers with the **:connection** option key.
This allows you to e.g. set custom headers (such as `Authorization`) that may be required by your service.

```ruby
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', {
service = FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc', {
name: 'ODataDemo',
connection: {
headers: {
Expand All @@ -115,7 +115,7 @@ This allows you to make use of Faraday's [authentication helpers][faraday-auth],
For instance, if your service requires HTTP basic authentication:

```ruby
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', {
service = FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc', {
name: 'ODataDemo'
}) do |conn|
conn.basic_auth('username', 'password')
Expand All @@ -139,7 +139,7 @@ If you already have a `Faraday::Connection` instance that you want the service t
In this case, you'll be setting the service URL on the connection object, as shown below:

```ruby
conn = Faraday.new('http://services.odata.org/V4/OData/OData.svc') do |conn|
conn = Faraday.new('https://services.odata.org/V4/OData/OData.svc') do |conn|
# ... customize connection ...
end

Expand All @@ -154,7 +154,7 @@ Alternatively, the connection object is also `yield`ed by the constructor, so yo
For instance, if you wanted to use [Typhoeus][typhoeus] as your HTTP library:

```ruby
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', {
service = FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc', {
name: 'ODataDemo'
}) do |conn|
conn.adapter :typhoeus
Expand Down Expand Up @@ -226,7 +226,7 @@ Under normal circumstances you should never need to worry about an `FrOData::Ent
For example, to get an `FrOData::EntitySet` for the products in the ODataDemo service simply access the entity set through the service like this:

```ruby
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc')
service = FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc')
products = service['ProductsSet'] # => FrOData::EntitySet
```

Expand Down Expand Up @@ -352,7 +352,7 @@ Simply add `strict: false` to the service constructor options.
In this mode, any property validation error will log a warning instead of raising an exception. The corresponding property value will be `nil` (even if the property is declared as not allowing NULL values).

```ruby
service = FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', strict: false)
service = FrOData::Service.new('https://services.odata.org/V4/OData/OData.svc', strict: false)
# -- alternatively, for an existing service instance --
service.options[:strict] = false
```
Expand Down
13 changes: 7 additions & 6 deletions frodata.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.2.0'

spec.add_dependency 'nokogiri', '~> 1.8'
spec.add_dependency 'nokogiri'
spec.add_dependency 'faraday', '~> 0.15'
spec.add_dependency 'andand', '~> 1.3'
spec.add_dependency 'bigdecimal'
spec.add_dependency 'base64'
spec.add_dependency 'logger'

spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'rake', '~> 0'
spec.add_development_dependency 'bundler', '>= 2.6'
spec.add_development_dependency 'rake', '>= 13.2'
spec.add_development_dependency 'simplecov', '~> 0.15'
spec.add_development_dependency 'rspec', '~> 3.7'
spec.add_development_dependency 'rspec-autotest', '~> 1.0'
spec.add_development_dependency 'autotest', '~> 4.4'
spec.add_development_dependency 'retest'
spec.add_development_dependency 'vcr', '~> 4.0'
spec.add_development_dependency 'timecop', '~> 0.9'
spec.add_development_dependency 'equivalent-xml', '~> 0.6'
Expand Down
1 change: 0 additions & 1 deletion lib/frodata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require 'nokogiri'
require 'faraday'
require 'logger'
require 'andand'
require 'json'

# require 'active_support'
Expand Down
9 changes: 5 additions & 4 deletions lib/frodata/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def get_property(property_name)

def property_names
[
@properties_xml_value.andand.keys,
@properties.andand.keys
@properties_xml_value&.keys,
@properties&.keys
].compact.flatten
end

Expand Down Expand Up @@ -205,7 +205,7 @@ def to_hash
# @return [String]
def id
@id ||= lambda {
entity_set = self.entity_set.andand.name
entity_set = self.entity_set&.name
entity_set ||= context.split('#').last.split('/').first
"#{entity_set}(#{self[primary_key]})"
}.call
Expand Down Expand Up @@ -279,7 +279,8 @@ def set_property_lazy_load(name, xml_value )
def self.process_properties(entity, xml_doc)
entity.instance_eval do
unless instance_variable_get(:@context)
context = xml_doc.xpath('/entry').first.andand['context']
first_entry = xml_doc.xpath('/entry').first
context = first_entry['context'] if first_entry
instance_variable_set(:@context, context)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/frodata/properties/date_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def type
# Value to be used in JSON.
# @return [String]
def xml_value
@value.andand.sub(/[\+\-]00:00$/, 'Z')
@value&.sub(/[\+\-]00:00$/, 'Z')
end

# Value to be used in JSON.
Expand Down
18 changes: 15 additions & 3 deletions lib/frodata/properties/decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Decimal < FrOData::Property
# Returns the property value, properly typecast
# @return [BigDecimal,nil]
def value
if (@value.nil? || @value.empty?) && (strict? && allows_nil?)
if (@value.nil? || (@value.respond_to?(:empty?) && @value.empty?)) && (strict? && allows_nil?)
nil
else
BigDecimal(@value)
Expand All @@ -15,8 +15,9 @@ def value
# Sets the property value
# @params new_value something BigDecimal() can parse
def value=(new_value)
validate(BigDecimal(new_value.to_s))
@value = new_value.to_s
cleaned_value = clean_value(new_value)
validate(BigDecimal(cleaned_value))
@value = cleaned_value
end

# The FrOData type name
Expand All @@ -32,6 +33,17 @@ def url_value

private

# Single pass cleaning a value to make it into a number based on the
# specs in decimal_spec.rb.
def clean_value(value)
BigDecimal(value) # Trigger any underlying exceptions.
value
rescue ArgumentError
clean_value = value.to_s.sub(/[^.[:digit:]].*/, "")
clean_value = "0" if clean_value.bytesize == 0
clean_value
end

def validate(value)
if value > max_value || value < min_value || value.precs.first > 29
validation_error "Value is outside accepted range: #{min_value} to #{max_value}, or has more than 29 significant digits"
Expand Down
12 changes: 6 additions & 6 deletions lib/frodata/properties/float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ def value=(new_value)
@value = new_value.to_f.to_s
end

# The FrOData type name
def type
'Edm.Double'
end

private

def min_value
Expand All @@ -38,7 +33,12 @@ def max_value
end

# Defines the Double (Float) FrOData type.
class Double < FrOData::Properties::Float; end
class Double < FrOData::Properties::Float
# The FrOData type name
def type
'Edm.Double'
end
end

# Defines the Single (Float) FrOData type.
class Single < FrOData::Properties::Float
Expand Down
2 changes: 1 addition & 1 deletion lib/frodata/properties/geography/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def to_xml(xml_builder)
# @param options [Hash]
# @return [FrOData::Properties::Geography]
def self.from_xml(property_xml, options = {})
if property_xml.attributes['null'].andand.value == 'true'
if property_xml.attributes['null']&.value == 'true'
content = nil
else
content = parse_xml(property_xml)
Expand Down
4 changes: 2 additions & 2 deletions lib/frodata/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def to_xml(xml_builder)
# @param options [Hash]
# @return [FrOData::Property]
def self.from_xml(property_xml, options = {})
if property_xml.attributes['null'].andand.value == 'true'
if property_xml.attributes['null']&.value == 'true'
content = nil
else
content = property_xml.content
Expand All @@ -124,7 +124,7 @@ def service

def logger
# Use a dummy logger if service is not available (-> unit tests)
@logger ||= service.andand.logger || Logger.new('/dev/null')
@logger ||= service&.logger || Logger.new('/dev/null')
end

def validation_error(message)
Expand Down
2 changes: 1 addition & 1 deletion lib/frodata/schema/enum_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def options
def collect_members
Hash[type_definition.xpath('./Member').map.with_index do |member_xml, index|
member_name = member_xml.attributes['Name'].value
member_value = member_xml.attributes['Value'].andand.value.andand.to_i
member_value = member_xml.attributes['Value']&.value&.to_i
[member_value || index, member_name]
end]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/frodata/service/response/atom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def next_page_url
end

def error_message
result_xml.xpath('//error/message').first.andand.text
result_xml.xpath('//error/message').first&.text
end

def parsed_body
Expand Down
2 changes: 1 addition & 1 deletion lib/frodata/service/response/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def next_page_url
end

def error_message
result_json['error'].andand['message']
result_json.dig('error', 'message')
end

def parsed_body
Expand Down
2 changes: 1 addition & 1 deletion lib/frodata/service/response/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def next_page_url
end

def error_message
response_xml.xpath('//error/message').first.andand.text
response_xml.xpath('//error/message').first&.text
end

def parsed_body
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/entity_to_xml.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:data="http://docs.oasis-open.org/odata/ns/data" xmlns:metadata="http://docs.oasis-open.org/odata/ns/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xml:base="http://services.odata.org/V4/OData/OData.svc">
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:data="http://docs.oasis-open.org/odata/ns/data" xmlns:metadata="http://docs.oasis-open.org/odata/ns/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xml:base="https://services.odata.org/V4/OData/OData.svc">
<category term="ODataDemo.Product" scheme="http://docs.oasis-open.org/odata/ns/scheme"/>
<author>
<name/>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/error.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://docs.oasis-open.org/odata/ns/metadata">
<m:error xmlns:m="https://docs.oasis-open.org/odata/ns/metadata">
<m:code />
<m:message>Resource not found for the segment 'Products'.</m:message>
</m:error>
2 changes: 1 addition & 1 deletion spec/fixtures/files/product_0.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@odata.context": "http://services.odata.org/V4/OData/OData.svc/$metadata#Products/$entity",
"@odata.context": "https://services.odata.org/V4/OData/OData.svc/$metadata#Products/$entity",
"ID": 0,
"Name": "Bread",
"Description": "Whole grain bread",
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/files/product_0.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://services.odata.org/V4/OData/OData.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://docs.oasis-open.org/odata/ns/data" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:context="http://services.odata.org/V4/OData/OData.svc/$metadata#Products/$entity">
<id>http://services.odata.org/V4/OData/OData.svc/Products(0)</id>
<entry xml:base="https://services.odata.org/V4/OData/OData.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://docs.oasis-open.org/odata/ns/data" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:context="https://services.odata.org/V4/OData/OData.svc/$metadata#Products/$entity">
<id>https://services.odata.org/V4/OData/OData.svc/Products(0)</id>
<category term="#ODataDemo.Product" scheme="http://docs.oasis-open.org/odata/ns/scheme" />
<link rel="edit" title="Product" href="Products(0)" />
<link rel="http://docs.oasis-open.org/odata/ns/relatedlinks/Categories" type="application/xml" title="Categories" href="Products(0)/Categories/$ref" />
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/products.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@odata.context": "http://services.odata.org/V4/OData/OData.svc/$metadata#Products",
"@odata.context": "https://services.odata.org/V4/OData/OData.svc/$metadata#Products",
"value": [
{
"ID": 0,
Expand Down
Loading