Class: Pinnacle::Contacts::Client
- Inherits:
-
Object
- Object
- Pinnacle::Contacts::Client
- Defined in:
- lib/pinnacle/contacts/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Pinnacle::Types::ContactId
Create a new contact for a given phone number.
-
#get(request_options: {}, **params) ⇒ Pinnacle::Types::Contact
Retrieve contact information for a given number.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Pinnacle::Types::ListContactsResponse
List all contacts with optional filtering and pagination.
-
#update(request_options: {}, **params) ⇒ Pinnacle::Types::UpdatedContactId
Update an existing contact.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/pinnacle/contacts/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Pinnacle::Types::ContactId
Create a new contact for a given phone number.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pinnacle/contacts/client.rb', line 64 def create(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "contacts", body: Pinnacle::Contacts::Types::CreateContactParams.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::ContactId.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Pinnacle::Types::Contact
Retrieve contact information for a given number.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pinnacle/contacts/client.rb', line 26 def get(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["id"] = params[:id] if params.key?(:id) query_params["phoneNumber"] = params[:phone_number] if params.key?(:phone_number) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "contacts", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::Contact.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Pinnacle::Types::ListContactsResponse
List all contacts with optional filtering and pagination. Results are sorted by creation date, newest first.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/pinnacle/contacts/client.rb', line 132 def list(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "contacts/list", body: Pinnacle::Contacts::Types::ListContactsParams.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::ListContactsResponse.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Pinnacle::Types::UpdatedContactId
Update an existing contact.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/pinnacle/contacts/client.rb', line 98 def update(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "contacts", body: Pinnacle::Contacts::Types::UpdateContactParams.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::UpdatedContactId.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |