Class: Verizon::DeviceGroupsController

Inherits:
BaseController show all
Defined in:
lib/verizon/controllers/device_groups_controller.rb

Overview

DeviceGroupsController

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_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from Verizon::BaseController

Instance Method Details

#create_device_group(body) ⇒ ApiResponse

Create a new device group and optionally add devices to the group. Device groups can make it easier to manage similar devices and to get reports on their usage. create a new device group.

Parameters:

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/verizon/controllers/device_groups_controller.rb', line 15

def create_device_group(body)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/m2m/v1/groups',
                                 Server::THINGSPACE)
               .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(And.new('thingspace_oauth', 'VZ-M2M-Token')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ConnectivityManagementSuccessResult.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Error response.',
                             ConnectivityManagementResultException))
    .execute
end

#delete_device_group(aname, gname) ⇒ ApiResponse

Deletes a device group from the account. Devices in the group are moved to the default device group and are not deleted from the account.

Parameters:

  • aname (String)

    Required parameter: Account name.

  • gname (String)

    Required parameter: Group name.

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



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

def delete_device_group(aname,
                        gname)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/m2m/v1/groups/{aname}/name/{gname}',
                                 Server::THINGSPACE)
               .template_param(new_parameter(aname, key: 'aname')
                                .should_encode(true))
               .template_param(new_parameter(gname, key: 'gname')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(And.new('thingspace_oauth', 'VZ-M2M-Token')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ConnectivityManagementSuccessResult.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Error response.',
                             ConnectivityManagementResultException))
    .execute
end

#get_device_group_information(aname, gname, mnext: nil) ⇒ ApiResponse

When HTTP status is 202, a URL will be returned in the Location header of the form /groups/aname/name/gname/?next=token. This URL can be used to request the next set of groups. from the pageUrl pagetoken.

Parameters:

  • aname (String)

    Required parameter: Account name.

  • gname (String)

    Required parameter: Group name.

  • mnext (Integer) (defaults to: nil)

    Optional parameter: Continue the previous query

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/verizon/controllers/device_groups_controller.rb', line 66

def get_device_group_information(aname,
                                 gname,
                                 mnext: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/m2m/v1/groups/{aname}/name/{gname}',
                                 Server::THINGSPACE)
               .template_param(new_parameter(aname, key: 'aname')
                                .should_encode(true))
               .template_param(new_parameter(gname, key: 'gname')
                                .should_encode(true))
               .query_param(new_parameter(mnext, key: 'next'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(And.new('thingspace_oauth', 'VZ-M2M-Token')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(DeviceGroupDevicesData.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Error response.',
                             ConnectivityManagementResultException))
    .execute
end

#list_device_groups(aname) ⇒ ApiResponse

Returns a list of all device groups in a specified account.

Parameters:

  • aname (String)

    Required parameter: Account name.

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/verizon/controllers/device_groups_controller.rb', line 38

def list_device_groups(aname)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/m2m/v1/groups/{aname}',
                                 Server::THINGSPACE)
               .template_param(new_parameter(aname, key: 'aname')
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(And.new('thingspace_oauth', 'VZ-M2M-Token')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(DeviceGroup.method(:from_hash))
                .is_api_response(true)
                .is_response_array(true)
                .local_error('400',
                             'Error response.',
                             ConnectivityManagementResultException))
    .execute
end

#update_device_group(aname, gname, body) ⇒ ApiResponse

Make changes to a device group, including changing the name and description, and adding or removing devices. update device group.

Parameters:

  • aname (String)

    Required parameter: Account name.

  • gname (String)

    Required parameter: Group name.

  • body (DeviceGroupUpdateRequest)

    Required parameter: Request to

Returns:

  • (ApiResponse)

    the complete http response with raw body and status code.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/verizon/controllers/device_groups_controller.rb', line 97

def update_device_group(aname,
                        gname,
                        body)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/m2m/v1/groups/{aname}/name/{gname}',
                                 Server::THINGSPACE)
               .template_param(new_parameter(aname, key: 'aname')
                                .should_encode(true))
               .template_param(new_parameter(gname, key: 'gname')
                                .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(And.new('thingspace_oauth', 'VZ-M2M-Token')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ConnectivityManagementSuccessResult.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Error response.',
                             ConnectivityManagementResultException))
    .execute
end