Class: NewStoreApi::AddressController

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

Overview

AddressController

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_or_show_address(profile_id, body) ⇒ AddressResponse

Retrieves an existing address or creates a new address in case it has not been added yet. Note: A maximum of 1000 addresses can be stored per customer profile. When a new address is added after reaching the 1000 limit, the oldest address will be automatically replaced.

Parameters:

  • profile_id (String)

    Required parameter: Profile ID

  • body (AddressModel)

    Required parameter: Request payload

Returns:



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

def create_or_show_address(profile_id,
                           body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/customer/profiles/{profile_id}/addresses',
                                 Server::API)
               .template_param(new_parameter(profile_id, key: 'profile_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(AddressResponse.method(:from_hash)))
    .execute
end

#destroy_address(profile_id, address_id) ⇒ void

This method returns an undefined value.

Deletes address from the latest customer profile.

Parameters:

  • profile_id (String)

    Required parameter: Profile ID

  • address_id (String)

    Required parameter: Address ID



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

def destroy_address(profile_id,
                    address_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/customer/profiles/{profile_id}/addresses/{address_id}',
                                 Server::API)
               .template_param(new_parameter(profile_id, key: 'profile_id')
                                .should_encode(true))
               .template_param(new_parameter(address_id, key: 'address_id')
                                .should_encode(true))
               .auth(Single.new('oauth')))
    .response(new_response_handler
                .is_response_void(true))
    .execute
end

#list_addresses(profile_id, offset: 0, count: 10) ⇒ ListAddressesResponse

Returns a list of addresses for given customer profile_id. addresses.

Parameters:

  • profile_id (String)

    Required parameter: Profile ID

  • offset (Integer) (defaults to: 0)

    Optional parameter: The addresses page offset.

  • count (Integer) (defaults to: 10)

    Optional parameter: The number of requested

Returns:



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

def list_addresses(profile_id,
                   offset: 0,
                   count: 10)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/customer/profiles/{profile_id}/addresses',
                                 Server::API)
               .template_param(new_parameter(profile_id, key: 'profile_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(ListAddressesResponse.method(:from_hash)))
    .execute
end

#show_address(profile_id, address_id) ⇒ AddressResponse

Returns an address for the given customer profile_id and address_id.

Parameters:

  • profile_id (String)

    Required parameter: Profile ID

  • address_id (String)

    Required parameter: Address ID

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/new_store_api/controllers/address_controller.rb', line 86

def show_address(profile_id,
                 address_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/customer/profiles/{profile_id}/addresses/{address_id}',
                                 Server::API)
               .template_param(new_parameter(profile_id, key: 'profile_id')
                                .should_encode(true))
               .template_param(new_parameter(address_id, key: 'address_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(AddressResponse.method(:from_hash)))
    .execute
end

#update_address(profile_id, address_id, body) ⇒ AddressResponse

Updates address for the given customer profile_id and address_id.

Parameters:

  • profile_id (String)

    Required parameter: Profile ID

  • address_id (String)

    Required parameter: Address ID

  • body (UpdateAddressRequest)

    Required parameter: Request payload

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/new_store_api/controllers/address_controller.rb', line 109

def update_address(profile_id,
                   address_id,
                   body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PATCH,
                                 '/customer/profiles/{profile_id}/addresses/{address_id}',
                                 Server::API)
               .template_param(new_parameter(profile_id, key: 'profile_id')
                                .should_encode(true))
               .template_param(new_parameter(address_id, key: 'address_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(AddressResponse.method(:from_hash)))
    .execute
end