reso_transport 1.5.2 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,12 +14,14 @@ module ResoTransport
14
14
  @current_complex_type = nil
15
15
  @current_enum_type = nil
16
16
  @current_member = nil
17
+
18
+ @datasystem = nil
17
19
  end
18
20
 
19
21
  def parse(doc)
20
22
  REXML::Document.parse_stream(doc, self)
21
23
  finalize
22
- return self
24
+ self
23
25
  end
24
26
 
25
27
  def finalize
@@ -54,55 +56,62 @@ module ResoTransport
54
56
 
55
57
  def tag_start(name, args)
56
58
  case name
57
- when "Schema"
59
+ when 'Schema'
58
60
  @schemas << ResoTransport::Schema.from_stream(args)
59
- when "EntitySet"
61
+ when 'EntitySet'
60
62
  @entity_sets << ResoTransport::EntitySet.from_stream(args)
61
- when "EntityType"
63
+ when 'EntityType'
62
64
  @current_entity_type = ResoTransport::EntityType.from_stream(args)
63
- when "ComplexType"
65
+ when 'ComplexType'
64
66
  @current_complex_type = ResoTransport::EntityType.from_stream(args)
65
- when "PropertyRef"
67
+ when 'PropertyRef'
66
68
  @current_entity_type.primary_key = args['Name']
67
- when "Property"
68
- @current_entity_type.properties << ResoTransport::Property.from_stream(args.merge(schema: @schemas.last)) if @current_entity_type
69
- @current_complex_type.properties << ResoTransport::Property.from_stream(args.merge(schema: @schemas.last)) if @current_complex_type
70
- when "NavigationProperty"
69
+ when 'Property'
70
+ if @current_entity_type
71
+ @current_entity_type.properties << ResoTransport::Property.from_stream(args.merge(schema: @schemas.last))
72
+ end
73
+ if @current_complex_type
74
+ @current_complex_type.properties << ResoTransport::Property.from_stream(args.merge(schema: @schemas.last))
75
+ end
76
+ when 'NavigationProperty'
71
77
  @current_entity_type.navigation_properties << ResoTransport::Property.from_stream(args)
72
- when "EnumType"
78
+ when 'EnumType'
73
79
  @current_enum_type = ResoTransport::Enum.from_stream(args.merge(schema: @schemas.last))
74
- when "Member"
80
+ when 'Member'
75
81
  @current_member = ResoTransport::Member.from_stream(args)
76
- when "Annotation"
82
+ when 'Annotation'
77
83
  if @current_enum_type && @current_member
78
84
  @current_member.annotation = args['String']
79
- else
80
- if @current_entity_type || @current_complex_type
81
- #raise args.inspect
82
- end
85
+ elsif @current_entity_type || @current_complex_type
86
+ # raise args.inspect
83
87
  end
84
88
  end
85
- rescue => e
89
+ rescue StandardError => e
86
90
  puts e.inspect
87
91
  puts "Error processing Tag: #{[name, args].inspect}"
88
92
  end
89
93
 
90
94
  def tag_end(name)
91
95
  case name
92
- when "EntityType"
96
+ when 'EntityType'
93
97
  @current_entity_type.schema = @schemas.last.namespace
94
98
  @schemas.last.entity_types << @current_entity_type
95
- when "ComplexType"
99
+ when 'ComplexType'
96
100
  @current_complex_type.schema = @schemas.last.namespace
97
101
  @schemas.last.complex_types << @current_complex_type
98
- when "EnumType"
102
+ when 'EnumType'
99
103
  @enumerations << @current_enum_type
100
104
  @current_enum_type = nil
101
- when "Member"
105
+ when 'Member'
102
106
  @current_enum_type.members << @current_member
103
107
  @current_member = nil
104
108
  end
105
109
  end
106
110
 
111
+ def datasystem?
112
+ return @datasystem unless @datasystem.nil?
113
+
114
+ @datasystem = @schemas.any? { |s| s.entity_types.any? { |t| t.name == 'DataSystem' } }
115
+ end
107
116
  end
108
117
  end
@@ -1,23 +1,22 @@
1
1
  module ResoTransport
2
2
  Query = Struct.new(:resource) do
3
-
4
- def all(*contexts, &block)
3
+ def all(*_contexts, &block)
5
4
  new_query_context('and')
6
5
  instance_eval(&block)
7
6
  clear_query_context
8
- return self
7
+ self
9
8
  end
10
9
 
11
10
  def any(&block)
12
11
  new_query_context('or')
13
12
  instance_eval(&block)
14
13
  clear_query_context
15
- return self
14
+ self
16
15
  end
17
16
 
18
- [:eq, :ne, :gt, :ge, :lt, :le].each do |op|
17
+ %i[eq ne gt ge lt le].each do |op|
19
18
  define_method(op) do |conditions|
20
- conditions.each_pair do |k,v|
19
+ conditions.each_pair do |k, v|
21
20
  current_query_context << "#{k} #{op} #{encode_value(k, v)}"
22
21
  end
23
22
  return self
@@ -26,67 +25,64 @@ module ResoTransport
26
25
 
27
26
  def limit(size)
28
27
  options[:top] = size
29
- return self
28
+ self
30
29
  end
31
30
 
32
31
  def offset(size)
33
32
  options[:skip] = size
34
- return self
33
+ self
35
34
  end
36
35
 
37
- def order(field, dir=nil)
38
- options[:orderby] = [field, dir].join(" ").strip
39
- return self
36
+ def order(field, dir = nil)
37
+ options[:orderby] = [field, dir].join(' ').strip
38
+ self
40
39
  end
41
40
 
42
41
  def include_count
43
42
  options[:count] = true
44
- return self
43
+ self
45
44
  end
46
45
 
47
46
  def select(*fields)
48
- os = options.fetch(:select, "").split(",")
49
- options[:select] = (os + Array(fields)).uniq.join(",")
47
+ os = options.fetch(:select, '').split(',')
48
+ options[:select] = (os + Array(fields)).uniq.join(',')
50
49
 
51
- return self
50
+ self
52
51
  end
53
52
 
54
53
  def expand(*names)
55
- ex = options.fetch(:expand, "").split(",")
56
- options[:expand] = (ex + Array(names)).uniq.join(",")
54
+ ex = options.fetch(:expand, '').split(',')
55
+ options[:expand] = (ex + Array(names)).uniq.join(',')
57
56
 
58
- return self
57
+ self
59
58
  end
60
59
 
61
60
  def count
62
- p compile_params
63
61
  limit(1).include_count
64
- resp = resource.get(compile_params)
65
- parsed_body = JSON.parse(resp.body)
66
- parsed_body.fetch("@odata.count", 0)
62
+ parsed = handle_response response
63
+ parsed.fetch('@odata.count', 0)
67
64
  end
68
65
 
69
66
  def results
70
- resp = execute
67
+ parsed = handle_response response
71
68
 
72
- if resp[:success]
73
- resp[:results]
74
- else
75
- puts resp[:meta]
76
- raise "Request Failed"
77
- end
69
+ results = Array(parsed.delete('value'))
70
+ resource.parse(results)
78
71
  end
79
72
 
80
- def execute
81
- resp = resource.get(compile_params)
82
- parsed_body = JSON.parse(resp.body)
83
- results = Array(parsed_body.delete("value"))
73
+ def response
74
+ resource.get(compile_params)
75
+ rescue Faraday::ConnectionFailed
76
+ raise NoResponse.new(resource.request, nil, resource)
77
+ end
78
+
79
+ def handle_response(response)
80
+ raise RequestError.new(resource.request, response, resource) unless response.success?
81
+
82
+ parsed = JSON.parse(response.body)
83
+ raise ResponseError.new(resource.request, response, resource) if parsed.key?('error')
84
84
 
85
- {
86
- success: resp.success? && !parsed_body.has_key?("error"),
87
- meta: parsed_body,
88
- results: resource.parse(results)
89
- }
85
+ parsed
90
86
  end
91
87
 
92
88
  def new_query_context(context)
@@ -110,7 +106,7 @@ module ResoTransport
110
106
  end
111
107
 
112
108
  def sub_queries
113
- @sub_queries ||= Hash.new {|h,k| h[k] = { context: 'and', criteria: [] } }
109
+ @sub_queries ||= Hash.new { |h, k| h[k] = { context: 'and', criteria: [] } }
114
110
  end
115
111
 
116
112
  def compile_filters
@@ -120,36 +116,32 @@ module ResoTransport
120
116
 
121
117
  filter_chunks = []
122
118
 
123
- if global && global[:criteria]&.any?
124
- filter_chunks << global[:criteria].join(" #{global[:context]} ")
125
- end
119
+ filter_chunks << global[:criteria].join(" #{global[:context]} ") if global && global[:criteria]&.any?
126
120
 
127
121
  filter_chunks << filter_groups.map do |g|
128
122
  "(#{g[:criteria].join(" #{g[:context]} ")})"
129
- end.join(" and ")
123
+ end.join(' and ')
130
124
 
131
- filter_chunks.reject {|c| c == ""}.join(" and ")
125
+ filter_chunks.reject { |c| c == '' }.join(' and ')
132
126
  end
133
127
 
134
128
  def compile_params
135
129
  params = {}
136
130
 
137
- options.each_pair do |k,v|
131
+ options.each_pair do |k, v|
138
132
  params["$#{k}"] = v
139
133
  end
140
134
 
141
- if !sub_queries.empty?
142
- params["$filter"] = compile_filters
143
- end
135
+ params['$filter'] = compile_filters unless sub_queries.empty?
144
136
 
145
137
  params
146
138
  end
147
139
 
148
- def encode_value(key, v)
140
+ def encode_value(key, val)
149
141
  field = resource.property(key.to_s)
150
- raise "Couldn't find property #{key} for #{resource.name}" if field.nil?
151
- field.encode(v)
152
- end
142
+ raise EncodeError.new(resource, key) if field.nil?
153
143
 
144
+ field.encode(val)
145
+ end
154
146
  end
155
147
  end
@@ -1,6 +1,5 @@
1
1
  module ResoTransport
2
- Resource = Struct.new(:client, :entity_set) do
3
-
2
+ Resource = Struct.new(:client, :entity_set, :localizations, :local) do
4
3
  def query
5
4
  Query.new(self)
6
5
  end
@@ -10,7 +9,7 @@ module ResoTransport
10
9
  end
11
10
 
12
11
  def property(name)
13
- properties.detect {|p| p.name == name }
12
+ properties.detect { |p| p.name == name }
14
13
  end
15
14
 
16
15
  def properties
@@ -20,13 +19,13 @@ module ResoTransport
20
19
  def expandable
21
20
  entity_type.navigation_properties
22
21
  end
23
-
22
+
24
23
  def entity_type
25
- @entity_type ||= schema.entity_types.detect {|et| et.name == entity_set.entity_type }
24
+ @entity_type ||= schema.entity_types.detect { |et| et.name == entity_set.entity_type }
26
25
  end
27
26
 
28
27
  def schema
29
- @schema ||= md.schemas.detect {|s| s.namespace == entity_set.schema }
28
+ @schema ||= md.schemas.detect { |s| s.namespace == entity_set.schema }
30
29
  end
31
30
 
32
31
  def md
@@ -34,15 +33,31 @@ module ResoTransport
34
33
  end
35
34
 
36
35
  def parse(results)
37
- results.map {|r| entity_type.parse(r) }
36
+ results.map { |r| entity_type.parse(r) }
38
37
  end
39
38
 
40
39
  def get(params)
41
- client.connection.get(name, params) do |req|
40
+ client.connection.get(url, params) do |req|
42
41
  req.headers['Accept'] = 'application/json'
42
+ @request = req
43
43
  end
44
44
  end
45
45
 
46
+ def url
47
+ return local['ResourcePath'].gsub(%r{^/}, '') if local
48
+
49
+ raise LocalizationRequired, self if localizations.any? && local.nil?
50
+
51
+ return "#{name}/replication" if client.use_replication_endpoint
52
+
53
+ name
54
+ end
55
+
56
+ def localization(name)
57
+ self.local = localizations[name] if localizations.key?(name)
58
+ self
59
+ end
60
+
46
61
  def to_s
47
62
  %(#<ResoTransport::Resource entity_set="#{name}", schema="#{schema&.namespace}">)
48
63
  end
@@ -51,5 +66,10 @@ module ResoTransport
51
66
  to_s
52
67
  end
53
68
 
69
+ def request
70
+ return @request.to_h if @request.respond_to? :to_h
71
+
72
+ {}
73
+ end
54
74
  end
55
75
  end
@@ -1,3 +1,3 @@
1
1
  module ResoTransport
2
- VERSION = "1.5.2"
2
+ VERSION = '1.5.8'.freeze
3
3
  end
@@ -1,35 +1,35 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "reso_transport/version"
3
+ require 'reso_transport/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "reso_transport"
6
+ spec.name = 'reso_transport'
8
7
  spec.version = ResoTransport::VERSION
9
- spec.authors = ["Jon Druse"]
10
- spec.email = ["jon@wrstudios.com"]
8
+ spec.authors = ['Jon Druse']
9
+ spec.email = ['jon@wrstudios.com']
11
10
 
12
- spec.summary = "A utility for consuming RESO Web API connections"
13
- spec.description = "Supports Trestle, Spark, Bridge Interactive, MLS Grid"
14
- spec.homepage = "http://github.com/wrstudios/reso_transport"
15
- spec.license = "MIT"
11
+ spec.summary = 'A utility for consuming RESO Web API connections'
12
+ spec.description = 'Supports Trestle, Spark, Bridge Interactive, MLS Grid'
13
+ spec.homepage = 'http://github.com/wrstudios/reso_transport'
14
+ spec.license = 'MIT'
16
15
 
16
+ spec.required_ruby_version = '>= 2.6'
17
17
 
18
18
  # Specify which files should be added to the gem when it is released.
19
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
21
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
22
  end
23
- spec.bindir = "exe"
23
+ spec.bindir = 'exe'
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
25
+ spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency "faraday", "~> 1.0.1"
27
+ spec.add_dependency 'faraday', '~> 1.0.1'
28
28
 
29
- spec.add_development_dependency "bundler", "~> 2"
30
- spec.add_development_dependency "rake", "~> 13"
31
- spec.add_development_dependency "minitest", "~> 5.0"
32
- spec.add_development_dependency "minitest-rg", "~> 5.0"
33
- spec.add_development_dependency "vcr", "~> 6.0"
34
- spec.add_development_dependency "byebug"
29
+ spec.add_development_dependency 'bundler', '~> 2'
30
+ spec.add_development_dependency 'byebug', '~> 11'
31
+ spec.add_development_dependency 'minitest', '~> 5.0'
32
+ spec.add_development_dependency 'minitest-rg', '~> 5.0'
33
+ spec.add_development_dependency 'rake', '~> 13'
34
+ spec.add_development_dependency 'vcr', '~> 6.0'
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reso_transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Druse
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-17 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '13'
47
+ version: '11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '13'
54
+ version: '11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -81,33 +81,33 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: vcr
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '6.0'
89
+ version: '13'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '6.0'
96
+ version: '13'
97
97
  - !ruby/object:Gem::Dependency
98
- name: byebug
98
+ name: vcr
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '6.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '6.0'
111
111
  description: Supports Trestle, Spark, Bridge Interactive, MLS Grid
112
112
  email:
113
113
  - jon@wrstudios.com
@@ -116,6 +116,8 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".gitpod.yml"
120
+ - ".rubocop.yml"
119
121
  - ".ruby-version"
120
122
  - ".travis.yml"
121
123
  - CODE_OF_CONDUCT.md
@@ -125,6 +127,7 @@ files:
125
127
  - README.md
126
128
  - Rakefile
127
129
  - bin/console
130
+ - bin/rake
128
131
  - bin/setup
129
132
  - lib/reso_transport.rb
130
133
  - lib/reso_transport/authentication.rb
@@ -133,12 +136,17 @@ files:
133
136
  - lib/reso_transport/authentication/fetch_token_auth.rb
134
137
  - lib/reso_transport/authentication/middleware.rb
135
138
  - lib/reso_transport/authentication/static_token_auth.rb
139
+ - lib/reso_transport/base_metadata.rb
136
140
  - lib/reso_transport/client.rb
137
141
  - lib/reso_transport/configuration.rb
142
+ - lib/reso_transport/datasystem.rb
143
+ - lib/reso_transport/datasystem_parser.rb
138
144
  - lib/reso_transport/entity_set.rb
139
145
  - lib/reso_transport/entity_type.rb
140
146
  - lib/reso_transport/enum.rb
147
+ - lib/reso_transport/errors.rb
141
148
  - lib/reso_transport/metadata.rb
149
+ - lib/reso_transport/metadata_cache.rb
142
150
  - lib/reso_transport/metadata_parser.rb
143
151
  - lib/reso_transport/property.rb
144
152
  - lib/reso_transport/query.rb
@@ -159,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
167
  requirements:
160
168
  - - ">="
161
169
  - !ruby/object:Gem::Version
162
- version: '0'
170
+ version: '2.6'
163
171
  required_rubygems_version: !ruby/object:Gem::Requirement
164
172
  requirements:
165
173
  - - ">="