droptoflare 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d9f1f4997bd2ad3921601f3522cb63f953a1aa2
4
- data.tar.gz: 2cf05fd60c42ffaaf61e4389d418b6b2ea756cd7
3
+ metadata.gz: 5206a2476c1518405ba79a15c60617010662003b
4
+ data.tar.gz: 5c5142dd3d4c8ccc52b8c8e497fc6112f06e0c18
5
5
  SHA512:
6
- metadata.gz: 6828113feed5ff94dce4f23ae7454f1de3d3b599ef31a9e70ec901f5d298db0beafd3aa38dde5c2f2235c2e74bc04e7b62fe104232949769801baece82836741
7
- data.tar.gz: 87d80f1b7bba0dc9a0b4a9f9cf85282ace8b298abd2e9433481209feae585540fa8c239a71dbc820c7267e3af2db6b8c505ab4e72d7ae6397624c5f5b009bc66
6
+ metadata.gz: 867aded3ad3d349dfbf12aa1263e3ed584d893227f5ed39f70dc4a7a43dfb13308d7dbebc6c2f1bc731d5b50bd75e1c711e16c863aa43ecd36f1903dcbd36d53
7
+ data.tar.gz: abefd38a02a8fb9ff8def4974a9005e8119f18b60f9e4ee4461c483cc2b6dbe5a45ddea7b502469394f164dae1dde738938e1cdc5feefdebef9b2396edf22639
data/.gemspec CHANGED
@@ -1,15 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'droptoflare'
3
- s.version = '0.0.2'
3
+ s.version = '0.0.4'
4
4
  s.author = 'Johan Haals'
5
5
  s.email = 'johan@haals.se'
6
6
  s.homepage = 'https://github.com/jhaals/droptoflare'
7
- s.summary = 'Populate Cloudflare DNS with DigitalOcean droplets'
7
+ s.summary = 'Populate Cloudflare DNS with DigitalOcean Droplets'
8
8
  s.license = 'Apache 2.0'
9
9
 
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.require_paths = ['lib', 'bin']
12
12
  s.executables = 'droptoflare'
13
- s.add_runtime_dependency 'httparty'
14
13
  end
15
14
 
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'droptoflare', :path => '.'
4
+ gem 'rspec'
5
+ gem 'vcr'
6
+ gem 'webmock'
7
+ gem 'multi_json'
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
  droptoflare adds your DigitalOcean Droplets as A records in Cloudflare.
3
3
  droptoflare will update DNS records if you re-create a Droplet with the same name.
4
4
 
5
- Please note that this code has poor error reporting and no tests.
5
+ ### Installation
6
+
7
+ gem install droptoflare
6
8
 
7
9
  Create `~/.droptoflare.yaml` and add the following
8
10
 
@@ -23,6 +25,6 @@ Run!
23
25
  Updated 0 record(s)
24
26
 
25
27
  ### Todo
26
- - tests
27
- - error handling
28
- - ability to set TTL (120s at the moment)
28
+ - more tests
29
+ - better error handling
30
+ - ability to set TTL (120s at the moment)
@@ -0,0 +1 @@
1
+ {"http_interactions":[{"request":{"method":"post","uri":"https://www.cloudflare.com/api_json.html","body":{"encoding":"UTF-8","string":"a=rec_load_all&tkn=access_token&email=johan%40haals.se&z=pyp.se"},"headers":{}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["cloudflare-nginx"],"Date":["Fri, 10 Oct 2014 14:29:29 GMT"],"Content-Type":["application/json"],"Transfer-Encoding":["chunked"],"Connection":["keep-alive"],"Set-Cookie":["__cfduid=de09a859009d80b70188528099bac0a1c1412951369196; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.cloudflare.com; HttpOnly","vses2=g7krd97t3hg9okt932f4o3idf3; path=/; domain=www.cloudflare.com; secure; HttpOnly"],"Expires":["Thu, 19 Nov 1981 08:52:00 GMT"],"Cache-Control":["no-store, no-cache, must-revalidate, post-check=0, pre-check=0"],"Pragma":["no-cache"],"Vary":["Accept-Encoding"],"Strict-Transport-Security":["max-age=31536000"],"Cf-Ray":["177382a97e680bf9-AMS"]},"body":{"encoding":"UTF-8","string":"{\"result\":\"error\",\"msg\":\"Invalid token or email\",\"err_code\":\"E_UNAUTH\"}"},"http_version":null},"recorded_at":"Fri, 10 Oct 2014 14:29:29 GMT"}],"recorded_with":"VCR 2.9.3"}
@@ -0,0 +1,69 @@
1
+ {
2
+ "http_interactions": [
3
+ {
4
+ "request": {
5
+ "method": "post",
6
+ "uri": "https://www.cloudflare.com/api_json.html",
7
+ "body": {
8
+ "encoding": "UTF-8",
9
+ "string": "a=rec_load_all&tkn=token&email=johan%40haals.se&z=pyp.se"
10
+ },
11
+ "headers": {
12
+
13
+ }
14
+ },
15
+ "response": {
16
+ "status": {
17
+ "code": 200,
18
+ "message": "OK"
19
+ },
20
+ "headers": {
21
+ "Server": [
22
+ "cloudflare-nginx"
23
+ ],
24
+ "Date": [
25
+ "Fri, 10 Oct 2014 14:24:27 GMT"
26
+ ],
27
+ "Content-Type": [
28
+ "application/json"
29
+ ],
30
+ "Transfer-Encoding": [
31
+ "chunked"
32
+ ],
33
+ "Connection": [
34
+ "keep-alive"
35
+ ],
36
+ "Set-Cookie": [
37
+ "__cfduid=ljk; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.cloudflare.com; HttpOnly",
38
+ "vses2=jkl; path=/; domain=www.cloudflare.com; secure; HttpOnly"
39
+ ],
40
+ "Expires": [
41
+ "Thu, 19 Nov 1981 08:52:00 GMT"
42
+ ],
43
+ "Cache-Control": [
44
+ "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
45
+ ],
46
+ "Pragma": [
47
+ "no-cache"
48
+ ],
49
+ "Vary": [
50
+ "Accept-Encoding"
51
+ ],
52
+ "Strict-Transport-Security": [
53
+ "max-age=31536000"
54
+ ],
55
+ "Cf-Ray": [
56
+ "17737b49374d0bf9-AMS"
57
+ ]
58
+ },
59
+ "body": {
60
+ "encoding": "UTF-8",
61
+ "string": "{\"request\":{\"act\":\"rec_load_all\"},\"response\":{\"recs\":{\"has_more\":false,\"count\":3,\"objs\":[{\"rec_id\":\"170347876\",\"rec_hash\":\"672943c14463f56c76890206c1313922\",\"zone_name\":\"pyp.se\",\"name\":\"d1.pyp.se\",\"display_name\":\"d1\",\"type\":\"A\",\"prio\":null,\"content\":\"178.62.36.22\",\"display_content\":\"178.62.36.22\",\"ttl\":\"120\",\"ttl_ceil\":86400,\"ssl_id\":\"89284\",\"ssl_status\":\"V\",\"ssl_expires_on\":null,\"auto_ttl\":0,\"service_mode\":\"0\",\"props\":{\"proxiable\":1,\"cloud_on\":0,\"cf_open\":1,\"ssl\":1,\"expired_ssl\":0,\"expiring_ssl\":0,\"pending_ssl\":0,\"vanity_lock\":0}},{\"rec_id\":\"171152869\",\"rec_hash\":\"62aa4f4a85ab2c3aed0ed7927df2a7ab\",\"zone_name\":\"pyp.se\",\"name\":\"t1.pyp.se\",\"display_name\":\"t1\",\"type\":\"A\",\"prio\":null,\"content\":\"178.62.20.222\",\"display_content\":\"178.62.20.222\",\"ttl\":\"120\",\"ttl_ceil\":86400,\"ssl_id\":\"89284\",\"ssl_status\":\"V\",\"ssl_expires_on\":null,\"auto_ttl\":0,\"service_mode\":\"0\",\"props\":{\"proxiable\":1,\"cloud_on\":0,\"cf_open\":1,\"ssl\":1,\"expired_ssl\":0,\"expiring_ssl\":0,\"pending_ssl\":0,\"vanity_lock\":0}},{\"rec_id\":\"170347888\",\"rec_hash\":\"4e3a8efa226d2019cf85f4dc05582c7c\",\"zone_name\":\"pyp.se\",\"name\":\"m.pyp.se\",\"display_name\":\"m\",\"type\":\"CNAME\",\"prio\":null,\"content\":\"d1.pyp.se\",\"display_content\":\"d1.pyp.se\",\"ttl\":\"1\",\"ttl_ceil\":86400,\"ssl_id\":\"89284\",\"ssl_status\":\"V\",\"ssl_expires_on\":null,\"auto_ttl\":1,\"service_mode\":\"0\",\"props\":{\"proxiable\":1,\"cloud_on\":0,\"cf_open\":1,\"ssl\":1,\"expired_ssl\":0,\"expiring_ssl\":0,\"pending_ssl\":0,\"vanity_lock\":0}}]}},\"result\":\"success\",\"msg\":null}"
62
+ },
63
+ "http_version": null
64
+ },
65
+ "recorded_at": "Fri, 10 Oct 2014 14:24:27 GMT"
66
+ }
67
+ ],
68
+ "recorded_with": "VCR 2.9.3"
69
+ }
@@ -0,0 +1,82 @@
1
+ {
2
+ "http_interactions": [
3
+ {
4
+ "request": {
5
+ "method": "get",
6
+ "uri": "https://api.digitalocean.com/v2/droplets",
7
+ "body": {
8
+ "encoding": "US-ASCII",
9
+ "string": ""
10
+ },
11
+ "headers": {
12
+ "Authorization": [
13
+ "Bearer token"
14
+ ]
15
+ }
16
+ },
17
+ "response": {
18
+ "status": {
19
+ "code": 200,
20
+ "message": "OK"
21
+ },
22
+ "headers": {
23
+ "Server": [
24
+ "cloudflare-nginx"
25
+ ],
26
+ "Date": [
27
+ "Fri, 10 Oct 2014 11:25:18 GMT"
28
+ ],
29
+ "Content-Type": [
30
+ "application/json; charset=utf-8"
31
+ ],
32
+ "Transfer-Encoding": [
33
+ "chunked"
34
+ ],
35
+ "Connection": [
36
+ "keep-alive"
37
+ ],
38
+ "Set-Cookie": [
39
+ "__cfduid=788974398745; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.digitalocean.com; HttpOnly"
40
+ ],
41
+ "Status": [
42
+ "200 OK"
43
+ ],
44
+ "Ratelimit-Limit": [
45
+ "1200"
46
+ ],
47
+ "Ratelimit-Remaining": [
48
+ "1193"
49
+ ],
50
+ "Ratelimit-Reset": [
51
+ "1412942947"
52
+ ],
53
+ "Etag": [
54
+ "W/\"a1691a2dce3ebd7f49fa4b528e9c7d6b\""
55
+ ],
56
+ "Cache-Control": [
57
+ "must-revalidate, private, max-age=0"
58
+ ],
59
+ "X-Request-Id": [
60
+ "ac73b7b03cc11fcac86701b11e51aac5"
61
+ ],
62
+ "X-Runtime": [
63
+ "0.223693"
64
+ ],
65
+ "X-Rack-Cache": [
66
+ "miss"
67
+ ],
68
+ "Cf-Ray": [
69
+ "177274dc31070f4b-FRA"
70
+ ]
71
+ },
72
+ "body": {
73
+ "encoding": "UTF-8",
74
+ "string": "{\n \"droplets\":[\n {\n \"id\":2793201,\n \"name\":\"d1\",\n \"memory\":1024,\n \"vcpus\":1,\n \"disk\":30,\n \"region\":{\n \"slug\":\"lon1\",\n \"name\":\"London 1\",\n \"sizes\":[\n \"512mb\",\n \"1gb\",\n \"2gb\",\n \"4gb\",\n \"8gb\",\n \"32gb\",\n \"48gb\",\n \"64gb\",\n \"16gb\"\n ],\n \"available\":true,\n \"features\":[\n \"virtio\",\n \"private_networking\",\n \"backups\",\n \"ipv6\",\n \"metadata\"\n ]\n },\n \"image\":{\n \"id\":6510539,\n \"name\":\"Ubuntu 14.04 x64\",\n \"distribution\":\"Ubuntu\",\n \"slug\":\"ubuntu-14-04-x64\",\n \"public\":true,\n \"regions\":[\n \"nyc1\",\n \"ams1\",\n \"sfo1\",\n \"nyc2\",\n \"ams2\",\n \"sgp1\",\n \"lon1\",\n \"nyc3\",\n \"ams3\"\n ],\n \"created_at\":\"2014-10-02T18:54:14Z\"\n },\n \"size\":{\n \"slug\":\"1gb\",\n \"transfer\":2,\n \"price_monthly\":10.0,\n \"price_hourly\":0.01488\n },\n \"locked\":false,\n \"status\":\"active\",\n \"networks\":{\n \"v4\":[\n {\n \"ip_address\":\"10.131.238.11\",\n \"netmask\":\"255.255.0.0\",\n \"gateway\":\"10.131.0.1\",\n \"type\":\"private\"\n },\n {\n \"ip_address\":\"178.62.36.22\",\n \"netmask\":\"255.255.192.0\",\n \"gateway\":\"178.62.0.1\",\n \"type\":\"public\"\n }\n ],\n \"v6\":[\n {\n \"ip_address\":\"2A03:B0C0:0001:00D0:0000:0000:00FC:D001\",\n \"cidr\":64,\n \"gateway\":\"2A03:B0C0:0001:00D0:0000:0000:0000:0001\",\n \"type\":\"public\"\n }\n ]\n },\n \"kernel\":{\n \"id\":1682,\n \"name\":\"Ubuntu 14.04 x64 vmlinuz-3.13.0-32-generic\",\n \"version\":\"3.13.0-32-generic\"\n },\n \"created_at\":\"2014-10-06T13:49:26Z\",\n \"features\":[\n \"private_networking\",\n \"ipv6\",\n \"virtio\"\n ],\n \"backup_ids\":[],\n \"snapshot_ids\":[]\n },\n {\n \"id\":2822856,\n \"name\":\"t1\",\n \"memory\":512,\n \"vcpus\":1,\n \"disk\":20,\n \"region\":{\n \"slug\":\"lon1\",\n \"name\":\"London 1\",\n \"sizes\":[\n \"512mb\",\n \"1gb\",\n \"2gb\",\n \"4gb\",\n \"8gb\",\n \"32gb\",\n \"48gb\",\n \"64gb\",\n \"16gb\"\n ],\n \"available\":true,\n \"features\":[\n \"virtio\",\n \"private_networking\",\n \"backups\",\n \"ipv6\",\n \"metadata\"\n ]\n },\n \"image\":{\n \"id\":6510539,\n \"name\":\"Ubuntu 14.04 x64\",\n \"distribution\":\"Ubuntu\",\n \"slug\":\"ubuntu-14-04-x64\",\n \"public\":true,\n \"regions\":[\n \"nyc1\",\n \"ams1\",\n \"sfo1\",\n \"nyc2\",\n \"ams2\",\n \"sgp1\",\n \"lon1\",\n \"nyc3\",\n \"ams3\"\n ],\n \"created_at\":\"2014-10-02T18:54:14Z\"\n },\n \"size\":{\n \"slug\":\"512mb\",\n \"transfer\":1,\n \"price_monthly\":5.0,\n \"price_hourly\":0.00744\n },\n \"locked\":false,\n \"status\":\"active\",\n \"networks\":{\n \"v4\":[\n {\n \"ip_address\":\"10.131.238.172\",\n \"netmask\":\"255.255.0.0\",\n \"gateway\":\"10.131.0.1\",\n \"type\":\"private\"\n },\n {\n \"ip_address\":\"178.62.20.222\",\n \"netmask\":\"255.255.192.0\",\n \"gateway\":\"178.62.0.1\",\n \"type\":\"public\"\n }\n ],\n \"v6\":[]\n },\n \"kernel\":{\n \"id\":1682,\n \"name\":\"Ubuntu 14.04 x64 vmlinuz-3.13.0-32-generic\",\n \"version\":\"3.13.0-32-generic\"\n },\n \"created_at\":\"2014-10-09T11:46:12Z\",\n \"features\":[\n \"private_networking\",\n \"virtio\"\n ],\n \"backup_ids\":[],\n \"snapshot_ids\":[]\n }\n ],\n \"meta\":{\n \"total\":2\n }\n}\n"
75
+ },
76
+ "http_version": null
77
+ },
78
+ "recorded_at": "Fri, 10 Oct 2014 11:25:19 GMT"
79
+ }
80
+ ],
81
+ "recorded_with": "VCR 2.9.3"
82
+ }
@@ -0,0 +1 @@
1
+ {"http_interactions":[{"request":{"method":"get","uri":"https://api.digitalocean.com/v2/droplets","body":{"encoding":"US-ASCII","string":""},"headers":{"Authorization":["Bearer t00ken"]}},"response":{"status":{"code":401,"message":"Unauthorized"},"headers":{"Server":["cloudflare-nginx"],"Date":["Fri, 10 Oct 2014 11:18:51 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Connection":["keep-alive"],"Set-Cookie":["__cfduid=23234235; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.digitalocean.com; HttpOnly"],"Status":["401 Unauthorized"],"Cache-Control":["no-store, private"],"Pragma":["no-cache"],"Www-Authenticate":["Bearer realm=\"DigitalOcean\", error=\"invalid_token\", error_description=\"The access token is invalid\""],"X-Request-Id":["7cb3304a7ec576bb554d613770acba0b"],"X-Runtime":["0.009026"],"X-Rack-Cache":["miss"],"Cf-Ray":["17726b66ea800f51-FRA"]},"body":{"encoding":"UTF-8","string":"{\"id\":\"unauthorized\",\"message\":\"Unable to authenticate you.\"}"},"http_version":null},"recorded_at":"Fri, 10 Oct 2014 11:18:51 GMT"}],"recorded_with":"VCR 2.9.3"}
@@ -1,6 +1,8 @@
1
1
  require 'json'
2
- require 'httparty'
2
+ require 'net/http'
3
+ require 'uri'
3
4
 
5
+ # methods to create/update/list Cloudflare A records
4
6
  class Cloudflare
5
7
  def initialize(cf_token, domain, email)
6
8
  @cf_token = cf_token
@@ -8,40 +10,31 @@ class Cloudflare
8
10
  @email = email
9
11
  end
10
12
 
13
+ # Create new A record
11
14
  def create_record(name, ip)
12
- options = {
13
- body: {
14
- a: 'rec_new',
15
- tkn: @cf_token,
16
- email: @email,
17
- z: @domain,
18
- name: name,
19
- content: ip,
20
- type: 'A',
21
- ttl: 120
22
- }
15
+ data = {
16
+ a: 'rec_new',
17
+ tkn: @cf_token,
18
+ email: @email,
19
+ z: @domain,
20
+ name: name,
21
+ content: ip,
22
+ type: 'A',
23
+ ttl: 120
23
24
  }
24
- r = JSON.parse(
25
- HTTParty.post('https://www.cloudflare.com/api_json.html', options).body)
26
- if r['result'] == 'error'
27
- puts r['msg']
28
- return false
29
- end
30
- return true if r['result'] == 'success'
25
+ query(data)
31
26
  end
32
27
 
28
+ # Return hash with all A records for domain
33
29
  def records
34
30
  entries = {}
35
- options = {
36
- body: {
37
- a: 'rec_load_all',
38
- tkn: @cf_token,
39
- email: @email,
40
- z: @domain
41
- }
31
+ data = {
32
+ a: 'rec_load_all',
33
+ tkn: @cf_token,
34
+ email: @email,
35
+ z: @domain
42
36
  }
43
- r = JSON.parse(
44
- HTTParty.post('https://www.cloudflare.com/api_json.html', options).body)
37
+ r = query(data)
45
38
  r['response']['recs']['objs'].each do |e|
46
39
  next if e['type'] != 'A'
47
40
  entries[e['name']] = { ip: e['content'], id: e['rec_id'] }
@@ -49,26 +42,29 @@ class Cloudflare
49
42
  entries
50
43
  end
51
44
 
45
+ # Update existing record
52
46
  def update_record(name, ip, id)
53
- options = {
54
- body: {
55
- a: 'rec_edit',
56
- tkn: @cf_token,
57
- email: @email,
58
- z: @domain,
59
- name: name,
60
- content: ip,
61
- id: id,
62
- type: 'A',
63
- ttl: 120
64
- }
47
+ data = {
48
+ a: 'rec_edit',
49
+ tkn: @cf_token,
50
+ email: @email,
51
+ z: @domain,
52
+ name: name,
53
+ content: ip,
54
+ id: id,
55
+ type: 'A',
56
+ ttl: 120
65
57
  }
66
- r = JSON.parse(
67
- HTTParty.post('https://www.cloudflare.com/api_json.html', options).body)
68
- if r['result'] == 'error'
69
- puts r['msg']
70
- return false
71
- end
72
- return true if r['result'] == 'success'
58
+ query(data)
59
+ end
60
+
61
+ private
62
+
63
+ def query(data)
64
+ uri = URI.parse('https://www.cloudflare.com/api_json.html')
65
+ resp = Net::HTTP.post_form(uri, data)
66
+ r = JSON.parse(resp.body)
67
+ fail r['msg'] if r['result'] != 'success'
68
+ r
73
69
  end
74
70
  end
@@ -1,15 +1,26 @@
1
- require 'httparty'
1
+ require 'net/http'
2
+ require 'uri'
2
3
  require 'json'
3
4
 
5
+ # list DigitalOcean Droplets
4
6
  class DigitalOcean
5
7
  def initialize(token)
6
8
  @token = token
7
9
  end
8
10
 
11
+ # Return hash with droplets: droplet_name => ipaddress
9
12
  def droplets
10
- r = HTTParty.get('https://api.digitalocean.com/v2/droplets',
11
- headers: { 'Authorization' => "Bearer #{@token}" })
12
- r = JSON.parse(r.body)
13
+ uri = URI.parse('https://api.digitalocean.com/v2/droplets')
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ http.use_ssl = true
16
+
17
+ req = Net::HTTP::Get.new(uri.request_uri)
18
+ req.add_field('Authorization', "Bearer #{@token}")
19
+
20
+ response = http.request(req)
21
+ r = JSON.parse(response.body)
22
+ fail r['message'] if response.code != '200'
23
+
13
24
  droplets = {}
14
25
  r['droplets'].each do |e|
15
26
  e['networks']['v4'].each do |i|
@@ -19,4 +30,4 @@ class DigitalOcean
19
30
  end
20
31
  droplets
21
32
  end
22
- end
33
+ end
@@ -0,0 +1,27 @@
1
+ require 'droptoflare/cloudflare'
2
+ require 'rspec'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
7
+ c.hook_into :webmock
8
+ end
9
+
10
+ RSpec.describe 'Cloudflare' do
11
+ it 'should raise NameError' do
12
+ expect { Cloudflare.new }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ cf = Cloudflare.new('access_token', 'pyp.se', 'johan@haals.se')
16
+ it 'should complain about invalid token or email' do
17
+ VCR.use_cassette('cf_invalid_token', serialize_with: :json) do
18
+ expect { cf.records }.to raise_error(RuntimeError, 'Invalid token or email')
19
+ end
20
+ end
21
+
22
+ it 'should list records' do
23
+ VCR.use_cassette('cf_records', serialize_with: :json) do
24
+ expect(cf.records).to include('d1.pyp.se' => { ip: '178.62.36.22', id: '170347876' })
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'droptoflare/digitalocean'
2
+ require 'rspec'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
7
+ c.hook_into :webmock
8
+ end
9
+
10
+ RSpec.describe 'DigitalOcean' do
11
+ it 'should raise NameError' do
12
+ expect { Digitalocean.new }.to raise_error(NameError)
13
+ end
14
+
15
+ it 'should complain about invalid token' do
16
+ VCR.use_cassette('do_invalid_token', serialize_with: :json) do
17
+ digitalocean = DigitalOcean.new('t00ken')
18
+ expect { digitalocean.droplets }.to raise_error(RuntimeError, 'Unable to authenticate you.')
19
+ end
20
+ end
21
+ it 'should return hash of droplets' do
22
+ VCR.use_cassette('do_droplets', serialize_with: :json) do
23
+ digitalocean = DigitalOcean.new('valid_token')
24
+ droplets = digitalocean.droplets
25
+ expect(droplets).to include('d1' => '178.62.36.22')
26
+ expect(droplets).to include('t1' => '178.62.20.222')
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droptoflare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Haals
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 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'
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description:
28
14
  email: johan@haals.se
29
15
  executables:
@@ -31,13 +17,19 @@ executables:
31
17
  extensions: []
32
18
  extra_rdoc_files: []
33
19
  files:
34
- - .gemspec
35
- - .gitignore
20
+ - ".gemspec"
21
+ - ".gitignore"
36
22
  - Gemfile
37
23
  - README.md
38
24
  - bin/droptoflare
25
+ - fixtures/vcr_cassettes/cf_invalid_token.json
26
+ - fixtures/vcr_cassettes/cf_records.json
27
+ - fixtures/vcr_cassettes/do_droplets.json
28
+ - fixtures/vcr_cassettes/do_invalid_token.json
39
29
  - lib/droptoflare/cloudflare.rb
40
30
  - lib/droptoflare/digitalocean.rb
31
+ - spec/cloudflare_spec.rb
32
+ - spec/digitalocean_spec.rb
41
33
  homepage: https://github.com/jhaals/droptoflare
42
34
  licenses:
43
35
  - Apache 2.0
@@ -49,18 +41,18 @@ require_paths:
49
41
  - bin
50
42
  required_ruby_version: !ruby/object:Gem::Requirement
51
43
  requirements:
52
- - - '>='
44
+ - - ">="
53
45
  - !ruby/object:Gem::Version
54
46
  version: '0'
55
47
  required_rubygems_version: !ruby/object:Gem::Requirement
56
48
  requirements:
57
- - - '>='
49
+ - - ">="
58
50
  - !ruby/object:Gem::Version
59
51
  version: '0'
60
52
  requirements: []
61
53
  rubyforge_project:
62
- rubygems_version: 2.0.14
54
+ rubygems_version: 2.2.2
63
55
  signing_key:
64
56
  specification_version: 4
65
- summary: Populate Cloudflare DNS with DigitalOcean droplets
57
+ summary: Populate Cloudflare DNS with DigitalOcean Droplets
66
58
  test_files: []