api_registro 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/api_registro.gemspec +25 -0
- data/lib/api_registro/client.rb +78 -0
- data/lib/api_registro/http_support.rb +26 -0
- data/lib/api_registro/version.rb +3 -0
- data/lib/api_registro.rb +17 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dbf83e994f40555ae914dbec6c76c8387739e308
|
4
|
+
data.tar.gz: 79179e27ee44f7e4fe258a21f2906cafb6bfd298
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00637fef648f80c1c04a8a45ab08f42898f63741417c12685cef9912adb408c669bea80c60b46abd2e971dd0f89144d3044947396e8fbd3ca9d8a789ba9394c6
|
7
|
+
data.tar.gz: 57c0c406d645fccb7cc1fff441908eebcdbe5d74e357b3205eb7e18d5f18d062f468b0153ea92b4af7a4a8ba1c782f11e3b46d2923ef594f532785b12f39f5fd
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
.rvmrc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
coverage
|
13
|
+
InstalledFiles
|
14
|
+
lib/bundler/man
|
15
|
+
pkg
|
16
|
+
rdoc
|
17
|
+
spec/reports
|
18
|
+
test/tmp
|
19
|
+
test/version_tmp
|
20
|
+
tmp
|
21
|
+
|
22
|
+
# YARD artifacts
|
23
|
+
.yardoc
|
24
|
+
_yardoc
|
25
|
+
doc/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Daniel Quirino Oliveira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# ApiRegistro
|
2
|
+
|
3
|
+
A simple client for APIRegistro Domain registration API service (http://apiregistro.com.br).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'api_registro'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install api_registro
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
client = ApiRegistro.client("INSERT YOUR TOKEN HERE") # uses production environment.
|
22
|
+
client = ApiRegistro.client("INSERT YOUR TOKEN HERE", ApiRegistro::Environments::SANDBOX) #uses sandbox environment for testing purposes.
|
23
|
+
h = {name: "John Doe", document: "111.111.111-11", email: "john@email.com"}
|
24
|
+
response = client.create_contact(h) # creates a contact
|
25
|
+
contact_json = client.find_contact("111.111.111-11") # retrieves a contact using contact's CPF.
|
26
|
+
response = client.find_domain("mydomain.com.br") # retrieves domain registration information
|
27
|
+
response = client.register_domain("mydomain.com.br", "111.111.111-11") # register domain testejoopp.com to contact assigned to CPF 111.111.111-11
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'api_registro/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "api_registro"
|
8
|
+
spec.version = ApiRegistro::VERSION
|
9
|
+
spec.authors = ["Daniel Quirino Oliveira"]
|
10
|
+
spec.email = ["danielqo@gmail.com"]
|
11
|
+
spec.description = %q{A client for APIRegistro.com.br API}
|
12
|
+
spec.summary = %q{APIRegistro.com.br API client}
|
13
|
+
spec.homepage = "https://github.com/danielqo/api_registro_rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_dependency "httparty"
|
25
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module ApiRegistro
|
2
|
+
class Client
|
3
|
+
include ApiRegistro::HTTPSupport
|
4
|
+
|
5
|
+
def initialize(token, environment)
|
6
|
+
@token = token
|
7
|
+
@env = environment
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_contact(opts={})
|
11
|
+
message = {
|
12
|
+
headers: { "Accept" => "application/json",
|
13
|
+
"Content-Type" => "application/json",
|
14
|
+
"Authorization" => "Token #{@token}"
|
15
|
+
},
|
16
|
+
body: opts.to_json
|
17
|
+
}
|
18
|
+
request(url_for(:create_contact), ApiRegistro::SupportedMethods::POST, message)
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_contact(document_number)
|
22
|
+
message = {
|
23
|
+
headers: { "Accept" => "application/json", "authorization" => @token }
|
24
|
+
}
|
25
|
+
request(url_for(:find_contact, document_number), ApiRegistro::SupportedMethods::GET, message)
|
26
|
+
end
|
27
|
+
|
28
|
+
def register_domain(domain, document_number)
|
29
|
+
message = {
|
30
|
+
headers: { "Accept" => "application/json",
|
31
|
+
"Content-Type" => "application/json",
|
32
|
+
"Authorization" => "Token #{@token}"
|
33
|
+
},
|
34
|
+
body: {document: document_number}.to_json
|
35
|
+
}
|
36
|
+
request(url_for(:register_domain, domain), ApiRegistro::SupportedMethods::POST, message)
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_domain(domain_name)
|
40
|
+
message = {
|
41
|
+
headers: { "Accept" => "application/json", "authorization" => @token }
|
42
|
+
}
|
43
|
+
request(url_for(:find_domain, domain_name), ApiRegistro::SupportedMethods::GET, message)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def request(url, http_method, message)
|
49
|
+
response = http_request(url, http_method, message)
|
50
|
+
if(response.code == 200)
|
51
|
+
response.body
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def uris
|
58
|
+
{
|
59
|
+
create_contact: "contacts/",
|
60
|
+
find_contact: "contacts/%s",
|
61
|
+
register_domain: "domains/%s/buy/",
|
62
|
+
find_domain: "domains/?search=%s"
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def base_url
|
67
|
+
@env == ApiRegistro::Environments::PRODUCTION ?
|
68
|
+
"http://apiregistro.com.br/api/v1" :
|
69
|
+
"http://sandbox.apiregistro.com.br/api/v1"
|
70
|
+
end
|
71
|
+
|
72
|
+
def url_for(resource, *params)
|
73
|
+
uri = uris[resource] % params
|
74
|
+
"#{base_url}/#{uri}"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module ApiRegistro
|
4
|
+
|
5
|
+
module SupportedMethods
|
6
|
+
POST = :post
|
7
|
+
GET = :get
|
8
|
+
PUT = :put
|
9
|
+
DELETE = :delete
|
10
|
+
ALL = [POST, GET, PUT, DELETE]
|
11
|
+
end
|
12
|
+
|
13
|
+
module HTTPSupport
|
14
|
+
|
15
|
+
def http_request(resource_url, http_method, message={}, &block)
|
16
|
+
if(ApiRegistro::SupportedMethods::ALL.include? http_method)
|
17
|
+
response = HTTParty.send(http_method, resource_url, message)
|
18
|
+
response = yield(response) if block_given?
|
19
|
+
response
|
20
|
+
else
|
21
|
+
raise ArgumentError, "Unsupported HTTP method #{http_method}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/api_registro.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module ApiRegistro
|
2
|
+
|
3
|
+
module Environments
|
4
|
+
SANDBOX = "sandbox"
|
5
|
+
PRODUCTION = "production"
|
6
|
+
ALL = [SANDBOX, PRODUCTION]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.client(token, environment=Environments::PRODUCTION)
|
10
|
+
ApiRegistro::Client.new(token, environment)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'api_registro/version'
|
16
|
+
require 'api_registro/http_support'
|
17
|
+
require 'api_registro/client'
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: api_registro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Quirino Oliveira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A client for APIRegistro.com.br API
|
70
|
+
email:
|
71
|
+
- danielqo@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- api_registro.gemspec
|
82
|
+
- lib/api_registro.rb
|
83
|
+
- lib/api_registro/client.rb
|
84
|
+
- lib/api_registro/http_support.rb
|
85
|
+
- lib/api_registro/version.rb
|
86
|
+
homepage: https://github.com/danielqo/api_registro_rb
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.1.11
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: APIRegistro.com.br API client
|
110
|
+
test_files: []
|