droplet_kit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +70 -0
  7. data/Rakefile +2 -0
  8. data/droplet_kit.gemspec +33 -0
  9. data/lib/droplet_kit.rb +63 -0
  10. data/lib/droplet_kit/client.rb +58 -0
  11. data/lib/droplet_kit/mappings/action_mapping.rb +19 -0
  12. data/lib/droplet_kit/mappings/backup_mapping.rb +19 -0
  13. data/lib/droplet_kit/mappings/domain_mapping.rb +15 -0
  14. data/lib/droplet_kit/mappings/domain_record_mapping.rb +18 -0
  15. data/lib/droplet_kit/mappings/droplet_mapping.rb +38 -0
  16. data/lib/droplet_kit/mappings/error_mapping.rb +19 -0
  17. data/lib/droplet_kit/mappings/image_action_mapping.rb +19 -0
  18. data/lib/droplet_kit/mappings/image_mapping.rb +17 -0
  19. data/lib/droplet_kit/mappings/kernel_mapping.rb +14 -0
  20. data/lib/droplet_kit/mappings/network_detail_mapping.rb +15 -0
  21. data/lib/droplet_kit/mappings/network_mapping.rb +12 -0
  22. data/lib/droplet_kit/mappings/region_mapping.rb +16 -0
  23. data/lib/droplet_kit/mappings/size_mapping.rb +15 -0
  24. data/lib/droplet_kit/mappings/snapshot_mapping.rb +19 -0
  25. data/lib/droplet_kit/mappings/ssh_key_mapping.rb +17 -0
  26. data/lib/droplet_kit/models/action.rb +12 -0
  27. data/lib/droplet_kit/models/backup.rb +12 -0
  28. data/lib/droplet_kit/models/base_model.rb +13 -0
  29. data/lib/droplet_kit/models/domain.rb +10 -0
  30. data/lib/droplet_kit/models/domain_record.rb +11 -0
  31. data/lib/droplet_kit/models/droplet.rb +15 -0
  32. data/lib/droplet_kit/models/image.rb +10 -0
  33. data/lib/droplet_kit/models/image_action.rb +12 -0
  34. data/lib/droplet_kit/models/kernel.rb +7 -0
  35. data/lib/droplet_kit/models/meta_information.rb +14 -0
  36. data/lib/droplet_kit/models/network.rb +4 -0
  37. data/lib/droplet_kit/models/network_hash.rb +4 -0
  38. data/lib/droplet_kit/models/pagination_information.rb +17 -0
  39. data/lib/droplet_kit/models/region.rb +9 -0
  40. data/lib/droplet_kit/models/size.rb +8 -0
  41. data/lib/droplet_kit/models/snapshot.rb +12 -0
  42. data/lib/droplet_kit/models/ssh_key.rb +8 -0
  43. data/lib/droplet_kit/paginated_resource.rb +71 -0
  44. data/lib/droplet_kit/resources/action_resource.rb +17 -0
  45. data/lib/droplet_kit/resources/domain_record_resource.rb +31 -0
  46. data/lib/droplet_kit/resources/domain_resource.rb +26 -0
  47. data/lib/droplet_kit/resources/droplet_action_resource.rb +49 -0
  48. data/lib/droplet_kit/resources/droplet_resource.rb +44 -0
  49. data/lib/droplet_kit/resources/image_action_resource.rb +14 -0
  50. data/lib/droplet_kit/resources/image_resource.rb +26 -0
  51. data/lib/droplet_kit/resources/region_resource.rb +13 -0
  52. data/lib/droplet_kit/resources/size_resource.rb +13 -0
  53. data/lib/droplet_kit/resources/ssh_key_resource.rb +26 -0
  54. data/lib/droplet_kit/version.rb +3 -0
  55. data/spec/fixtures/actions/all.json +17 -0
  56. data/spec/fixtures/actions/find.json +12 -0
  57. data/spec/fixtures/domain_records/all.json +52 -0
  58. data/spec/fixtures/domain_records/create.json +11 -0
  59. data/spec/fixtures/domain_records/find.json +11 -0
  60. data/spec/fixtures/domain_records/update.json +11 -0
  61. data/spec/fixtures/domains/all.json +12 -0
  62. data/spec/fixtures/domains/create.json +7 -0
  63. data/spec/fixtures/domains/find.json +7 -0
  64. data/spec/fixtures/droplets/all.json +84 -0
  65. data/spec/fixtures/droplets/create.json +79 -0
  66. data/spec/fixtures/droplets/find.json +79 -0
  67. data/spec/fixtures/droplets/list_actions.json +17 -0
  68. data/spec/fixtures/droplets/list_backups.json +18 -0
  69. data/spec/fixtures/droplets/list_kernels.json +17 -0
  70. data/spec/fixtures/droplets/list_snapshots.json +18 -0
  71. data/spec/fixtures/image_actions/create.json +12 -0
  72. data/spec/fixtures/image_actions/find.json +12 -0
  73. data/spec/fixtures/images/all.json +29 -0
  74. data/spec/fixtures/images/find.json +13 -0
  75. data/spec/fixtures/regions/all.json +47 -0
  76. data/spec/fixtures/sizes/all.json +35 -0
  77. data/spec/fixtures/ssh_keys/all.json +13 -0
  78. data/spec/fixtures/ssh_keys/create.json +8 -0
  79. data/spec/fixtures/ssh_keys/find.json +8 -0
  80. data/spec/fixtures/ssh_keys/update.json +8 -0
  81. data/spec/lib/droplet_kit/client_spec.rb +22 -0
  82. data/spec/lib/droplet_kit/paginated_resource_spec.rb +69 -0
  83. data/spec/lib/droplet_kit/resources/action_resource_spec.rb +26 -0
  84. data/spec/lib/droplet_kit/resources/domain_record_resource_spec.rb +83 -0
  85. data/spec/lib/droplet_kit/resources/domain_resource_spec.rb +53 -0
  86. data/spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb +150 -0
  87. data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +194 -0
  88. data/spec/lib/droplet_kit/resources/image_action_resource_spec.rb +45 -0
  89. data/spec/lib/droplet_kit/resources/image_resource_spec.rb +56 -0
  90. data/spec/lib/droplet_kit/resources/region_resource_spec.rb +16 -0
  91. data/spec/lib/droplet_kit/resources/size_resource_spec.rb +16 -0
  92. data/spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb +80 -0
  93. data/spec/spec_helper.rb +11 -0
  94. data/spec/support/fake_server.rb +4 -0
  95. data/spec/support/null_hash_load.rb +9 -0
  96. data/spec/support/request_stub_helpers.rb +9 -0
  97. data/spec/support/resource_context.rb +4 -0
  98. metadata +309 -0
@@ -0,0 +1,79 @@
1
+ {
2
+ "droplet": {
3
+ "id": 19,
4
+ "name": "test.example.com",
5
+ "memory": 1024,
6
+ "vcpus": 2,
7
+ "disk": 20,
8
+ "region": {
9
+ "slug": "nyc1",
10
+ "name": "New York",
11
+ "sizes": [
12
+ "1024mb",
13
+ "512mb"
14
+ ],
15
+ "available": true,
16
+ "features": [
17
+ "virtio",
18
+ "private_networking",
19
+ "backups",
20
+ "ipv6"
21
+ ]
22
+ },
23
+ "image": {
24
+ "id": 119192817,
25
+ "name": "Ubuntu 13.04",
26
+ "distribution": "ubuntu",
27
+ "slug": "ubuntu1304",
28
+ "public": true,
29
+ "regions": [
30
+ "nyc1"
31
+ ],
32
+ "created_at": "2014-07-29T14:35:37Z"
33
+ },
34
+ "size": {
35
+ "slug": "1024mb",
36
+ "transfer": 2,
37
+ "price_monthly": 10.0,
38
+ "price_hourly": 0.01488
39
+ },
40
+ "locked": false,
41
+ "status": "active",
42
+ "networks": {
43
+ "v4": [
44
+ {
45
+ "ip_address": "127.0.0.19",
46
+ "netmask": "255.255.255.0",
47
+ "gateway": "127.0.0.20",
48
+ "type": "public"
49
+ }
50
+ ],
51
+ "v6": [
52
+ {
53
+ "ip_address": "2001::13",
54
+ "cidr": 124,
55
+ "gateway": "2400:6180:0000:00D0:0000:0000:0009:7000",
56
+ "type": "public"
57
+ }
58
+ ]
59
+ },
60
+ "kernel": {
61
+ "id": 485432985,
62
+ "name": "DO-recovery-static-fsck",
63
+ "version": "3.8.0-25-generic"
64
+ },
65
+ "created_at": "2014-07-29T14:35:37Z",
66
+ "features": [
67
+ "ipv6"
68
+ ],
69
+ "backup_ids": [
70
+ 449676382
71
+ ],
72
+ "snapshot_ids": [
73
+ 449676383
74
+ ],
75
+ "action_ids": [
76
+
77
+ ]
78
+ }
79
+ }
@@ -0,0 +1,79 @@
1
+ {
2
+ "droplet": {
3
+ "id": 19,
4
+ "name": "test.example.com",
5
+ "memory": 1024,
6
+ "vcpus": 2,
7
+ "disk": 20,
8
+ "region": {
9
+ "slug": "nyc1",
10
+ "name": "New York",
11
+ "sizes": [
12
+ "1024mb",
13
+ "512mb"
14
+ ],
15
+ "available": true,
16
+ "features": [
17
+ "virtio",
18
+ "private_networking",
19
+ "backups",
20
+ "ipv6"
21
+ ]
22
+ },
23
+ "image": {
24
+ "id": 119192817,
25
+ "name": "Ubuntu 13.04",
26
+ "distribution": "ubuntu",
27
+ "slug": "ubuntu1304",
28
+ "public": true,
29
+ "regions": [
30
+ "nyc1"
31
+ ],
32
+ "created_at": "2014-07-29T14:35:37Z"
33
+ },
34
+ "size": {
35
+ "slug": "1024mb",
36
+ "transfer": 2,
37
+ "price_monthly": 10.0,
38
+ "price_hourly": 0.01488
39
+ },
40
+ "locked": false,
41
+ "status": "active",
42
+ "networks": {
43
+ "v4": [
44
+ {
45
+ "ip_address": "127.0.0.19",
46
+ "netmask": "255.255.255.0",
47
+ "gateway": "127.0.0.20",
48
+ "type": "public"
49
+ }
50
+ ],
51
+ "v6": [
52
+ {
53
+ "ip_address": "2001::13",
54
+ "cidr": 124,
55
+ "gateway": "2400:6180:0000:00D0:0000:0000:0009:7000",
56
+ "type": "public"
57
+ }
58
+ ]
59
+ },
60
+ "kernel": {
61
+ "id": 485432985,
62
+ "name": "DO-recovery-static-fsck",
63
+ "version": "3.8.0-25-generic"
64
+ },
65
+ "created_at": "2014-07-29T14:35:37Z",
66
+ "features": [
67
+ "ipv6"
68
+ ],
69
+ "backup_ids": [
70
+ 449676382
71
+ ],
72
+ "snapshot_ids": [
73
+ 449676383
74
+ ],
75
+ "action_ids": [
76
+
77
+ ]
78
+ }
79
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "actions": [
3
+ {
4
+ "id": 19,
5
+ "status": "in-progress",
6
+ "type": "create",
7
+ "started_at": "2014-07-29T14:35:39Z",
8
+ "completed_at": null,
9
+ "resource_id": 24,
10
+ "resource_type": "droplet",
11
+ "region": "nyc1"
12
+ }
13
+ ],
14
+ "meta": {
15
+ "total": 1
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "backups": [
3
+ {
4
+ "id": 449676388,
5
+ "name": "Ubuntu 13.04",
6
+ "distribution": "ubuntu",
7
+ "slug": null,
8
+ "public": false,
9
+ "regions": [
10
+ "nyc1"
11
+ ],
12
+ "created_at": "2014-07-29T14:35:38Z"
13
+ }
14
+ ],
15
+ "meta": {
16
+ "total": 1
17
+ }
18
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "kernels": [
3
+ {
4
+ "id": 61833229,
5
+ "name": "Ubuntu 14.04 x32 vmlinuz-3.13.0-24-generic",
6
+ "version": "3.13.0-24-generic"
7
+ },
8
+ {
9
+ "id": 485432972,
10
+ "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-24-generic (1221)",
11
+ "version": "3.13.0-24-generic"
12
+ }
13
+ ],
14
+ "meta": {
15
+ "total": 2
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "snapshots": [
3
+ {
4
+ "id": 449676387,
5
+ "name": "Ubuntu 13.04",
6
+ "distribution": "ubuntu",
7
+ "slug": null,
8
+ "public": false,
9
+ "regions": [
10
+ "nyc1"
11
+ ],
12
+ "created_at": "2014-07-29T14:35:38Z"
13
+ }
14
+ ],
15
+ "meta": {
16
+ "total": 1
17
+ }
18
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "action": {
3
+ "id": 23,
4
+ "status": "in-progress",
5
+ "type": "transfer",
6
+ "started_at": "2014-08-05T15:15:28Z",
7
+ "completed_at": null,
8
+ "resource_id": 449676391,
9
+ "resource_type": "image",
10
+ "region": "nyc1"
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "action": {
3
+ "id": 23,
4
+ "status": "in-progress",
5
+ "type": "transfer",
6
+ "started_at": "2014-08-05T15:15:28Z",
7
+ "completed_at": null,
8
+ "resource_id": 449676391,
9
+ "resource_type": "image",
10
+ "region": "nyc1"
11
+ }
12
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "images": [
3
+ {
4
+ "id": 119192817,
5
+ "name": "Ubuntu 13.04",
6
+ "distribution": "ubuntu",
7
+ "slug": "ubuntu1304",
8
+ "public": true,
9
+ "regions": [
10
+ "nyc1"
11
+ ],
12
+ "created_at": "2014-07-29T14:35:40Z"
13
+ },
14
+ {
15
+ "id": 449676376,
16
+ "name": "Ubuntu 13.04",
17
+ "distribution": "ubuntu",
18
+ "slug": "ubuntu1404",
19
+ "public": true,
20
+ "regions": [
21
+ "nyc1"
22
+ ],
23
+ "created_at": "2014-07-29T14:35:40Z"
24
+ }
25
+ ],
26
+ "meta": {
27
+ "total": 2
28
+ }
29
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "image": {
3
+ "id": 146,
4
+ "name": "Ubuntu 13.04",
5
+ "distribution": null,
6
+ "slug": null,
7
+ "public": false,
8
+ "regions": [
9
+ "region--1"
10
+ ],
11
+ "created_at": "2014-07-29T14:35:41Z"
12
+ }
13
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "regions": [
3
+ {
4
+ "slug": "nyc1",
5
+ "name": "New York",
6
+ "sizes": [
7
+
8
+ ],
9
+ "available": false,
10
+ "features": [
11
+ "virtio",
12
+ "private_networking",
13
+ "backups",
14
+ "ipv6"
15
+ ]
16
+ },
17
+ {
18
+ "slug": "sfo1",
19
+ "name": "San Francisco",
20
+ "sizes": [
21
+ "1gb",
22
+ "512mb"
23
+ ],
24
+ "available": true,
25
+ "features": [
26
+ "virtio",
27
+ "backups"
28
+ ]
29
+ },
30
+ {
31
+ "slug": "ams1",
32
+ "name": "Amsterdam",
33
+ "sizes": [
34
+ "1gb",
35
+ "512mb"
36
+ ],
37
+ "available": true,
38
+ "features": [
39
+ "virtio",
40
+ "backups"
41
+ ]
42
+ }
43
+ ],
44
+ "meta": {
45
+ "total": 3
46
+ }
47
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "sizes": [
3
+ {
4
+ "slug": "512mb",
5
+ "memory": 512,
6
+ "vcpus": 1,
7
+ "disk": 20,
8
+ "transfer": 1,
9
+ "price_monthly": 5.0,
10
+ "price_hourly": 0.00744,
11
+ "regions": [
12
+ "nyc1",
13
+ "ams1",
14
+ "sfo1"
15
+ ]
16
+ },
17
+ {
18
+ "slug": "1gb",
19
+ "memory": 1024,
20
+ "vcpus": 2,
21
+ "disk": 30,
22
+ "transfer": 2,
23
+ "price_monthly": 10.0,
24
+ "price_hourly": 0.01488,
25
+ "regions": [
26
+ "nyc1",
27
+ "ams1",
28
+ "sfo1"
29
+ ]
30
+ }
31
+ ],
32
+ "meta": {
33
+ "total": 2
34
+ }
35
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "ssh_keys": [
3
+ {
4
+ "id": 1,
5
+ "fingerprint": "f5:d1:78:ed:28:72:5f:e1:ac:94:fd:1f:e0:a3:48:6d",
6
+ "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDGk5V68BJ4P3Ereh779Vi/Ft2qs/rbXrcjKLGo6zsyeyFUE0svJUpRDEJvFSf8RlezKx1/1ulJu9+kZsxRiUKn example",
7
+ "name": "Example Key"
8
+ }
9
+ ],
10
+ "meta": {
11
+ "total": 1
12
+ }
13
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "ssh_key": {
3
+ "id": 2,
4
+ "fingerprint": "bf:3a:82:fc:4a:25:0b:a3:23:97:fb:4e:e4:88:e1:0e",
5
+ "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDbW5JSFLg70Z0/MNNUncNgfxnrHfjBSlWzyF3e+3tNLUVgGagZISnzF4Y03/aS79aiCmbd4vCEcxyB4Wxtpddh example",
6
+ "name": "Example Key"
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "ssh_key": {
3
+ "id": 3,
4
+ "fingerprint": "32:af:23:06:21:fb:e6:5b:d3:cc:7f:b7:00:0f:79:aa",
5
+ "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDZEgsAbWmQF+f8TU3F4fCg4yjVzdKudQbbhGb+qRKP5ju4Yo0Zzneia+oFm4bfzG+ydxUlOlbzq+Tpoj+INFv5 example",
6
+ "name": "Example Key"
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "ssh_key": {
3
+ "id": 123,
4
+ "fingerprint": "32:af:23:06:21:fb:e6:5b:d3:cc:7f:b7:00:0f:79:aa",
5
+ "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDZEgsAbWmQF+f8TU3F4fCg4yjVzdKudQbbhGb+qRKP5ju4Yo0Zzneia+oFm4bfzG+ydxUlOlbzq+Tpoj+INFv5 example",
6
+ "name": "Example Key"
7
+ }
8
+ }
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DropletKit::Client do
4
+ subject(:client) { DropletKit::Client.new(access_token: 'bunk') }
5
+
6
+ describe '#initialize' do
7
+ it 'initializes with an access token' do
8
+ client = DropletKit::Client.new(access_token: 'my-token')
9
+ expect(client.access_token).to eq('my-token')
10
+ end
11
+ end
12
+
13
+ describe '#connection' do
14
+ it 'populates the authorization header correctly' do
15
+ expect(client.connection.headers['Authorization']).to eq("Bearer #{client.access_token}")
16
+ end
17
+
18
+ it 'sets the content type' do
19
+ expect(client.connection.headers['Content-Type']).to eq("application/json")
20
+ end
21
+ end
22
+ end