elasticweb 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 +18 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/elasticweb.gemspec +28 -0
- data/lib/elasticweb.rb +11 -0
- data/lib/elasticweb/client.rb +35 -0
- data/lib/elasticweb/client/accounts.rb +25 -0
- data/lib/elasticweb/client/accounts/cron.rb +11 -0
- data/lib/elasticweb/client/aliases.rb +21 -0
- data/lib/elasticweb/client/billing.rb +13 -0
- data/lib/elasticweb/client/connection.rb +62 -0
- data/lib/elasticweb/client/databases.rb +21 -0
- data/lib/elasticweb/client/databases/users.rb +27 -0
- data/lib/elasticweb/client/dns.rb +21 -0
- data/lib/elasticweb/client/domains.rb +21 -0
- data/lib/elasticweb/client/errors.rb +14 -0
- data/lib/elasticweb/client/nginx_configurations.rb +9 -0
- data/lib/elasticweb/client/servers.rb +9 -0
- data/lib/elasticweb/client/user.rb +9 -0
- data/lib/elasticweb/relation.rb +17 -0
- data/lib/elasticweb/relation_collection.rb +23 -0
- data/lib/elasticweb/resource.rb +36 -0
- data/lib/elasticweb/resource_collection.rb +38 -0
- data/lib/elasticweb/version.rb +3 -0
- data/spec/spec_helper.rb +4 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e402c8bd59b5bac5a655a13c75d63e2bdc40536
|
4
|
+
data.tar.gz: 9a189398c400597f4a2bb93d86247792bab51abd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9055ada90c6d40039e5280066ee77f17cb722b794a3b87cb0e8ad8f47c8dabf7ad793c151723d483ae683f01bb516c533b610461695bb7eff2eff8b60b754bfb
|
7
|
+
data.tar.gz: afbe1d23e6d744e8c8ef094d99b75acb06b6f4e4631623097d8ff88bdfe50dc93ce6505a33f0bda8c367051b13d9cc6a2e66273afcd607caccd9dc391e9781b8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Vitaly Lazorka
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
## ElasticWeb ruby client library
|
2
|
+
|
3
|
+
Client library for talking to [Elasticweb API](http://elasticweb.org/ru/user/api). Supports all endpoints.
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'elasticweb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install elasticweb
|
20
|
+
|
21
|
+
### Usage
|
22
|
+
|
23
|
+
Initialize client:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = ElasticWeb::Client.new('API_KEY')
|
27
|
+
```
|
28
|
+
|
29
|
+
And then talk to API:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
client.me
|
33
|
+
```
|
34
|
+
|
35
|
+
### List of all methods
|
36
|
+
|
37
|
+
Client methods just map 1 to 1 to API, see all of them beyond. Check [API docs](https://github.com/elasticweb/api) for list of available `options`.
|
38
|
+
|
39
|
+
#### User
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
me
|
43
|
+
```
|
44
|
+
|
45
|
+
#### Account
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
accounts
|
49
|
+
create_account(options)
|
50
|
+
update_account(id, options)
|
51
|
+
delete_account(id)
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Account cron
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
update_cron(id, options)
|
58
|
+
```
|
59
|
+
|
60
|
+
#### Server
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
servers
|
64
|
+
```
|
65
|
+
|
66
|
+
#### Alias
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
aliases(account_id)
|
70
|
+
create_alias(account_id, options)
|
71
|
+
update_alias(alias_name, options)
|
72
|
+
delete_alias(alias_name)
|
73
|
+
```
|
74
|
+
|
75
|
+
#### Domain
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
domains(account_id)
|
79
|
+
create_domain(account_id, options)
|
80
|
+
update_domain(domain_name, options)
|
81
|
+
delete_domain(domain_name)
|
82
|
+
```
|
83
|
+
|
84
|
+
#### DNS
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
domain_dns(domain_name)
|
88
|
+
dns(id)
|
89
|
+
create_dns(domain_name, options)
|
90
|
+
delete_dns(id)
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Database
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
databases(account_id)
|
97
|
+
create_database(account_id, options)
|
98
|
+
delete_database(account_id, db_name)
|
99
|
+
```
|
100
|
+
|
101
|
+
#### Database user
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
databases_users(account_id)
|
105
|
+
database_user_info(account_id, db_user_name)
|
106
|
+
create_database_user(account_id, options)
|
107
|
+
update_database_user(account_id, db_user_name, options)
|
108
|
+
delete_database_user(account_id, db_user_name)
|
109
|
+
```
|
110
|
+
|
111
|
+
#### Billing
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
operation_types
|
115
|
+
operations(type_name)
|
116
|
+
```
|
117
|
+
|
118
|
+
### Contributing
|
119
|
+
|
120
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dev1vitaly/elasticweb.
|
121
|
+
|
122
|
+
|
123
|
+
### License
|
124
|
+
|
125
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
126
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "elasticweb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/elasticweb.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'elasticweb/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'elasticweb'
|
7
|
+
spec.version = ElasticWeb::VERSION
|
8
|
+
spec.authors = ['Vitaly Lazorka']
|
9
|
+
spec.email = ['dev1.vitaly@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = %q{Client library for Elasticweb API.}
|
12
|
+
spec.description = %q{Client library for Elasticweb API.}
|
13
|
+
spec.homepage = 'https://github.com/dev1vitaly/elasticweb'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '>= 2.3.0'
|
22
|
+
|
23
|
+
spec.add_dependency 'httparty'
|
24
|
+
spec.add_dependency 'activesupport'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
end
|
data/lib/elasticweb.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
require 'httparty'
|
3
|
+
require 'elasticweb/version'
|
4
|
+
require 'elasticweb/client'
|
5
|
+
require 'elasticweb/resource'
|
6
|
+
require 'elasticweb/resource_collection'
|
7
|
+
require 'elasticweb/relation'
|
8
|
+
require 'elasticweb/relation_collection'
|
9
|
+
|
10
|
+
module ElasticWeb
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'elasticweb/client/connection'
|
2
|
+
require 'elasticweb/client/errors'
|
3
|
+
require 'elasticweb/client/user'
|
4
|
+
require 'elasticweb/client/accounts'
|
5
|
+
require 'elasticweb/client/servers'
|
6
|
+
require 'elasticweb/client/aliases'
|
7
|
+
require 'elasticweb/client/domains'
|
8
|
+
require 'elasticweb/client/nginx_configurations'
|
9
|
+
require 'elasticweb/client/dns'
|
10
|
+
require 'elasticweb/client/databases'
|
11
|
+
require 'elasticweb/client/billing'
|
12
|
+
|
13
|
+
module ElasticWeb
|
14
|
+
class Client
|
15
|
+
include HTTParty
|
16
|
+
include ElasticWeb::Client::Connection
|
17
|
+
include ElasticWeb::Client::User
|
18
|
+
include ElasticWeb::Client::Accounts
|
19
|
+
include ElasticWeb::Client::Servers
|
20
|
+
include ElasticWeb::Client::Aliases
|
21
|
+
include ElasticWeb::Client::Domains
|
22
|
+
include ElasticWeb::Client::NGINXConfigurations
|
23
|
+
include ElasticWeb::Client::DNS
|
24
|
+
include ElasticWeb::Client::Databases
|
25
|
+
include ElasticWeb::Client::Billing
|
26
|
+
|
27
|
+
base_uri 'https://elasticweb.org/api'
|
28
|
+
format :json
|
29
|
+
|
30
|
+
def initialize(access_token = nil)
|
31
|
+
access_token ||= ENV['ELASTICWEB_ACCESS_TOKEN']
|
32
|
+
self.class.default_options.merge!(headers: { 'X-API-KEY' => access_token })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'elasticweb/client/accounts/cron'
|
2
|
+
|
3
|
+
module ElasticWeb
|
4
|
+
class Client
|
5
|
+
module Accounts
|
6
|
+
include ElasticWeb::Client::Accounts::Cron
|
7
|
+
|
8
|
+
def accounts
|
9
|
+
get('/account/list')
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_account(options)
|
13
|
+
post('/account/entry', options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_account(id, options)
|
17
|
+
patch("/account/entry/#{id}", options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_account(id)
|
21
|
+
delete("/account/entry/#{id}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Client
|
3
|
+
module Aliases
|
4
|
+
def aliases(account_id)
|
5
|
+
get("/alias/list/#{account_id}")
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_alias(account_id, options)
|
9
|
+
post("/alias/entry/#{account_id}", options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_alias(alias_name, options)
|
13
|
+
patch("/alias/entry/#{alias_name}", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_alias(alias_name)
|
17
|
+
delete("/alias/entry/#{alias_name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Client
|
3
|
+
module Connection
|
4
|
+
|
5
|
+
def get(path, options = {})
|
6
|
+
request :get, path, options
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(path, options = {})
|
10
|
+
request :post, path, options
|
11
|
+
end
|
12
|
+
|
13
|
+
def put(path, options = {})
|
14
|
+
request :put, path, options
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(path, options = {})
|
18
|
+
request :delete, path, options
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def request(http_method, path, options = {})
|
24
|
+
response = self.class.send(http_method, path, { query: options })
|
25
|
+
original_data = response.parsed_response
|
26
|
+
|
27
|
+
return unless original_data
|
28
|
+
|
29
|
+
data = original_data.with_indifferent_access
|
30
|
+
|
31
|
+
case response.code
|
32
|
+
when 200..201
|
33
|
+
parse_data(data)
|
34
|
+
when 400..600
|
35
|
+
parse_errors(data)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_data(data)
|
40
|
+
# При создании аккаунта возвращаются данные с ключом account вместо data.
|
41
|
+
if data.has_key?(:account)
|
42
|
+
data[:data] = data.delete(:account)
|
43
|
+
end
|
44
|
+
|
45
|
+
case data.dig(:data)
|
46
|
+
when Hash then Resource.new(data)
|
47
|
+
when Array then ResourceCollection.new(data)
|
48
|
+
when nil then nil
|
49
|
+
else data
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_errors(data)
|
54
|
+
case data
|
55
|
+
when Hash then Client::Errors.new(data)
|
56
|
+
when nil then nil
|
57
|
+
else data
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'elasticweb/client/databases/users'
|
2
|
+
|
3
|
+
module ElasticWeb
|
4
|
+
class Client
|
5
|
+
module Databases
|
6
|
+
include ElasticWeb::Client::Databases::Users
|
7
|
+
|
8
|
+
def databases(account_id)
|
9
|
+
get("/database/list/#{account_id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_database(account_id, options)
|
13
|
+
post("/database/entry/#{account_id}", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_database(account_id, db_name)
|
17
|
+
delete("/database/entry/#{account_id}/#{db_name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Client
|
3
|
+
module Databases
|
4
|
+
module Users
|
5
|
+
def databases_users(account_id)
|
6
|
+
get("/database_user/list/#{account_id}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def database_user_info(account_id, db_user_name)
|
10
|
+
get("/database_user/entry/#{account_id}/#{db_user_name}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_database_user(account_id, options)
|
14
|
+
post("/database_user/entry/#{account_id}", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_database_user(account_id, db_user_name, options)
|
18
|
+
patch("/database_user/entry/#{account_id}/#{db_user_name}", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_database_user(account_id, db_user_name)
|
22
|
+
delete("/database_user/entry/#{account_id}/#{db_user_name}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Client
|
3
|
+
module DNS
|
4
|
+
def domain_dns(domain_name)
|
5
|
+
get("/dns/list/#{domain_name}")
|
6
|
+
end
|
7
|
+
|
8
|
+
def dns(id)
|
9
|
+
get("/dns/entry/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_dns(domain_name, options)
|
13
|
+
post("/dns/entry/#{domain_name}", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_dns(id)
|
17
|
+
delete("/dns/entry/#{id}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Client
|
3
|
+
module Domains
|
4
|
+
def domains(account_id)
|
5
|
+
get("/domain/list/#{account_id}")
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_domain(account_id, options)
|
9
|
+
post("/domain/entry/#{account_id}", options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_domain(domain_name, options)
|
13
|
+
patch("/domain/entry/#{domain_name}", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_domain(domain_name)
|
17
|
+
delete("/domain/entry/#{domain_name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Client
|
3
|
+
class Errors
|
4
|
+
attr_reader :status, :message, :errors
|
5
|
+
|
6
|
+
def initialize(data)
|
7
|
+
@status = data.dig(:status)
|
8
|
+
@message = data.dig(:message)
|
9
|
+
# Нету общего формата ошибок
|
10
|
+
@errors = data.dig(:errors) || data.dig(:error)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Relation
|
3
|
+
attr_reader :data
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@data = OpenStruct.new(data)
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(method_sym, *arguments, &block)
|
10
|
+
if @data.respond_to?(method_sym)
|
11
|
+
@data.send(method_sym)
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class RelationCollection < Relation
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :options, :collection
|
6
|
+
|
7
|
+
def initialize(data, options = {})
|
8
|
+
data = [] unless data.is_a?(Array)
|
9
|
+
|
10
|
+
@collection = Array(data).map do |item|
|
11
|
+
Relation.new(item)
|
12
|
+
end
|
13
|
+
|
14
|
+
@options = options.with_indifferent_access
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
return enum_for(:each) unless block_given?
|
19
|
+
|
20
|
+
@collection.each { |item| yield item }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class Resource
|
3
|
+
attr_reader :data, :refs, :status, :message
|
4
|
+
|
5
|
+
def initialize(original_data)
|
6
|
+
@status = original_data.dig(:status)
|
7
|
+
@message = original_data.dig(:message)
|
8
|
+
|
9
|
+
original_data = {} unless original_data.dig(:data).is_a?(Hash)
|
10
|
+
|
11
|
+
references = original_data.delete(:references)
|
12
|
+
refs_collection = parse_references(references)
|
13
|
+
@refs = refs_collection.present? ? OpenStruct.new(refs_collection) : nil
|
14
|
+
|
15
|
+
data = original_data.dig(:data)
|
16
|
+
@data = OpenStruct.new(data.with_indifferent_access)
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_references(references)
|
20
|
+
(references || {}).each_with_object({}) do |(reference, value), result|
|
21
|
+
case value
|
22
|
+
when Hash then result[reference] = Relation.new(value)
|
23
|
+
when Array then result[reference] = RelationCollection.new(value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(method_sym, *arguments, &block)
|
29
|
+
if @data.respond_to?(method_sym)
|
30
|
+
@data.send(method_sym)
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ElasticWeb
|
2
|
+
class ResourceCollection < Resource
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :options, :collection, :pager
|
6
|
+
|
7
|
+
def initialize(original_data, options = {})
|
8
|
+
original_data.merge!({ data: [] }) unless original_data.dig(:data).is_a?(Array)
|
9
|
+
|
10
|
+
data = original_data.dig(:data)
|
11
|
+
@collection = Array(data).map do |resource|
|
12
|
+
Resource.new(data: resource)
|
13
|
+
end
|
14
|
+
|
15
|
+
if (pager = original_data.delete(:pager))
|
16
|
+
@pager = OpenStruct.new({
|
17
|
+
total: pager[:total],
|
18
|
+
per_page: pager[:per_page],
|
19
|
+
current_page: pager[:current_page],
|
20
|
+
next_page_url: pager[:next_page_url],
|
21
|
+
prev_page_url: pager[:prev_page_url]
|
22
|
+
})
|
23
|
+
else
|
24
|
+
@pager = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
references = original_data.delete(:references) { Hash.new }
|
28
|
+
@refs = references.present? ? OpenStruct.new(parse_references(references)) : nil
|
29
|
+
@options = options.with_indifferent_access
|
30
|
+
end
|
31
|
+
|
32
|
+
def each
|
33
|
+
return enum_for(:each) unless block_given?
|
34
|
+
|
35
|
+
@collection.each { |item| yield item }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elasticweb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vitaly Lazorka
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Client library for Elasticweb API.
|
70
|
+
email:
|
71
|
+
- dev1.vitaly@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- elasticweb.gemspec
|
84
|
+
- lib/elasticweb.rb
|
85
|
+
- lib/elasticweb/client.rb
|
86
|
+
- lib/elasticweb/client/accounts.rb
|
87
|
+
- lib/elasticweb/client/accounts/cron.rb
|
88
|
+
- lib/elasticweb/client/aliases.rb
|
89
|
+
- lib/elasticweb/client/billing.rb
|
90
|
+
- lib/elasticweb/client/connection.rb
|
91
|
+
- lib/elasticweb/client/databases.rb
|
92
|
+
- lib/elasticweb/client/databases/users.rb
|
93
|
+
- lib/elasticweb/client/dns.rb
|
94
|
+
- lib/elasticweb/client/domains.rb
|
95
|
+
- lib/elasticweb/client/errors.rb
|
96
|
+
- lib/elasticweb/client/nginx_configurations.rb
|
97
|
+
- lib/elasticweb/client/servers.rb
|
98
|
+
- lib/elasticweb/client/user.rb
|
99
|
+
- lib/elasticweb/relation.rb
|
100
|
+
- lib/elasticweb/relation_collection.rb
|
101
|
+
- lib/elasticweb/resource.rb
|
102
|
+
- lib/elasticweb/resource_collection.rb
|
103
|
+
- lib/elasticweb/version.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: https://github.com/dev1vitaly/elasticweb
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.3.0
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.5.1
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Client library for Elasticweb API.
|
129
|
+
test_files:
|
130
|
+
- spec/spec_helper.rb
|