Class: BuildingSync::SelectionTool
- Inherits:
-
Object
- Object
- BuildingSync::SelectionTool
- Defined in:
- lib/buildingsync/selection_tool.rb
Overview
Class for communicating with SelectionTool on the BuildingSync website
Instance Attribute Summary collapse
-
#hash_response ⇒ Object
readonly
Returns the value of attribute hash_response.
Instance Method Summary collapse
-
#initialize(xml_path, version = '2.4.0') ⇒ SelectionTool
constructor
initialize the selection tools class.
-
#validate_schema ⇒ Object
validate schema.
-
#validate_use_case(use_case) ⇒ Object
validate use case.
Constructor Details
#initialize(xml_path, version = '2.4.0') ⇒ SelectionTool
Note:
See documentation here: github.com/buildingsync/buildingsync-website#validator
Note:
Use core Net::HTTPS
initialize the selection tools class
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/buildingsync/selection_tool.rb', line 50 def initialize(xml_path, version = '2.4.0') @hash_response = nil version = '2.4.0' if version.nil? url = URI.parse('https://buildingsync.net/api/validate') params = { 'schema_version' => version } params[:file] = UploadIO.new(xml_path, 'text/xml', File.basename(xml_path)) request = Net::HTTP::Post::Multipart.new(url.path, params) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE response = http.request(request) @hash_response = JSON.parse(response.read_body) end |
Instance Attribute Details
#hash_response ⇒ Object (readonly)
Returns the value of attribute hash_response.
96 97 98 |
# File 'lib/buildingsync/selection_tool.rb', line 96 def hash_response @hash_response end |
Instance Method Details
#validate_schema ⇒ Object
validate schema
87 88 89 90 91 92 93 94 |
# File 'lib/buildingsync/selection_tool.rb', line 87 def validate_schema if !@hash_response['validation_results']['schema']['valid'] @hash_response['validation_results']['schema']['errors'].each do |error| puts error end end return @hash_response['validation_results']['schema']['valid'] end |
#validate_use_case(use_case) ⇒ Object
validate use case
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/buildingsync/selection_tool.rb', line 70 def validate_use_case(use_case) use_cases = @hash_response['validation_results']['use_cases'] if use_cases.key?(use_case) if !use_cases[use_case]['valid'] use_cases[use_case]['errors'].each do |error| puts error end end return use_cases[use_case]['valid'] else puts "BuildingSync::SelectionTool.validate_use_case, Use Case #{use_case} is not an option. The available use cases to validate against are: #{use_cases}" return false end end |