reso_transport 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40a3ea232e3c5de03eea4c842abd89c85747dc0e67af48ed60a27dcefca572e1
4
- data.tar.gz: 68c92d6a7282c9de70d4667275da926a0ea160a24c5daa515e2cb09af9a17bee
3
+ metadata.gz: 9d8d276bf6165281a38be1f3eecda4f50c530bb7a2a2d40b2f8382ae44211bf9
4
+ data.tar.gz: 2ecab6485d270956e91e5e3278fd46a9c1cd65a8960914dfccf86fa530d4c561
5
5
  SHA512:
6
- metadata.gz: adf38742bf879054b2c6a83ca4cec083ae2aae478ff132e896e3e73eef09de7ba39e385ecf5588cf71760a6e28e01f0fb67917379347b00729eb70837adb4210
7
- data.tar.gz: 2d59a335393538b6902ae6db24963284894c24f5c092bbf02cb403ec55a88270d83b3733b19abc8906946f1ee3ede4127eb68d9d0cd9d6dfd9621ff8490dfd48
6
+ metadata.gz: 55b29a0d927e87fa2aef9736bed074b72dfdce04d866ec6b4f1b9f1e4a237d4d7ef44199e19956b45bdf879954f5575e055049adb3b550f80eb10ec2ad42ca10
7
+ data.tar.gz: 91366382060311726be58cf26c1439aad63e6fcfb96f1b6044465fdc630bc499d8ef0edcd6c1443d4ce06b0acc881009977584faed9b2bc6ebe3efbcc121bcb4
data/README.md CHANGED
@@ -82,7 +82,7 @@ If the connection requires requesting a new token periodically, it's easy to pro
82
82
  client_id: CLIENT_ID,
83
83
  client_secret: CLIENT_SECRET,
84
84
  grant_type: "client_credentials", # these are the default and can be ommitted
85
- scope: "api" #
85
+ scope: "api"
86
86
  }
87
87
  })
88
88
  ```
@@ -90,6 +90,64 @@ If the connection requires requesting a new token periodically, it's easy to pro
90
90
  This will pre-fetch a token from the provided endpoint when the current token is either non-existent or has expired.
91
91
 
92
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
+
93
151
  ### Resources
94
152
 
95
153
  Once you have a successful connection you can explore what resources are available from the API:
@@ -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
- @bridge = ResoTransport::Client.new(SECRETS[:bridge].merge(logger: Logger.new($stdout)))
26
+ #@bridge = ResoTransport::Client.new(SECRETS[:bridge].merge(logger: Logger.new($stdout)))
27
27
  # @spark = ResoTransport::Client.new(SECRETS[:spark])
28
- @crmls = ResoTransport::Client.new(SECRETS[:crmls])
28
+ #@crmls = ResoTransport::Client.new(SECRETS[:crmls])
29
29
 
30
30
  IRB.start(__FILE__)
@@ -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"
@@ -53,7 +54,7 @@ module ResoTransport
53
54
  end
54
55
 
55
56
  def self.split_schema_and_class_name(s)
56
- s.partition(/(\w+)$/).first(2).map {|s| s.sub(/\.$/, '') }
57
+ s.to_s.partition(/(\w+)$/).first(2).map {|s| s.sub(/\.$/, '') }
57
58
  end
58
59
 
59
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,6 +9,7 @@ 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
@@ -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
- if File.exist?(client.md_file) && File.size(client.md_file) > 0
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
@@ -77,18 +77,7 @@ module ResoTransport
77
77
  end
78
78
  end
79
79
 
80
- def raw_results
81
- resp = execute(false)
82
-
83
- if resp[:success]
84
- resp[:results]
85
- else
86
- puts resp[:meta]
87
- raise "Request Failed"
88
- end
89
- end
90
-
91
- def execute(parse_values=true)
80
+ def execute
92
81
  resp = resource.get(compile_params)
93
82
  parsed_body = JSON.parse(resp.body)
94
83
  results = Array(parsed_body.delete("value"))
@@ -96,7 +85,7 @@ module ResoTransport
96
85
  {
97
86
  success: resp.success? && !parsed_body.has_key?("error"),
98
87
  meta: parsed_body,
99
- results: parse_values ? resource.parse(results) : results
88
+ results: resource.parse(results)
100
89
  }
101
90
  end
102
91
 
@@ -1,3 +1,3 @@
1
1
  module ResoTransport
2
- VERSION = "1.5.3"
2
+ VERSION = "1.5.4"
3
3
  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.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Druse
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2021-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -139,6 +139,7 @@ files:
139
139
  - lib/reso_transport/entity_type.rb
140
140
  - lib/reso_transport/enum.rb
141
141
  - lib/reso_transport/metadata.rb
142
+ - lib/reso_transport/metadata_cache.rb
142
143
  - lib/reso_transport/metadata_parser.rb
143
144
  - lib/reso_transport/property.rb
144
145
  - lib/reso_transport/query.rb
@@ -151,7 +152,7 @@ homepage: http://github.com/wrstudios/reso_transport
151
152
  licenses:
152
153
  - MIT
153
154
  metadata: {}
154
- post_install_message:
155
+ post_install_message:
155
156
  rdoc_options: []
156
157
  require_paths:
157
158
  - lib
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: '0'
168
169
  requirements: []
169
170
  rubygems_version: 3.1.2
170
- signing_key:
171
+ signing_key:
171
172
  specification_version: 4
172
173
  summary: A utility for consuming RESO Web API connections
173
174
  test_files: []