reso_transport 1.4.0 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +9 -9
- data/README.md +79 -1
- data/bin/console +3 -3
- data/lib/reso_transport.rb +14 -11
- data/lib/reso_transport/client.rb +4 -4
- data/lib/reso_transport/enum.rb +1 -1
- data/lib/reso_transport/metadata.rb +5 -7
- data/lib/reso_transport/metadata_cache.rb +21 -0
- data/lib/reso_transport/query.rb +2 -1
- data/lib/reso_transport/version.rb +1 -1
- data/reso_transport.gemspec +4 -4
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e936cab60989d16c28cef1265638fee97c6d10e94b9d2814de93f69f237c5ffd
|
4
|
+
data.tar.gz: 0e597dea0da08a2aada6b54cc4a5243e8352b442538d78d584555bb1be05dfcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4d69fc29b8dde541d9665e80ab60973df81b1f794dbee2e9fffe1877b3fbff3fec62ebe2ff69899c4cc7d4287e7e5f4570d02f66338d8c84d8a4341f0a9aed1
|
7
|
+
data.tar.gz: ad04f1a60eeecf6731d619be5c16830fd6887d8783f10cbaa44c29a70e6c28491dae55bf49ce29d0f415c6e58b458d73e7bc7161f99767c7e4b402c7f74077d8
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/Gemfile.lock
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
reso_transport (1.
|
5
|
-
faraday (~> 0.
|
4
|
+
reso_transport (1.5.5)
|
5
|
+
faraday (~> 1.0.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
byebug (11.0.1)
|
11
|
-
faraday (0.
|
11
|
+
faraday (1.0.1)
|
12
12
|
multipart-post (>= 1.2, < 3)
|
13
13
|
minitest (5.13.0)
|
14
14
|
minitest-rg (5.2.0)
|
15
15
|
minitest (~> 5.0)
|
16
16
|
multipart-post (2.1.1)
|
17
|
-
rake (
|
18
|
-
vcr (
|
17
|
+
rake (13.0.1)
|
18
|
+
vcr (6.0.0)
|
19
19
|
|
20
20
|
PLATFORMS
|
21
21
|
ruby
|
22
22
|
|
23
23
|
DEPENDENCIES
|
24
|
-
bundler (~>
|
24
|
+
bundler (~> 2)
|
25
25
|
byebug
|
26
26
|
minitest (~> 5.0)
|
27
27
|
minitest-rg (~> 5.0)
|
28
|
-
rake (~>
|
28
|
+
rake (~> 13)
|
29
29
|
reso_transport!
|
30
|
-
vcr (~>
|
30
|
+
vcr (~> 6.0)
|
31
31
|
|
32
32
|
BUNDLED WITH
|
33
|
-
1.
|
33
|
+
2.1.4
|
data/README.md
CHANGED
@@ -30,6 +30,25 @@ This gem has been tested to work with:
|
|
30
30
|
* [Bridge Interactive](https://www.bridgeinteractive.com)
|
31
31
|
|
32
32
|
|
33
|
+
### Logging
|
34
|
+
|
35
|
+
You can either set a global logger in an initializer file:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
ResoTransport.configure do |c|
|
39
|
+
c.logger = Logger.new("some_log_file")
|
40
|
+
# OR
|
41
|
+
c.logger = Rails.logger
|
42
|
+
end
|
43
|
+
|
44
|
+
```
|
45
|
+
Or you can set a logger for each specific instance of a client which can be useful for debugging:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
@client = ResoTransport::Client.new(config.merge(logger: Logger.new("logfile")))
|
49
|
+
```
|
50
|
+
|
51
|
+
|
33
52
|
### Getting Connected
|
34
53
|
|
35
54
|
There are 2 strategies for authentication.
|
@@ -63,7 +82,7 @@ If the connection requires requesting a new token periodically, it's easy to pro
|
|
63
82
|
client_id: CLIENT_ID,
|
64
83
|
client_secret: CLIENT_SECRET,
|
65
84
|
grant_type: "client_credentials", # these are the default and can be ommitted
|
66
|
-
scope: "api"
|
85
|
+
scope: "api"
|
67
86
|
}
|
68
87
|
})
|
69
88
|
```
|
@@ -71,6 +90,64 @@ If the connection requires requesting a new token periodically, it's easy to pro
|
|
71
90
|
This will pre-fetch a token from the provided endpoint when the current token is either non-existent or has expired.
|
72
91
|
|
73
92
|
|
93
|
+
|
94
|
+
### Caching Metadata
|
95
|
+
|
96
|
+
The metadata file itself is large and parsing it is slow, so ResoTransport has built in support for caching the metadata to your file system. In the example above
|
97
|
+
you would replace `METADATA_CACHE` with a path to a file to store the metadata.
|
98
|
+
|
99
|
+
```
|
100
|
+
md_file: "reso_md_cache/#{@mls.name}",
|
101
|
+
```
|
102
|
+
|
103
|
+
This will store the metadata to a file with `@mls.name` in a folder named `reso_md_cache` in the relative root of your app.
|
104
|
+
|
105
|
+
**Customize your cache**
|
106
|
+
|
107
|
+
If you don't have access to the file system, like on Heroku, or you just don't want to store the metadata on the file system, you can provide your down metadata cache class.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
class MyCacheStore < ResoTransport::MetadataCache
|
111
|
+
|
112
|
+
def read
|
113
|
+
# read `name` from somewhere
|
114
|
+
end
|
115
|
+
|
116
|
+
def write(data)
|
117
|
+
# write `name` with `data` somewhere
|
118
|
+
# return an IO instance
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
The metadata parser expects to recieve an IO instance so just make sure your `read` and `write` methods return one.
|
125
|
+
|
126
|
+
And you can instruct the client to use that cache store like so:
|
127
|
+
|
128
|
+
```
|
129
|
+
md_file: "reso_md_cache/#{@mls.name}",
|
130
|
+
md_cache: MyCacheStore
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
**Skip cache altogether**
|
135
|
+
|
136
|
+
Caching the metadata is not actually required, just be aware that it will be much slower. To skip caching just omit the related keys
|
137
|
+
when instantiating a new Client.
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
@client = ResoTransport::Client.new({
|
141
|
+
endpoint: ENDPOINT_URL
|
142
|
+
authentication: {
|
143
|
+
endpoint: AUTH_ENDPOINT,
|
144
|
+
client_id: CLIENT_ID,
|
145
|
+
client_secret: CLIENT_SECRET,
|
146
|
+
}
|
147
|
+
})
|
148
|
+
```
|
149
|
+
|
150
|
+
|
74
151
|
### Resources
|
75
152
|
|
76
153
|
Once you have a successful connection you can explore what resources are available from the API:
|
@@ -189,6 +266,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
189
266
|
|
190
267
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
191
268
|
|
269
|
+
|
192
270
|
## Contributing
|
193
271
|
|
194
272
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/reso_transport. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/bin/console
CHANGED
@@ -23,8 +23,8 @@ require 'byebug'
|
|
23
23
|
SECRETS = YAML.load_file("secrets.yml")
|
24
24
|
|
25
25
|
@trestle = ResoTransport::Client.new(SECRETS[:trestle].merge(logger: Logger.new($stdout)))
|
26
|
-
|
27
|
-
@spark = ResoTransport::Client.new(SECRETS[:spark])
|
28
|
-
|
26
|
+
#@bridge = ResoTransport::Client.new(SECRETS[:bridge].merge(logger: Logger.new($stdout)))
|
27
|
+
# @spark = ResoTransport::Client.new(SECRETS[:spark])
|
28
|
+
#@crmls = ResoTransport::Client.new(SECRETS[:crmls])
|
29
29
|
|
30
30
|
IRB.start(__FILE__)
|
data/lib/reso_transport.rb
CHANGED
@@ -11,6 +11,7 @@ require "reso_transport/authentication"
|
|
11
11
|
require "reso_transport/client"
|
12
12
|
require "reso_transport/resource"
|
13
13
|
require "reso_transport/metadata"
|
14
|
+
require "reso_transport/metadata_cache"
|
14
15
|
require "reso_transport/metadata_parser"
|
15
16
|
require "reso_transport/schema"
|
16
17
|
require "reso_transport/entity_set"
|
@@ -21,22 +22,24 @@ require "reso_transport/query"
|
|
21
22
|
|
22
23
|
|
23
24
|
|
24
|
-
module Faraday
|
25
|
-
|
25
|
+
# module Faraday
|
26
|
+
# module Utils
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
# def escape(str)
|
29
|
+
# str.to_s.gsub(ESCAPE_RE) do |match|
|
30
|
+
# '%' + match.unpack('H2' * match.bytesize).join('%').upcase
|
31
|
+
# end.gsub(" ","%20")
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
end
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
|
37
|
+
Faraday::Utils.default_space_encoding = "%20"
|
35
38
|
|
36
39
|
module ResoTransport
|
37
40
|
class Error < StandardError; end
|
38
41
|
class AccessDenied < StandardError; end
|
39
|
-
ODATA_TIME_FORMAT = "%Y-%m-%dT%H:%M:%
|
42
|
+
ODATA_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
|
40
43
|
|
41
44
|
class << self
|
42
45
|
attr_writer :configuration
|
@@ -51,7 +54,7 @@ module ResoTransport
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def self.split_schema_and_class_name(s)
|
54
|
-
s.partition(/(\w+)$/).first(2).map {|s| s.sub(/\.$/, '') }
|
57
|
+
s.to_s.partition(/(\w+)$/).first(2).map {|s| s.sub(/\.$/, '') }
|
55
58
|
end
|
56
59
|
|
57
60
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ResoTransport
|
2
2
|
class Client
|
3
|
-
attr_reader :connection, :uid, :vendor, :endpoint, :auth, :md_file
|
3
|
+
attr_reader :connection, :uid, :vendor, :endpoint, :auth, :md_file, :md_cache
|
4
4
|
|
5
5
|
def initialize(options)
|
6
6
|
@endpoint = options.fetch(:endpoint)
|
@@ -9,12 +9,12 @@ module ResoTransport
|
|
9
9
|
@vendor = options.fetch(:vendor, {})
|
10
10
|
@faraday_options = options.fetch(:faraday_options, {})
|
11
11
|
@logger = options.fetch(:logger, nil)
|
12
|
+
@md_cache = options.fetch(:md_cache, ResoTransport::MetadataCache)
|
12
13
|
|
13
14
|
@connection = Faraday.new(@endpoint, @faraday_options) do |faraday|
|
14
15
|
faraday.request :url_encoded
|
15
|
-
faraday.response :logger,
|
16
|
-
faraday
|
17
|
-
#yield faraday if block_given?
|
16
|
+
faraday.response :logger, @logger || ResoTransport.configuration.logger
|
17
|
+
#yield faraday if block_given?
|
18
18
|
faraday.use Authentication::Middleware, @authentication
|
19
19
|
faraday.adapter Faraday.default_adapter #unless faraday.builder.send(:adapter_set?)
|
20
20
|
end
|
data/lib/reso_transport/enum.rb
CHANGED
@@ -7,7 +7,7 @@ module ResoTransport
|
|
7
7
|
|
8
8
|
Enum = Struct.new(:name, :type, :is_flags) do
|
9
9
|
def self.from_stream(args)
|
10
|
-
new("#{args[:schema].namespace}.#{args["Name"]}", args["UnderlyingType"], args["IsFlags"])
|
10
|
+
new("#{args[:schema].namespace}.#{args["Name"]}", args["UnderlyingType"], args["IsFlags"].to_s.downcase == "true")
|
11
11
|
end
|
12
12
|
|
13
13
|
def members
|
@@ -18,15 +18,13 @@ module ResoTransport
|
|
18
18
|
@parser ||= MetadataParser.new.parse(get_data)
|
19
19
|
end
|
20
20
|
|
21
|
+
def md_cache
|
22
|
+
@md_cache ||= client.md_cache.new(client.md_file)
|
23
|
+
end
|
24
|
+
|
21
25
|
def get_data
|
22
26
|
if client.md_file
|
23
|
-
|
24
|
-
File.new(client.md_file)
|
25
|
-
else
|
26
|
-
raw_md = raw
|
27
|
-
File.open(client.md_file, "w") {|f| f.write(raw.force_encoding("UTF-8")) } unless raw_md.length == 0
|
28
|
-
File.new(client.md_file)
|
29
|
-
end
|
27
|
+
md_cache.read || md_cache.write(raw)
|
30
28
|
else
|
31
29
|
raw
|
32
30
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ResoTransport
|
2
|
+
class MetadataCache
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def read
|
10
|
+
if File.exist?(name) && File.size(name) > 0
|
11
|
+
File.new(name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(raw)
|
16
|
+
File.open(name, "w") {|f| f.write(raw.force_encoding("UTF-8")) } unless raw.length == 0
|
17
|
+
File.new(name)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/reso_transport/query.rb
CHANGED
@@ -59,6 +59,7 @@ module ResoTransport
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def count
|
62
|
+
p compile_params
|
62
63
|
limit(1).include_count
|
63
64
|
resp = resource.get(compile_params)
|
64
65
|
parsed_body = JSON.parse(resp.body)
|
@@ -71,7 +72,7 @@ module ResoTransport
|
|
71
72
|
if resp[:success]
|
72
73
|
resp[:results]
|
73
74
|
else
|
74
|
-
puts resp
|
75
|
+
puts resp.inspect
|
75
76
|
raise "Request Failed"
|
76
77
|
end
|
77
78
|
end
|
data/reso_transport.gemspec
CHANGED
@@ -24,12 +24,12 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
-
spec.add_dependency "faraday", "~> 0.
|
27
|
+
spec.add_dependency "faraday", "~> 1.0.1"
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler", "~>
|
30
|
-
spec.add_development_dependency "rake", "~>
|
29
|
+
spec.add_development_dependency "bundler", "~> 2"
|
30
|
+
spec.add_development_dependency "rake", "~> 13"
|
31
31
|
spec.add_development_dependency "minitest", "~> 5.0"
|
32
32
|
spec.add_development_dependency "minitest-rg", "~> 5.0"
|
33
|
-
spec.add_development_dependency "vcr", "~>
|
33
|
+
spec.add_development_dependency "vcr", "~> 6.0"
|
34
34
|
spec.add_development_dependency "byebug"
|
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.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Druse
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 1.0.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 1.0.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13'
|
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: '
|
54
|
+
version: '13'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '6.0'
|
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: '
|
96
|
+
version: '6.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: byebug
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
|
+
- ".ruby-version"
|
119
120
|
- ".travis.yml"
|
120
121
|
- CODE_OF_CONDUCT.md
|
121
122
|
- Gemfile
|
@@ -138,6 +139,7 @@ files:
|
|
138
139
|
- lib/reso_transport/entity_type.rb
|
139
140
|
- lib/reso_transport/enum.rb
|
140
141
|
- lib/reso_transport/metadata.rb
|
142
|
+
- lib/reso_transport/metadata_cache.rb
|
141
143
|
- lib/reso_transport/metadata_parser.rb
|
142
144
|
- lib/reso_transport/property.rb
|
143
145
|
- lib/reso_transport/query.rb
|
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
167
|
- !ruby/object:Gem::Version
|
166
168
|
version: '0'
|
167
169
|
requirements: []
|
168
|
-
rubygems_version: 3.
|
170
|
+
rubygems_version: 3.1.2
|
169
171
|
signing_key:
|
170
172
|
specification_version: 4
|
171
173
|
summary: A utility for consuming RESO Web API connections
|