Class: UscreenAPI::Customers
Constant Summary collapse
- PATH =
"customers"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#accesses(id:, page: nil, from: nil, to: nil) ⇒ Object
Get paginated list of accesses for a customer.
-
#create(email:, name:, password: nil, payment_user_id: nil, skip_invite: nil, opted_in_for_news_and_updates: nil, custom_fields: {}) ⇒ Object
Invite a new customer.
-
#get(id:) ⇒ Object
Get a customer information.
-
#grant_access(id:, product_id:, product_type: nil, perform_action_at: nil, with_manual_billing: false) ⇒ Object
Grant access to a customer.
-
#list(page: nil, from: nil, to: nil, date_field: nil) ⇒ Object
Get paginated list of customers.
-
#revoke_access(id:, access_id:) ⇒ Object
Revoke access by ID.
-
#tokenized_url(id:) ⇒ Object
Generates a Single Sign-On link for a customer.
-
#update(id:, email: nil, name: nil, password: nil, custom_fields: {}) ⇒ Object
Update a customer information.
Methods inherited from Base
Constructor Details
This class inherits a constructor from UscreenAPI::Base
Instance Method Details
#accesses(id:, page: nil, from: nil, to: nil) ⇒ Object
Get paginated list of accesses for a customer
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/uscreen_api/customers.rb', line 119 def accesses( id:, page: nil, from: nil, to: nil ) response = client.connection.get("#{PATH}/#{id}/accesses") handle_errors(response.status, response.body) response.body end |
#create(email:, name:, password: nil, payment_user_id: nil, skip_invite: nil, opted_in_for_news_and_updates: nil, custom_fields: {}) ⇒ Object
Invite a new customer
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/uscreen_api/customers.rb', line 40 def create( email:, name:, password: nil, payment_user_id: nil, skip_invite: nil, opted_in_for_news_and_updates: nil, custom_fields: {} ) response = client.connection.post(PATH) do |req| req.body = { email: email, name: name } req.body["password"] = password if password req.body["payment_user_id"] = payment_user_id if payment_user_id req.body["skip_invite"] = skip_invite if skip_invite req.body["opted_in_for_news_and_updates"] = opted_in_for_news_and_updates if opted_in_for_news_and_updates custom_fields.each { |key, value| req.body[key] = value } if custom_fields.any? end handle_errors(response.status, response.body) response.body end |
#get(id:) ⇒ Object
Get a customer information
69 70 71 72 73 74 75 |
# File 'lib/uscreen_api/customers.rb', line 69 def get(id:) response = client.connection.get("#{PATH}/#{id}") handle_errors(response.status, response.body) response.body end |
#grant_access(id:, product_id:, product_type: nil, perform_action_at: nil, with_manual_billing: false) ⇒ Object
Grant access to a customer
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/uscreen_api/customers.rb', line 137 def grant_access( id:, product_id:, product_type: nil, perform_action_at: nil, with_manual_billing: false ) response = client.connection.post("#{PATH}/#{id}/accesses") do |req| req.body = { product_id: product_id, with_manual_billing: with_manual_billing } req.body["product_type"] = product_type if product_type req.body["perform_action_at"] = perform_action_at if perform_action_at end handle_errors(response.status, response.body) response.body end |
#list(page: nil, from: nil, to: nil, date_field: nil) ⇒ Object
Get paginated list of customers
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/uscreen_api/customers.rb', line 12 def list( page: nil, from: nil, to: nil, date_field: nil ) response = client.connection.get(PATH) do |req| req.params = {} req.params["page"] = page if page req.params["from"] = from if from req.params["to"] = to if to req.params["date_field"] = date_field if date_field end handle_errors(response.status, response.body) response.body end |
#revoke_access(id:, access_id:) ⇒ Object
Revoke access by ID
161 162 163 164 165 166 167 168 169 |
# File 'lib/uscreen_api/customers.rb', line 161 def revoke_access( id:, access_id: ) response = client.connection.delete("#{PATH}/#{id}/accesses/#{access_id}") handle_errors(response.status, response.body) response.body end |
#tokenized_url(id:) ⇒ Object
Generates a Single Sign-On link for a customer
107 108 109 110 111 112 |
# File 'lib/uscreen_api/customers.rb', line 107 def tokenized_url(id:) response = client.connection.post("#{PATH}/#{id}/tokenized_url") handle_errors(response.status, response.body) response.body end |
#update(id:, email: nil, name: nil, password: nil, custom_fields: {}) ⇒ Object
Update a customer information
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/uscreen_api/customers.rb', line 83 def update( id:, email: nil, name: nil, password: nil, custom_fields: {} ) response = client.connection.put("#{PATH}/#{id}") do |req| req.body = {} req.body["email"] = email if email req.body["name"] = name if name req.body["password"] = password if password custom_fields.each { |key, value| req.body[key] = value } if custom_fields.any? end handle_errors(response.status, response.body) response.body end |