English | Русский
A comprehensive Ruby wrapper for the Yandex 360 API, allowing you to manage organizations, users, departments, groups, domains, DNS records, security settings, and more.
- Features
- Requirements
- Installation
- Authentication
- Getting Started
- Usage Guide
- Error Handling
- Development
- Contributing
- License
- ✅ Complete API Coverage - Full support for all Yandex 360 API endpoints
- 🔒 OAuth Authentication - Secure token-based authentication
- 📦 Resource-based Organization - Clean, intuitive API interface
- 🎯 Type Safety - Structured response objects for easy data access
- 🔄 Pagination Support - Built-in handling for paginated responses
- 🛡️ Error Handling - Comprehensive exception handling for API errors
- 🧪 Well Tested - Extensive test coverage with RSpec
- Ruby >= 2.6
- Faraday >= 1.7, < 3.0
Add this line to your application's Gemfile:
gem 'yandex360', '~> 1.1', '>= 1.1.4'Then execute:
bundle installgem install yandex360To use the Yandex 360 API, you need an OAuth token. You can obtain this token by:
- Registering your application at Yandex OAuth
- Requesting the necessary scopes for Yandex 360 API access
- Obtaining an access token through the OAuth flow
For more information, visit the Yandex 360 API Documentation.
require "yandex360"
# Initialize the client with your OAuth token
client = Yandex360::Client.new(token: "your_access_token_here")
# List all organizations
organizations = client.organizations.list
puts "Organizations: #{organizations.count}"
# Get organization info
org = client.organizations.info(org_id: 1234567)
puts "Organization: #{org.name}"
# List users in an organization
users = client.users.list(org_id: 1234567, page: 1, per_page: 50)
users.each do |user|
puts "User: #{user.email}"
end
# Get organization domains
domains = client.domains.list(org_id: 1234567)
domains.each do |domain|
puts "Domain: #{domain.name}"
end
# Check 2FA status for a user
two_fa_status = client.two_fa.status(org_id: 1234567, user_id: 987654321)
puts "2FA enabled: #{two_fa_status.enabled}"Manage organization information and access.
organizations = client.organizations.list
organizations.each do |org|
puts "ID: #{org.id}, Name: #{org.name}"
endorg = client.organizations.info(org_id: 1234567)
puts "Organization: #{org.name}"
puts "Email: #{org.email}"
puts "Subscription plan: #{org.subscription_plan}"Comprehensive user management including creation, updates, aliases, and deletion.
user = client.users.add(
org_id: 1234567,
dep_id: 1,
nickname: "john.doe",
password: "SecurePass123!",
firstName: "John",
lastName: "Doe",
gender: "male",
position: "Developer",
about: "Senior Ruby Developer"
)
puts "Created user: #{user.email}"# Basic listing with pagination
users = client.users.list(org_id: 1234567, page: 1, per_page: 50)
puts "Total users: #{users.total}"
puts "Current page: #{users.page}"
users.each do |user|
puts "#{user.nickname} - #{user.email}"
enduser = client.users.info(org_id: 1234567, user_id: 987654321)
puts "User: #{user.name.first} #{user.name.last}"
puts "Email: #{user.email}"
puts "Department: #{user.department_id}"
puts "Position: #{user.position}"updated_user = client.users.update(
org_id: 1234567,
user_id: 987654321,
firstName: "Jane",
position: "Senior Developer"
)
puts "Updated: #{updated_user.email}"# Add an alias
alias_result = client.users.add_alias(
org_id: 1234567,
user_id: 987654321,
user_alias: "j.doe"
)
# Delete an alias
client.users.delete_alias(
org_id: 1234567,
user_id: 987654321,
user_alias: "j.doe"
)# Get full 2FA information
two_fa_info = client.users.get2FA(org_id: 1234567, user_id: 987654321)
puts "Has 2FA: #{two_fa_info.has2fa}"
# Simple boolean check
has_2fa = client.users.has2FA?(org_id: 1234567, user_id: 987654321)
puts "2FA enabled: #{has_2fa}"deleted_user = client.users.delete(org_id: 1234567, user_id: 987654321)
puts "Deleted: #{deleted_user.email}"Organize users into departments with hierarchical structures.
department = client.departments.create(
org_id: 1234567,
name: "Engineering",
parent_id: 1,
description: "Software Engineering Department",
label: "ENG",
headId: 123,
externalId: "ext-eng-001"
)
puts "Created department: #{department.name}"departments = client.departments.list(
org_id: 1234567,
page: 1,
per_page: 20,
parent_id: 0, # Root departments
order_by: "id" # or "name"
)
departments.each do |dept|
puts "Department: #{dept.name} (ID: #{dept.id})"
enddept = client.departments.info(org_id: 1234567, dep_id: 5)
puts "Name: #{dept.name}"
puts "Parent ID: #{dept.parent_id}"
puts "Head ID: #{dept.head_id}"
puts "Members count: #{dept.members_count}"updated_dept = client.departments.update(
org_id: 1234567,
dep_id: 5,
parent_id: 2,
name: "Software Engineering",
description: "Updated description"
)# Add an alias
alias_result = client.departments.add_alias(
org_id: 1234567,
dep_id: 5,
name: "SWE"
)
# Delete an alias
client.departments.delete_alias(
org_id: 1234567,
dep_id: 5,
name: "SWE"
)client.departments.delete(org_id: 1234567, dep_id: 5)Create and manage user groups for better organization and access control.
group = client.groups.create(
org_id: 1234567,
name: "Developers",
label: "dev-team",
description: "Development team members",
adminIds: [123, 456]
)
puts "Created group: #{group.name}"groups = client.groups.list(org_id: 1234567, page: 1, per_page: 20)
groups.each do |group|
puts "Group: #{group.name} (#{group.members_count} members)"
endgroup = client.groups.params(org_id: 1234567, group_id: 789)
puts "Name: #{group.name}"
puts "Label: #{group.label}"
puts "Members: #{group.members_count}"updated_group = client.groups.update(
org_id: 1234567,
group_id: 789,
name: "Senior Developers",
description: "Updated description"
)# Add a user to a group
result = client.groups.add_user(
org_id: 1234567,
group_id: 789,
user_id: 987654321,
type: "user" # or "department"
)
# List group members
members = client.groups.users(org_id: 1234567, group_id: 789)
members.each do |member|
puts "Member: #{member.email}"
end
# Remove a user from a group
client.groups.delete_user(
org_id: 1234567,
group_id: 789,
type: "user",
user_id: 987654321
)client.groups.delete(org_id: 1234567, group_id: 789)Manage organization domains and verify ownership.
domains = client.domains.list(org_id: 1234567)
domains.each do |domain|
puts "Domain: #{domain.name}"
puts "Status: #{domain.status}"
puts "Verified: #{domain.verified}"
enddomain = client.domains.add(
org_id: 1234567,
name: "example.com"
)
puts "Added domain: #{domain.name}"
puts "Verification status: #{domain.status}"domain = client.domains.info(org_id: 1234567, domain: "example.com")
puts "Domain: #{domain.name}"
puts "Status: #{domain.status}"
puts "Verified: #{domain.verified}"
puts "Master admin email: #{domain.master_admin}"domain = client.domains.verify(org_id: 1234567, domain: "example.com")
puts "Verification status: #{domain.status}"client.domains.delete(org_id: 1234567, domain: "example.com")Manage DNS records for your domains directly through the API.
records = client.dns.list(org_id: 1234567, domain: "example.com")
records.each do |record|
puts "Record: #{record.type} #{record.name} -> #{record.data}"
puts "TTL: #{record.ttl}"
end# A Record
record = client.dns.create(
org_id: 1234567,
domain: "example.com",
type: "A",
name: "www",
data: "192.0.2.1",
ttl: 3600
)
# MX Record
mx_record = client.dns.create(
org_id: 1234567,
domain: "example.com",
type: "MX",
name: "@",
data: "mail.example.com",
priority: 10,
ttl: 3600
)
# CNAME Record
cname_record = client.dns.create(
org_id: 1234567,
domain: "example.com",
type: "CNAME",
name: "blog",
data: "example.github.io",
ttl: 3600
)updated_record = client.dns.update(
org_id: 1234567,
domain: "example.com",
record_id: 456789,
data: "192.0.2.2",
ttl: 7200
)client.dns.delete(
org_id: 1234567,
domain: "example.com",
record_id: 456789
)Manage two-factor authentication settings for users and the entire domain.
result = client.two_fa.enable(org_id: 1234567, user_id: 987654321)
puts "2FA enabled successfully"result = client.two_fa.disable(org_id: 1234567, user_id: 987654321)
puts "2FA disabled successfully"status = client.two_fa.status(org_id: 1234567, user_id: 987654321)
puts "2FA enabled: #{status.enabled}"
puts "Has TOTP: #{status.has_totp}"domain_status = client.two_fa.domain_status(org_id: 1234567)
puts "Domain 2FA enabled: #{domain_status.enabled}"# Enable 2FA for entire domain
result = client.two_fa.configure_domain(
org_id: 1234567,
enabled: true
)
# Disable 2FA for entire domain
result = client.two_fa.configure_domain(
org_id: 1234567,
enabled: false
)Access and export audit logs for security and compliance tracking.
# Basic listing
events = client.audit.list(
org_id: 1234567,
page: 1,
per_page: 100
)
events.each do |event|
puts "Event: #{event.type}"
puts "User: #{event.user_id}"
puts "Time: #{event.created_at}"
puts "---"
end
# With filters
filtered_events = client.audit.list(
org_id: 1234567,
page: 1,
per_page: 100,
from: "2024-01-01",
to: "2024-12-31",
event_type: "user.created"
)# Export logs for a specific time range
export_result = client.audit.export(
org_id: 1234567,
from: "2024-01-01",
to: "2024-12-31",
format: "json" # or "csv"
)
puts "Export ID: #{export_result.export_id}"Manage email settings for users including forwarding rules.
settings = client.post_settings.list(org_id: 1234567, user_id: 987654321)
puts "Signature: #{settings.signature}"
puts "Reply-to: #{settings.reply_to}"updated = client.post_settings.update(
org_id: 1234567,
user_id: 987654321,
signature: "Best regards,\nJohn Doe",
replyTo: "john.doe@example.com"
)# List forwarding addresses
forwardings = client.post_settings.forwarding_list(
org_id: 1234567,
user_id: 987654321
)
forwardings.each do |forwarding|
puts "Forwarding to: #{forwarding.address}"
end
# Add forwarding address
client.post_settings.add_forwarding(
org_id: 1234567,
user_id: 987654321,
address: "forward@example.com"
)
# Delete forwarding address
client.post_settings.delete_forwarding(
org_id: 1234567,
user_id: 987654321,
address: "forward@example.com"
)Manage IP allowlist for antispam protection.
allowlist = client.antispam.list(org_id: 1234567)
puts "Allowed IPs: #{allowlist.allow_list}"# Add single IP
result = client.antispam.create(1234567, "192.0.2.1")
# Add multiple IPs
result = client.antispam.create(1234567, "192.0.2.1", "192.0.2.2", "192.0.2.3")
# Add IP ranges
result = client.antispam.create(1234567, "192.0.2.0/24")
puts "Updated allowlist: #{result.allow_list}"client.antispam.delete(org_id: 1234567)
puts "Allowlist cleared"The gem provides specific exception classes for different error scenarios:
begin
user = client.users.info(org_id: 1234567, user_id: 999999)
rescue Yandex360::AuthenticationError => e
puts "Authentication failed: #{e.message}"
rescue Yandex360::AuthorizationError => e
puts "Access denied: #{e.message}"
rescue Yandex360::NotFoundError => e
puts "Resource not found: #{e.message}"
rescue Yandex360::ValidationError => e
puts "Invalid parameters: #{e.message}"
rescue Yandex360::RateLimitError => e
puts "Rate limit exceeded: #{e.message}"
rescue Yandex360::ServerError => e
puts "Server error: #{e.message}"
rescue Yandex360::Error => e
puts "API error: #{e.message}"
endYandex360::Error- Base exception classYandex360::AuthenticationError- Invalid or missing token (401)Yandex360::AuthorizationError- Insufficient permissions (403)Yandex360::NotFoundError- Resource not found (404)Yandex360::ValidationError- Invalid request parameters (422)Yandex360::RateLimitError- API rate limit exceeded (429)Yandex360::ServerError- Server-side error (5xx)
git clone https://github.com/ruby-api-client/yandex360.git
cd yandex360
bundle installbundle exec rspec# Run RuboCop
bundle exec rubocop
# Auto-fix issues
bundle exec rubocop -aTest coverage is tracked using SimpleCov and reported to Coveralls. After running tests, open coverage/index.html to view the coverage report.
| Resource | Available Methods |
|---|---|
| Organizations | list, info |
| Users | add, add_alias, update, info, list, get2FA, has2FA?, delete_alias, delete |
| Departments | create, add_alias, update, info, list, delete_alias, delete |
| Groups | create, add_user, update, params, list, users, delete, delete_user |
| Domains | list, add, info, verify, delete |
| DNS | list, create, update, delete |
| Two FA | enable, disable, status, domain_status, configure_domain |
| Audit | list, export |
| Post Settings | list, update, forwarding_list, add_forwarding, delete_forwarding |
| Antispam | list, create, delete |
# Organizations
organizations.list()
organizations.info(org_id:)
# Users
users.add(org_id:, dep_id:, **user_params)
users.add_alias(org_id:, user_id:, user_alias:)
users.update(org_id:, user_id:, **user_params)
users.info(org_id:, user_id:)
users.list(org_id:, page: 1, per_page: 10)
users.get2FA(org_id:, user_id:)
users.has2FA?(org_id:, user_id:)
users.delete_alias(org_id:, user_id:, user_alias:)
users.delete(org_id:, user_id:)
# Departments
departments.create(org_id:, name:, parent_id:, **params)
departments.add_alias(org_id:, dep_id:, name:)
departments.update(org_id:, dep_id:, parent_id:, **params)
departments.info(org_id:, dep_id:)
departments.list(org_id:, page: 1, per_page: 10, parent_id: 0, order_by: "id")
departments.delete_alias(org_id:, dep_id:, name:)
departments.delete(org_id:, dep_id:)
# Groups
groups.create(org_id:, name:, **group_params)
groups.add_user(org_id:, group_id:, user_id:, type: "user")
groups.update(org_id:, group_id:, **user_params)
groups.params(org_id:, group_id:)
groups.list(org_id:, page: 1, per_page: 10)
groups.users(org_id:, group_id:)
groups.delete(org_id:, group_id:)
groups.delete_user(org_id:, group_id:, type:, user_id:)
# Domains
domains.list(org_id:)
domains.add(org_id:, name:, **params)
domains.info(org_id:, domain:)
domains.verify(org_id:, domain:)
domains.delete(org_id:, domain:)
# DNS Records
dns.list(org_id:, domain:)
dns.create(org_id:, domain:, **params)
dns.update(org_id:, domain:, record_id:, **params)
dns.delete(org_id:, domain:, record_id:)
# Two-Factor Authentication
two_fa.enable(org_id:, user_id:)
two_fa.disable(org_id:, user_id:)
two_fa.status(org_id:, user_id:)
two_fa.domain_status(org_id:)
two_fa.configure_domain(org_id:, enabled:)
# Audit Logs
audit.list(org_id:, page: 1, per_page: 100, **params)
audit.export(org_id:, **params)
# Post Settings
post_settings.list(org_id:, user_id:)
post_settings.update(org_id:, user_id:, **params)
post_settings.forwarding_list(org_id:, user_id:)
post_settings.add_forwarding(org_id:, user_id:, address:)
post_settings.delete_forwarding(org_id:, user_id:, address:)
# Antispam
antispam.list(org_id:)
antispam.create(org_id, *strings)
antispam.delete(org_id:)Contributions are welcome! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -am 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure:
- All tests pass (
bundle exec rspec) - Code follows the style guide (
bundle exec rubocop) - New features include appropriate tests
- Documentation is updated as needed
This gem is available as open source under the terms of the MIT License.
Copyright (c) 2022 Ilya Brin
If you have any questions or need help, please:
- Check the documentation
- Open an issue
- Refer to the Yandex 360 API docs
Made with ❤️ by the Ruby API Client community