dnsimple 2.2.0 → 3.0.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -1
  4. data/CHANGELOG.md +13 -2
  5. data/CONTRIBUTING.md +35 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +1 -1
  8. data/README.md +30 -82
  9. data/dnsimple.gemspec +2 -1
  10. data/lib/dnsimple.rb +0 -2
  11. data/lib/dnsimple/client.rb +64 -64
  12. data/lib/dnsimple/client/clients.rb +82 -58
  13. data/lib/dnsimple/client/contacts.rb +74 -37
  14. data/lib/dnsimple/client/domains.rb +82 -28
  15. data/lib/dnsimple/client/domains_email_forwards.rb +107 -0
  16. data/lib/dnsimple/client/identity.rb +38 -0
  17. data/lib/dnsimple/client/oauth.rb +42 -0
  18. data/lib/dnsimple/client/registrar.rb +64 -72
  19. data/lib/dnsimple/client/registrar_auto_renewal.rb +41 -0
  20. data/lib/dnsimple/client/registrar_whois_privacy.rb +74 -0
  21. data/lib/dnsimple/client/tlds.rb +88 -0
  22. data/lib/dnsimple/client/webhooks.rb +82 -0
  23. data/lib/dnsimple/client/zones.rb +68 -0
  24. data/lib/dnsimple/client/zones_records.rb +127 -0
  25. data/lib/dnsimple/default.rb +10 -17
  26. data/lib/dnsimple/error.rb +5 -8
  27. data/lib/dnsimple/extra.rb +1 -1
  28. data/lib/dnsimple/response.rb +80 -0
  29. data/lib/dnsimple/struct.rb +13 -14
  30. data/lib/dnsimple/struct/account.rb +13 -0
  31. data/lib/dnsimple/struct/contact.rb +6 -3
  32. data/lib/dnsimple/struct/domain.rb +10 -10
  33. data/lib/dnsimple/struct/domain_check.rb +16 -0
  34. data/lib/dnsimple/struct/email_forward.rb +11 -1
  35. data/lib/dnsimple/struct/oauth_token.rb +19 -0
  36. data/lib/dnsimple/struct/record.rb +25 -7
  37. data/lib/dnsimple/struct/tld.rb +22 -0
  38. data/lib/dnsimple/struct/user.rb +3 -7
  39. data/lib/dnsimple/struct/webhook.rb +13 -0
  40. data/lib/dnsimple/struct/whois_privacy.rb +8 -5
  41. data/lib/dnsimple/struct/zone.rb +25 -0
  42. data/lib/dnsimple/version.rb +1 -1
  43. data/spec/dnsimple/client/client_service_spec.rb +37 -0
  44. data/spec/dnsimple/client/contacts_spec.rb +108 -78
  45. data/spec/dnsimple/client/domains_email_forwards_spec.rb +190 -0
  46. data/spec/dnsimple/client/domains_spec.rb +121 -58
  47. data/spec/dnsimple/client/identity_spec.rb +56 -0
  48. data/spec/dnsimple/client/oauth_spec.rb +48 -0
  49. data/spec/dnsimple/client/registrar_auto_renewal_spec.rb +80 -0
  50. data/spec/dnsimple/client/registrar_spec.rb +109 -122
  51. data/spec/dnsimple/client/registrar_whois_privacy_spec.rb +119 -0
  52. data/spec/dnsimple/client/tlds_spec.rb +139 -0
  53. data/spec/dnsimple/client/webhooks_spec.rb +142 -0
  54. data/spec/dnsimple/client/zones_records_spec.rb +277 -0
  55. data/spec/dnsimple/client/zones_spec.rb +109 -0
  56. data/spec/dnsimple/client_spec.rb +34 -46
  57. data/spec/dnsimple/extra_spec.rb +22 -0
  58. data/spec/{files → fixtures.http}/badgateway.http +14 -14
  59. data/spec/fixtures.http/checkDomain/success.http +17 -0
  60. data/spec/fixtures.http/createContact/created.http +17 -0
  61. data/spec/fixtures.http/createDomain/created.http +16 -0
  62. data/spec/fixtures.http/createEmailForward/created.http +17 -0
  63. data/spec/fixtures.http/createWebhook/created.http +17 -0
  64. data/spec/fixtures.http/createZoneRecord/created.http +17 -0
  65. data/spec/fixtures.http/deleteContact/success.http +13 -0
  66. data/spec/fixtures.http/deleteDomain/success.http +13 -0
  67. data/spec/fixtures.http/deleteEmailForward/success.http +12 -0
  68. data/spec/fixtures.http/deleteWebhook/success.http +13 -0
  69. data/spec/fixtures.http/deleteZoneRecord/success.http +13 -0
  70. data/spec/fixtures.http/disableAutoRenewal/success.http +12 -0
  71. data/spec/fixtures.http/disableWhoisPrivacy/success.http +17 -0
  72. data/spec/fixtures.http/enableAutoRenewal/success.http +12 -0
  73. data/spec/fixtures.http/enableWhoisPrivacy/created.http +17 -0
  74. data/spec/fixtures.http/enableWhoisPrivacy/success.http +17 -0
  75. data/spec/fixtures.http/getContact/success.http +17 -0
  76. data/spec/fixtures.http/getDomain/success.http +16 -0
  77. data/spec/fixtures.http/getEmailForward/success.http +17 -0
  78. data/spec/fixtures.http/getTld/success.http +17 -0
  79. data/spec/fixtures.http/getTldExtendedAttributes/success-noattributes.http +17 -0
  80. data/spec/fixtures.http/getTldExtendedAttributes/success.http +17 -0
  81. data/spec/fixtures.http/getWebhook/success.http +17 -0
  82. data/spec/fixtures.http/getWhoisPrivacy/success.http +17 -0
  83. data/spec/fixtures.http/getZone/success.http +17 -0
  84. data/spec/fixtures.http/getZoneRecord/success.http +17 -0
  85. data/spec/fixtures.http/listContacts/success.http +17 -0
  86. data/spec/fixtures.http/listDomains/success.http +16 -0
  87. data/spec/fixtures.http/listEmailForwards/success.http +17 -0
  88. data/spec/fixtures.http/listTlds/success.http +17 -0
  89. data/spec/fixtures.http/listWebhooks/success.http +17 -0
  90. data/spec/fixtures.http/listZoneRecords/success.http +17 -0
  91. data/spec/fixtures.http/listZones/success.http +17 -0
  92. data/spec/fixtures.http/notfound-contact.http +12 -0
  93. data/spec/fixtures.http/notfound-domain.http +12 -0
  94. data/spec/fixtures.http/notfound-emailforward.http +12 -0
  95. data/spec/fixtures.http/notfound-record.http +12 -0
  96. data/spec/fixtures.http/notfound-webhook.http +12 -0
  97. data/spec/fixtures.http/notfound-zone.http +12 -0
  98. data/spec/fixtures.http/oauthAccessToken/success.http +17 -0
  99. data/spec/fixtures.http/pages-1of3.http +16 -0
  100. data/spec/fixtures.http/pages-2of3.http +16 -0
  101. data/spec/fixtures.http/pages-3of3.http +16 -0
  102. data/spec/fixtures.http/registerDomain/success.http +17 -0
  103. data/spec/fixtures.http/renewDomain/error-tooearly.http +15 -0
  104. data/spec/fixtures.http/renewDomain/success.http +17 -0
  105. data/spec/fixtures.http/resetDomainToken/success.http +17 -0
  106. data/spec/fixtures.http/response.http +16 -0
  107. data/spec/fixtures.http/transferDomain/error-indnsimple.http +15 -0
  108. data/spec/fixtures.http/transferDomain/error-missing-authcode.http +15 -0
  109. data/spec/fixtures.http/transferDomain/success.http +17 -0
  110. data/spec/fixtures.http/transferDomainOut/success.http +13 -0
  111. data/spec/fixtures.http/updateContact/success.http +17 -0
  112. data/spec/fixtures.http/updateZoneRecord/success.http +17 -0
  113. data/spec/fixtures.http/whoami/success.http +16 -0
  114. data/spec/fixtures.http/whoami/success_account.http +16 -0
  115. data/spec/fixtures.http/whoami/success_user.http +16 -0
  116. data/spec/spec_helper.rb +0 -6
  117. data/spec/support/helpers.rb +4 -4
  118. metadata +161 -238
  119. data/lib/dnsimple/client/certificates.rb +0 -100
  120. data/lib/dnsimple/client/domains_autorenewal.rb +0 -35
  121. data/lib/dnsimple/client/domains_forwards.rb +0 -71
  122. data/lib/dnsimple/client/domains_privacy.rb +0 -35
  123. data/lib/dnsimple/client/domains_records.rb +0 -90
  124. data/lib/dnsimple/client/domains_sharing.rb +0 -54
  125. data/lib/dnsimple/client/domains_zones.rb +0 -22
  126. data/lib/dnsimple/client/name_servers.rb +0 -71
  127. data/lib/dnsimple/client/services.rb +0 -37
  128. data/lib/dnsimple/client/services_domains.rb +0 -68
  129. data/lib/dnsimple/client/templates.rb +0 -88
  130. data/lib/dnsimple/client/templates_domains.rb +0 -23
  131. data/lib/dnsimple/client/templates_records.rb +0 -88
  132. data/lib/dnsimple/client/users.rb +0 -39
  133. data/lib/dnsimple/client/vanity_name_servers.rb +0 -39
  134. data/lib/dnsimple/compatibility.rb +0 -46
  135. data/lib/dnsimple/struct/certificate.rb +0 -56
  136. data/lib/dnsimple/struct/membership.rb +0 -22
  137. data/lib/dnsimple/struct/price.rb +0 -16
  138. data/lib/dnsimple/struct/service.rb +0 -19
  139. data/lib/dnsimple/struct/template.rb +0 -19
  140. data/lib/dnsimple/struct/template_record.rb +0 -24
  141. data/lib/dnsimple/struct/transfer_order.rb +0 -10
  142. data/spec/dnsimple/client/certificates_spec.rb +0 -196
  143. data/spec/dnsimple/client/domains_autorenewals_spec.rb +0 -72
  144. data/spec/dnsimple/client/domains_forwards_spec.rb +0 -146
  145. data/spec/dnsimple/client/domains_privacy_spec.rb +0 -74
  146. data/spec/dnsimple/client/domains_records_spec.rb +0 -191
  147. data/spec/dnsimple/client/domains_sharing_spec.rb +0 -109
  148. data/spec/dnsimple/client/domains_zones_spec.rb +0 -40
  149. data/spec/dnsimple/client/name_servers_spec.rb +0 -131
  150. data/spec/dnsimple/client/services_domains_spec.rb +0 -101
  151. data/spec/dnsimple/client/services_spec.rb +0 -69
  152. data/spec/dnsimple/client/templates_domains_spec.rb +0 -38
  153. data/spec/dnsimple/client/templates_records_spec.rb +0 -180
  154. data/spec/dnsimple/client/templates_spec.rb +0 -166
  155. data/spec/dnsimple/client/users_spec.rb +0 -70
  156. data/spec/dnsimple/client/vanity_name_servers_spec.rb +0 -61
  157. data/spec/dnsimple/compatibility_spec.rb +0 -57
  158. data/spec/files/2fa/error-badtoken.http +0 -22
  159. data/spec/files/2fa/error-required.http +0 -23
  160. data/spec/files/2fa/exchange-token.http +0 -22
  161. data/spec/files/certificates/configure/success.http +0 -19
  162. data/spec/files/certificates/get/success.http +0 -19
  163. data/spec/files/certificates/list/success.http +0 -19
  164. data/spec/files/certificates/notfound.http +0 -19
  165. data/spec/files/certificates/purchase/success.http +0 -19
  166. data/spec/files/certificates/submit/success.http +0 -19
  167. data/spec/files/contacts/contact/success.http +0 -19
  168. data/spec/files/contacts/contacts/success.http +0 -23
  169. data/spec/files/contacts/create_contact/badrequest-missingcontact.http +0 -19
  170. data/spec/files/contacts/create_contact/badrequest-validationerror.http +0 -19
  171. data/spec/files/contacts/create_contact/created.http +0 -22
  172. data/spec/files/contacts/delete_contact/success-204.http +0 -18
  173. data/spec/files/contacts/delete_contact/success.http +0 -19
  174. data/spec/files/contacts/notfound-contact.http +0 -19
  175. data/spec/files/contacts/update_contact/success.http +0 -21
  176. data/spec/files/domains/create_domain/created.http +0 -21
  177. data/spec/files/domains/create_forward/created.http +0 -22
  178. data/spec/files/domains/create_membership/success.http +0 -21
  179. data/spec/files/domains/create_record/created.http +0 -21
  180. data/spec/files/domains/delete_domain/success-204.http +0 -18
  181. data/spec/files/domains/delete_domain/success.http +0 -19
  182. data/spec/files/domains/delete_forward/success.http +0 -17
  183. data/spec/files/domains/delete_membership/success.http +0 -17
  184. data/spec/files/domains/delete_record/success-204.http +0 -18
  185. data/spec/files/domains/delete_record/success.http +0 -19
  186. data/spec/files/domains/disable_auto_renewal/success.http +0 -21
  187. data/spec/files/domains/disable_whois_privacy/success.http +0 -21
  188. data/spec/files/domains/domain/success.http +0 -21
  189. data/spec/files/domains/domains/success.http +0 -21
  190. data/spec/files/domains/enable_auto_renewal/success.http +0 -21
  191. data/spec/files/domains/enable_whois_privacy/success.http +0 -22
  192. data/spec/files/domains/forward/success.http +0 -21
  193. data/spec/files/domains/forwards/success.http +0 -21
  194. data/spec/files/domains/memberships/success.http +0 -21
  195. data/spec/files/domains/notfound-domain.http +0 -19
  196. data/spec/files/domains/notfound-forward.http +0 -19
  197. data/spec/files/domains/notfound-membership.http +0 -19
  198. data/spec/files/domains/record/success.http +0 -19
  199. data/spec/files/domains/records/success.http +0 -19
  200. data/spec/files/domains/update_record/success.http +0 -21
  201. data/spec/files/domains/zone/success.http +0 -21
  202. data/spec/files/nameservers/change/success.http +0 -23
  203. data/spec/files/nameservers/deregister/success.http +0 -17
  204. data/spec/files/nameservers/name_servers/success.http +0 -23
  205. data/spec/files/nameservers/notfound-domain.http +0 -19
  206. data/spec/files/nameservers/register/badrequest-valueerror.http +0 -19
  207. data/spec/files/nameservers/register/success.http +0 -21
  208. data/spec/files/nameservers/vanity_name_servers/disabled.http +0 -23
  209. data/spec/files/nameservers/vanity_name_servers/enabled.http +0 -23
  210. data/spec/files/registrar/check/available.http +0 -19
  211. data/spec/files/registrar/check/registered.http +0 -21
  212. data/spec/files/registrar/extended_attributes/success.http +0 -21
  213. data/spec/files/registrar/prices/success.http +0 -21
  214. data/spec/files/registrar/register/badrequest-missingdomain.http +0 -19
  215. data/spec/files/registrar/register/badrequest-missingregistrant.http +0 -19
  216. data/spec/files/registrar/register/success.http +0 -21
  217. data/spec/files/registrar/renew/badrequest-missingrenewal.http +0 -19
  218. data/spec/files/registrar/renew/badrequest-unable.http +0 -19
  219. data/spec/files/registrar/renew/success.http +0 -21
  220. data/spec/files/registrar/transfer/success.http +0 -21
  221. data/spec/files/services/applied/success.http +0 -21
  222. data/spec/files/services/apply/success.http +0 -21
  223. data/spec/files/services/available/success.http +0 -21
  224. data/spec/files/services/notfound-service.http +0 -19
  225. data/spec/files/services/service/success.http +0 -21
  226. data/spec/files/services/services/success.http +0 -21
  227. data/spec/files/services/unapply/success.http +0 -21
  228. data/spec/files/subscriptions/subscription/success.http +0 -21
  229. data/spec/files/templates/apply_template/success.http +0 -21
  230. data/spec/files/templates/create_template/created.http +0 -22
  231. data/spec/files/templates/delete_template/success-204.http +0 -21
  232. data/spec/files/templates/delete_template/success.http +0 -21
  233. data/spec/files/templates/notfound-template.http +0 -19
  234. data/spec/files/templates/template/success.http +0 -21
  235. data/spec/files/templates/templates/success.http +0 -21
  236. data/spec/files/templates/update_template/success.http +0 -21
  237. data/spec/files/templates_records/create_record/created.http +0 -22
  238. data/spec/files/templates_records/delete_record/success-204.http +0 -19
  239. data/spec/files/templates_records/delete_record/success.http +0 -21
  240. data/spec/files/templates_records/notfound-template-record.http +0 -19
  241. data/spec/files/templates_records/record/success.http +0 -21
  242. data/spec/files/templates_records/records/success.http +0 -21
  243. data/spec/files/templates_records/update_record/success.http +0 -21
  244. data/spec/files/users/user/success.http +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b4fdacf67fa0361f299902ba1f3c323150320c0
4
- data.tar.gz: be9c4fd05ecbc4c638d1cdda892d99ecbeab8d8d
3
+ metadata.gz: 6571b9393456ff941623f5001f393bfd819493f3
4
+ data.tar.gz: bf1878874ee2fa403519e51bcf28e7c1a36afbd9
5
5
  SHA512:
6
- metadata.gz: 5f5bcf78ff845d629377ac08c4f37ed8a31bb9e13f22218fa9b70d28e20245c8a5e8b9b667ce8c2b7fc9d9485698e3d84e5214920cab795b2f876f0c380b9080
7
- data.tar.gz: 584c677a4e3c36d8a1e8fd63c86723b74bbe516ea570fa7eb3c15264d0a8a4a7a0cc40b25402a578a3d9337d7ad70b7c674db50503a1b37e2d61cf972cfa08c8
6
+ metadata.gz: 2fb5142d55bbc3408be6b2626c67a7c2c41caeb4239ace0a1b3624e870857bfb987e0073e3cea7180eec3fb935c819441d9ff1f6eee3de6c9c38b5de2f184763
7
+ data.tar.gz: e681b2fc92d3c1c4d6c51bf9407c28c89b3129e73180009ab6a1e2aabf2ebf7579b70af34c638e8e627dd1979724de3313bdd58057e42b68de1361e19878f433
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1
1
+ ruby-2.3.0
data/.travis.yml CHANGED
@@ -1,9 +1,11 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 1.9.3
4
4
  - 2.0
5
5
  - 2.1
6
6
  - 2.2
7
+ - 2.3.0
7
8
  env: COVERALL=1
9
+
8
10
  before_install:
9
11
  - gem install bundler
data/CHANGELOG.md CHANGED
@@ -1,8 +1,19 @@
1
1
  # Changelog
2
2
 
3
- #### 2.2.0
3
+ This project uses [Semantic Versioning 2.0.0](http://semver.org/).
4
4
 
5
- - NEW: Add support for Vanity Name Servers (GH-67, GH-63, GH-60). Thanks @iseem.
5
+
6
+ #### 3.0
7
+
8
+ ##### beta1
9
+
10
+ - CHANGED: Minimum Ruby version >= 2
11
+
12
+ - CHANGED: Renamed `api_endpoint` to `base_url` to match the other clients.
13
+
14
+ The client has been completely redesigned to support the [API v2](https://developer.dnsimple.com/v2). Overall, the client behaves like the previous version, however it has been rewritten to leverage the API v2 features specifically.
15
+
16
+ Internal changes were made to match conventions adopted in other clients, such as the Go one and the Elixir one.
6
17
 
7
18
  #### 2.1.1
8
19
 
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,35 @@
1
+ # Contributing to DNSimple/Ruby
2
+
3
+ ## Getting started
4
+
5
+ Clone the repository and move into it:
6
+
7
+ ```
8
+ $ git clone git@github.com:aetrion/dnsimple-ruby.git
9
+ $ cd dnsimple-ruby
10
+ ```
11
+
12
+ Install the dependencies using [Bundler](http://bundler.io/):
13
+
14
+ ```
15
+ $ bundle
16
+ ```
17
+
18
+ [Run the test suite](#testing) to check everything works as expected.
19
+
20
+
21
+ ## Testing
22
+
23
+ To run the test suite:
24
+
25
+ ```
26
+ $ rake
27
+ ```
28
+
29
+
30
+ ## Tests
31
+
32
+ Submit unit tests for your changes. You can test your changes on your machine by [running the test suite](#testing).
33
+
34
+ When you submit a PR, tests will also be run on the continuous integration environment [through Travis](https://travis-ci.org/aetrion/dnsimple-ruby).
35
+
data/Gemfile CHANGED
@@ -2,4 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'rake', '< 11'
5
6
  gem 'coveralls', require: false
7
+ gem 'rspec-core', '>= 3.4.4'
data/LICENSE.txt CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,14 +1,21 @@
1
1
  # DNSimple Ruby Client
2
2
 
3
- A Ruby client for the [DNSimple API](https://developer.dnsimple.com/).
3
+ A Ruby client for the [DNSimple API v2](https://developer.dnsimple.com/v2/).
4
4
 
5
- [![Build Status](https://travis-ci.org/aetrion/dnsimple-ruby.svg?branch=master-v1)](https://travis-ci.org/aetrion/dnsimple-ruby)
6
- [![Coverage Status](https://img.shields.io/coveralls/aetrion/dnsimple-ruby.svg)](https://coveralls.io/r/aetrion/dnsimple-ruby?branch=master-v1)
5
+ [![Build Status](https://travis-ci.org/aetrion/dnsimple-ruby.svg?branch=master)](https://travis-ci.org/aetrion/dnsimple-ruby)
6
+ [![Coverage Status](https://img.shields.io/coveralls/aetrion/dnsimple-ruby.svg)](https://coveralls.io/r/aetrion/dnsimple-ruby?branch=master)
7
7
 
8
8
  [DNSimple](https://dnsimple.com/) provides DNS hosting and domain registration that is simple and friendly.
9
9
  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.
10
10
 
11
11
 
12
+ ## :warning: Beta Warning
13
+
14
+ 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.
15
+
16
+ This library is currently in beta version, the methods and the implementation should be considered a work-in-progress. Changes in the method naming, method signatures, public or internal APIs may happen during the beta period.
17
+
18
+
12
19
  ## Installation
13
20
 
14
21
  ```
@@ -16,103 +23,44 @@ $ gem install dnsimple
16
23
  ```
17
24
 
18
25
 
19
- ## Getting Started
26
+ ## Usage
20
27
 
21
- This library is a Ruby client you can use to interact with the [DNSimple API](https://developer.dnsimple.com/). Here are some examples.
28
+ 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.
22
29
 
23
30
  ```ruby
24
31
  require 'dnsimple'
25
32
 
26
- client = Dnsimple::Client.new(username: 'YOUR_USERNAME', api_token: 'YOUR_TOKEN')
33
+ client = Dnsimple::Client.new(access_token: "a1b2c3")
27
34
 
28
- # Fetch your user details
29
- user = client.users.user
30
- puts "My email is #{user.email}"
35
+ # Fetch your details
36
+ response = client.identity.whoami # execute the call
37
+ response.data # extract the relevant data from the response or
38
+ client.identity.whoami.data # execute the call and get the data in one line
31
39
 
40
+ # Define an account ID.
41
+ account_id = 1010
42
+
43
+ # You can also fetch it from the whoami response
44
+ whoami = client.identity.whoami.data
45
+ account_id = whoami.account.id
32
46
 
33
47
  # List your domains
34
- domains = client.domains.list
35
- domains.each do |domain|
36
- puts "Domain: %s (id: %d)" % [domain.name, domain.id]
37
- end
48
+ puts client.domains.list_domains(account_id).data # => domains from the account 1234, first page
49
+ puts client.domains.list_domains(account_id, query: { page: 3 }).data # => domains from the account 1234, third page
50
+ puts client.domains.all_domains(account_id).data # => all domains from the account 1234 (use carefully)
38
51
 
39
52
  # Create a domain
40
- domain = client.domains.create(name: "example.com")
41
- puts "Domain: %s (id: %d)" % [domain.name, domain.id]
53
+ response = client.domains.create_domain(account_id, name: "example.com")
54
+ puts response.data
42
55
 
43
56
  # Get a domain
44
- domain = client.domains.domain("example.com")
45
- puts "Domain: %s (id: %d)" % [domain.name, domain.id]
46
-
47
-
48
- # Create a domain record
49
- record = client.domains.create_record("example.com", record_type: "A", name: "www", content: "127.0.0.1")
50
- puts "Record: %s (id: %d)" % [record.name, record.id]
51
-
52
- # Get a domain record
53
- record = client.domains.record("example.com", 1234)
54
- puts "Record: %s (id: %d)" % [record.name, record.id]
55
-
56
- # List domain records
57
- records = client.domains.records("example.com")
58
- records.each do |record|
59
- puts "Record: %s (id: %d)" % [record.name, record.id]
60
- end
57
+ response = client.domains.domain(account_id, "example.com")
58
+ puts response.data
61
59
  ```
62
60
 
63
61
  For the full library documentation visit http://rubydoc.info/gems/dnsimple
64
62
 
65
63
 
66
- ## Authentication
67
-
68
- This client supports both the HTTP Basic and API Token authentication mechanism.
69
-
70
- #### HTTP Basic
71
-
72
- ```ruby
73
- client = Dnsimple::Client.new(username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD')
74
- client.users.user
75
- # => Dnsimple::Struct::User
76
- ```
77
-
78
- #### HTTP Basic with two-factor authentication enabled
79
-
80
- See the [2FA API documentation](https://developer.dnsimple.com/authentication/#twofa).
81
-
82
- ```ruby
83
- # Request the 2FA exchange token
84
- client = Dnsimple::Client.new(username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD')
85
- token = client.users.exchange_token('otp-token')
86
-
87
- # Authenticate with the exchange token
88
- client.exchange_token = token
89
- client.users.user
90
- # => Dnsimple::Struct::User
91
- ```
92
-
93
- #### API Token
94
-
95
- ```ruby
96
- client = Dnsimple::Client.new(username: 'YOUR_USERNAME', api_token: 'YOUR_TOKEN')
97
-
98
- client.users.user
99
- # => Dnsimple::Struct::User
100
- ```
101
-
102
- #### Domain API Token
103
-
104
- The domain API token grants [limited access]](https://developer.dnsimple.com/v1/authentication/#domain-token) to a single domain.
105
-
106
- ```ruby
107
- client = Dnsimple::Client.new(domain_api_token: 'DOMAIN_TOKEN')
108
-
109
- client.domains.records("example.com")
110
- # => [Dnsimple::Struct::Record, Dnsimple::Struct::Record, ...]
111
-
112
- client.domains.records("foobar.com")
113
- # => Authentication error
114
- ```
115
-
116
64
  ## License
117
65
 
118
66
  Copyright (c) 2010-2016 Aetrion LLC. This is Free Software distributed under the MIT license.
data/dnsimple.gemspec CHANGED
@@ -11,11 +11,12 @@ Gem::Specification.new do |s|
11
11
  s.summary = 'The DNSimple API client for Ruby'
12
12
  s.description = 'The DNSimple API client for Ruby.'
13
13
 
14
- s.required_ruby_version = ">= 1.9.3"
14
+ s.required_ruby_version = ">= 2.0"
15
15
 
16
16
  s.require_paths = ['lib']
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.extra_rdoc_files = %w( LICENSE.txt )
19
20
 
20
21
  s.add_dependency 'httparty'
21
22
 
data/lib/dnsimple.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'httparty'
2
-
3
1
  module Dnsimple
4
2
 
5
3
  # Echoes a deprecation warning message.
@@ -1,25 +1,23 @@
1
- require 'dnsimple/compatibility'
1
+ require 'httparty'
2
2
  require 'dnsimple/extra'
3
3
  require 'dnsimple/struct'
4
+ require 'dnsimple/response'
4
5
  require 'dnsimple/client/clients'
5
6
 
6
7
  module Dnsimple
7
8
 
8
9
  # Client for the DNSimple API
9
10
  #
10
- # @see http://developer.dnsimple.com
11
+ # @see https://developer.dnsimple.com/
11
12
  class Client
12
- include Dnsimple::Compatibility
13
13
 
14
- HEADER_2FA_STRICT = "X-DNSimple-2FA-Strict"
15
- HEADER_API_TOKEN = "X-DNSimple-Token"
16
14
  HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token"
17
- HEADER_OTP_TOKEN = "X-DNSimple-OTP"
18
- HEADER_EXCHANGE_TOKEN = "X-DNSimple-OTP-Token"
15
+ HEADER_AUTHORIZATION = "Authorization"
16
+ WILDCARD_ACCOUNT = "_"
19
17
 
20
18
 
21
19
  # @return [String] The current API version.
22
- API_VERSION = "v1"
20
+ API_VERSION = "v2"
23
21
 
24
22
 
25
23
  # Prepends the correct API version to +path+.
@@ -30,29 +28,27 @@ module Dnsimple
30
28
  end
31
29
 
32
30
 
33
- # @!attribute api_endpoint
34
- # @return [String] Base URL for API requests. (default: https://api.dnsimple.com/)
35
31
  # @!attribute username
32
+ # @see https://developer.dnsimple.com/v2/#authentication
36
33
  # @return [String] DNSimple username for Basic Authentication
37
34
  # @!attribute password
38
- # @see http://developer.dnsimple.com/authentication/
35
+ # @see https://developer.dnsimple.com/v2/#authentication
39
36
  # @return [String] DNSimple password for Basic Authentication
40
- # @!attribute exchange_token
41
- # @see http://developer.dnsimple.com/authentication/
42
- # @return [String] Exchange Token for Basic Authentication with 2FA
43
- # @!attribute api_token
44
- # @see http://developer.dnsimple.com/authentication/
45
- # @return [String] API access token for authentication
46
37
  # @!attribute domain_api_token
47
- # @see http://developer.dnsimple.com/authentication/
38
+ # @see https://developer.dnsimple.com/v2/#authentication
39
+ # @return [String] Domain API access token for authentication
40
+ # @!attribute access_token
41
+ # @see https://developer.dnsimple.com/v2/#authentication
48
42
  # @return [String] Domain API access token for authentication
43
+ # @!attribute base_url
44
+ # @return [String] Base URL for API requests. (default: https://api.dnsimple.com/)
49
45
  # @!attribute user_agent
50
46
  # @return [String] Configure User-Agent header for requests.
51
47
  # @!attribute proxy
52
48
  # @return [String,nil] Configure address:port values for proxy server
53
49
 
54
- attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
55
- :user_agent, :proxy
50
+ attr_accessor :username, :password, :domain_api_token, :access_token,
51
+ :base_url, :user_agent, :proxy
56
52
 
57
53
 
58
54
  def initialize(options = {})
@@ -66,61 +62,79 @@ module Dnsimple
66
62
  end
67
63
 
68
64
 
65
+ # @return [String] Base URL for API requests.
66
+ def base_url
67
+ Extra.join_uri(@base_url, "")
68
+ end
69
+
70
+
69
71
  # Make a HTTP GET request.
70
72
  #
71
- # @param [String] path The path, relative to {#api_endpoint}
72
- # @param [Hash] options Query and header params for request
73
+ # @param [String] path The path, relative to {#base_url}
74
+ # @param [Hash] options The query and header params for the request
73
75
  # @return [HTTParty::Response]
74
76
  def get(path, options = {})
75
- execute :get, path, options
77
+ execute :get, path, nil, options
76
78
  end
77
79
 
78
80
  # Make a HTTP POST request.
79
81
  #
80
- # @param [String] path The path, relative to {#api_endpoint}
81
- # @param [Hash] options Body and header params for request
82
+ # @param [String] path The path, relative to {#base_url}
83
+ # @param [Hash] data The body for the request
84
+ # @param [Hash] options The query and header params for the request
82
85
  # @return [HTTParty::Response]
83
- def post(path, options = {})
84
- execute :post, path, options
86
+ def post(path, data = nil, options= {})
87
+ execute :post, path, data, options
85
88
  end
86
89
 
87
90
  # Make a HTTP PUT request.
88
91
  #
89
- # @param [String] path The path, relative to {#api_endpoint}
90
- # @param [Hash] options Body and header params for request
92
+ # @param [String] path The path, relative to {#base_url}
93
+ # @param [Hash] data The body for the request
94
+ # @param [Hash] options The query and header params for the request
91
95
  # @return [HTTParty::Response]
92
- def put(path, options = {})
93
- execute :put, path, options
96
+ def put(path, data = nil, options = {})
97
+ execute :put, path, data, options
94
98
  end
95
99
 
96
- # Make a HTTP DELETE request.
100
+ # Make a HTTP PATCH request.
97
101
  #
98
- # @param [String] path The path, relative to {#api_endpoint}
99
- # @param [Hash] options Query and header params for request
102
+ # @param [String] path The path, relative to {#base_url}
103
+ # @param [Hash] data The body for the request
104
+ # @param [Hash] options The query and header params for the request
100
105
  # @return [HTTParty::Response]
101
- def delete(path, options = {})
102
- execute :delete, path, options
106
+ def patch(path, data = nil, options = {})
107
+ execute :patch, path, data, options
103
108
  end
104
109
 
110
+ # Make a HTTP DELETE request.
111
+ #
112
+ # @param [String] path The path, relative to {#base_url}
113
+ # @param [Hash] options The query and header params for the request
114
+ # @return [HTTParty::Response]
115
+ def delete(path, data = nil, options = {})
116
+ execute :delete, path, data, options
117
+ end
105
118
 
106
119
  # Executes a request, validates and returns the response.
107
120
  #
108
121
  # @param [String] method The HTTP method
109
- # @param [String] path The path, relative to {#api_endpoint}
110
- # @param [Hash] options Query and header params for request
122
+ # @param [String] path The path, relative to {#base_url}
123
+ # @param [Hash] data The body for the request
124
+ # @param [Hash] options The query and header params for the request
111
125
  # @return [HTTParty::Response]
112
126
  # @raise [RequestError]
113
127
  # @raise [NotFoundError]
114
128
  # @raise [AuthenticationFailed]
115
129
  # @raise [TwoFactorAuthenticationRequired]
116
- def execute(method, path, data, options = {})
130
+ def execute(method, path, data = nil, options = {})
117
131
  response = request(method, path, data, options)
118
132
 
119
133
  case response.code
120
134
  when 200..299
121
135
  response
122
136
  when 401
123
- raise (response.headers[HEADER_OTP_TOKEN] == "required" ? TwoFactorAuthenticationRequired : AuthenticationFailed), response["message"]
137
+ raise AuthenticationFailed.new(response["message"])
124
138
  when 404
125
139
  raise NotFoundError.new(response)
126
140
  else
@@ -128,7 +142,6 @@ module Dnsimple
128
142
  end
129
143
  end
130
144
 
131
-
132
145
  # Make a HTTP request.
133
146
  #
134
147
  # This method doesn't validate the response and never raise errors
@@ -138,25 +151,14 @@ module Dnsimple
138
151
  # Therefore, it's up to the caller to properly handle and validate the response.
139
152
  #
140
153
  # @param [String] method The HTTP method
141
- # @param [String] path The path, relative to {#api_endpoint}
142
- # @param [Hash] options Query and header params for request
154
+ # @param [String] path The path, relative to {#base_url}
155
+ # @param [Hash] data The body for the request
156
+ # @param [Hash] options The query and header params for the request
143
157
  # @return [HTTParty::Response]
144
- def request(method, path, data, options = {})
145
- if data.is_a?(Hash)
146
- options[:query] = data.delete(:query) if data.key?(:query)
147
- options[:headers] = data.delete(:headers) if data.key?(:headers)
148
- end
149
- if !data.empty?
150
- options[:body] = data
151
- end
158
+ def request(method, path, data = nil, options = {})
159
+ options[:body] = data if data
152
160
 
153
- HTTParty.send(method, api_endpoint + path, Extra.deep_merge!(base_options, options))
154
- end
155
-
156
-
157
- # @return [String] Base URL for API requests.
158
- def api_endpoint
159
- Extra.join_uri(@api_endpoint, "")
161
+ HTTParty.send(method, base_url + path, Extra.deep_merge!(base_options, options))
160
162
  end
161
163
 
162
164
 
@@ -173,16 +175,14 @@ module Dnsimple
173
175
  options.merge!(http_proxyaddr: address, http_proxyport: port)
174
176
  end
175
177
 
176
- if exchange_token
177
- options[:basic_auth] = { username: exchange_token, password: "x-2fa-basic" }
178
- elsif password
178
+ if password
179
179
  options[:basic_auth] = { username: username, password: password }
180
180
  elsif domain_api_token
181
181
  options[:headers][HEADER_DOMAIN_API_TOKEN] = domain_api_token
182
- elsif api_token
183
- options[:headers][HEADER_API_TOKEN] = "#{username}:#{api_token}"
182
+ elsif access_token
183
+ options[:headers][HEADER_AUTHORIZATION] = "Bearer #{access_token}"
184
184
  else
185
- raise Error, 'A password or API token is required for all API requests.'
185
+ raise Error, 'A password, domain API token or access token is required for all API requests.'
186
186
  end
187
187
 
188
188
  options