Skip to content

Commit

Permalink
Promote API v2 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Jan 7, 2016
2 parents aa6405c + e410edb commit bb67f0b
Show file tree
Hide file tree
Showing 161 changed files with 726 additions and 5,524 deletions.
File renamed without changes.
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Contributing to DNSimple/Ruby

## Getting started

### Environment Setup

- Clone the repository and move into it:

```
$ git clone git@github.com:aetrion/dnsimple-ruby.git
$ cd dnsimple-ruby
```

- Install the dependencies using [Bundler](http://bundler.io/):

```
$ bundle
```

- [Run the test suite](#testing) to check everything works as expected.

### Testing

```
$ rake
```

## Tests

Submit unit tests for your changes. You can test your changes on your machine by [running the test suite](#testing).

When you submit a PR, tests will also be run on the continuous integration environment [through Travis](https://travis-ci.org/aetrion/dnsimple-ruby).

13 changes: 6 additions & 7 deletions LICENSE → LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Copyright (c) 2010-2015 Aetrion LLC
The MIT License (MIT)

MIT License
Copyright (c) 2010-2016 Aetrion LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,14 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
118 changes: 0 additions & 118 deletions README.markdown

This file was deleted.

66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# DNSimple Ruby Client

A Ruby client for the [DNSimple API v2](https://developer.dnsimple.com/v2/).

[![Build Status](https://travis-ci.org/aetrion/dnsimple-ruby.svg?branch=api-v2)](https://travis-ci.org/aetrion/dnsimple-ruby)
[![Coverage Status](https://img.shields.io/coveralls/aetrion/dnsimple-ruby.svg)](https://coveralls.io/r/aetrion/dnsimple-ruby?branch=api-v2)

[DNSimple](https://dnsimple.com/) provides DNS hosting and domain registration that is simple and friendly.
We provide a full API and an easy-to-use web interface so you can get your domain registered and set up with a minimal amount of effort.


## Development Warning

This branch targets the development of the API client for the [DNSimple API v2](https://developer.dnsimple.com/v2/). If you are looking for the stable version of the client for [DNSimple API v1](https://developer.dnsimple.com/v1/) then use the [`master-v1`](https://github.com/aetrion/dnsimple-ruby/tree/master-v1) branch.

This version is currently under development, therefore the methods and the implementation should he considered a work-in-progress. Changes in the method naming, method signatures, public or internal APIs may happen at any time.

The code is tested with an automated test suite connected to a continuous integration tool, therefore you should not expect destructive bugs to be merged into master. Regardless, use this library at your own risk.


## Installation

```
$ gem install dnsimple
```


## Getting Started

This library is a Ruby client you can use to interact with the [DNSimple API v2](https://developer.dnsimple.com/v2/). Here are some examples.

```ruby
require 'dnsimple'

client = Dnsimple::Client.new(access_token: "a1b2c3")

# Fetch your details
response = client.domains.whoami # execute the call
response.data # extract the relevant data from the response or
client.domains.whoami.data # execute the call and get the data in one line

# List your domains
client.domains.list(1234).data # => domains from the account 1234, first page
client.domains.list(1234, query: { page: 3 }).data # => domains from the account 1234, third page
client.domains.all(1234).data # => all domains from the account 1234 (use carefully)

# Create a domain

# Get a domain

# Create a domain record

# Get a domain record

# List domain records
```

For the full library documentation visit http://rubydoc.info/gems/dnsimple


## Authentication


## License

Copyright (c) 2010-2016 Aetrion LLC. This is Free Software distributed under the MIT license.
File renamed without changes.
2 changes: 1 addition & 1 deletion dnsimple.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.extra_rdoc_files = %w( README.markdown CHANGELOG.markdown LICENSE )
s.extra_rdoc_files = %w( README.md CHANGELOG.md UPGRADING.md LICENSE.txt )

s.add_dependency 'httparty'

Expand Down
54 changes: 23 additions & 31 deletions lib/dnsimple/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'dnsimple/compatibility'
require 'dnsimple/extra'
require 'dnsimple/struct'
require 'dnsimple/response'
require 'dnsimple/client/clients'

module Dnsimple
Expand All @@ -9,17 +9,15 @@ module Dnsimple
#
# @see http://developer.dnsimple.com
class Client
include Dnsimple::Compatibility

HEADER_2FA_STRICT = "X-DNSimple-2FA-Strict"
HEADER_API_TOKEN = "X-DNSimple-Token"
HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token"
HEADER_OTP_TOKEN = "X-DNSimple-OTP"
HEADER_EXCHANGE_TOKEN = "X-DNSimple-OTP-Token"
HEADER_AUTHORIZATION = "Authorization"
WILDCARD_ACCOUNT = "_"


# @return [String] The current API version.
API_VERSION = "v1"
API_VERSION = "v2"


# Prepends the correct API version to +path+.
Expand All @@ -33,26 +31,24 @@ def self.versioned(path)
# @!attribute api_endpoint
# @return [String] Base URL for API requests. (default: https://api.dnsimple.com/)
# @!attribute username
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] DNSimple username for Basic Authentication
# @!attribute password
# @see http://developer.dnsimple.com/authentication/
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] DNSimple password for Basic Authentication
# @!attribute exchange_token
# @see http://developer.dnsimple.com/authentication/
# @return [String] Exchange Token for Basic Authentication with 2FA
# @!attribute api_token
# @see http://developer.dnsimple.com/authentication/
# @return [String] API access token for authentication
# @!attribute domain_api_token
# @see http://developer.dnsimple.com/authentication/
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] Domain API access token for authentication
# @!attribute access_token
# @see https://developer.dnsimple.com/v2/#authentication
# @return [String] Domain API access token for authentication
# @!attribute user_agent
# @return [String] Configure User-Agent header for requests.
# @!attribute proxy
# @return [String,nil] Configure address:port values for proxy server

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy
attr_accessor :api_endpoint, :username, :password, :domain_api_token, :access_token,
:oauth_client_id, :oauth_client_secret, :user_agent, :proxy


def initialize(options = {})
Expand All @@ -66,6 +62,12 @@ def initialize(options = {})
end


# @return [String] Base URL for API requests.
def api_endpoint
Extra.join_uri(@api_endpoint, "")
end


# Make a HTTP GET request.
#
# @param [String] path The path, relative to {#api_endpoint}
Expand Down Expand Up @@ -102,7 +104,6 @@ def delete(path, options = {})
execute :delete, path, options
end


# Executes a request, validates and returns the response.
#
# @param [String] method The HTTP method
Expand All @@ -120,15 +121,14 @@ def execute(method, path, data, options = {})
when 200..299
response
when 401
raise (response.headers[HEADER_OTP_TOKEN] == "required" ? TwoFactorAuthenticationRequired : AuthenticationFailed), response["message"]
raise AuthenticationFailed.new(response["message"])
when 404
raise NotFoundError.new(response)
else
raise RequestError.new(response)
end
end


# Make a HTTP request.
#
# This method doesn't validate the response and never raise errors
Expand All @@ -154,12 +154,6 @@ def request(method, path, data, options = {})
end


# @return [String] Base URL for API requests.
def api_endpoint
Extra.join_uri(@api_endpoint, "")
end


private

def base_options
Expand All @@ -173,16 +167,14 @@ def base_options
options.merge!(http_proxyaddr: address, http_proxyport: port)
end

if exchange_token
options[:basic_auth] = { username: exchange_token, password: "x-2fa-basic" }
elsif password
if password
options[:basic_auth] = { username: username, password: password }
elsif domain_api_token
options[:headers][HEADER_DOMAIN_API_TOKEN] = domain_api_token
elsif api_token
options[:headers][HEADER_API_TOKEN] = "#{username}:#{api_token}"
elsif access_token
options[:headers][HEADER_AUTHORIZATION] = "Bearer #{access_token}"
else
raise Error, 'A password or API token is required for all API requests.'
raise Error, 'A password, domain API token or OAuth access token is required for all API requests.'
end

options
Expand Down
Loading

0 comments on commit bb67f0b

Please sign in to comment.