lib/spacebunny/endpoint_connection.rb
def fetch
      uri_builder = case scheme.to_s
                      when 'http'
                        URI::HTTP
                      when 'https'
                        URI::HTTPS
                    end

      unless uri = uri_builder.build(host: host, port: port, path: "#{configs_path}")
        raise SchemeNotValid.new(scheme)
      end

      response = contact_endpoint_with uri
      content = JSON.parse(response.to_s, symbolize_names: true) rescue nil
      status = response.status

      if status != 200
        if content
          phrase = "Auto-configuration failed:  #{response.status} => #{content[:error]}"
          if status == 401
            if device?
              phrase = "#{phrase}. Is Device Key correct?"
            else
              phrase = "#{phrase} Are Client and Secret correct?"
            end
          end
        else
          phrase = "#{response.status}"
        end
        raise EndpointError, phrase
      end

      content
    end
# Contact APIs endpoint to retrieve configs
Contact APIs endpoint to retrieve configs
Contact APIs endpoint to retrieve configs
def fetch
      uri_builder = case scheme.to_s
                      when 'http'
                        URI::HTTP
                      when 'https'
                        URI::HTTPS
                    end
      unless uri = uri_builder.build(host: host, port: port, path: "#{configs_path}")
        raise SchemeNotValid.new(scheme)
      end
      response = contact_endpoint_with uri
      content = JSON.parse(response.to_s, symbolize_names: true) rescue nil
      status = response.status
      if status != 200
        if content
          phrase = "Auto-configuration failed:  #{response.status} => #{content[:error]}"
          if status == 401
            if device?
              phrase = "#{phrase}. Is Device Key correct?"
            else
              phrase = "#{phrase} Are Client and Secret correct?"
            end
          end
        else
          phrase = "#{response.status}"
        end
        raise EndpointError, phrase
      end
      content
    end
def fetch uri_builder = case scheme . to_s when 'http' URI :: HTTP when 'https' URI :: HTTPS end unless uri = uri_builder . build ( host : host , port : port , path : "#{configs_path}" ) raise SchemeNotValid . new ( scheme ) end response = contact_endpoint_with uri content = JSON . parse ( response . to_s , symbolize_names : true ) rescue nil status = response . status if status != 200 if content phrase = "Auto-configuration failed:  #{response.status} => #{content[:error]}" if status == 401 if device? phrase = "#{phrase}. Is Device Key correct?" else phrase = "#{phrase} Are Client and Secret correct?" end end else phrase = "#{response.status}" end raise EndpointError , phrase end content end
Contact APIs endpoint to retrieve configs
Contact APIs endpoint to retrieve configs