Module: TrestleData::API::Util
Constant Summary collapse
- ROOT_URL =
'https://api.trestleiq.com'
Instance Attribute Summary
Attributes included from Configurable
Instance Method Summary collapse
- #build_url(path, api_version) ⇒ Object
- #call(path, api_version = "3.0", type = :get, params = {}) ⇒ Object
- #phone_number_valid?(phone_number) ⇒ Boolean
Methods included from Configurable
Instance Method Details
#build_url(path, api_version) ⇒ Object
33 34 35 |
# File 'lib/trestle-data/api/util.rb', line 33 def build_url(path, api_version) "#{ File.join(ROOT_URL, api_version, path) }" end |
#call(path, api_version = "3.0", type = :get, params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/trestle-data/api/util.rb', line 12 def call(path, api_version = "3.0", type = :get, params = {}) uri = URI.parse(build_url(path, api_version)) uri.query = URI.encode_www_form(params) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme.upcase == "HTTPS" http.verify_mode = OpenSSL::SSL::VERIFY_NONE if uri.scheme.upcase == "HTTPS" case type when :get request = Net::HTTP::Get.new(uri.request_uri) when :post request = Net::HTTP::Post.new(uri.request_uri) end response = http.request(request) JSON.parse(response.body) end |
#phone_number_valid?(phone_number) ⇒ Boolean
37 38 39 |
# File 'lib/trestle-data/api/util.rb', line 37 def phone_number_valid?(phone_number) return true end |