ivapi 1.0.4 → 1.1.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.
- checksums.yaml +4 -4
- data/.gitignore +5 -5
- data/.travis.yml +13 -3
- data/Gemfile +5 -5
- data/README.md +41 -14
- data/ivapi.gemspec +10 -10
- data/lib/ivapi.rb +26 -6
- data/lib/ivapi/authentication.rb +2 -2
- data/lib/ivapi/client.rb +20 -11
- data/lib/ivapi/client/account.rb +6 -6
- data/lib/ivapi/client/base.rb +34 -0
- data/lib/ivapi/client/server.rb +20 -12
- data/lib/ivapi/configuration.rb +32 -26
- data/lib/ivapi/default.rb +86 -0
- data/lib/ivapi/error.rb +19 -22
- data/lib/ivapi/response/raise_error.rb +21 -0
- data/lib/ivapi/response/rename_keys.rb +38 -0
- data/lib/ivapi/version.rb +1 -1
- data/spec/ivapi/client/account_spec.rb +60 -26
- data/spec/ivapi/client/server_spec.rb +136 -63
- data/spec/ivapi/client_spec.rb +47 -2
- data/spec/ivapi_spec.rb +10 -10
- data/spec/spec_helper.rb +2 -3
- metadata +39 -33
- data/lib/faraday/response/raise_ivapi_error.rb +0 -24
- data/lib/ivapi/connection.rb +0 -29
- data/lib/ivapi/request.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f16f6f658dc9c5313b61480a9e80d0ec23b3f192
|
4
|
+
data.tar.gz: 25d6a316598b14a45a0ead33578b71905ff02dc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eb17f1b2ed5a8b476d9c7b6ef746fe38b93a75680d8bd31e2b3b751be23e28b02331b08f068448e59b2350eaa4ce64989c171736e0b4f7a0053ace4f84b6b25
|
7
|
+
data.tar.gz: 0bae8edb9d16cf01d12e8cdd493dcd662cb6c18612194391facfa32b591ab31257df3da110783760986fcefd0cb9e5ff0184f727f7ca0e6b804cb5675bf2282f
|
data/.gitignore
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
*.rbc
|
3
3
|
.bundle
|
4
4
|
.config
|
5
|
+
.DS_Store
|
5
6
|
.yardoc
|
6
|
-
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
7
|
+
bin/test.rb
|
9
8
|
coverage
|
10
9
|
doc/
|
10
|
+
Gemfile.lock
|
11
|
+
InstalledFiles
|
11
12
|
lib/bundler/man
|
12
13
|
pkg
|
13
14
|
rdoc
|
@@ -15,5 +16,4 @@ spec/reports
|
|
15
16
|
test/tmp
|
16
17
|
test/version_tmp
|
17
18
|
tmp
|
18
|
-
|
19
|
-
.DS_Store
|
19
|
+
_yardoc
|
data/.travis.yml
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
bundler_args: --without development
|
2
|
+
|
2
3
|
language: ruby
|
4
|
+
|
3
5
|
rvm:
|
4
|
-
- jruby-19mode
|
5
|
-
- rbx-19mode
|
6
|
-
- 1.9.2
|
7
6
|
- 1.9.3
|
8
7
|
- 2.0.0
|
8
|
+
- 2.1.0
|
9
|
+
- ruby-head
|
10
|
+
- jruby-19mode
|
11
|
+
- jruby-head
|
12
|
+
- rbx
|
13
|
+
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: ruby-head
|
17
|
+
- rvm: jruby-head
|
18
|
+
- rvm: rbx
|
data/Gemfile
CHANGED
@@ -3,12 +3,12 @@ source 'https://rubygems.org'
|
|
3
3
|
gem 'rake'
|
4
4
|
|
5
5
|
group :test do
|
6
|
-
gem 'json', '~> 1.8.
|
6
|
+
gem 'json', '~> 1.8.1', platforms: [:jruby]
|
7
7
|
gem 'rspec', '~> 2.14.1'
|
8
|
-
gem 'simplecov', '~> 0.
|
9
|
-
gem 'webmock', '~> 1.
|
10
|
-
gem 'coveralls', '~> 0.
|
11
|
-
gem 'guard-rspec', '~>
|
8
|
+
gem 'simplecov', '~> 0.8.2', require: false
|
9
|
+
gem 'webmock', '~> 1.17.1'
|
10
|
+
gem 'coveralls', '~> 0.7.0', require: false
|
11
|
+
gem 'guard-rspec', '~> 4.2.4'
|
12
12
|
end
|
13
13
|
|
14
14
|
gemspec
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Ivapi
|
2
2
|
|
3
|
-
Gem which helps to communicate with [http://iv.lt][iv.lt] ([http://dedikuoti.lt][dedikuoti.lt]) API.
|
3
|
+
Gem which helps to communicate with Interneto vizija [http://iv.lt][iv.lt] ([http://dedikuoti.lt][dedikuoti.lt]) API.
|
4
4
|
|
5
|
-
[][rubygems]
|
6
|
+
[][travis]
|
7
7
|
[][gemnasium]
|
8
|
-
[][coveralls]
|
9
|
+
[][codeclimate]
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -24,29 +24,56 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
27
|
+
> The Ivapi Wiki has lots of additional information about this gem including many examples. Please browse the Wiki at:
|
28
|
+
https://github.com/jpalumickas/ivapi/wiki
|
28
29
|
|
29
|
-
|
30
|
-
require 'ivapi'
|
30
|
+
Create a new account at https://klientams.iv.lt/users.php with description "API".
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
### Authentication
|
33
|
+
```rb
|
34
|
+
Ivapi::Client.new(username: 'foo', password: 'bar')
|
35
|
+
```
|
36
|
+
|
37
|
+
Or create file under `config/initializers/ivapi.rb`
|
38
|
+
|
39
|
+
```rb
|
40
|
+
Ivapi.configure do |config|
|
41
|
+
config.username = 'foo'
|
42
|
+
config.password = 'bar'
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
### Account information
|
47
|
+
|
48
|
+
Basic information
|
49
|
+
```rb
|
50
|
+
Ivapi.account.information
|
51
|
+
```
|
52
|
+
|
53
|
+
Orders
|
54
|
+
```
|
55
|
+
Ivapi.account.orders
|
56
|
+
```
|
57
|
+
|
58
|
+
### Server information
|
34
59
|
|
35
|
-
|
36
|
-
|
60
|
+
Basic information
|
61
|
+
```rb
|
62
|
+
Ivapi.server.information
|
37
63
|
```
|
38
64
|
|
65
|
+
|
39
66
|
## Supported Ruby Versions
|
40
67
|
|
41
68
|
This library aims to support and is [tested against][travis] the following Ruby
|
42
69
|
implementations:
|
43
70
|
|
44
|
-
* Ruby 1.9.2
|
45
71
|
* Ruby 1.9.3
|
46
72
|
* Ruby 2.0.0
|
73
|
+
* Ruby 2.1.0
|
47
74
|
|
48
75
|
## Copyright
|
49
|
-
Copyright (c) 2012-
|
76
|
+
Copyright (c) 2012-2014 Justas Palumickas.
|
50
77
|
See [LICENSE][] for details.
|
51
78
|
|
52
79
|
[rubygems]: https://rubygems.org/gems/ivapi
|
data/ivapi.gemspec
CHANGED
@@ -4,25 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'ivapi/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
8
|
-
gem.
|
9
|
-
gem.email =
|
10
|
-
gem.description = %q{ Gem which helps to communicate with iv.lt API }
|
7
|
+
gem.name = 'ivapi'
|
8
|
+
gem.author = 'Justas Palumickas'
|
9
|
+
gem.email = 'jpalumickas@gmail.com'
|
10
|
+
gem.description = %q{ Gem which helps to communicate with http://www.iv.lt API. }
|
11
11
|
gem.summary = gem.description
|
12
|
-
gem.homepage =
|
13
|
-
gem.
|
12
|
+
gem.homepage = 'https://github.com/jpalumickas/ivapi/'
|
13
|
+
gem.license = 'MIT'
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
18
|
+
gem.require_paths = ['lib']
|
19
19
|
|
20
20
|
gem.add_development_dependency 'bundler', '~> 1.0'
|
21
21
|
gem.add_dependency 'addressable', '~> 2.3'
|
22
|
-
gem.add_dependency 'faraday', '
|
22
|
+
gem.add_dependency 'faraday', ['>= 0.8.4', '< 0.9']
|
23
23
|
gem.add_dependency 'faraday_middleware', '~> 0.9'
|
24
|
-
gem.add_dependency 'hashie', '~> 2.
|
25
|
-
gem.add_dependency 'multi_json', '~> 1.
|
24
|
+
gem.add_dependency 'hashie', '~> 2.1'
|
25
|
+
gem.add_dependency 'multi_json', '~> 1.9'
|
26
26
|
|
27
27
|
gem.version = Ivapi::VERSION
|
28
28
|
end
|
data/lib/ivapi.rb
CHANGED
@@ -1,15 +1,35 @@
|
|
1
|
-
require 'ivapi/configuration'
|
2
|
-
require 'ivapi/error'
|
3
1
|
require 'ivapi/client'
|
4
|
-
|
2
|
+
require 'ivapi/default'
|
3
|
+
require 'pry'
|
5
4
|
module Ivapi
|
6
|
-
extend Configuration
|
5
|
+
extend Ivapi::Configuration
|
7
6
|
|
8
7
|
class << self
|
9
8
|
|
10
|
-
def
|
11
|
-
|
9
|
+
def client
|
10
|
+
unless defined?(@client) && @client.same_options?(options)
|
11
|
+
@client = Ivapi::Client.new(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
@client
|
15
|
+
end
|
16
|
+
|
17
|
+
def respond_to_missing?(method_name, include_private = false)
|
18
|
+
client.respond_to?(method_name, include_private)
|
19
|
+
end if RUBY_VERSION >= '1.9'
|
20
|
+
|
21
|
+
def respond_to?(method_name, include_private = false)
|
22
|
+
client.respond_to?(method_name, include_private) || super
|
23
|
+
end if RUBY_VERSION < '1.9'
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def method_missing(method_name, *args, &block)
|
28
|
+
return super unless client.respond_to?(method_name)
|
29
|
+
client.send(method_name, *args, &block)
|
12
30
|
end
|
13
31
|
|
14
32
|
end
|
15
33
|
end
|
34
|
+
|
35
|
+
Ivapi.setup
|
data/lib/ivapi/authentication.rb
CHANGED
data/lib/ivapi/client.rb
CHANGED
@@ -1,27 +1,36 @@
|
|
1
|
+
require 'ivapi/configuration'
|
1
2
|
require 'ivapi/authentication'
|
2
|
-
require 'ivapi/connection'
|
3
|
-
require 'ivapi/request'
|
4
3
|
|
4
|
+
require 'ivapi/client/base'
|
5
5
|
require 'ivapi/client/account'
|
6
6
|
require 'ivapi/client/server'
|
7
7
|
|
8
8
|
module Ivapi
|
9
9
|
class Client
|
10
|
-
|
10
|
+
include Ivapi::Authentication
|
11
|
+
include Ivapi::Configuration
|
12
|
+
|
13
|
+
attr_reader *Ivapi::Configuration.keys
|
11
14
|
|
12
15
|
def initialize(options = {})
|
13
|
-
options
|
14
|
-
Configuration
|
15
|
-
|
16
|
+
# Use options passed in, but fall back to module defaults
|
17
|
+
Ivapi::Configuration.keys.each do |key|
|
18
|
+
instance_variable_set(
|
19
|
+
:"@#{key}", options[key] || Ivapi.instance_variable_get(:"@#{key}")
|
20
|
+
)
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
def account
|
25
|
+
Ivapi::Client::Account.new(self)
|
26
|
+
end
|
22
27
|
|
23
|
-
|
24
|
-
|
28
|
+
def server(server_id = @server_id)
|
29
|
+
Ivapi::Client::Server.new(self, server_id)
|
30
|
+
end
|
25
31
|
|
32
|
+
def same_options?(opts)
|
33
|
+
opts.hash == options.hash
|
34
|
+
end
|
26
35
|
end
|
27
36
|
end
|
data/lib/ivapi/client/account.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Ivapi
|
2
2
|
class Client
|
3
|
-
|
3
|
+
class Account < Base
|
4
4
|
|
5
5
|
# Get information about account.
|
6
6
|
#
|
7
7
|
# Returns the Hash of account information.
|
8
|
-
def
|
8
|
+
def information
|
9
9
|
params = { command: 'account_info' }
|
10
10
|
get('/json.php', params)
|
11
11
|
end
|
@@ -13,7 +13,7 @@ module Ivapi
|
|
13
13
|
# Get account orders.
|
14
14
|
#
|
15
15
|
# Returns the Hash of account orders.
|
16
|
-
def
|
16
|
+
def orders
|
17
17
|
params = { command: 'account_orders' }
|
18
18
|
get('/json.php', params)
|
19
19
|
end
|
@@ -21,7 +21,7 @@ module Ivapi
|
|
21
21
|
# Get account services.
|
22
22
|
#
|
23
23
|
# Returns the Hash of account services.
|
24
|
-
def
|
24
|
+
def services
|
25
25
|
params = { command: 'account_services' }
|
26
26
|
get('/json.php', params)
|
27
27
|
end
|
@@ -31,7 +31,7 @@ module Ivapi
|
|
31
31
|
# count - The Integer of how many rows need to return (default: 10).
|
32
32
|
#
|
33
33
|
# Returns the Hash of account credits.
|
34
|
-
def
|
34
|
+
def credits(count = 10)
|
35
35
|
params = { command: 'account_credits', count: count }
|
36
36
|
get('/json.php', params)
|
37
37
|
end
|
@@ -41,7 +41,7 @@ module Ivapi
|
|
41
41
|
# count - The Integer of how many rows need to return (default: 10).
|
42
42
|
#
|
43
43
|
# Returns the Hash of account bonuses.
|
44
|
-
def
|
44
|
+
def bonuses(count = 10)
|
45
45
|
params = { command: 'account_bonuses', count: count }
|
46
46
|
get('/json.php', params)
|
47
47
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Ivapi
|
2
|
+
class Client
|
3
|
+
class Base
|
4
|
+
attr_reader :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def get(path, options = {})
|
11
|
+
request(:get, path, options).body
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def request(method, path, options = {})
|
17
|
+
options.merge!(client.authentication)
|
18
|
+
|
19
|
+
response = connection.send(method) do |request|
|
20
|
+
request.url(path, options)
|
21
|
+
end
|
22
|
+
response
|
23
|
+
end
|
24
|
+
|
25
|
+
def connection(options = {})
|
26
|
+
conn_opts = client.connection_options
|
27
|
+
conn_opts[:url] = client.api_endpoint
|
28
|
+
conn_opts[:builder] = client.middleware if client.middleware
|
29
|
+
|
30
|
+
Faraday.new(conn_opts)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/ivapi/client/server.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
module Ivapi
|
2
2
|
class Client
|
3
|
-
|
3
|
+
class Server < Base
|
4
|
+
attr_reader :server_id
|
5
|
+
|
6
|
+
def initialize(client, server_id)
|
7
|
+
super(client)
|
8
|
+
@server_id = server_id
|
9
|
+
end
|
4
10
|
|
5
11
|
# Get information about server.
|
6
12
|
#
|
7
13
|
# Returns the Hash of server information.
|
8
|
-
def
|
14
|
+
def information
|
9
15
|
params = { command: 'server_info', id: server_id }
|
10
16
|
get('/json.php', params)
|
11
17
|
end
|
18
|
+
alias_method :info, :information
|
12
19
|
|
13
20
|
# Get server tasks.
|
14
21
|
#
|
@@ -18,7 +25,7 @@ module Ivapi
|
|
18
25
|
# :task_id - The Integer of task id (optional).
|
19
26
|
#
|
20
27
|
# Returns the Hash of server tasks.
|
21
|
-
def
|
28
|
+
def tasks(count, options = {})
|
22
29
|
params = options.merge({
|
23
30
|
command: 'server_tasks', id: server_id, count: count })
|
24
31
|
|
@@ -31,7 +38,7 @@ module Ivapi
|
|
31
38
|
# ip - The String of ip, from which graphs can be viewed.
|
32
39
|
#
|
33
40
|
# Returns the Hash of server graphs.
|
34
|
-
def
|
41
|
+
def graphs(width, ip)
|
35
42
|
params = {
|
36
43
|
command: 'server_graphs',
|
37
44
|
id: server_id,
|
@@ -45,7 +52,7 @@ module Ivapi
|
|
45
52
|
# Get all available server operating systems.
|
46
53
|
#
|
47
54
|
# Returns the Hash of available server os.
|
48
|
-
def
|
55
|
+
def os
|
49
56
|
params = { command: 'server_os', id: server_id }
|
50
57
|
get('/json.php', params)
|
51
58
|
end
|
@@ -53,7 +60,7 @@ module Ivapi
|
|
53
60
|
# Send command to reboot the server.
|
54
61
|
#
|
55
62
|
# Returns the Integer of task id.
|
56
|
-
def
|
63
|
+
def reboot
|
57
64
|
params = { command: 'server_reboot', id: server_id }
|
58
65
|
get('/json.php', params)
|
59
66
|
end
|
@@ -66,7 +73,7 @@ module Ivapi
|
|
66
73
|
# password (min: 8, max: 64).
|
67
74
|
#
|
68
75
|
# Returns the Integer of task id.
|
69
|
-
def
|
76
|
+
def recreate(os, options = {})
|
70
77
|
params = options.merge({
|
71
78
|
command: 'server_recreate',
|
72
79
|
id: server_id,
|
@@ -83,7 +90,7 @@ module Ivapi
|
|
83
90
|
# password (min: 8, max: 64).
|
84
91
|
#
|
85
92
|
# Returns the Integer of task id.
|
86
|
-
def
|
93
|
+
def reset_password(options = {})
|
87
94
|
params = options.merge({
|
88
95
|
command: 'server_reset_password',
|
89
96
|
id: server_id
|
@@ -95,7 +102,7 @@ module Ivapi
|
|
95
102
|
# Send command to clean server firewall rules.
|
96
103
|
#
|
97
104
|
# Returns the Integer of task id.
|
98
|
-
def
|
105
|
+
def flush_iptables
|
99
106
|
params = { command: 'server_flush_iptables', id: server_id }
|
100
107
|
get('/json.php', params)
|
101
108
|
end
|
@@ -115,7 +122,7 @@ module Ivapi
|
|
115
122
|
# IP (0 or min: 16, max: 512).
|
116
123
|
#
|
117
124
|
# Returns the Hash of new firewall settings.
|
118
|
-
def
|
125
|
+
def firewall(options = {})
|
119
126
|
params = options.merge({ command: 'server_firewall', id: server_id })
|
120
127
|
get('/json.php', params)
|
121
128
|
end
|
@@ -129,7 +136,7 @@ module Ivapi
|
|
129
136
|
# :bandwidth - The Integer of Mbps (min: 20, max: 400).
|
130
137
|
#
|
131
138
|
# Returns the Integer of task id.
|
132
|
-
def
|
139
|
+
def change(options = {})
|
133
140
|
params = options.merge({ command: 'server_change', id: server_id })
|
134
141
|
get('/json.php', params)
|
135
142
|
end
|
@@ -139,10 +146,11 @@ module Ivapi
|
|
139
146
|
# domain - The String of new server hostname.
|
140
147
|
#
|
141
148
|
# Returns the Integer of task id.
|
142
|
-
def
|
149
|
+
def domain(domain)
|
143
150
|
params = { command: 'server_domain', id: server_id, domain: domain }
|
144
151
|
get('/json.php', params)
|
145
152
|
end
|
153
|
+
alias_method :hostname, :domain
|
146
154
|
end
|
147
155
|
end
|
148
156
|
end
|