yandex360 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile.lock +1 -4
- data/README.md +6 -0
- data/lib/yandex360/client.rb +16 -1
- data/lib/yandex360/collection.rb +22 -0
- data/lib/yandex360/error.rb +6 -0
- data/lib/yandex360/object.rb +25 -0
- data/lib/yandex360/objects/types.rb +20 -0
- data/lib/yandex360/resource.rb +59 -0
- data/lib/yandex360/resources/antispam.rb +18 -0
- data/lib/yandex360/resources/departments.rb +52 -0
- data/lib/yandex360/resources/groups.rb +47 -0
- data/lib/yandex360/resources/users.rb +50 -0
- data/lib/yandex360/version.rb +1 -1
- data/lib/yandex360.rb +22 -2
- data/yandex360.gemspec +0 -1
- metadata +11 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a5a0d2ac0b76df152ea5246600c6c01469a7f5716970f2db2e10af22d5ca322
|
4
|
+
data.tar.gz: 3d0b28a3871390e29479f34b56eaa7637c3a0a6e98f25fc57982e9e6eaf5f540
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05a2ba164cb6e206081d718505eb62df6c1ef032815e7f1b7d76d809a64026bcd2c91faeeccb0af78a77d4f2140af030d455b10f2447bada3e910a86b86565e5
|
7
|
+
data.tar.gz: b03c6852ea6c5b5f87d869412e834a12156422b3dd4adcb36c75c5f534df2adfb3565a29869dfd3cbb71c4a5281641a0cf560711d29abe33a12542244c9572cc
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yandex360 (
|
4
|
+
yandex360 (1.0.1)
|
5
5
|
addressable (~> 2.3, >= 2.3.7)
|
6
6
|
faraday (~> 1.7)
|
7
|
-
faraday_middleware (~> 1.1)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
@@ -34,8 +33,6 @@ GEM
|
|
34
33
|
faraday-patron (1.0.0)
|
35
34
|
faraday-rack (1.0.0)
|
36
35
|
faraday-retry (1.0.3)
|
37
|
-
faraday_middleware (1.2.0)
|
38
|
-
faraday (~> 1.0)
|
39
36
|
multipart-post (2.2.3)
|
40
37
|
public_suffix (5.0.0)
|
41
38
|
ruby2_keywords (0.0.5)
|
data/README.md
CHANGED
data/lib/yandex360/client.rb
CHANGED
@@ -13,13 +13,28 @@ module Yandex360
|
|
13
13
|
@stubs = stubs # Test stubs for requests
|
14
14
|
end
|
15
15
|
|
16
|
+
def antispam
|
17
|
+
AntispamResource.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def departments
|
21
|
+
DepartmentsResource.new(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def groups
|
25
|
+
GroupsResource.new(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def users
|
29
|
+
UsersResource.new(self)
|
30
|
+
end
|
31
|
+
|
16
32
|
def connection
|
17
33
|
@connection ||= Faraday.new(BASE_URL) do |conn|
|
18
34
|
conn.request :authorization, :OAuth, token
|
19
35
|
conn.request :json
|
20
36
|
conn.request :url_encoded
|
21
37
|
|
22
|
-
conn.response :dates
|
23
38
|
conn.response :json, content_type: "application/json"
|
24
39
|
|
25
40
|
conn.adapter adapter, @stubs
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yandex360
|
4
|
+
class Collection
|
5
|
+
attr_reader :data, :items, :total
|
6
|
+
|
7
|
+
def self.from_response(response, key:, type:)
|
8
|
+
body = response.body
|
9
|
+
new(
|
10
|
+
data: body[key].map {|attrs| type.new(attrs) },
|
11
|
+
items: body["items"],
|
12
|
+
total: body["total"]
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(data:, items:, total:)
|
17
|
+
@data = data
|
18
|
+
@items = items
|
19
|
+
@total = total
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module Yandex360
|
6
|
+
class Object < OpenStruct
|
7
|
+
def initialize(attributes)
|
8
|
+
super to_ostruct(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Convert Array or Hash to OpenStruct
|
12
|
+
def to_ostruct(obj)
|
13
|
+
case obj
|
14
|
+
when Hash
|
15
|
+
# rubocop:disable Style/HashTransformValues
|
16
|
+
OpenStruct.new(obj.map {|key, val| [key, to_ostruct(val)] }.to_h)
|
17
|
+
# rubocop:enable Style/HashTransformValues
|
18
|
+
when Array
|
19
|
+
obj.map {|o| to_ostruct(o) }
|
20
|
+
else
|
21
|
+
obj
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yandex360
|
4
|
+
class AllowList < Object; end
|
5
|
+
class Department < Object; end
|
6
|
+
class Group < Object; end
|
7
|
+
class User < Object; end
|
8
|
+
class UserList < Object; end
|
9
|
+
|
10
|
+
class DeletedDepartment < Object; end
|
11
|
+
class DeletedGroup < Object; end
|
12
|
+
class DeletedUser < Object; end
|
13
|
+
class DepartmentAlias < Object; end
|
14
|
+
class DepartmentList < Object; end
|
15
|
+
class DeletedDepartmentAlias < Object; end
|
16
|
+
|
17
|
+
class GroupList < Object; end
|
18
|
+
|
19
|
+
class Alias < Object; end
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yandex360
|
4
|
+
class Resource
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def get(url, params: {}, headers: {})
|
14
|
+
handle_response client.connection.get(url, params, headers)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(url, body:, headers: {})
|
18
|
+
handle_response client.connection.post(url, body, headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def patch(url, body:, headers: {})
|
22
|
+
handle_response client.connection.patch(url, body, headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def put(url, body:, headers: {})
|
26
|
+
handle_response client.connection.put(url, body, headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(url, params: {}, headers: {})
|
30
|
+
handle_response client.connection.delete(url, params, headers)
|
31
|
+
end
|
32
|
+
alias delete_request delete
|
33
|
+
|
34
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
35
|
+
# rubocop:disable Metrics/AbcSize
|
36
|
+
def handle_response(response)
|
37
|
+
case response.status
|
38
|
+
when 400
|
39
|
+
raise Error, "Your request was malformed. #{response.body['error']}"
|
40
|
+
when 401
|
41
|
+
raise Error, "You did not supply valid authentication credentials. #{response.body['error']}"
|
42
|
+
when 403
|
43
|
+
raise Error, "You are not allowed to perform that action. #{response.body['error']}"
|
44
|
+
when 404
|
45
|
+
raise Error, "No results were found for your request. #{response.body['error']}"
|
46
|
+
when 429
|
47
|
+
raise Error, "Your request exceeded the API rate limit. #{response.body['error']}"
|
48
|
+
when 500
|
49
|
+
raise Error, "We were unable to perform the request due to server-side problems. #{response.body['error']}"
|
50
|
+
when 503
|
51
|
+
raise Error, "You have been rate limited for sending more requests per second. #{response.body['error']}"
|
52
|
+
end
|
53
|
+
|
54
|
+
response
|
55
|
+
end
|
56
|
+
# rubocop:enable Metrics/AbcSize
|
57
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yandex360
|
4
|
+
class AntispamResource < Resource
|
5
|
+
def list(org_id:)
|
6
|
+
AllowList.new get("/admin/v1/org/#{org_id}/mail/antispam/allowlist/ips").body
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(org_id, *strings)
|
10
|
+
body = {allowList: strings}
|
11
|
+
AllowList.new post("admin/v1/org/#{org_id}/mail/antispam/allowlist/ips", body: body).body
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete(org_id:)
|
15
|
+
delete_request("admin/v1/org/#{org_id}/mail/antispam/allowlist/ips")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yandex360
|
4
|
+
class DepartmentsResource < Resource
|
5
|
+
def add_alias(org_id:, dep_id:, name:)
|
6
|
+
dep_alias = {alias: name}
|
7
|
+
DepartmentAlias.new post("directory/v1/org/#{org_id}/departments/#{dep_id}/aliases", body: dep_alias).body
|
8
|
+
end
|
9
|
+
|
10
|
+
def update(org_id:, dep_id:, **params)
|
11
|
+
department = {}
|
12
|
+
params.each {|param, value| department[param] = value }
|
13
|
+
Department.new patch("directory/v1/org/#{org_id}/departments/#{dep_id}", body: department).body
|
14
|
+
end
|
15
|
+
|
16
|
+
def info(org_id:, dep_id:)
|
17
|
+
Department.new get("directory/v1/org/#{org_id}/departments/#{dep_id}").body
|
18
|
+
end
|
19
|
+
|
20
|
+
def list(org_id:, page: 1, per_page: 10, parent_id: 0, order_by: "id")
|
21
|
+
resp = get(%{
|
22
|
+
directory/v1/org/#{org_id}/departments\
|
23
|
+
?page=#{page}\
|
24
|
+
&perPage=#{per_page}\
|
25
|
+
&parentId=#{parent_id}\
|
26
|
+
&orderBy=#{order_by}")
|
27
|
+
}.gsub(/\s+/, "").strip)
|
28
|
+
Collection.from_response(resp, key: "departments", type: GroupList)
|
29
|
+
end
|
30
|
+
|
31
|
+
# parent_id:, name:, description: "", external_id: "", head_id: 0, label: ""
|
32
|
+
def create(org_id:, name:, parent_id:, **params)
|
33
|
+
department = {
|
34
|
+
parentId: parent_id,
|
35
|
+
name: name
|
36
|
+
}
|
37
|
+
params.each do |param, value|
|
38
|
+
department[param] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
Department.new post("directory/v1/org/#{org_id}/departments", body: department).body
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_alias(org_id:, dep_id:, name:)
|
45
|
+
Object.new delete_request("directory/v1/org/#{org_id}/departments/#{dep_id}/aliases/#{name}").body
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete(org_id:, dep_id:)
|
49
|
+
Object.new delete_request("directory/v1/org/#{org_id}/departments/#{dep_id}").body
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yandex360
|
4
|
+
class GroupsResource < Resource
|
5
|
+
def add_user(org_id:, group_id:, id:, type: "user")
|
6
|
+
user = {
|
7
|
+
id: id,
|
8
|
+
type: type
|
9
|
+
}
|
10
|
+
Group.new post("directory/v1/org/#{org_id}/groups/#{group_id}/members", body: user).body
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(org_id:, group_id:, **user_params)
|
14
|
+
user = {}
|
15
|
+
user_params.each {|param, value| user[param] = value }
|
16
|
+
Group.new patch("directory/v1/org/#{org_id}/groups/#{group_id}", body: user).body
|
17
|
+
end
|
18
|
+
|
19
|
+
def params(org_id:, group_id:)
|
20
|
+
Group.new get("directory/v1/org/#{org_id}/groups/#{group_id}").body
|
21
|
+
end
|
22
|
+
|
23
|
+
def list(org_id:, page: 1, per_page: 10)
|
24
|
+
resp = get("directory/v1/org/#{org_id}/groups?page=#{page}&perPage=#{per_page}")
|
25
|
+
Collection.from_response(resp, key: "groups", type: Object)
|
26
|
+
end
|
27
|
+
|
28
|
+
def users(org_id:, group_id:)
|
29
|
+
# TODO: GroupUserList.new type
|
30
|
+
Object.new get("directory/v1/org/#{org_id}/groups/#{group_id}/members").body
|
31
|
+
end
|
32
|
+
|
33
|
+
def create(org_id:, **group_params)
|
34
|
+
group = {}
|
35
|
+
group_params.each {|param, value| group[param] = value }
|
36
|
+
Group.new post("directory/v1/org/#{org_id}/groups", body: group).body
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(org_id:, group_id:)
|
40
|
+
delete_request("directory/v1/org/#{org_id}/groups/#{group_id}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_user(org_id:, group_id:, type:, id:)
|
44
|
+
Object.new delete_request("directory/v1/org/#{org_id}/groups/#{group_id}/members/#{type}/#{id}").body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yandex360
|
4
|
+
class UsersResource < Resource
|
5
|
+
def add(org_id:, dep_id:, **user_params)
|
6
|
+
user = {
|
7
|
+
departmentId: dep_id
|
8
|
+
}
|
9
|
+
user_params.each {|param, value| user[param] = value }
|
10
|
+
|
11
|
+
User.new post("directory/v1/org/#{org_id}/users", body: user).body
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_alias(org_id:, user_id:, user_alias:)
|
15
|
+
body = {alias: user_alias}
|
16
|
+
User.new post("directory/v1/org/#{org_id}/users/#{user_id}/aliases", body: body).body
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(org_id:, user_id:, **user_params)
|
20
|
+
user = {}
|
21
|
+
user_params.each {|param, value| user[param] = value }
|
22
|
+
|
23
|
+
User.new patch("directory/v1/org/#{org_id}/users/#{user_id}", body: user).body
|
24
|
+
end
|
25
|
+
|
26
|
+
def info(org_id:, user_id:)
|
27
|
+
User.new get("directory/v1/org/#{org_id}/users/#{user_id}").body
|
28
|
+
end
|
29
|
+
|
30
|
+
def list(org_id:, page: 1, per_page: 10)
|
31
|
+
resp = get("directory/v1/org/#{org_id}/users?page=#{page}&perPage=#{per_page}")
|
32
|
+
Collection.from_response(resp, key: "users", type: UserList)
|
33
|
+
end
|
34
|
+
|
35
|
+
# rubocop:disable Naming/MethodName
|
36
|
+
def get2FA(org_id:, user_id:)
|
37
|
+
# TODO: add User2FA.new type
|
38
|
+
Object.new get("directory/v1/org/#{org_id}/users/#{user_id}/2fa").body
|
39
|
+
end
|
40
|
+
|
41
|
+
def has2FA?(org_id:, user_id:)
|
42
|
+
get2FA(org_id: org_id, user_id: user_id).has2fa
|
43
|
+
end
|
44
|
+
# rubocop:enable Naming/MethodName
|
45
|
+
|
46
|
+
def delete_alias(org_id:, user_id:, user_alias:)
|
47
|
+
Alias.new delete_request("directory/v1/org/#{org_id}/users/#{user_id}/aliases/#{user_alias}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/yandex360/version.rb
CHANGED
data/lib/yandex360.rb
CHANGED
@@ -2,9 +2,29 @@
|
|
2
2
|
|
3
3
|
require "addressable/uri"
|
4
4
|
require "faraday"
|
5
|
-
require "faraday_middleware"
|
6
5
|
require "yandex360/version"
|
7
6
|
|
8
|
-
module
|
7
|
+
module Yandex360
|
9
8
|
autoload :Client, "yandex360/client"
|
9
|
+
autoload :Object, "yandex360/object"
|
10
|
+
autoload :Resource, "yandex360/resource"
|
11
|
+
autoload :Collection, "yandex360/collection"
|
12
|
+
autoload :Error, "yandex360/error"
|
13
|
+
|
14
|
+
autoload :AntispamResource, "yandex360/resources/antispam"
|
15
|
+
autoload :AllowList, "yandex360/objects/types"
|
16
|
+
|
17
|
+
autoload :DepartmentsResource, "yandex360/resources/departments"
|
18
|
+
autoload :Departments, "yandex360/objects/types"
|
19
|
+
autoload :DepartmentList, "yandex360/objects/types"
|
20
|
+
autoload :DepartmentAlias, "yandex360/objects/types"
|
21
|
+
autoload :DeletedDepartment, "yandex360/objects/types"
|
22
|
+
autoload :DeletedDepartmentAlias, "yandex360/objects/types"
|
23
|
+
|
24
|
+
autoload :GroupsResource, "yandex360/resources/groups"
|
25
|
+
autoload :Group, "yandex360/objects/types"
|
26
|
+
autoload :GroupList, "yandex360/objects/types"
|
27
|
+
|
28
|
+
autoload :UsersResource, "yandex360/resources/users"
|
29
|
+
autoload :UserList, "yandex360/objects/types"
|
10
30
|
end
|
data/yandex360.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex360
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Brin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -44,20 +44,6 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.7'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: faraday_middleware
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '1.1'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '1.1'
|
61
47
|
description: WIP - Yandex 360 API wrapper written in Ruby
|
62
48
|
email: ilya@codeplay.ru
|
63
49
|
executables: []
|
@@ -73,6 +59,15 @@ files:
|
|
73
59
|
- Rakefile
|
74
60
|
- lib/yandex360.rb
|
75
61
|
- lib/yandex360/client.rb
|
62
|
+
- lib/yandex360/collection.rb
|
63
|
+
- lib/yandex360/error.rb
|
64
|
+
- lib/yandex360/object.rb
|
65
|
+
- lib/yandex360/objects/types.rb
|
66
|
+
- lib/yandex360/resource.rb
|
67
|
+
- lib/yandex360/resources/antispam.rb
|
68
|
+
- lib/yandex360/resources/departments.rb
|
69
|
+
- lib/yandex360/resources/groups.rb
|
70
|
+
- lib/yandex360/resources/users.rb
|
76
71
|
- lib/yandex360/version.rb
|
77
72
|
- yandex360.gemspec
|
78
73
|
homepage: https://github.com/ruby-api-client/yandex360
|