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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -1
- data/.travis.yml +7 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +11 -1
- data/Guardfile +13 -0
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +28 -26
- data/Rakefile +8 -1
- data/ivapi.gemspec +20 -13
- data/lib/faraday/response/raise_ivapi_error.rb +24 -0
- data/lib/ivapi.rb +6 -30
- data/lib/ivapi/authentication.rb +15 -0
- data/lib/ivapi/client.rb +27 -0
- data/lib/ivapi/client/account.rb +30 -0
- data/lib/ivapi/client/server.rb +92 -0
- data/lib/ivapi/configuration.rb +43 -0
- data/lib/ivapi/connection.rb +29 -0
- data/lib/ivapi/error.rb +35 -0
- data/lib/ivapi/request.rb +22 -0
- data/lib/ivapi/version.rb +1 -1
- data/spec/fixtures/account_bonuses.json +20 -0
- data/spec/fixtures/account_info.json +42 -0
- data/spec/fixtures/account_orders.json +29 -0
- data/spec/fixtures/account_services.json +35 -0
- data/spec/fixtures/server_change.json +3 -0
- data/spec/fixtures/server_domain.json +3 -0
- data/spec/fixtures/server_graphs.json +26 -0
- data/spec/fixtures/server_info.json +30 -0
- data/spec/fixtures/server_os.json +132 -0
- data/spec/fixtures/server_reboot.json +3 -0
- data/spec/fixtures/server_recreate.json +3 -0
- data/spec/fixtures/server_reset_password.json +3 -0
- data/spec/fixtures/server_tasks.json +14 -0
- data/spec/fixtures/version.json +3 -0
- data/spec/ivapi/client/account_spec.rb +34 -0
- data/spec/ivapi/client/server_spec.rb +58 -0
- data/spec/ivapi/client_spec.rb +13 -0
- data/spec/spec_helper.rb +64 -15
- metadata +130 -21
- data/lib/ivapi/account.rb +0 -32
- data/lib/ivapi/base.rb +0 -23
- data/lib/ivapi/railtie.rb +0 -26
- data/lib/ivapi/server.rb +0 -59
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e76fb70e5319fa1db6830dff860f4cf79f49b0d
|
4
|
+
data.tar.gz: c7ca20f56256497ba8a9eb184b2e74f11aedfee7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 530f3e953afad096b62f63e405bb18b400a61157a41a273fa5c7b7338aa0ac455513f0c325642368a3c1a40749d9633ca347a77f7fcc763fde0b2da26e5c48b7
|
7
|
+
data.tar.gz: 912b91d1715e72958d4f5d0aaad29617ad28b3d15a09dcb16625125b63efab9661e035171af6299e7fcc62f3a63782ddd625dae49dcf5b60bf552c0da66d4cb4
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# How to contribute
|
2
|
+
|
3
|
+
I like to encourage you to contribute to the repository.
|
4
|
+
This should be as easy as possible for you but there are a few things to consider when contributing.
|
5
|
+
The following guidelines for contribution should be followed if you want to submit a pull request.
|
6
|
+
|
7
|
+
## How to prepare
|
8
|
+
|
9
|
+
* You need a [GitHub account](https://github.com/signup/free)
|
10
|
+
* Submit an [issue ticket](https://github.com/jpalumickas/ivapi/issues) for your issue if the is no one yet.
|
11
|
+
* Describe the issue and include steps to reproduce when it's a bug.
|
12
|
+
* Ensure to mention the earliest version that you know is affected.
|
13
|
+
* Fork the repository on GitHub
|
14
|
+
|
15
|
+
## Make Changes
|
16
|
+
|
17
|
+
* In your forked repository, create a topic branch for your upcoming patch.
|
18
|
+
* Usually this is based on the master branch.
|
19
|
+
* Create a branch based on master; `git branch
|
20
|
+
fix/master/my_contribution master` then checkout the new branch with `git
|
21
|
+
checkout fix/master/my_contribution`. Please avoid working directly on the `master` branch.
|
22
|
+
* Make commits of logical units and describe them properly.
|
23
|
+
* Check for unnecessary whitespace with `git diff --check` before committing.
|
24
|
+
|
25
|
+
* If possible, submit tests to your patch / new feature so it can be tested easily.
|
26
|
+
* Assure nothing is broken by running all the tests.
|
27
|
+
|
28
|
+
## Submit Changes
|
29
|
+
|
30
|
+
* Push your changes to a topic branch in your fork of the repository.
|
31
|
+
* Open a pull request to the original repository and choose the right original branch you want to patch.
|
32
|
+
* If not done in commit messages (which you really should do) please reference and update your issue with the code changes.
|
33
|
+
* Even if you have write access to the repository, do not directly push or merge pull-requests. Let another team member review your pull request and approve.
|
34
|
+
|
35
|
+
# Additional Resources
|
36
|
+
|
37
|
+
* [General GitHub documentation](http://help.github.com/)
|
38
|
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
data/Gemfile
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
gem 'rake'
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'json', '~> 1.7', platforms: [:ruby_18, :jruby]
|
7
|
+
gem 'rspec', '>= 2.13'
|
8
|
+
gem 'simplecov', require: false
|
9
|
+
gem 'webmock'
|
10
|
+
gem 'coveralls', require: false
|
11
|
+
gem 'guard-rspec'
|
12
|
+
end
|
13
|
+
|
4
14
|
gemspec
|
data/Guardfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# More info at https://github.com/guard/guard#readme
|
2
|
+
|
3
|
+
guard 'bundler' do
|
4
|
+
watch('Gemfile')
|
5
|
+
#Uncomment next line if Gemfile contain `gemspec' command
|
6
|
+
watch(/^.+\.gemspec/)
|
7
|
+
end
|
8
|
+
|
9
|
+
guard 'rspec' do
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
12
|
+
watch('spec/spec_helper.rb') { "spec" }
|
13
|
+
end
|
data/{LICENSE.txt → LICENSE.md}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Ivapi
|
2
2
|
|
3
|
-
Gem which helps to communicate with iv.lt API
|
3
|
+
Gem which helps to communicate with [iv.lt][] API
|
4
|
+
|
5
|
+
[][rubygems]
|
6
|
+
[][travis]
|
7
|
+
[][gemnasium]
|
8
|
+
[][coveralls]
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -18,38 +23,35 @@ Or install it yourself as:
|
|
18
23
|
|
19
24
|
## Usage
|
20
25
|
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
username: YOUR USERNAME
|
24
|
-
password: YOUR PASSWORD
|
25
|
-
```
|
26
|
-
|
26
|
+
Create new account at https://klientams.iv.lt/users.php with description "API".
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
require 'ivapi'
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
client = Ivapi::Client.new(username: 'foo', password: 'bar')
|
32
|
+
account_info = client.account_info
|
33
33
|
|
34
|
-
|
34
|
+
puts "Account name: #{account_info.ac_name}"
|
35
|
+
puts "Account created: #{account_info.ac_created}"
|
36
|
+
```
|
35
37
|
|
36
|
-
|
37
|
-
puts "Account created: #{account.info['ac_created']}"
|
38
|
+
## Supported Ruby Versions
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
40
|
+
This library aims to support and is [tested against][travis] the following Ruby
|
41
|
+
implementations:
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
* Ruby 1.9.2
|
44
|
+
* Ruby 1.9.3
|
45
|
+
* Ruby 2.0.0
|
46
|
+
|
47
|
+
## Copyright
|
48
|
+
Copyright (c) 2012-2013 Justas Palumickas.
|
49
|
+
See [LICENSE][] for details.
|
48
50
|
|
49
|
-
|
51
|
+
[rubygems]: https://rubygems.org/gems/ivapi
|
52
|
+
[travis]: http://travis-ci.org/jpalumickas/ivapi
|
53
|
+
[gemnasium]: https://gemnasium.com/jpalumickas/ivapi
|
54
|
+
[coveralls]: https://coveralls.io/r/jpalumickas/ivapi
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
-
5. Create new Pull Request
|
56
|
+
[iv.lt]: http://www.iv.lt
|
57
|
+
[license]: LICENSE.md
|
data/Rakefile
CHANGED
data/ivapi.gemspec
CHANGED
@@ -1,21 +1,28 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$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.
|
10
|
-
gem.
|
11
|
-
gem.
|
12
|
-
gem.
|
13
|
-
gem.
|
7
|
+
gem.name = "ivapi"
|
8
|
+
gem.authors = ["Justas Palumickas"]
|
9
|
+
gem.email = ["justas@elish.lt"]
|
10
|
+
gem.description = %q{ Gem which helps to communicate with iv.lt API }
|
11
|
+
gem.summary = gem.description
|
12
|
+
gem.homepage = "https://github.com/jpalumickas/ivapi/"
|
13
|
+
gem.licenses = ['MIT']
|
14
14
|
|
15
|
-
gem.files
|
16
|
-
gem.executables
|
17
|
-
gem.test_files
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
|
20
|
-
gem.
|
19
|
+
|
20
|
+
gem.add_development_dependency 'bundler', '~> 1.0'
|
21
|
+
gem.add_dependency 'addressable', '~> 2.2'
|
22
|
+
gem.add_dependency 'faraday', '~> 0.8'
|
23
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9'
|
24
|
+
gem.add_dependency 'hashie', '~> 2.0'
|
25
|
+
gem.add_dependency 'multi_json', '~> 1.3'
|
26
|
+
|
27
|
+
gem.version = Ivapi::VERSION
|
21
28
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
class Response::RaiseIvapiError < Response::Middleware
|
6
|
+
ERROR_MAP = {
|
7
|
+
400 => Ivapi::BadRequest,
|
8
|
+
401 => Ivapi::Unauthorized,
|
9
|
+
403 => Ivapi::Forbidden,
|
10
|
+
404 => Ivapi::NotFound,
|
11
|
+
406 => Ivapi::NotAcceptable,
|
12
|
+
422 => Ivapi::UnprocessableEntity,
|
13
|
+
500 => Ivapi::InternalServerError,
|
14
|
+
501 => Ivapi::NotImplemented,
|
15
|
+
502 => Ivapi::BadGateway,
|
16
|
+
503 => Ivapi::ServiceUnavailable
|
17
|
+
}
|
18
|
+
|
19
|
+
def on_complete(response)
|
20
|
+
key = response[:status].to_i
|
21
|
+
raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ivapi.rb
CHANGED
@@ -1,35 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
# Iv.lt returing invalid error status, so we don't want to see it while they don't fix it.
|
6
|
-
module HTTParty
|
7
|
-
class Parser
|
8
|
-
protected
|
9
|
-
def json
|
10
|
-
if MultiJson.respond_to?(:adapter)
|
11
|
-
MultiJson.load(body) rescue {}
|
12
|
-
else
|
13
|
-
MultiJson.decode(body) rescue {}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require 'ivapi/configuration'
|
2
|
+
require 'ivapi/error'
|
3
|
+
require 'ivapi/client'
|
18
4
|
|
19
5
|
module Ivapi
|
20
|
-
|
21
|
-
autoload :Server, 'ivapi/server'
|
22
|
-
|
23
|
-
def self.config=(hash)
|
24
|
-
@@config = hash
|
25
|
-
end
|
6
|
+
extend Configuration
|
26
7
|
|
27
|
-
def
|
28
|
-
|
29
|
-
@@config
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.setup(config)
|
33
|
-
self.config = config
|
8
|
+
def new(options={})
|
9
|
+
Ivapi::Client.new(options)
|
34
10
|
end
|
35
11
|
end
|
data/lib/ivapi/client.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ivapi/authentication'
|
2
|
+
require 'ivapi/connection'
|
3
|
+
require 'ivapi/request'
|
4
|
+
|
5
|
+
require 'ivapi/client/account'
|
6
|
+
require 'ivapi/client/server'
|
7
|
+
|
8
|
+
module Ivapi
|
9
|
+
class Client
|
10
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
options = Ivapi.options.merge(options)
|
14
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
15
|
+
send("#{key}=", options[key])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
include Ivapi::Authentication
|
20
|
+
include Ivapi::Connection
|
21
|
+
include Ivapi::Request
|
22
|
+
|
23
|
+
include Ivapi::Client::Account
|
24
|
+
include Ivapi::Client::Server
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ivapi
|
2
|
+
class Client
|
3
|
+
module Account
|
4
|
+
def account_info
|
5
|
+
params = { command: 'account_info' }
|
6
|
+
get('/json.php', params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def account_orders
|
10
|
+
params = { command: 'account_orders' }
|
11
|
+
get('/json.php', params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def account_services
|
15
|
+
params = { command: 'account_services' }
|
16
|
+
get('/json.php', params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def account_credits(count = 10)
|
20
|
+
options = { command: 'account_credits', count: count }
|
21
|
+
get('/json.php', params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def account_bonuses(count = 10)
|
25
|
+
params = { :command => 'account_bonuses', count: count }
|
26
|
+
get('/json.php', params)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Ivapi
|
2
|
+
class Client
|
3
|
+
module Server
|
4
|
+
|
5
|
+
# Get server information.
|
6
|
+
#
|
7
|
+
# Returns the hash of server information.
|
8
|
+
def server_info
|
9
|
+
params = { command: 'server_info', id: server_id }
|
10
|
+
get('/json.php', params)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Get server tasks.
|
14
|
+
#
|
15
|
+
# count - The Integer number of results count (Max 1000).
|
16
|
+
# options - The Hash of options (Available: task, task_id).
|
17
|
+
#
|
18
|
+
# Returns The Hash of server tasks.
|
19
|
+
def server_tasks(count, options={})
|
20
|
+
params = options.merge({ command: 'server_tasks', id: server_id, count: count })
|
21
|
+
get('/json.php', params)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get server graphs.
|
25
|
+
#
|
26
|
+
# width - The Integer number of graphs width (Max 1000, Optimal: 768).
|
27
|
+
# ip - The String of IP, who can view graphs.
|
28
|
+
#
|
29
|
+
# Returns the hash of server graphs.
|
30
|
+
def server_graphs(width, ip)
|
31
|
+
params = { command: 'server_graphs' , id: server_id, width: width, ip: ip }
|
32
|
+
get('/json.php', params)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get all available server os.
|
36
|
+
#
|
37
|
+
# Returns the hash of server os.
|
38
|
+
def server_os
|
39
|
+
params = { command: 'server_os', id: server_id }
|
40
|
+
get('/json.php', params)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Send command to reboot the server.
|
44
|
+
#
|
45
|
+
# Returns The Integer of task id.
|
46
|
+
def server_reboot
|
47
|
+
params = { command: 'server_reboot', id: server_id }
|
48
|
+
get('/json.php', params)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Send command to recreate the server.
|
52
|
+
#
|
53
|
+
# Returns The Integer of task id.
|
54
|
+
def server_recreate
|
55
|
+
params = { command: 'server_recreate', id: server_id }
|
56
|
+
get('/json.php', params)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Send command to reset server password.
|
60
|
+
#
|
61
|
+
# Returns The Integer of task id.
|
62
|
+
def server_reset_password
|
63
|
+
params = { command: 'server_reset_password', id: server_id }
|
64
|
+
get('/json.php', params)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Send command to clean server firewall rules.
|
68
|
+
#
|
69
|
+
# Returns The Integer of task id.
|
70
|
+
def server_flush_iptables
|
71
|
+
params = { command: 'server_flush_iptables', id: server_id }
|
72
|
+
get('/json.php', params)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Send command to change server plan.
|
76
|
+
#
|
77
|
+
# Returns The Integer of task id.
|
78
|
+
def server_change
|
79
|
+
params = { command: 'server_change', id: server_id }
|
80
|
+
get('/json.php', params)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Send command to change server hostname.
|
84
|
+
#
|
85
|
+
# Returns The Integer of task id.
|
86
|
+
def server_domain
|
87
|
+
params = { command: 'server_domain', id: server_id }
|
88
|
+
get('/json.php', params)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|