Class: ApiRegistro::Client

Inherits:
Object
  • Object
show all
Includes:
HTTPSupport
Defined in:
lib/api_registro/client.rb

Instance Method Summary collapse

Methods included from HTTPSupport

#http_request

Constructor Details

#initialize(token, environment) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/api_registro/client.rb', line 5

def initialize(token, environment)
  @token = token
  @env   = environment
end

Instance Method Details

#create_contact(opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/api_registro/client.rb', line 10

def create_contact(opts={})
  message = {
    headers:    { "Accept"        => "application/json", 
                  "Content-Type"  => "application/json",
                  "Authorization" => "Token #{@token}"
                },
    body: opts.to_json
  }
  JSON.parse(request(url_for(:create_contact), ApiRegistro::SupportedMethods::POST, message))
end

#find_contact(document_number) ⇒ Object



21
22
23
24
25
26
# File 'lib/api_registro/client.rb', line 21

def find_contact(document_number)
  message = {
    headers:    { "Accept" => "application/json", "authorization" => @token }
  }
  JSON.parse(request(url_for(:find_contact, document_number), ApiRegistro::SupportedMethods::GET, message))
end

#find_domain(domain_name) ⇒ Object



39
40
41
42
43
44
# File 'lib/api_registro/client.rb', line 39

def find_domain(domain_name)
  message = {
    headers:    { "Accept" => "application/json", "authorization" => @token }
  }
  JSON.parse(request(url_for(:find_domain, domain_name), ApiRegistro::SupportedMethods::GET, message))
end

#register_domain(domain, document_number) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/api_registro/client.rb', line 28

def register_domain(domain, document_number)
  message = {
    headers:    { "Accept"        => "application/json", 
                  "Content-Type"  => "application/json",
                  "Authorization" => "Token #{@token}"
                },
    body: {document: document_number}.to_json
  }
  JSON.parse(request(url_for(:register_domain, domain), ApiRegistro::SupportedMethods::POST, message))
end