ivapi 0.0.6 → 1.0.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 (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -1
  4. data/.travis.yml +7 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +11 -1
  7. data/Guardfile +13 -0
  8. data/{LICENSE.txt → LICENSE.md} +0 -0
  9. data/README.md +28 -26
  10. data/Rakefile +8 -1
  11. data/ivapi.gemspec +20 -13
  12. data/lib/faraday/response/raise_ivapi_error.rb +24 -0
  13. data/lib/ivapi.rb +6 -30
  14. data/lib/ivapi/authentication.rb +15 -0
  15. data/lib/ivapi/client.rb +27 -0
  16. data/lib/ivapi/client/account.rb +30 -0
  17. data/lib/ivapi/client/server.rb +92 -0
  18. data/lib/ivapi/configuration.rb +43 -0
  19. data/lib/ivapi/connection.rb +29 -0
  20. data/lib/ivapi/error.rb +35 -0
  21. data/lib/ivapi/request.rb +22 -0
  22. data/lib/ivapi/version.rb +1 -1
  23. data/spec/fixtures/account_bonuses.json +20 -0
  24. data/spec/fixtures/account_info.json +42 -0
  25. data/spec/fixtures/account_orders.json +29 -0
  26. data/spec/fixtures/account_services.json +35 -0
  27. data/spec/fixtures/server_change.json +3 -0
  28. data/spec/fixtures/server_domain.json +3 -0
  29. data/spec/fixtures/server_graphs.json +26 -0
  30. data/spec/fixtures/server_info.json +30 -0
  31. data/spec/fixtures/server_os.json +132 -0
  32. data/spec/fixtures/server_reboot.json +3 -0
  33. data/spec/fixtures/server_recreate.json +3 -0
  34. data/spec/fixtures/server_reset_password.json +3 -0
  35. data/spec/fixtures/server_tasks.json +14 -0
  36. data/spec/fixtures/version.json +3 -0
  37. data/spec/ivapi/client/account_spec.rb +34 -0
  38. data/spec/ivapi/client/server_spec.rb +58 -0
  39. data/spec/ivapi/client_spec.rb +13 -0
  40. data/spec/spec_helper.rb +64 -15
  41. metadata +130 -21
  42. data/lib/ivapi/account.rb +0 -32
  43. data/lib/ivapi/base.rb +0 -23
  44. data/lib/ivapi/railtie.rb +0 -26
  45. data/lib/ivapi/server.rb +0 -59
@@ -0,0 +1,3 @@
1
+ {
2
+ "task_id": "11"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "task_id": "12"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "task_id": "13"
3
+ }
@@ -0,0 +1,14 @@
1
+ [
2
+ {
3
+ "ta_id": "1",
4
+ "ta_activated": "2013-04-04 04:04:04",
5
+ "ta_assigned": "2013-04-04 04:04:08",
6
+ "ta_completed": "2013-04-04 04:04:12",
7
+ "ta_command": "server_recreate",
8
+ "ta_params": {
9
+ "domain": "server.example.com",
10
+ "os": "debian-6.0-x86_64"
11
+ },
12
+ "ta_results": "Stopping container ...\nContainer was stopped\nContainer is unmounted\nDestroying container private area: /vz/private/11\nContainer private area was destroyed\nCreating container private area (debian-6.0-x86_64)\nPerforming postcreate actions\nCT configuration saved to /etc/vz/conf/1.conf\nContainer private area was created\nStarting container...\nContainer is mounted\nContainer start in progress...\nKilling container ...\nContainer was stopped\nContainer is unmounted\nCT configuration saved to /etc/vz/conf/1.conf\nCT configuration saved to /etc/vz/conf/1.conf\nStarting container...\nContainer is mounted\nAdding IP address(es): 12.23.34.45\nSetting CPU limit: 0\nSetting CPU units: 200\nSetting CPUs: 1\nContainer start in progress...\n\nID: 1\nHost: server.example.com\nBandwidth: 10240 Kbps\nQuota: 10 GB\nCPU: 1 unit(s)\nRAM: 1024 MB\nIP: 12.23.34.45\nPassword: secret"
13
+ }
14
+ ]
@@ -0,0 +1,3 @@
1
+ {
2
+ "version":"0.1"
3
+ }
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ivapi::Client::Account do
4
+
5
+ before do
6
+ @client = Ivapi::Client.new(username: 'foo', password: 'bar')
7
+ end
8
+
9
+ it "returns account information" do
10
+ stub_command("account_info").to_return(json_response("account_info.json"))
11
+ account_info = @client.account_info
12
+ expect(account_info.ac_name).to eq("Name Surname")
13
+ end
14
+
15
+ it "returns account orders" do
16
+ stub_command("account_orders").to_return(json_response("account_orders.json"))
17
+ account_orders = @client.account_orders
18
+ expect(account_orders.count).to eq(3)
19
+ expect(account_orders.first.or_cost).to eq("11.11")
20
+ end
21
+
22
+ it "returns account services" do
23
+ stub_command("account_services").to_return(json_response("account_services.json"))
24
+ account_services = @client.account_services
25
+ expect(account_services.count).to eq(3)
26
+ expect(account_services.first.se_description).to eq("Adreso metinis mokestis (example.com)")
27
+ end
28
+
29
+ it "returns account bonuses" do
30
+ stub_command("account_bonuses", {count: 10}).to_return(json_response("account_bonuses.json"))
31
+ account_bonuses = @client.account_bonuses
32
+ expect(account_bonuses[2].bo_description).to eq("SMS +370.61234569 (example)")
33
+ end
34
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ivapi::Client::Server do
4
+
5
+ before do
6
+ @client = Ivapi::Client.new(username: 'foo', password: 'bar', server_id: 3)
7
+ end
8
+
9
+ it "should return server information" do
10
+ stub_command("server_info", {id: 3}).to_return(json_response("server_info.json"))
11
+ server_info = @client.server_info
12
+ expect(server_info.se_domain).to eq("server.example.com")
13
+ expect(server_info.se_info.in_node).to eq("Robinija")
14
+ end
15
+
16
+ it "should return server graphs" do
17
+ stub_command("server_graphs", {id: 3, width: 1000, ip: "12.23.34.45"}).to_return(json_response("server_graphs.json"))
18
+ server_graphs = @client.server_graphs(1000, "12.23.34.45")
19
+ expect(server_graphs.cpu_weekly).to eq("//stats.serveriai.lt/graph.php?Ds252x+6Lek1o0SV2+u99fqhNaiflbCcb6QuGzlRJ9yy2R1VycHOc6baz3zRB6Am1RJcniVrpCjj+A47DMwkyfQ==")
20
+ end
21
+
22
+ it "should return server os" do
23
+ stub_command("server_os", {id: 3}).to_return(json_response("server_os.json"))
24
+ server_os = @client.server_os
25
+ expect(server_os["debian-6.0-x86_64"].title).to eq("Debian 6")
26
+ end
27
+
28
+ it "should reboot server" do
29
+ stub_command("server_reboot", {id: 3}).to_return(json_response("server_reboot.json"))
30
+ server_reboot = @client.server_reboot
31
+ expect(server_reboot.task_id).to eq("11")
32
+ end
33
+
34
+ it "should recreate server" do
35
+ stub_command("server_recreate", {id: 3}).to_return(json_response("server_recreate.json"))
36
+ server_recreate = @client.server_recreate
37
+ expect(server_recreate.task_id).to eq("12")
38
+ end
39
+
40
+ it "should reset server password" do
41
+ stub_command("server_reset_password", {id: 3}).to_return(json_response("server_reset_password.json"))
42
+ server_reset_password = @client.server_reset_password
43
+ expect(server_reset_password.task_id).to eq("13")
44
+ end
45
+
46
+ it "should change server plan" do
47
+ stub_command("server_change", {id: 3}).to_return(json_response("server_change.json"))
48
+ server_change = @client.server_change
49
+ expect(server_change.task_id).to eq("14")
50
+ end
51
+
52
+ it "should change server hostname" do
53
+ stub_command("server_domain", {id: 3}).to_return(json_response("server_domain.json"))
54
+ server_domain = @client.server_domain
55
+ expect(server_domain.task_id).to eq("15")
56
+ end
57
+
58
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ivapi::Client do
4
+
5
+ it "works with basic auth and password" do
6
+ stub_request(:get, "https://api.iv.lt/json.php?nick=foo&password=bar&command=version").
7
+ to_return(:status => 200, :body => '{"commits":[]}', :headers => {})
8
+ expect {
9
+ Ivapi::Client.new(:username => 'foo', :password => 'bar')
10
+ }.not_to raise_exception
11
+ end
12
+
13
+ end
@@ -1,17 +1,66 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
10
+ require 'ivapi'
11
+ require 'rspec'
12
+ require 'webmock/rspec'
13
+
14
+ WebMock.disable_net_connect!(allow: 'coveralls.io')
15
+
7
16
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
- config.run_all_when_everything_filtered = true
10
- config.filter_run :focus
11
-
12
- # Run specs in random order to surface order dependencies. If you find an
13
- # order dependency and want to debug it, you can fix the order by providing
14
- # the seed, which is printed after each run.
15
- # --seed 1234
16
- config.order = 'random'
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+ end
21
+
22
+ def stub_get(url)
23
+ stub_request(:get, iv_url(url))
24
+ end
25
+
26
+ def stub_command(command, options={})
27
+
28
+ params = { command: command }
29
+ params.merge!(options)
30
+ params.merge!(@client.authentication)
31
+
32
+ stub_request(:get, "https://api.iv.lt/json.php").with(query: params)
33
+ end
34
+
35
+ def fixture_path
36
+ File.expand_path("../fixtures", __FILE__)
37
+ end
38
+
39
+ def fixture(file)
40
+ File.new(fixture_path + '/' + file)
41
+ end
42
+
43
+ def json_response(file)
44
+ {
45
+ :body => fixture(file),
46
+ :headers => {
47
+ :content_type => 'application/json; charset=utf-8'
48
+ }
49
+ }
50
+ end
51
+
52
+ def iv_url(url)
53
+ if url =~ /^http/
54
+ url
55
+ else
56
+ "https://api.iv.lt#{url}"
57
+ end
58
+ end
59
+
60
+ def iv_command_url(command)
61
+ if @client && @client.authenticated?
62
+ "https://api.iv.lt?nick=#{@client.username}&password=#{@client.password}&command=#{command}"
63
+ else
64
+ "https://api.iv.lt?command=#{command}"
65
+ end
17
66
  end
metadata CHANGED
@@ -1,33 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ivapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Justas Palumickas
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
11
+ date: 2013-04-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: httparty
14
+ name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 0.9.0
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: addressable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: multi_json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
22
90
  type: :runtime
23
91
  prerelease: false
24
92
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
93
  requirements:
27
94
  - - ~>
28
95
  - !ruby/object:Gem::Version
29
- version: 0.9.0
30
- description: ! ' Gem which helps to communicate with iv.lt API '
96
+ version: '1.3'
97
+ description: ' Gem which helps to communicate with iv.lt API '
31
98
  email:
32
99
  - justas@elish.lt
33
100
  executables: []
@@ -36,41 +103,83 @@ extra_rdoc_files: []
36
103
  files:
37
104
  - .gitignore
38
105
  - .rspec
106
+ - .travis.yml
107
+ - CONTRIBUTING.md
39
108
  - Gemfile
40
- - LICENSE.txt
109
+ - Guardfile
110
+ - LICENSE.md
41
111
  - README.md
42
112
  - Rakefile
43
113
  - ivapi.gemspec
114
+ - lib/faraday/response/raise_ivapi_error.rb
44
115
  - lib/ivapi.rb
45
- - lib/ivapi/account.rb
46
- - lib/ivapi/base.rb
47
- - lib/ivapi/railtie.rb
48
- - lib/ivapi/server.rb
116
+ - lib/ivapi/authentication.rb
117
+ - lib/ivapi/client.rb
118
+ - lib/ivapi/client/account.rb
119
+ - lib/ivapi/client/server.rb
120
+ - lib/ivapi/configuration.rb
121
+ - lib/ivapi/connection.rb
122
+ - lib/ivapi/error.rb
123
+ - lib/ivapi/request.rb
49
124
  - lib/ivapi/version.rb
125
+ - spec/fixtures/account_bonuses.json
126
+ - spec/fixtures/account_info.json
127
+ - spec/fixtures/account_orders.json
128
+ - spec/fixtures/account_services.json
129
+ - spec/fixtures/server_change.json
130
+ - spec/fixtures/server_domain.json
131
+ - spec/fixtures/server_graphs.json
132
+ - spec/fixtures/server_info.json
133
+ - spec/fixtures/server_os.json
134
+ - spec/fixtures/server_reboot.json
135
+ - spec/fixtures/server_recreate.json
136
+ - spec/fixtures/server_reset_password.json
137
+ - spec/fixtures/server_tasks.json
138
+ - spec/fixtures/version.json
139
+ - spec/ivapi/client/account_spec.rb
140
+ - spec/ivapi/client/server_spec.rb
141
+ - spec/ivapi/client_spec.rb
50
142
  - spec/spec_helper.rb
51
143
  homepage: https://github.com/jpalumickas/ivapi/
52
- licenses: []
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
53
147
  post_install_message:
54
148
  rdoc_options: []
55
149
  require_paths:
56
150
  - lib
57
151
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
152
  requirements:
60
- - - ! '>='
153
+ - - '>='
61
154
  - !ruby/object:Gem::Version
62
155
  version: '0'
63
156
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
157
  requirements:
66
- - - ! '>='
158
+ - - '>='
67
159
  - !ruby/object:Gem::Version
68
160
  version: '0'
69
161
  requirements: []
70
162
  rubyforge_project:
71
- rubygems_version: 1.8.24
163
+ rubygems_version: 2.0.3
72
164
  signing_key:
73
- specification_version: 3
165
+ specification_version: 4
74
166
  summary: Gem which helps to communicate with iv.lt API
75
167
  test_files:
168
+ - spec/fixtures/account_bonuses.json
169
+ - spec/fixtures/account_info.json
170
+ - spec/fixtures/account_orders.json
171
+ - spec/fixtures/account_services.json
172
+ - spec/fixtures/server_change.json
173
+ - spec/fixtures/server_domain.json
174
+ - spec/fixtures/server_graphs.json
175
+ - spec/fixtures/server_info.json
176
+ - spec/fixtures/server_os.json
177
+ - spec/fixtures/server_reboot.json
178
+ - spec/fixtures/server_recreate.json
179
+ - spec/fixtures/server_reset_password.json
180
+ - spec/fixtures/server_tasks.json
181
+ - spec/fixtures/version.json
182
+ - spec/ivapi/client/account_spec.rb
183
+ - spec/ivapi/client/server_spec.rb
184
+ - spec/ivapi/client_spec.rb
76
185
  - spec/spec_helper.rb
@@ -1,32 +0,0 @@
1
- require "ivapi/base"
2
-
3
- module Ivapi
4
- class Account < Base
5
-
6
- def info
7
- options = { :command => 'account_info' }
8
- self.class.get(self.file, :query => options.merge!(@auth))
9
- end
10
-
11
- def orders
12
- options = { :command => 'account_orders' }
13
- self.class.get(self.file, :query => options.merge!(@auth))
14
- end
15
-
16
- def services
17
- options = { :command => 'account_services' }
18
- self.class.get(self.file, :query => options.merge!(@auth))
19
- end
20
-
21
- def credits(o = { :count => 10 })
22
- options = { :command => 'account_credits' }.merge!(o)
23
- self.class.get(self.file, :query => options.merge!(@auth))
24
- end
25
-
26
- def bonuses(o = { :count => 10 })
27
- options = { :command => 'account_bonuses' }.merge!(o)
28
- self.class.get(self.file, :query => options.merge!(@auth))
29
- end
30
-
31
- end
32
- end