Class: NewStoreApi::RolesController

Inherits:
BaseController show all
Defined in:
lib/new_store_api/controllers/roles_controller.rb

Overview

RolesController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from NewStoreApi::BaseController

Instance Method Details

#create_role(body) ⇒ Role

Creates a new role. here

Parameters:

Returns:

  • (Role)

    Response from the API call.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/new_store_api/controllers/roles_controller.rb', line 46

def create_role(body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/iam/roles',
                                 Server::API)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Role.method(:from_hash)))
    .execute
end

#destroy_role(id) ⇒ void

This method returns an undefined value.

Deletes the user role with the specified ID. Once deleted, the user role is unassigned from all associated user accounts.

Parameters:

  • id (String)

    Required parameter: role id



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/new_store_api/controllers/roles_controller.rb', line 67

def destroy_role(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/iam/roles/{id}',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end

#list_permissionsGetPermissionsResponse

Lists all the user permissions available for the retailer.

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/new_store_api/controllers/roles_controller.rb', line 11

def list_permissions
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/iam/permissions',
                                 Server::API)
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(GetPermissionsResponse.method(:from_hash)))
    .execute
end

#list_roles(q: nil) ⇒ GetRolesResponse

Lists all available user roles for the retailer. Search if the query parameter is used.

Parameters:

  • q (String) (defaults to: nil)

    Optional parameter: Query the resulting list by name.

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/new_store_api/controllers/roles_controller.rb', line 28

def list_roles(q: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/iam/roles',
                                 Server::API)
               .query_param(new_parameter(q, key: 'q'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(GetRolesResponse.method(:from_hash)))
    .execute
end

#list_users_by_role(id, offset: 0, count: 25) ⇒ GetUsersByRoleResponse

Retrieves all user accounts that have been assigned the specified user role. resulting user account list. accounts.

Parameters:

  • id (String)

    Required parameter: role id

  • offset (Integer) (defaults to: 0)

    Optional parameter: The offset to be used for the

  • count (Integer) (defaults to: 25)

    Optional parameter: The number of requested user

Returns:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/new_store_api/controllers/roles_controller.rb', line 130

def list_users_by_role(id,
                       offset: 0,
                       count: 25)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/iam/roles/{id}/users',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .query_param(new_parameter(offset, key: 'offset'))
               .query_param(new_parameter(count, key: 'count'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(GetUsersByRoleResponse.method(:from_hash)))
    .execute
end

#replace_role(id, body) ⇒ Role

Updates the user role with the specified ID. description here

Parameters:

  • id (String)

    Required parameter: role id

  • body (PutRolesByIdRequest)

    Required parameter: TODO: type

Returns:

  • (Role)

    Response from the API call.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/new_store_api/controllers/roles_controller.rb', line 103

def replace_role(id,
                 body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/iam/roles/{id}',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Role.method(:from_hash)))
    .execute
end

#show_role(id) ⇒ Role

Retrieves the user role with the specified ID.

Parameters:

  • id (String)

    Required parameter: role id

Returns:

  • (Role)

    Response from the API call.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/new_store_api/controllers/roles_controller.rb', line 83

def show_role(id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/iam/roles/{id}',
                                 Server::API)
               .template_param(new_parameter(id, key: 'id')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Role.method(:from_hash)))
    .execute
end