Class: Paid::ContactsClient
- Inherits:
-
Object
- Object
- Paid::ContactsClient
- Defined in:
- lib/paid_ruby/contacts/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#create(external_id: nil, customer_id: nil, customer_external_id: nil, salutation:, first_name:, last_name:, email:, phone: nil, billing_street: nil, billing_city: nil, billing_state_province: nil, billing_country: nil, billing_postal_code: nil, request_options: nil) ⇒ Object
).
-
#delete(contact_id:, request_options: nil) ⇒ Object
api.contacts.delete(contact_id: “contactId”).
-
#delete_by_external_id(external_id:, request_options: nil) ⇒ Object
api.contacts.delete_by_external_id(external_id: “externalId”).
-
#get(contact_id:, request_options: nil) ⇒ Object
api.contacts.get(contact_id: “contactId”).
-
#get_by_external_id(external_id:, request_options: nil) ⇒ Object
api.contacts.get_by_external_id(external_id: “externalId”).
- #initialize(request_client:) ⇒ Paid::ContactsClient constructor
-
#list(request_options: nil) ⇒ Object
api.contacts.list.
Constructor Details
#initialize(request_client:) ⇒ Paid::ContactsClient
22 23 24 |
# File 'lib/paid_ruby/contacts/client.rb', line 22 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Paid::RequestClient (readonly)
17 18 19 |
# File 'lib/paid_ruby/contacts/client.rb', line 17 def request_client @request_client end |
Instance Method Details
#create(external_id: nil, customer_id: nil, customer_external_id: nil, salutation:, first_name:, last_name:, email:, phone: nil, billing_street: nil, billing_city: nil, billing_state_province: nil, billing_country: nil, billing_postal_code: nil, request_options: nil) ⇒ Object
)
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/paid_ruby/contacts/client.rb', line 85 def create(external_id: nil, customer_id: nil, customer_external_id: nil, salutation:, first_name:, last_name:, email:, phone: nil, billing_street: nil, billing_city: nil, billing_state_province: nil, billing_country: nil, billing_postal_code: nil, request_options: nil) response = @request_client.conn.post do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), externalId: external_id, customerId: customer_id, customerExternalId: customer_external_id, salutation: salutation, firstName: first_name, lastName: last_name, email: email, phone: phone, billingStreet: billing_street, billingCity: billing_city, billingStateProvince: billing_state_province, billingCountry: billing_country, billingPostalCode: billing_postal_code }.compact req.url "#{@request_client.get_url(request_options: )}/contacts" end Paid::Contact.from_json(json_object: response.body) end |
#delete(contact_id:, request_options: nil) ⇒ Object
api.contacts.delete(contact_id: “contactId”)
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/paid_ruby/contacts/client.rb', line 141 def delete(contact_id:, request_options: nil) response = @request_client.conn.delete do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/contacts/#{contact_id}" end end |
#delete_by_external_id(external_id:, request_options: nil) ⇒ Object
api.contacts.delete_by_external_id(external_id: “externalId”)
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/paid_ruby/contacts/client.rb', line 198 def delete_by_external_id(external_id:, request_options: nil) response = @request_client.conn.delete do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/contacts/external/#{external_id}" end end |
#get(contact_id:, request_options: nil) ⇒ Object
api.contacts.get(contact_id: “contactId”)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/paid_ruby/contacts/client.rb', line 112 def get(contact_id:, request_options: nil) response = @request_client.conn.get do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/contacts/#{contact_id}" end Paid::Contact.from_json(json_object: response.body) end |
#get_by_external_id(external_id:, request_options: nil) ⇒ Object
api.contacts.get_by_external_id(external_id: “externalId”)
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/paid_ruby/contacts/client.rb', line 169 def get_by_external_id(external_id:, request_options: nil) response = @request_client.conn.get do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/contacts/external/#{external_id}" end Paid::Contact.from_json(json_object: response.body) end |
#list(request_options: nil) ⇒ Object
api.contacts.list
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/paid_ruby/contacts/client.rb', line 34 def list(request_options: nil) response = @request_client.conn.get do | req | unless &.timeout_in_seconds.nil? req..timeout = .timeout_in_seconds end unless &.token.nil? req.headers["Authorization"] = .token end req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(request_options: )}/contacts" end parsed_json = JSON.parse(response.body) parsed_json&.map do | item | item = item.to_json Paid::Contact.from_json(json_object: item) end end |