ivapi 1.5.0 → 1.6.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -7
  3. data/.travis.yml +2 -2
  4. data/Gemfile +6 -4
  5. data/LICENSE +1 -1
  6. data/README.md +1 -3
  7. data/Rakefile +2 -0
  8. data/ivapi.gemspec +34 -20
  9. data/lib/ivapi.rb +3 -0
  10. data/lib/ivapi/authentication.rb +2 -0
  11. data/lib/ivapi/client.rb +2 -0
  12. data/lib/ivapi/client/account.rb +2 -0
  13. data/lib/ivapi/client/base.rb +2 -0
  14. data/lib/ivapi/client/hosting.rb +2 -0
  15. data/lib/ivapi/client/server.rb +2 -0
  16. data/lib/ivapi/configuration.rb +2 -0
  17. data/lib/ivapi/default.rb +4 -2
  18. data/lib/ivapi/error.rb +3 -1
  19. data/lib/ivapi/mash.rb +2 -0
  20. data/lib/ivapi/response/raise_error.rb +2 -0
  21. data/lib/ivapi/response/rename_keys.rb +2 -0
  22. data/lib/ivapi/version.rb +3 -1
  23. metadata +18 -70
  24. data/spec/fixtures/account_bonuses.json +0 -20
  25. data/spec/fixtures/account_credits.json +0 -1
  26. data/spec/fixtures/account_info.json +0 -42
  27. data/spec/fixtures/account_orders.json +0 -29
  28. data/spec/fixtures/account_services.json +0 -35
  29. data/spec/fixtures/hosting_info.json +0 -3
  30. data/spec/fixtures/server_change.json +0 -3
  31. data/spec/fixtures/server_domain.json +0 -3
  32. data/spec/fixtures/server_firewall.json +0 -3
  33. data/spec/fixtures/server_flush_iptables.json +0 -3
  34. data/spec/fixtures/server_graphs.json +0 -26
  35. data/spec/fixtures/server_info.json +0 -30
  36. data/spec/fixtures/server_move_ip.json +0 -4
  37. data/spec/fixtures/server_os.json +0 -132
  38. data/spec/fixtures/server_ptr.json +0 -4
  39. data/spec/fixtures/server_reboot.json +0 -3
  40. data/spec/fixtures/server_recreate.json +0 -3
  41. data/spec/fixtures/server_reset_password.json +0 -3
  42. data/spec/fixtures/server_tasks.json +0 -14
  43. data/spec/fixtures/version.json +0 -3
  44. data/spec/ivapi/client/account_spec.rb +0 -95
  45. data/spec/ivapi/client/hosting_spec.rb +0 -32
  46. data/spec/ivapi/client/server_spec.rb +0 -191
  47. data/spec/ivapi/client_spec.rb +0 -62
  48. data/spec/ivapi/error_spec.rb +0 -22
  49. data/spec/ivapi_spec.rb +0 -7
  50. data/spec/spec_helper.rb +0 -66
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ivapi::Client::Server do
4
- before do
5
- Ivapi.configure do |config|
6
- config.username = 'foo'
7
- config.password = 'bar'
8
- config.hosting_id = 1
9
- end
10
- end
11
-
12
- after do
13
- Ivapi.reset!
14
- end
15
-
16
- describe '#information' do
17
- let(:info) { Ivapi.hosting.information }
18
-
19
- before do
20
- stub_command('hosting_info', id: 1)
21
- .to_return(json_response('hosting_info.json'))
22
- end
23
-
24
- it 'has alias info method' do
25
- expect(Ivapi.hosting.info).to eq(info)
26
- end
27
-
28
- it 'has correct id' do
29
- expect(info.id).to eq('1')
30
- end
31
- end
32
- end
@@ -1,191 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ivapi::Client::Server do
4
- before(:each) do
5
- Ivapi.configure do |config|
6
- config.username = 'foo'
7
- config.password = 'bar'
8
- config.server_id = 3
9
- end
10
- end
11
-
12
- after(:each) do
13
- Ivapi.reset!
14
- end
15
-
16
- describe 'server information' do
17
- before(:each) do
18
- stub_command('server_info', id: 3)
19
- .to_return(json_response('server_info.json'))
20
- @info = Ivapi.server.information
21
- end
22
-
23
- it 'should response with alias method' do
24
- expect(Ivapi.server.info.domain).to eq('server.example.com')
25
- end
26
-
27
- it 'should return domain name' do
28
- expect(@info.domain).to eq('server.example.com')
29
- end
30
-
31
- it 'should return node name' do
32
- expect(@info.info.node).to eq('Robinija')
33
- end
34
- end
35
-
36
- describe 'server tasks' do
37
- before(:each) do
38
- stub_command('server_tasks', id: 3, count: 1)
39
- .to_return(json_response('server_tasks.json'))
40
- @tasks = Ivapi.server.tasks(1)
41
- @task = @tasks.first
42
- end
43
-
44
- it 'should return params domain name' do
45
- expect(@task.params.domain).to eq('server.example.com')
46
- end
47
- end
48
-
49
- describe 'server graphs' do
50
- before(:each) do
51
- stub_command('server_graphs', id: 3, width: 1000, ip: '12.23.34.45')
52
- .to_return(json_response('server_graphs.json'))
53
- @graphs = Ivapi.server.graphs(1000, '12.23.34.45')
54
- end
55
-
56
- it 'should return cpu weekly' do
57
- expect(@graphs.cpu_weekly).to eq('//stats.serveriai.lt/graph.php?Ds252x')
58
- end
59
- end
60
-
61
- it 'should return server tasks with specified options' do
62
- stub_command('server_tasks', id: 3, count: 1, task_id: 1)
63
- .to_return(json_response('server_tasks.json'))
64
- server_tasks = Ivapi.client.server(3).tasks(1, task_id: 1)
65
- expect(server_tasks.first.params.domain).to eq('server.example.com')
66
- end
67
-
68
- describe 'server os' do
69
- before(:each) do
70
- stub_command('server_os', id: 3)
71
- .to_return(json_response('server_os.json'))
72
- @os = Ivapi.server.os['debian-6.0-x86_64']
73
- end
74
-
75
- it 'should return cpu weekly' do
76
- expect(@os.title).to eq('Debian 6')
77
- end
78
- end
79
-
80
- describe 'server reboot' do
81
- before(:each) do
82
- stub_command('server_reboot', id: 3)
83
- .to_return(json_response('server_reboot.json'))
84
- @reboot_response = Ivapi.server.reboot
85
- end
86
-
87
- it 'should return task id' do
88
- expect(@reboot_response.task_id).to eq('11')
89
- end
90
- end
91
-
92
- describe 'server recreate server' do
93
- before(:each) do
94
- stub_command('server_recreate', id: 3, os: 'debian-6.0-x86_64')
95
- .to_return(json_response('server_recreate.json'))
96
- @recreate_response = Ivapi.server.recreate('debian-6.0-x86_64')
97
- end
98
-
99
- it 'should return task id' do
100
- expect(@recreate_response.task_id).to eq('12')
101
- end
102
- end
103
-
104
- describe 'reset server password' do
105
- before(:each) do
106
- stub_command('server_reset_password', id: 3)
107
- .to_return(json_response('server_reset_password.json'))
108
- @reset_pwd_response = Ivapi.server.reset_password
109
- end
110
-
111
- it 'should return task id' do
112
- expect(@reset_pwd_response.task_id).to eq('13')
113
- end
114
- end
115
-
116
- describe 'flush server iptables' do
117
- before(:each) do
118
- stub_command('server_flush_iptables', id: 3)
119
- .to_return(json_response('server_flush_iptables.json'))
120
- @flush_response = Ivapi.server.flush_iptables
121
- end
122
-
123
- it 'should return task id' do
124
- expect(@flush_response.task_id).to eq('16')
125
- end
126
- end
127
-
128
- describe 'change server firewall settings' do
129
- before(:each) do
130
- stub_command('server_firewall', id: 3)
131
- .to_return(json_response('server_firewall.json'))
132
- @firewall = Ivapi.server.firewall
133
- end
134
-
135
- it 'should return correct pps' do
136
- expect(@firewall.pps).to eq('1000')
137
- end
138
- end
139
-
140
- describe '#ptr' do
141
- let(:ptr) { Ivapi.server.ptr(ip: '1.2.3.4', domain: 'example.com') }
142
- before do
143
- stub_command('server_ptr', id: 3, ip: '1.2.3.4', domain: 'example.com')
144
- .to_return(json_response('server_ptr.json'))
145
- end
146
-
147
- it 'has correct domain' do
148
- expect(ptr.domain).to eq('example.com')
149
- end
150
- end
151
-
152
- describe '#move_ip' do
153
- let(:move_ip) { Ivapi.server.move_ip('1.2.3.4', 123) }
154
- before do
155
- stub_command('server_move_ip', id: 3, ip: '1.2.3.4', target_id: 123)
156
- .to_return(json_response('server_move_ip.json'))
157
- end
158
-
159
- it 'has correct ip address' do
160
- expect(move_ip.ip).to eq('1.2.3.4')
161
- end
162
- end
163
-
164
- describe 'change server plan' do
165
- before(:each) do
166
- stub_command('server_change', id: 3)
167
- .to_return(json_response('server_change.json'))
168
- @plan_response = Ivapi.server.change
169
- end
170
-
171
- it 'should return correct pps' do
172
- expect(@plan_response.task_id).to eq('14')
173
- end
174
- end
175
-
176
- describe 'change server hostname' do
177
- before(:each) do
178
- stub_command('server_domain', id: 3, domain: 'example.com')
179
- .to_return(json_response('server_domain.json'))
180
- @hostname_response = Ivapi.server.domain('example.com')
181
- end
182
-
183
- it 'should return task id' do
184
- expect(@hostname_response.task_id).to eq('15')
185
- end
186
-
187
- it 'should response with alias method' do
188
- expect(Ivapi.server.hostname('example.com').task_id).to eq('15')
189
- end
190
- end
191
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ivapi::Client do
4
- after(:each) do
5
- Ivapi.reset!
6
- end
7
-
8
- it 'works with basic auth and password' do
9
- expect { Ivapi::Client.new(username: 'foo', password: 'bar') }
10
- .not_to raise_exception
11
- end
12
-
13
- describe 'authentication' do
14
- it 'should possible to authenticate with configure' do
15
- Ivapi.configure do |config|
16
- config.username = 'foo'
17
- config.password = 'bar'
18
- end
19
-
20
- expect(Ivapi.client).to be_authenticated
21
- end
22
-
23
- it 'should possible to authenticate with basic username and password' do
24
- client = Ivapi::Client.new(username: 'foo', password: 'bar')
25
- expect(client).to be_authenticated
26
- end
27
-
28
- it 'should not possible to authenticate without username and password' do
29
- client = Ivapi::Client.new
30
- expect(client).to_not be_authenticated
31
- end
32
- end
33
-
34
- describe 'setting server id from client' do
35
- it 'should not have server id' do
36
- client = Ivapi::Client.new(username: 'foo', password: 'bar')
37
- expect(client.server_id).to be_nil
38
- end
39
-
40
- it 'should have server id when set manualy' do
41
- client = Ivapi::Client.new(username: 'foo', password: 'bar', server_id: 3)
42
- expect(client.server_id).to eq(3)
43
- end
44
- end
45
-
46
- describe 'manualy setting server id' do
47
- before(:each) do
48
- Ivapi.configure do |config|
49
- config.username = 'foo'
50
- config.password = 'bar'
51
- end
52
- end
53
-
54
- it 'should not have server id' do
55
- expect(Ivapi.server_id).to be_nil
56
- end
57
-
58
- it 'should have server id when set manualy' do
59
- expect(Ivapi.server(3).server_id).to eq(3)
60
- end
61
- end
62
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- describe Ivapi::Error do
3
- describe '.from_response' do
4
- it 'has bad request error raised when status is 400' do
5
- response = { status: 400 }
6
- expect { raise Ivapi::Error.from_response(response) }
7
- .to raise_error(Ivapi::BadRequest)
8
- end
9
-
10
- it 'has unauthorized error raised when status is 401' do
11
- response = { status: 401 }
12
- expect { raise Ivapi::Error.from_response(response) }
13
- .to raise_error(Ivapi::Unauthorized)
14
- end
15
-
16
- it 'has forbidden error raised when status is 403' do
17
- response = { status: 403 }
18
- expect { raise Ivapi::Error.from_response(response) }
19
- .to raise_error(Ivapi::Forbidden)
20
- end
21
- end
22
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Ivapi do
4
- it 'responds to config' do
5
- expect(Ivapi.respond_to?(:account)).to be_truthy
6
- end
7
- end
@@ -1,66 +0,0 @@
1
- require 'simplecov'
2
-
3
- SimpleCov.formatters = [
4
- SimpleCov::Formatter::HTMLFormatter
5
- ]
6
-
7
- SimpleCov.start
8
-
9
- require 'ivapi'
10
- require 'rspec'
11
- require 'webmock/rspec'
12
-
13
- WebMock.disable_net_connect!(allow: ['codeclimate.com'])
14
-
15
- RSpec.configure do |config|
16
- config.expect_with :rspec do |c|
17
- c.syntax = :expect
18
- end
19
- end
20
-
21
- def stub_get(url)
22
- stub_request(:get, iv_url(url))
23
- end
24
-
25
- def stub_command(command, options = {})
26
- params = { command: command }
27
- params.merge!(options)
28
- client = @client || Ivapi.client
29
- params.merge!(client.authentication)
30
- stub_request(:get, 'https://api.iv.lt/json.php').with(query: params)
31
- end
32
-
33
- def fixture_path
34
- File.expand_path('fixtures', __dir__)
35
- end
36
-
37
- def fixture(file)
38
- File.new(fixture_path + '/' + file)
39
- end
40
-
41
- def json_response(file)
42
- {
43
- body: fixture(file),
44
- headers: {
45
- content_type: 'application/json; charset=utf-8'
46
- }
47
- }
48
- end
49
-
50
- def iv_url(url)
51
- if url =~ /^http/
52
- url
53
- else
54
- "https://api.iv.lt#{url}"
55
- end
56
- end
57
-
58
- def iv_command_url(command)
59
- data = { command: command }
60
-
61
- if @client && @client.authenticated?
62
- data.merge(nick: @client.username, password: @client.password)
63
- end
64
-
65
- iv_url('/json.php?' + URI.encode_www_form(data))
66
- end