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
-
#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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pinnacle/contacts/client.rb', line 66 def create(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) body_prop_names = i[phone_number description email name ] body_bag = params.slice(*body_prop_names) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "contacts", body: Pinnacle::Contacts::Types::CreateContactParams.new(body_bag).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 52 53 |
# File 'lib/pinnacle/contacts/client.rb', line 26 def get(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) query_param_names = i[id phone_number] query_params = {} query_params["id"] = params[:id] if params.key?(:id) query_params["phoneNumber"] = params[:phone_number] if params.key?(:phone_number) params.except(*query_param_names) 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 |
#update(request_options: {}, **params) ⇒ Pinnacle::Types::UpdatedContactId
Update an existing contact.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/pinnacle/contacts/client.rb', line 103 def update(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) body_prop_names = i[id description email name ] body_bag = params.slice(*body_prop_names) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "contacts", body: Pinnacle::Contacts::Types::UpdateContactParams.new(body_bag).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 |