Class: DataValidation::API

Inherits:
Object
  • Object
show all
Defined in:
lib/data_validation/api.rb

Constant Summary collapse

BASE_URI =
"https://api.datavalidation.com/1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ API

Returns a new instance of API.



10
11
12
# File 'lib/data_validation/api.rb', line 10

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/data_validation/api.rb', line 8

def key
  @key
end

Instance Method Details

#get(uri, h = {}) ⇒ Object



14
15
16
# File 'lib/data_validation/api.rb', line 14

def get(uri, h = {})
  HTTParty.get("#{BASE_URI}/#{uri}", headers: headers.merge(h))
end

#post(uri, body = nil, h = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/data_validation/api.rb', line 18

def post(uri, body = nil, h = {})
  q = {}
  q[:body] = body unless body.nil?
  q[:headers] = headers.merge(h)
  HTTParty.post("#{BASE_URI}/#{uri}", q)
end

#valid_response?(response) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/data_validation/api.rb', line 25

def valid_response?(response)
  code = response.code
  code >= 200 && code <= 299
end