Class: Syntaxdb::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/syntaxdb/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#apiObject

Returns the value of attribute api.



7
8
9
# File 'lib/syntaxdb/request.rb', line 7

def api
  @api
end

Class Method Details

.send_request(options = {}, endpoint) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/syntaxdb/request.rb', line 13

def self.send_request(options = {}, endpoint)
  @api = "https://syntaxdb.com/api/v1" if @api.nil?
  url = @api + endpoint + "?"
  options.each do |key, value|
    url += key.to_s + "=" + value.to_s
  end

  uri = URI.parse(url)
  header = {
    'Content-Type' => 'text/json'
  }

  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Get.new(uri.request_uri, header)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  response = http.request(request)
  JSON.parse(response.body)
end

Instance Method Details

#initalizeObject



9
10
11
# File 'lib/syntaxdb/request.rb', line 9

def initalize
  @api = "https://syntaxdb.com/api/v1"
end