ivapi 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +9 -2
- data/lib/ivapi.rb +28 -0
- data/lib/ivapi/account.rb +5 -5
- data/lib/ivapi/base.rb +4 -4
- data/lib/ivapi/railtie.rb +26 -0
- data/lib/ivapi/server.rb +7 -7
- data/lib/ivapi/version.rb +1 -1
- metadata +3 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,13 +18,20 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
Config file in **config/ivapi.yml**
|
22
|
+
```ruby
|
23
|
+
username: YOUR USERNAME
|
24
|
+
password: YOUR PASSWORD
|
25
|
+
```
|
26
|
+
|
27
|
+
|
21
28
|
```ruby
|
22
29
|
require 'ivapi'
|
23
30
|
|
24
31
|
API_NAME = "your_account_name" #You must to set it on https://klientams.iv.lt/users.php with description "API".
|
25
32
|
API_PASSWORD = "your_account_password"
|
26
33
|
|
27
|
-
account = Ivapi::Account.new
|
34
|
+
account = Ivapi::Account.new
|
28
35
|
|
29
36
|
puts "Account name: #{account.info['ac_name']}"
|
30
37
|
puts "Account created: #{account.info['ac_created']}"
|
@@ -33,7 +40,7 @@ account.services.each do |order|
|
|
33
40
|
puts "Id: #{order['se_id']} Description: #{order['se_description']}"
|
34
41
|
end
|
35
42
|
|
36
|
-
server = Ivapi::Server.new
|
43
|
+
server = Ivapi::Server.new.id(123) # Where is id, there is your service id.
|
37
44
|
server.tasks.each do |task| # can be: server.tasks(:count => 15) (Max: 1000)
|
38
45
|
puts "Id: #{task['ta_id']} Command: #{task['ta_command']}"
|
39
46
|
end
|
data/lib/ivapi.rb
CHANGED
@@ -1,7 +1,35 @@
|
|
1
1
|
require "ivapi/version"
|
2
2
|
require "httparty"
|
3
|
+
require "ivapi/railtie" if defined?(Rails)
|
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
|
3
18
|
|
4
19
|
module Ivapi
|
5
20
|
autoload :Account, 'ivapi/account'
|
6
21
|
autoload :Server, 'ivapi/server'
|
22
|
+
|
23
|
+
def self.config=(hash)
|
24
|
+
@@config = hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.config
|
28
|
+
raise 'Set Ivapi config before connecting.' unless defined?(@@config)
|
29
|
+
@@config
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.setup(config)
|
33
|
+
self.config = config
|
34
|
+
end
|
7
35
|
end
|
data/lib/ivapi/account.rb
CHANGED
@@ -12,18 +12,18 @@ module Ivapi
|
|
12
12
|
options = { :command => 'account_orders' }
|
13
13
|
self.class.get(self.file, :query => options.merge!(@auth))
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def services
|
17
17
|
options = { :command => 'account_services' }
|
18
18
|
self.class.get(self.file, :query => options.merge!(@auth))
|
19
19
|
end
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
def credits(o = { :count => 10 })
|
22
22
|
options = { :command => 'account_credits' }.merge!(o)
|
23
23
|
self.class.get(self.file, :query => options.merge!(@auth))
|
24
24
|
end
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
def bonuses(o = { :count => 10 })
|
27
27
|
options = { :command => 'account_bonuses' }.merge!(o)
|
28
28
|
self.class.get(self.file, :query => options.merge!(@auth))
|
29
29
|
end
|
data/lib/ivapi/base.rb
CHANGED
@@ -2,15 +2,15 @@ require 'ivapi/account'
|
|
2
2
|
|
3
3
|
module Ivapi
|
4
4
|
class Base
|
5
|
-
|
5
|
+
|
6
6
|
include HTTParty
|
7
7
|
base_uri 'https://api.iv.lt'
|
8
8
|
format :json
|
9
9
|
|
10
10
|
attr_reader :auth, :file
|
11
11
|
|
12
|
-
def initialize
|
13
|
-
@auth = {:nick =>
|
12
|
+
def initialize
|
13
|
+
@auth = {:nick => Ivapi.config['username'], :password => Ivapi.config['password'] }
|
14
14
|
@file = '/json.php'
|
15
15
|
end
|
16
16
|
|
@@ -18,6 +18,6 @@ module Ivapi
|
|
18
18
|
options = { :command => 'version' }
|
19
19
|
self.class.get(self.file, :query => options.merge!(@auth))['version']
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "ivapi"
|
2
|
+
require "rails"
|
3
|
+
require "active_model/railtie"
|
4
|
+
|
5
|
+
module Ivapi
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
|
8
|
+
config.ivapi = ActiveSupport::OrderedOptions.new
|
9
|
+
|
10
|
+
initializer "ivapi.set_configs" do |app|
|
11
|
+
ActiveSupport.on_load(:ivapi) do
|
12
|
+
app.config.ivapi.each do |k,v|
|
13
|
+
send "#{k}=", v
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
initializer "ivapi.initialize_database" do |app|
|
19
|
+
config_file = Rails.root.join('config/ivapi.yml')
|
20
|
+
if config_file.file?
|
21
|
+
config = YAML.load(ERB.new(config_file.read).result)
|
22
|
+
Ivapi.setup(config)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/ivapi/server.rb
CHANGED
@@ -19,7 +19,7 @@ module Ivapi
|
|
19
19
|
options = { :command => 'server_tasks' , :id => self.server_id, :count => 10 }.merge!(o)
|
20
20
|
self.class.get(self.file, :query => options.merge!(@auth))
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def graphs(o={})
|
24
24
|
options = { :command => 'server_graphs' , :id => self.server_id }.merge!(o)
|
25
25
|
self.class.get(self.file, :query => options.merge!(@auth))
|
@@ -29,31 +29,31 @@ module Ivapi
|
|
29
29
|
options = { :command => 'server_os' , :id => self.server_id }
|
30
30
|
self.class.get(self.file, :query => options.merge!(@auth))
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def reboot
|
34
34
|
options = { :command => 'server_reboot' , :id => self.server_id }
|
35
35
|
self.class.get(self.file, :query => options.merge!(@auth))
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def recreate(o={})
|
39
39
|
options = { :command => 'server_recreate' , :id => self.server_id }.merge!(o)
|
40
40
|
self.class.get(self.file, :query => options.merge!(@auth))
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def reset_password
|
44
44
|
options = { :command => 'server_reset_password' , :id => self.server_id }
|
45
45
|
self.class.get(self.file, :query => options.merge!(@auth))
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def change(o={})
|
49
49
|
options = { :command => 'server_change' , :id => self.server_id }.merge!(o)
|
50
50
|
self.class.get(self.file, :query => options.merge!(@auth))
|
51
|
-
end
|
51
|
+
end
|
52
52
|
|
53
53
|
def domain(o={})
|
54
54
|
options = { :command => 'server_domain' , :id => self.server_id }.merge!(o)
|
55
55
|
self.class.get(self.file, :query => options.merge!(@auth))
|
56
|
-
end
|
56
|
+
end
|
57
57
|
|
58
58
|
end
|
59
59
|
end
|
data/lib/ivapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ivapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/ivapi.rb
|
45
45
|
- lib/ivapi/account.rb
|
46
46
|
- lib/ivapi/base.rb
|
47
|
+
- lib/ivapi/railtie.rb
|
47
48
|
- lib/ivapi/server.rb
|
48
49
|
- lib/ivapi/version.rb
|
49
50
|
- spec/spec_helper.rb
|