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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14d8f0abbc80a600939fc7ac3a1c81a3ea22e47b
4
- data.tar.gz: 6cbbf8322b4186982f36db9230a57e77d1dc596b
3
+ metadata.gz: f16f6f658dc9c5313b61480a9e80d0ec23b3f192
4
+ data.tar.gz: 25d6a316598b14a45a0ead33578b71905ff02dc6
5
5
  SHA512:
6
- metadata.gz: cbb878f44d033f5828404fdf56bbe666e80349c81f40812797f7645b4d97face5408cfdd08fd348c98b11c273822540d1f82ed1a5cc3cf87ac4daa09dc13f318
7
- data.tar.gz: ac15b5f60eb95e680cf72ee609861ea499da56e05dbfeef6172c425f7fc7f549c2593af1ae4ff96a3549f6a9f4b93b75ae49a6e597ccda985c0ca46e10df98ca
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
- Gemfile.lock
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
- bin/test.rb
19
- .DS_Store
19
+ _yardoc
@@ -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.0', platforms: [:ruby_18, :jruby]
6
+ gem 'json', '~> 1.8.1', platforms: [:jruby]
7
7
  gem 'rspec', '~> 2.14.1'
8
- gem 'simplecov', '~> 0.7.1', require: false
9
- gem 'webmock', '~> 1.13.0'
10
- gem 'coveralls', '~> 0.6.7', require: false
11
- gem 'guard-rspec', '~> 3.0.2'
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
- [![Gem Version](https://badge.fury.io/rb/ivapi.png)][rubygems]
6
- [![Build Status](https://secure.travis-ci.org/jpalumickas/ivapi.png?branch=master)][travis]
5
+ [![Gem Version](https://badge.fury.io/rb/ivapi.svg)][rubygems]
6
+ [![Build Status](https://secure.travis-ci.org/jpalumickas/ivapi.svg?branch=master)][travis]
7
7
  [![Dependency Status](https://gemnasium.com/jpalumickas/ivapi.png?travis)][gemnasium]
8
- [![Coverage Status](https://coveralls.io/repos/jpalumickas/ivapi/badge.png?branch=master)][coveralls]
9
- [![Code Climate](https://codeclimate.com/github/jpalumickas/ivapi.png)][codeclimate]
8
+ [![Coverage Status](http://img.shields.io/coveralls/jpalumickas/ivapi/master.svg)][coveralls]
9
+ [![Code Climate](http://img.shields.io/codeclimate/github/jpalumickas/ivapi.svg)][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
- Create new account at https://klientams.iv.lt/users.php with description "API".
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
- ```ruby
30
- require 'ivapi'
30
+ Create a new account at https://klientams.iv.lt/users.php with description "API".
31
31
 
32
- client = Ivapi::Client.new(username: 'foo', password: 'bar')
33
- account_info = client.account_info
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
- puts "Account name: #{account_info.ac_name}"
36
- puts "Account created: #{account_info.ac_created}"
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-2013 Justas Palumickas.
76
+ Copyright (c) 2012-2014 Justas Palumickas.
50
77
  See [LICENSE][] for details.
51
78
 
52
79
  [rubygems]: https://rubygems.org/gems/ivapi
@@ -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 = "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 }
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 = "https://github.com/jpalumickas/ivapi/"
13
- gem.licenses = ['MIT']
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 = ["lib"]
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', '~> 0.8'
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.0'
25
- gem.add_dependency 'multi_json', '~> 1.7'
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
@@ -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 new(options = {})
11
- Ivapi::Client.new(options)
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
@@ -1,8 +1,8 @@
1
1
  module Ivapi
2
2
  module Authentication
3
3
  def authentication
4
- if username && password
5
- { nick: username, password: password }
4
+ if @username && @password
5
+ { nick: @username, password: @password }
6
6
  else
7
7
  {}
8
8
  end
@@ -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
- attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
10
+ include Ivapi::Authentication
11
+ include Ivapi::Configuration
12
+
13
+ attr_reader *Ivapi::Configuration.keys
11
14
 
12
15
  def initialize(options = {})
13
- options = Ivapi.options.merge(options)
14
- Configuration::VALID_OPTIONS_KEYS.each do |key|
15
- send("#{key}=", options[key])
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
- include Ivapi::Authentication
20
- include Ivapi::Connection
21
- include Ivapi::Request
24
+ def account
25
+ Ivapi::Client::Account.new(self)
26
+ end
22
27
 
23
- include Ivapi::Client::Account
24
- include Ivapi::Client::Server
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
@@ -1,11 +1,11 @@
1
1
  module Ivapi
2
2
  class Client
3
- module Account
3
+ class Account < Base
4
4
 
5
5
  # Get information about account.
6
6
  #
7
7
  # Returns the Hash of account information.
8
- def account_info
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 account_orders
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 account_services
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 account_credits(count = 10)
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 account_bonuses(count = 10)
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
@@ -1,14 +1,21 @@
1
1
  module Ivapi
2
2
  class Client
3
- module Server
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 server_info
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 server_tasks(count, options = {})
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 server_graphs(width, ip)
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 server_os
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 server_reboot
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 server_recreate(os, options = {})
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 server_reset_password(options = {})
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 server_flush_iptables
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 server_firewall(options = {})
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 server_change(options = {})
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 server_domain(domain)
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