Class: Starling::Services::ContactsService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/starling/services/contacts_service.rb

Overview

A service for accessing the Contact’s API’s Get Contacts, Get Contact, Delete Contact and Create Contact and Account endpoints

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from Starling::Services::BaseService

Instance Method Details

#create(params:, headers: {}) ⇒ Resources::ContactResource

Returns the created contact.

Parameters:

  • params (Hash)

    Parameters which will be included in the HTTP request, included in the body

  • headers (Hash) (defaults to: {})

    Headers which be included in the HTTP request, merged on top of the headers set at the Client level

Returns:

Raises:

  • (Errors::ApiError)

    if the HTTP request returns a status indicating that it was unsuccessful



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/starling/services/contacts_service.rb', line 53

def create(params:, headers: {})
  post_response = api_service.make_request(:post, '/contacts', params: params,
                                                               headers: headers)

  get_response = api_service.make_request(
    :get,
    convert_location_header_to_relative_path(post_response.headers['Location']),
    headers: headers
  )

  resource.new(response: get_response)
end

#delete(id, params: {}, headers: {}) ⇒ Faraday::Response

Returns the raw response from the Starling Bank API.

Parameters:

  • id (String)

    The Starling internal ID of the contact

  • params (Hash) (defaults to: {})

    Parameters which will be included in the HTTP request, included in the body

  • headers (Hash) (defaults to: {})

    Headers which be included in the HTTP request, merged on top of the headers set at the Client level

Returns:

  • (Faraday::Response)

    the raw response from the Starling Bank API

Raises:

  • (Errors::ApiError)

    if the HTTP request returns a status indicating that it was unsuccessful



28
29
30
31
# File 'lib/starling/services/contacts_service.rb', line 28

def delete(id, params: {}, headers: {})
  api_service.make_request(:delete, "/contacts/#{id}", params: params,
                                                       headers: headers)
end

#get(id, params: {}, headers: {}) ⇒ Resources::ContactResource

Parameters:

  • id (String)

    The Starling internal ID of the contact

  • params (Hash) (defaults to: {})

    Parameters which will be included in the HTTP request, included in the URL as a query string

  • headers (Hash) (defaults to: {})

    Headers which be included in the HTTP request, merged on top of the headers set at the Client level

Returns:

Raises:

  • (Errors::ApiError)

    if the HTTP request returns a status indicating that it was unsuccessful



14
15
16
17
18
# File 'lib/starling/services/contacts_service.rb', line 14

def get(id, params: {}, headers: {})
  response = api_service.make_request(:get, "/contacts/#{id}", params: params,
                                                               headers: headers)
  resource.new(response: response)
end

#list(params: {}, headers: {}) ⇒ Array<Resources::ContactResource>

Parameters:

  • params (Hash) (defaults to: {})

    Parameters which will be included in the HTTP request, included in the URL as a query string

  • headers (Hash) (defaults to: {})

    Headers which be included in the HTTP request, merged on top of the headers set at the Client level

Returns:

Raises:

  • (Errors::ApiError)

    if the HTTP request returns a status indicating that it was unsuccessful



40
41
42
43
44
# File 'lib/starling/services/contacts_service.rb', line 40

def list(params: {}, headers: {})
  response = api_service.make_request(:get, '/contacts', params: params,
                                                         headers: headers)
  build_collection_from_embedded_key(response, key: 'contacts', resource: resource)
end