dnsimpler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e55d0899d0aba7fa5de9ae93c0ce236ae0638d0c
4
+ data.tar.gz: ad731d225b710cf02f4e972f3b3ffd70d8af8adf
5
+ SHA512:
6
+ metadata.gz: 7fe6d9c382f0cfdf5f67f7eee0984c3ce7f847d4c0ecb933e0fff2c37a861cdf4a7d900f8a0e56404ad8d363cc4f1feb505eac09600c815656124c0bfec3046f
7
+ data.tar.gz: 7c88d152dfd412c80ca7f36df6f82a80147b6a28cc106485ce85277096018a2e780b98cab619d12850994555b3c64ac137f2eec8ac9a805c4b27a459e1b7387f
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.2.0"
4
+ script:
5
+ - bundle exec rake test
6
+ deploy:
7
+ provider: rubygems
8
+ api_key:
9
+ secure: F1Drh/pkUEDBvn0l6ZpFJeCeJk0FGReu98Ce3PMiIHjHngGsC3xDOTbkQ7+TUQHlfc0g3Hpc4pYmHxL3w/6TJwbx9csRX0Np4yaNfJZJdHR8uzAi7mpY32APXeLCJkV5En3h1B/G1V3qQ+AhH0Ez6nlOiSEhocJ+MVq9jFXagM4=
10
+ addons:
11
+ code_climate:
12
+ repo_token: 4ee7d32ad4a19408aa4c0d5846e6451a05635e4c1a31109cb0eac9d3a2efa265
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dnsimpler.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'minitest'
8
+ gem 'guard', "2.10.0"
9
+ gem 'guard-minitest'
10
+ end
11
+
12
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,6 @@
1
+ guard :minitest do
2
+ # with Minitest::Unit
3
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
4
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
5
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
6
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Daniel Westendorf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # Dnsimpler
2
+ [![TravisCI](https://travis-ci.org/danielwestendorf/dnsimpler.svg)](https://travis-ci.org/danielwestendorf/dnsimpler)[![Code Climate](https://codeclimate.com/github/danielwestendorf/dnsimpler/badges/gpa.svg)](https://codeclimate.com/github/danielwestendorf/dnsimpler)[![Test Coverage](https://codeclimate.com/github/danielwestendorf/dnsimpler/badges/coverage.svg)](https://codeclimate.com/github/danielwestendorf/dnsimpler)
3
+
4
+ A simple API wrapper for [DNSimple](https://dnsimple.com). Always returns the full response. Requires you to use the [API documentation](https://developer.dnsimple.com).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'dnsimpler'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install dnsimpler
21
+
22
+ ## Usage
23
+
24
+ Configure the gem
25
+ ```ruby
26
+ DNSimpler.setup do |config|
27
+ config.username = "bob@example.com"
28
+ config.token = "DNSIMPLE_API_TOKEN"
29
+ config.base_uri = "https://api.dnsimple.com" # For testing you can use the sandbox
30
+ config.debug = false
31
+ config.proxy = {addr: 'http://example.com', port: 8080, user: 'bob', pass: 'password'}
32
+ end
33
+ ```
34
+
35
+ Make your API calls.
36
+ ```ruby
37
+ domains_response = DNSimpler.get('v1/domains')
38
+ p domains_response.code
39
+ => 200
40
+ p domains_response.body
41
+ [ { domain: { ... } }, { domain: { ... } } ]
42
+ ```
43
+
44
+ Some API calls require parameters. Just pass them as a hash
45
+ ```ruby
46
+ registration = DNSimpler.post('v1/domain_registrations', domain: {name: 'example.com', registrant_id: 1234})
47
+ p registration.code
48
+ => 201
49
+ p domains_response.body
50
+ { domain: { name: 'example.com', .... } }
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/[my-github-username]/dnsimpler/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << "lib"
9
+ t.libs << "test"
10
+ t.test_files = FileList["test/**/*_test.rb"]
11
+ t.verbose = true
12
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dnsimpler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dnsimpler"
8
+ spec.version = DNSimpler::VERSION
9
+ spec.authors = ["Daniel Westendorf"]
10
+ spec.email = ["daniel@prowestech.com"]
11
+ spec.summary = %q{A simple DNSimple API wrapper that always provides the response you're looking for.}
12
+ spec.description = %q{dnsimple-ruby is too opinionated on how to use its method calls. We're all capable devs, righ? Let's just use the API like a developer would.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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
+ spec.required_ruby_version = "~> 2.0"
21
+
22
+ spec.add_runtime_dependency "httparty"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "webmock"
27
+ end
@@ -0,0 +1,62 @@
1
+ require 'ostruct'
2
+ require "dnsimpler/version"
3
+ require 'dnsimpler/http'
4
+
5
+ module DNSimpler
6
+ MATTRS = %w[username token base_uri debug]
7
+
8
+ MATTRS.each do |mattr|
9
+ module_eval <<-RUBY_EVAL, __FILE__, __LINE__
10
+ def self.#{mattr}; return @@#{mattr}; end;
11
+ def self.#{mattr}=(attr); @@#{mattr} = attr; end;
12
+ RUBY_EVAL
13
+ end
14
+
15
+ # Debuggin is off by default
16
+ @@debug = false
17
+
18
+ # API username
19
+ @@username = ''
20
+
21
+ # API token
22
+ @@token = ''
23
+
24
+ # URI for the requests. Defaults to https://api.dnsimple.com/
25
+ @@base_uri = 'https://api.dnsimple.com/'
26
+
27
+ # http proxy info. Should be a hash {addr: 'http://example.com', port: 8080, user: 'bob', pass: 'ed'}
28
+ @@http_proxy = nil
29
+
30
+ def self.http_proxy=(opts)
31
+ @@http_proxy = OpenStruct.new(opts)
32
+ end
33
+
34
+ def self.http_proxy
35
+ @@http_proxy
36
+ end
37
+
38
+ # Allow configuring Dnsimpler with a block
39
+ #
40
+ # Example:
41
+ #
42
+ # Dnsimpler.setup do |config|
43
+ # config.username = 'bob@example.com'
44
+ # config.token = '1234'
45
+ # ....
46
+ # end
47
+ def self.setup
48
+ yield self
49
+ end
50
+
51
+ # Delegate the class methods to the HTTP class
52
+ %w[get post head delete patch put].each do |method|
53
+ module_eval <<-RUBY_EVAL, __FILE__, __LINE__
54
+
55
+ def self.#{method}(path, options = {}, &blk)
56
+ HTTP.#{method}(path, options, &blk)
57
+ end
58
+
59
+ RUBY_EVAL
60
+ end
61
+
62
+ end
@@ -0,0 +1,55 @@
1
+ require 'httparty'
2
+
3
+ module DNSimpler
4
+ class HTTP
5
+ include HTTParty
6
+
7
+ def self.base_options
8
+ opts = {
9
+ base_uri: DNSimpler.base_uri,
10
+ format: :json,
11
+ headers: {
12
+ 'Accept' => 'application/json',
13
+ 'User-Agent' => "dnsimpler/#{DNSimpler::VERSION}",
14
+ 'X-DNSimple-Token' => "#{DNSimpler.username}:#{DNSimpler.token}"
15
+ }
16
+ }
17
+
18
+ unless DNSimpler.http_proxy.nil?
19
+ proxy = DNSimpler.http_proxy
20
+ opts[:http_proxy_addr] = proxy[:addr]
21
+ opts[:http_proxy_port] = proxy[:port]
22
+ opts[:http_proxy_user] = proxy[:user]
23
+ opts[:http_proxy_pass] = proxy[:pass]
24
+ end
25
+
26
+ puts "Base Options: #{opts}" if DNSimpler.debug
27
+
28
+ return opts
29
+ end
30
+
31
+ %w[get post head delete patch put].each do |method|
32
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__
33
+
34
+ def self.#{method}(path, opts = {}, &blk)
35
+ opts = {body: opts}
36
+ opts.merge!(self.base_options)
37
+
38
+ req = super path, opts, &blk
39
+
40
+ response = OpenStruct.new(code: req.code, body: req.parsed_response)
41
+
42
+ if DNSimpler.debug
43
+ response.request = req
44
+
45
+ puts "Request Options: " + opts.to_s
46
+ end
47
+
48
+ return response
49
+ end
50
+
51
+ RUBY_EVAL
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module DNSimpler
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ module DNSimpler
4
+ class HTTPTest < MiniTest::Test
5
+
6
+ test "#base_options" do
7
+ assert_instance_of Hash, HTTP.base_options
8
+ end
9
+
10
+ %w[get post head delete patch put].each do |method|
11
+ class_eval <<-RUBY_EVAL
12
+
13
+ test "#{method}" do
14
+ response = HTTP.#{method}('v1/domains')
15
+ assert_instance_of OpenStruct, response
16
+ end
17
+
18
+ RUBY_EVAL
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class DNSimplerTest < MiniTest::Test
4
+ CONFIGS = %w[username token base_uri debug]
5
+
6
+ CONFIGS.each do |config|
7
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__
8
+ test "##{config}" do
9
+ refute_nil DNSimpler.#{config}
10
+ end
11
+
12
+ test "##{config}=" do
13
+ refute_nil DNSimpler.#{config}= 'test-string'
14
+ end
15
+
16
+ test "##{config}= in setup block" do
17
+ DNSimpler.setup do |config|
18
+ config.#{config} = "#{config}-test-string"
19
+ end
20
+
21
+ assert DNSimpler.#{config}, "#{config}-test-string"
22
+ end
23
+ RUBY_EVAL
24
+ end
25
+
26
+ %w[get post head delete patch put].each do |method|
27
+ class_eval <<-RUBY_EVAL
28
+
29
+ test "#{method}" do
30
+ response = DNSimpler.#{method}('v1/domains')
31
+ assert_instance_of OpenStruct, response
32
+ end
33
+
34
+ RUBY_EVAL
35
+ end
36
+
37
+ test "invalid config variable" do
38
+ assert_raises NoMethodError do
39
+ DNSimpler.nonconfig = 'bob'
40
+ end
41
+
42
+ assert_raises NoMethodError do
43
+ DNSimpler.setup do |config|
44
+ config.fake = 'ed'
45
+ end
46
+ end
47
+ end
48
+
49
+ test "#{}http_proxy" do
50
+ DNSimpler.http_proxy = {addr: 'http://example.com', port: 8080, user: 'bob', pass: 'password'}
51
+ assert_instance_of OpenStruct, DNSimpler.http_proxy
52
+ end
53
+
54
+ end
@@ -0,0 +1,35 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require "minitest/autorun"
5
+ require 'dnsimpler'
6
+ require 'webmock/minitest'
7
+
8
+ class MiniTest::Test
9
+
10
+ def setup
11
+ DNSimpler.setup do |config|
12
+ config.base_uri = "https://api.sandbox.dnsimple.com/"
13
+ config.http_proxy = nil
14
+ config.debug = false
15
+ end
16
+
17
+ WebMock.disable_net_connect!(allow: "codeclimate.com")
18
+ stub_request(:any, "#{DNSimpler.base_uri}v1/domains").to_return(status: 200, body: [{domain: {id: 707}}, {domain: {id: 708}}].to_json)
19
+ end
20
+
21
+ # Stolen from rails source cause I like the syntax
22
+ def self.test(name, &block)
23
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
24
+ defined = method_defined? test_name
25
+ raise "#{test_name} is already defined in #{self}" if defined
26
+ if block_given?
27
+ define_method(test_name, &block)
28
+ else
29
+ define_method(test_name) do
30
+ flunk "No implementation provided for #{name}"
31
+ end
32
+ end
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dnsimpler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Westendorf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: dnsimple-ruby is too opinionated on how to use its method calls. We're
70
+ all capable devs, righ? Let's just use the API like a developer would.
71
+ email:
72
+ - daniel@prowestech.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - dnsimpler.gemspec
85
+ - lib/dnsimpler.rb
86
+ - lib/dnsimpler/http.rb
87
+ - lib/dnsimpler/version.rb
88
+ - test/dnsimpler/http_test.rb
89
+ - test/dnsimpler_test.rb
90
+ - test/test_helper.rb
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: A simple DNSimple API wrapper that always provides the response you're looking
115
+ for.
116
+ test_files:
117
+ - test/dnsimpler/http_test.rb
118
+ - test/dnsimpler_test.rb
119
+ - test/test_helper.rb