domainr 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bf2a895932dc0a644e69b58273546a8c5b80b27
4
- data.tar.gz: c04c463acfb2dfd58820bb802073c2a692d0b723
3
+ metadata.gz: 2f3dca9b3449f32e2a54c52f63160064d64b1600
4
+ data.tar.gz: abed36cdfb84dce7364959200b0efcaff27d682e
5
5
  SHA512:
6
- metadata.gz: 61709312a0d83ba43dbb689130dab896e93d59a69afe8a087efb09d1cb86eaa326d50046293a90c537cc91f0940d755fc5b435cb0b3670c50edd4f104fc2a5e7
7
- data.tar.gz: 8d3a9dcb449994ab51645cdfa8ba5c241a5f2049be5f984e6af9523ef36e2dfcd38393c8defdd1a441fd2c25934f7ea4a29c6f1fec45c92aa2c7a016fa120ef3
6
+ metadata.gz: 53d3cf3e64837cbdc63aa35ccf535385a1a91f36b0efd0bdf094f43208f21bc6eb4390d7e226add77ab8d83c6b7e88fc0369f8c065387f6047625a3053852c62
7
+ data.tar.gz: 2631250f4efc1859f4cc01474c0e6753f1058f7fa7751fd7f10bf213d2d79adb3db903f0ed81da90dd7537c3ed5ddfae2763fd2482de29a332d50eb46385bbac
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Steve Agalloco
1
+ Copyright (c) 2016 Steve Agalloco
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # domainr
2
2
 
3
- Ruby wrapper for the [Domainr API](https://domainr.com/api).
3
+ Ruby wrapper for the [Domainr API](http://domainr.build/).
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,13 +8,26 @@ Ruby wrapper for the [Domainr API](https://domainr.com/api).
8
8
 
9
9
  ## Usage
10
10
 
11
- You can use Domainr to retrieve information about a domain:
11
+ Instantiate a new client:
12
12
 
13
- Domainr.info('google.com')
13
+ client = Domainr::Client.new(mashape_key: 'abcdefghijklmnopqrstuvwxyz')
14
+
15
+ If you are using Domainr's high volume API endpoints, you can pass a `client_id` and `endpoint` instead:
16
+
17
+ client = Domainr::Client.new(client_id: '123456789', endpoint: 'https://api.domainr.com')
18
+
19
+ Once configured, you can use the `Domainr::Client` to retrieve information about a domain:
20
+
21
+ client.status('google.com')
14
22
 
15
23
  You can also search Domainr based on a search term:
16
24
 
17
- Domainr.search('twitter')
25
+ client.search('twitter')
26
+
27
+ ## Documentation
28
+ [http://rdoc.info/gems/domainr][documentation]
29
+
30
+ [documentation]: http://rdoc.info/gems/domainr}}
18
31
 
19
32
  ## Contributing
20
33
 
@@ -22,4 +35,4 @@ Pull requests welcome: fork, make a topic branch, commit (squash when possible)
22
35
 
23
36
  ## Copyright
24
37
 
25
- Copyright (c) 2014 Steve Agalloco. See [LICENSE](LICENSE.md) for detail
38
+ Copyright (c) 2016 Steve Agalloco. See [LICENSE](LICENSE.md) for detail
@@ -4,25 +4,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'domainr/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = 'domainr'
8
- spec.version = Domainr::VERSION
9
- spec.homepage = 'https://github.com/stve/domainr'
10
-
7
+ spec.add_dependency 'http', '~> 1.0'
8
+ spec.add_dependency 'virtus', '~> 1.0'
9
+ spec.add_development_dependency 'bundler', '~> 1.0'
11
10
  spec.author = "Steve Agalloco"
12
- spec.email = 'steve.agalloco@gmail.com'
13
11
  spec.description = 'Ruby wrapper for the Domainr API'
14
- spec.summary = 'Ruby wrapper for the Domainr API'
15
-
12
+ spec.email = 'steve.agalloco@gmail.com'
13
+ spec.files = %w(LICENSE.md README.md domainr.gemspec) + Dir['lib/**/*.rb']
14
+ spec.homepage = 'https://github.com/stve/domainr'
16
15
  spec.licenses = ['MIT']
17
-
18
- spec.executables = Dir.glob("bin/**/*")
19
- spec.files = %w(.yardopts LICENSE.md README.md Rakefile domainr.gemspec)
20
- spec.files += Dir.glob("lib/**/*.rb")
21
- spec.files += Dir.glob("spec/**/*")
22
- spec.test_files = Dir.glob("spec/**/*")
23
-
24
- spec.add_dependency(%q<httparty>, [">= 0.5.2"])
25
- spec.add_dependency(%q<hashie>, [">= 0.2.0"])
26
-
16
+ spec.name = 'domainr'
27
17
  spec.require_paths = ['lib']
18
+ spec.required_ruby_version = '>= 2.0.0'
19
+ spec.summary = 'Domainr API Ruby Client'
20
+ spec.version = Domainr::VERSION
28
21
  end
@@ -1,29 +1 @@
1
- require 'hashie'
2
- require 'httparty'
3
-
4
- module Domainr
5
- extend self
6
-
7
- include HTTParty
8
- format :json
9
- base_uri 'https://api.domainr.com'
10
-
11
- def self.client_id=(id)
12
- @client_id = id
13
- end
14
-
15
- def self.client_id
16
- @client_id || 'domainr_rubygem'
17
- end
18
-
19
- def search(term)
20
- options = { :q => term, :client_id => client_id }
21
- Hashie::Mash.new(get('/v1/search', { :query => options }))
22
- end
23
-
24
- def info(domain)
25
- options = { :q => domain, :client_id => client_id }
26
- Hashie::Mash.new(get('/v1/info', { :query => options }))
27
- end
28
-
29
- end
1
+ require 'domainr/client'
@@ -0,0 +1,55 @@
1
+ require 'http'
2
+ require 'domainr/domain'
3
+ require 'domainr/http/response'
4
+
5
+ module Domainr
6
+ class Client
7
+ DEFAULT_ENDPOINT = 'https://domainr.p.mashape.com'
8
+
9
+ attr_accessor :client_id, :mashape_key, :endpoint
10
+
11
+ def initialize(options = {})
12
+ @client_id = options.delete(:client_id)
13
+ @mashape_key = options.delete(:mashape_key)
14
+ @endpoint = options.delete(:endpoint) || DEFAULT_ENDPOINT
15
+ end
16
+
17
+ def search(query, options = {})
18
+ perform_get_with_objects('/v2/search', options.merge(query: query), 'results', Domainr::Domain)
19
+ end
20
+
21
+ def status(domain, options = {})
22
+ perform_get_with_objects('/v2/status', options.merge(domain: domain), 'status', Domainr::Domain)
23
+ end
24
+
25
+ private
26
+
27
+ # @param path [String]
28
+ # @param options [Hash]
29
+ # @param response_path [String]
30
+ # @param klass [Class]
31
+ def perform_get_with_objects(path, options, response_path, klass)
32
+ perform_request(path, options)[response_path].collect do |element|
33
+ klass.new(element)
34
+ end
35
+ end
36
+
37
+ def perform_request(path, params)
38
+ response = ::HTTP.headers(accept: 'application/json')
39
+ .get(endpoint + path, params: params.merge(authentication_params))
40
+
41
+ resp = Domainr::HTTP::Response.new(response)
42
+ resp.valid? && resp.body
43
+ end
44
+
45
+ def authentication_params
46
+ if mashape_key
47
+ {'mashape-key' => mashape_key}
48
+ elsif client_id
49
+ {'client_id' => client_id}
50
+ else
51
+ {}
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,15 @@
1
+ require 'virtus'
2
+
3
+ module Domainr
4
+ class Domain
5
+ include Virtus.value_object
6
+
7
+ attribute :domain, String
8
+ attribute :host, String
9
+ attribute :subdomain, String
10
+ attribute :zone, String
11
+ attribute :path, String
12
+ attribute :register_url, String
13
+ attribute :summary, String
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Domainr
2
+ class Error < StandardError
3
+ # @return [Integer]
4
+ attr_reader :code
5
+
6
+ def self.from_response(error)
7
+ new(error['message'], error['status'])
8
+ end
9
+
10
+ # Initializes a new Error object
11
+ #
12
+ # @param message [Exception, String]
13
+ # @param code [Integer]
14
+ # @return [Instapaper::Error]
15
+ def initialize(message = '', code = nil)
16
+ super(message)
17
+ @code = code
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ require 'domainr/error'
2
+
3
+ module Domainr
4
+ module HTTP
5
+ class Response
6
+ attr_reader :response
7
+
8
+ def initialize(response)
9
+ @response = response
10
+ end
11
+
12
+ def valid?
13
+ !error?
14
+ end
15
+
16
+ def error?
17
+ fail_if_body_contains_error
18
+ fail_if_http_error
19
+ end
20
+
21
+ def body
22
+ parsed
23
+ end
24
+
25
+ private
26
+
27
+ def parsed
28
+ response.parse(:json)
29
+ end
30
+
31
+ def fail_if_http_error
32
+ return if response.status.ok?
33
+
34
+ raise Domainr::Error.new(response.status.reason, response.status.code)
35
+ end
36
+
37
+ def fail_if_body_contains_error
38
+ if parsed.key?('error')
39
+ raise Domainr::Error.from_response(parsed['error'])
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Domainr
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,62 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domainr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Agalloco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-08 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
14
+ name: http
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.2
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.2
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: hashie
28
+ name: virtus
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.0
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.0
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  description: Ruby wrapper for the Domainr API
42
56
  email: steve.agalloco@gmail.com
43
57
  executables: []
44
58
  extensions: []
45
59
  extra_rdoc_files: []
46
60
  files:
47
- - ".yardopts"
48
61
  - LICENSE.md
49
62
  - README.md
50
- - Rakefile
51
63
  - domainr.gemspec
52
64
  - lib/domainr.rb
65
+ - lib/domainr/client.rb
66
+ - lib/domainr/domain.rb
67
+ - lib/domainr/error.rb
68
+ - lib/domainr/http/response.rb
53
69
  - lib/domainr/version.rb
54
- - spec/domainr_spec.rb
55
- - spec/fixtures/empty_info.json
56
- - spec/fixtures/empty_search.json
57
- - spec/fixtures/info.json
58
- - spec/fixtures/search.json
59
- - spec/spec_helper.rb
60
70
  homepage: https://github.com/stve/domainr
61
71
  licenses:
62
72
  - MIT
@@ -69,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
79
  requirements:
70
80
  - - ">="
71
81
  - !ruby/object:Gem::Version
72
- version: '0'
82
+ version: 2.0.0
73
83
  required_rubygems_version: !ruby/object:Gem::Requirement
74
84
  requirements:
75
85
  - - ">="
@@ -77,15 +87,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
87
  version: '0'
78
88
  requirements: []
79
89
  rubyforge_project:
80
- rubygems_version: 2.2.2
90
+ rubygems_version: 2.4.8
81
91
  signing_key:
82
92
  specification_version: 4
83
- summary: Ruby wrapper for the Domainr API
84
- test_files:
85
- - spec/domainr_spec.rb
86
- - spec/fixtures/empty_info.json
87
- - spec/fixtures/empty_search.json
88
- - spec/fixtures/info.json
89
- - spec/fixtures/search.json
90
- - spec/spec_helper.rb
93
+ summary: Domainr API Ruby Client
94
+ test_files: []
91
95
  has_rdoc:
data/.yardopts DELETED
@@ -1,3 +0,0 @@
1
- --markup markdown
2
- -
3
- LICENSE.md
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env rake
2
-
3
- require 'bundler/gem_tasks'
4
-
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new(:spec) do |t|
7
- t.ruby_opts = '-w'
8
- end
9
-
10
- task :default => :spec
11
- task :test => :spec
12
-
13
- require 'yard'
14
- namespace :doc do
15
- YARD::Rake::YardocTask.new do |task|
16
- task.files = ['LICENSE.md', 'lib/**/*.rb']
17
- task.options = ['--markup', 'markdown']
18
- end
19
- end
@@ -1,73 +0,0 @@
1
- RSpec.describe Domainr do
2
-
3
- describe '#client_id=' do
4
- after do
5
- Domainr.client_id = nil
6
- end
7
-
8
- it 'returns "domainr_rubygem" by default' do
9
- expect(Domainr.client_id).to eq('domainr_rubygem')
10
- end
11
-
12
- it 'allows a client_id to be defined' do
13
- Domainr.client_id = 'domainr_test_suite'
14
- expect(Domainr.client_id).to eq('domainr_test_suite')
15
- end
16
- end
17
-
18
- describe '#search' do
19
- context "with a search term" do
20
- subject { Domainr.search('domainr') }
21
-
22
- it "includes the query term" do
23
- expect(subject.query).to eq('domainr')
24
- end
25
-
26
- it "returns results" do
27
- expect(subject.results.size).to eq(16)
28
-
29
- first_result = subject.results.first
30
- expect(first_result.domain).to eq('domainr.com')
31
- expect(first_result.availability).to eq('maybe')
32
-
33
- second_result = subject.results[1]
34
- expect(second_result.domain).to eq('domainr.net')
35
- expect(second_result.availability).to eq('maybe')
36
- end
37
- end
38
-
39
- context "without a search term" do
40
- subject { Domainr.search(nil) }
41
-
42
- it "returns an error" do
43
- expect(subject.results.size).to eq(0)
44
- expect(subject.error).to be
45
- expect(subject.error.status).to eq(404)
46
- expect(subject.error.message).to eq('No results found.')
47
- end
48
- end
49
- end
50
-
51
- context "Retrieving info from Domainr" do
52
- context "with a valid search term"do
53
- subject { Domainr.info('domai.nr') }
54
-
55
- it "return results" do
56
- expect(subject.registrars)
57
- expect(subject.domain).to eq('domai.nr')
58
- expect(subject.availability).to eq('taken')
59
- expect(subject.tld.domain).to eq('nr')
60
- end
61
- end
62
-
63
- context "with an invalid search term" do
64
- subject { Domainr.info('d') }
65
-
66
- it "returns an error" do
67
- expect(subject.error).to be
68
- expect(subject.error.status).to eq(404)
69
- expect(subject.error.message).to eq('No results found.')
70
- end
71
- end
72
- end
73
- end
@@ -1,10 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Content-Type: text/javascript+json
3
- Date: Wed, 07 Jul 2010 03:36:37 GMT
4
- Server: Google Frontend
5
- Cache-Control: private, x-gzip-ok=""
6
- X-Xss-Protection: 0
7
- Transfer-Encoding: Identity
8
- Connection: close
9
-
10
- {"query": "d", "error": {"status": 404, "message": "No results found."}}
@@ -1,10 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Content-Type: text/javascript+json
3
- Date: Wed, 07 Jul 2010 03:27:35 GMT
4
- Server: Google Frontend
5
- Cache-Control: private, x-gzip-ok=""
6
- X-Xss-Protection: 0
7
- Transfer-Encoding: Identity
8
- Connection: close
9
-
10
- {"query": "", "results": [], "error": {"status": 404, "message": "No results found."}}
@@ -1,10 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Content-Type: text/javascript+json
3
- Date: Wed, 07 Jul 2010 02:48:41 GMT
4
- Server: Google Frontend
5
- Cache-Control: private, x-gzip-ok=""
6
- X-Xss-Protection: 0
7
- Transfer-Encoding: Identity
8
- Connection: close
9
-
10
- {"domain": "domai.nr", "whois_url": "http://domainr.com/domai.nr/whois", "register_url": "http://domainr.com/domai.nr/register", "tld": {"domain": "nr", "domain_idna": "nr", "wikipedia_url": "http://wikipedia.org/wiki/.nr", "iana_url": "http://www.iana.org/domains/root/db/nr.html"}, "registrars": [{"registrar": "cenpac.net.nr", "name": "CenpacNET", "register_url": "http://domainr.com/domai.nr/register/cenpac.net.nr"}], "host": "", "path": "", "www_url": "http://domainr.com/domai.nr/www", "query": "domai.nr", "subdomain": "domai.nr", "domain_idna": "domai.nr", "availability": "taken"}
@@ -1,10 +0,0 @@
1
- HTTP/1.1 200 OK
2
- Content-Type: text/javascript+json
3
- Date: Wed, 07 Jul 2010 02:49:22 GMT
4
- Server: Google Frontend
5
- Cache-Control: private, x-gzip-ok=""
6
- X-Xss-Protection: 0
7
- Transfer-Encoding: Identity
8
- Connection: close
9
-
10
- {"query": "domainr", "results": [{"domain": "domainr.com", "register_url": "http://domainr.com/domainr.com/register", "host": "", "path": "", "subdomain": "domainr.com", "availability": "maybe"}, {"domain": "domainr.net", "register_url": "http://domainr.com/domainr.net/register", "host": "", "path": "", "subdomain": "domainr.net", "availability": "maybe"}, {"domain": "domainr.org", "register_url": "http://domainr.com/domainr.org/register", "host": "", "path": "", "subdomain": "domainr.org", "availability": "maybe"}, {"domain": "domai.nr", "register_url": "http://domainr.com/domai.nr/register", "host": "", "path": "", "subdomain": "domai.nr", "availability": "taken"}, {"domain": "doma.in", "register_url": "http://domainr.com/doma.in/register", "host": "", "path": "/r", "subdomain": "doma.in", "availability": "maybe"}, {"domain": "dom.ai", "register_url": "http://domainr.com/dom.ai/register", "host": "", "path": "/nr", "subdomain": "dom.ai", "availability": "maybe"}, {"domain": "do.ma", "register_url": "http://domainr.com/do.ma/register", "host": "", "path": "/inr", "subdomain": "do.ma", "availability": "maybe"}, {"domain": "d.om", "register_url": "http://domainr.com/d.om/register", "host": "", "path": "/ainr", "subdomain": "d.om", "availability": "unavailable"}, {"domain": "dm.nr", "register_url": "http://domainr.com/dm.nr/register", "host": "", "path": "", "subdomain": "dm.nr", "availability": "maybe"}, {"domain": "d.mai.nr", "register_url": "http://domainr.com/d.mai.nr/register", "host": "d.", "path": "", "subdomain": "mai.nr", "availability": "available"}, {"domain": "d.mn", "register_url": "http://domainr.com/d.mn/register", "host": "", "path": "/r", "subdomain": "d.mn", "availability": "unavailable"}, {"domain": "d.ma.in", "register_url": "http://domainr.com/d.ma.in/register", "host": "d.", "path": "/r", "subdomain": "ma.in", "availability": "unavailable"}, {"domain": "d.m.ai", "register_url": "http://domainr.com/d.m.ai/register", "host": "d.", "path": "/nr", "subdomain": "m.ai", "availability": "taken"}, {"domain": "d.ma", "register_url": "http://domainr.com/d.ma/register", "host": "", "path": "/inr", "subdomain": "d.ma", "availability": "available"}, {"domain": "dm", "register_url": "http://domainr.com/dm/register", "host": "", "path": "/nr", "subdomain": "dm", "availability": "tld"}, {"domain": "do", "register_url": "http://domainr.com/do/register", "host": "", "path": "/mainr", "subdomain": "do", "availability": "tld"}]}
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- unless ENV['CI']
3
- require 'simplecov'
4
- SimpleCov.start do
5
- add_group 'Domainr', 'lib/domainr'
6
- add_group 'Specs', 'spec'
7
- end
8
- end
9
-
10
- require 'fakeweb'
11
- require 'domainr'
12
-
13
- FakeWeb.allow_net_connect = false
14
-
15
- FakeWeb.register_uri(:get, "https://api.domainr.com/v1/info?q=domai.nr&client_id=domainr_rubygem", :response => File.join(File.dirname(__FILE__), 'fixtures', 'info.json'), :content_type => "text/javascript+json; charset=utf-8", :status => ["200", "OK"])
16
- FakeWeb.register_uri(:get, "https://api.domainr.com/v1/info?q=d&client_id=domainr_rubygem", :response => File.join(File.dirname(__FILE__), 'fixtures', 'empty_info.json'), :content_type => "text/javascript+json; charset=utf-8", :status => ["200", "OK"])
17
- FakeWeb.register_uri(:get, "https://api.domainr.com/v1/search?q=domainr&client_id=domainr_rubygem", :response => File.join(File.dirname(__FILE__), 'fixtures', 'search.json'), :content_type => "text/javascript+json; charset=utf-8", :status => ["200", "OK"])
18
- FakeWeb.register_uri(:get, "https://api.domainr.com/v1/search?q=&client_id=domainr_rubygem", :response => File.join(File.dirname(__FILE__), 'fixtures', 'empty_search.json'), :content_type => "text/javascript+json; charset=utf-8", :status => ["200", "OK"])
19
-
20
- RSpec.configure do |config|
21
- config.order = :random
22
- config.expect_with :rspec do |expectations|
23
- expectations.syntax = :expect
24
- end
25
- end