atlantic_net 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 299bbd01dc49308dc29dcd96726cb87d285ea780
4
- data.tar.gz: 4a88ca4ab658e36d2304751256add890efb9aff5
3
+ metadata.gz: 1f11c5b0a4d7a3fa1b38dfebec04ff9426433a5a
4
+ data.tar.gz: d4458c00fd3b5ab52f232090be26444e72c925eb
5
5
  SHA512:
6
- metadata.gz: a71669c2dcb9c443e6a82dd7a2272b040b80bea41e449ce399caee070ccd86debe8a2ef2cadbfdc6924a9cfb7d2499d8de0c79c968ddb89964dbbe02c33ab5e4
7
- data.tar.gz: 13edd8a8cb2ce77f949d6fbea6ed3b0e7fb5c3e6f1b711cc586d9d12859879cf4dd4879c5f69f6c7ca48eb72109529bc406cae5bd51915212f6f6be35c07a4ae
6
+ metadata.gz: 235396cac8f1bb392921918f60848927fe6c8a738cd27a58776bf0cecb2ffdc41b696f0a67ddd7d350e163bd34cdbe2dda1fef5c1f2863ccd1fae9fd676949b7
7
+ data.tar.gz: 76af83ddec3aac53a6415c3bd92fffc760372d4edd5d92cd7263092baa1593f6adeac88dcc71b85a243fb93fec92c5f5c71e60061948b4fa7a0c6406f4f1bc27
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/jrstarke/atlantic_net.png?branch=master)](https://travis-ci.org/jrstarke/atlantic_net)
4
4
  [![Coverage Status](https://coveralls.io/repos/jrstarke/atlantic_net/badge.png)](https://coveralls.io/r/jrstarke/atlantic_net)
5
+ [![Gem Version](https://badge.fury.io/rb/atlantic_net.svg)](https://badge.fury.io/rb/atlantic_net)
6
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/jrstarke/atlantic_net/master/LICENSE)
5
7
 
6
8
  A lightweight ruby interface for interacting with the Atlantic.net API.
7
9
 
data/atlantic_net.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "atlantic_net"
3
- spec.version = "0.1.1"
3
+ spec.version = "0.1.2"
4
4
  spec.authors = ["Jamie Starke"]
5
5
  spec.email = ["git@jamiestarke.com"]
6
6
  spec.description = "A Ruby wrapper of the Atlantic.net API"
data/lib/atlantic_net.rb CHANGED
@@ -79,7 +79,12 @@ class AtlanticNet
79
79
  #
80
80
  def list_instances
81
81
  response = api_call('list-instances')
82
- response['list-instancesresponse']['instancesSet'].values
82
+ instances = response['list-instancesresponse']['instancesSet']
83
+ if instances
84
+ instances.values
85
+ else
86
+ []
87
+ end
83
88
  end
84
89
 
85
90
  # Restart a specific cloud server.
@@ -170,6 +175,9 @@ class AtlanticNet
170
175
  #
171
176
  # @return [Array<Hash>] A array of image descriptions
172
177
  #
178
+ # @raise [AtlanticNetException] if the image_id specified in the options does not
179
+ # match an image id on Atlantic.net
180
+ #
173
181
  def describe_images(options={})
174
182
  args = {}
175
183
 
@@ -198,7 +206,12 @@ class AtlanticNet
198
206
  response = api_call('describe-plan',options)
199
207
  end
200
208
 
201
- response["describe-planresponse"]["plans"].values
209
+ plans = response["describe-planresponse"]["plans"]
210
+ if plans.respond_to?(:values)
211
+ plans.values
212
+ else
213
+ []
214
+ end
202
215
  end
203
216
 
204
217
  # Retrieve the details of all SSH Keys associated with the account
@@ -207,7 +220,12 @@ class AtlanticNet
207
220
  #
208
221
  def list_ssh_keys
209
222
  response = api_call('list-sshkeys')
210
- response["list-sshkeysresponse"]["KeysSet"].values
223
+ keys_set = response["list-sshkeysresponse"]["KeysSet"]
224
+ if keys_set
225
+ keys_set.values
226
+ else
227
+ []
228
+ end
211
229
  end
212
230
 
213
231
 
@@ -112,15 +112,31 @@ describe AtlanticNet do
112
112
  ]
113
113
  }
114
114
 
115
- # it 'calls api_call with list-instances api' do
116
- # expect(subject).to receive(:api_call).with("list-instances").and_return(sample_api_response)
117
- # subject.list_instances
118
- # end
119
-
120
- it 'calls api_call with list-instances and returns a list of instance hashes' do
121
- allow(subject).to receive(:api_call).with("list-instances").and_return(sample_api_response)
122
- instances = subject.list_instances
123
- expect(instances).to eq expected_instances
115
+ context "instances have been set up" do
116
+ it 'calls api_call with list-instances and returns a list of instance hashes' do
117
+ allow(subject).to receive(:api_call).with("list-instances").and_return(sample_api_response)
118
+ instances = subject.list_instances
119
+ expect(instances).to eq expected_instances
120
+ end
121
+ end
122
+
123
+ context "no instances exist yet" do
124
+ let(:sample_api_response) {
125
+ {
126
+ "list-instancesresponse" => {
127
+ "requestid" => "310db3f4-4250-4b2e-8e18-57b967a767ab",
128
+ "instancesSet" => nil
129
+ },
130
+ "Timestamp"=>1464539924
131
+ }
132
+ }
133
+ let(:expected_instances) { [] }
134
+
135
+ it 'calls api_call with list-instances and returns an empty array' do
136
+ allow(subject).to receive(:api_call).with("list-instances").and_return(sample_api_response)
137
+ instances = subject.list_instances
138
+ expect(instances).to eq expected_instances
139
+ end
124
140
  end
125
141
  end
126
142
 
@@ -495,6 +511,31 @@ describe AtlanticNet do
495
511
  expect(result).to eq plan_descriptions
496
512
  end
497
513
  end
514
+
515
+ context 'No plans exist for options' do
516
+ let(:plan_name) { "GO" }
517
+ let(:platform) { "linux" }
518
+
519
+ let(:sample_api_response) {
520
+ {
521
+ "Timestamp" => 1439932362,
522
+ "describe-planresponse" => {
523
+ "plans" => [],
524
+ "requestid" => "4aae48ae-af7b-4bbd-9309-58aadbfd02d3"
525
+ }
526
+ }
527
+ }
528
+ let(:plan_descriptions) {
529
+ []
530
+ }
531
+ it 'calls api_call with describe-plan plan_name and platform and returns an empty array' do
532
+ expect(subject).to receive(:api_call)
533
+ .with("describe-plan", {plan_name: plan_name, platform: platform})
534
+ .and_return(sample_api_response)
535
+ result = subject.describe_plans({plan_name: plan_name, platform: platform})
536
+ expect(result).to eq plan_descriptions
537
+ end
538
+ end
498
539
  end
499
540
 
500
541
  describe "#list_ssh_keys" do
@@ -523,12 +564,35 @@ describe AtlanticNet do
523
564
  ]
524
565
  }
525
566
 
526
- it 'calls api_call with list-sshkeys and returns a list of ssh key hashes' do
527
- expect(subject).to receive(:api_call)
528
- .with("list-sshkeys")
529
- .and_return(sample_api_response)
530
- result = subject.list_ssh_keys
531
- expect(result).to eq ssh_keys
567
+ context 'SSH Keys on atlantic.net have been set' do
568
+ it 'calls api_call with list-sshkeys and returns a list of ssh key hashes' do
569
+ expect(subject).to receive(:api_call)
570
+ .with("list-sshkeys")
571
+ .and_return(sample_api_response)
572
+ result = subject.list_ssh_keys
573
+ expect(result).to eq ssh_keys
574
+ end
575
+ end
576
+
577
+ context 'No SSH Keys setup' do
578
+ let(:sample_api_response) {
579
+ {
580
+ "list-sshkeysresponse" => {
581
+ "requestid" => "ba77409d-e74a-4d86-a6b1-847ac2adb6dd",
582
+ "KeysSet" => nil
583
+ },
584
+ "Timestamp"=>1464539384
585
+ }
586
+ }
587
+ let(:ssh_keys) { [] }
588
+
589
+ it 'calls api_call with list-sshkeys and returns a nil KeysSet' do
590
+ expect(subject).to receive(:api_call)
591
+ .with("list-sshkeys")
592
+ .and_return(sample_api_response)
593
+ result = subject.list_ssh_keys
594
+ expect(result).to eq ssh_keys
595
+ end
532
596
  end
533
597
  end
534
598
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlantic_net
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Starke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  requirements: []
203
203
  rubyforge_project:
204
- rubygems_version: 2.4.6
204
+ rubygems_version: 2.5.1
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: A Ruby wrapper of the Atlantic.net API