Class: MxHero::API::Groups
- Inherits:
-
Object
- Object
- MxHero::API::Groups
- Includes:
- Communication, Urls
- Defined in:
- lib/groups.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
Instance Method Summary collapse
-
#accounts(group_name, options = { per_page: nil, page: nil }) ⇒ MxHero::API::PaginatedElements
Retrieve all the accounts for one group.
-
#add_account(group_name, account_name) ⇒ MxHero::API::Response
Add an account to a group.
-
#all(pagination = { page: nil, per_page: nil }) ⇒ PaginatedElement
Retrieve all the groups.
-
#delete(group_name) ⇒ MxHero::API::Response
Delete the group.
-
#initialize(domain, config = {}) ⇒ Groups
constructor
A new instance of Groups.
-
#remove_account(group_name, account_name) ⇒ MxHero::API::Response
With content empty.
-
#save(group) ⇒ MxHero::API::Response
Save a new group.
-
#search_accounts(term) ⇒ Object
Search available accounts.
Methods included from Urls
#domain_by_id_url, #domains_url, #service_url
Methods included from Communication
Constructor Details
#initialize(domain, config = {}) ⇒ Groups
Returns a new instance of Groups.
26 27 28 29 30 31 32 33 |
# File 'lib/groups.rb', line 26 def initialize(domain, config = {}) @domain = domain @service_url = config[:api_url] @username = config[:username] @password = config[:password] @verbose = config[:verbose] || false @as_user = config[:as_user] end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
24 25 26 |
# File 'lib/groups.rb', line 24 def domain @domain end |
Instance Method Details
#accounts(group_name, options = { per_page: nil, page: nil }) ⇒ MxHero::API::PaginatedElements
Retrieve all the accounts for one group
84 85 86 87 88 89 |
# File 'lib/groups.rb', line 84 def accounts(group_name, = { per_page: nil, page: nil }) response = call(:get, group_accounts_url(group_name, )) paginate_wrap response do |hash| hash[:elements].map { |e| Account.new(e) } end end |
#add_account(group_name, account_name) ⇒ MxHero::API::Response
Add an account to a group
100 101 102 103 |
# File 'lib/groups.rb', line 100 def add_account(group_name, account_name) response = call(:post, group_add_accounts_url(group_name, account_name), nil, throw_exception: false) wrap_response_from response end |
#all(pagination = { page: nil, per_page: nil }) ⇒ PaginatedElement
Retrieve all the groups
42 43 44 45 46 47 |
# File 'lib/groups.rb', line 42 def all(pagination = { page: nil, per_page: nil }) response = call(:get, groups_url(pagination)) paginate_wrap(response) do |hash| hash[:elements].map { |e| Group.new(e) } end end |
#delete(group_name) ⇒ MxHero::API::Response
Delete the group
72 73 74 75 |
# File 'lib/groups.rb', line 72 def delete(group_name) response = call(:delete, group_url(group_name), nil, throw_exception: false) wrap_response_from response end |
#remove_account(group_name, account_name) ⇒ MxHero::API::Response
Returns with content empty. In case on error, may be one of the following:
+ domain.account.not.found : Inexistent account
+ domain.group.account.not.in.group : Try to remove an account that is not in the group.
113 114 115 116 |
# File 'lib/groups.rb', line 113 def remove_account(group_name, account_name) response = call(:delete, group_remove_accounts_url(group_name, account_name), nil, throw_exception: false) wrap_response_from response end |
#save(group) ⇒ MxHero::API::Response
Save a new group
60 61 62 63 |
# File 'lib/groups.rb', line 60 def save(group) group.domain = domain wrap_response_from call(:post, groups_url, group.to_json) end |
#search_accounts(term) ⇒ Object
Search available accounts
50 51 52 53 |
# File 'lib/groups.rb', line 50 def search_accounts(term) response = call(:get, search_accounts_url(term) ,nil, throw_exception: false) Response.new(response.status, json_parse(response.content)) end |