Module: PropelAuth::Client
- Defined in:
- lib/propelauth/client.rb
Class Method Summary collapse
- .create_user(email, email_confirmed: false, send_email_to_confirm_email_address: false, password: nil, username: nil, first_name: nil, last_name: nil) ⇒ Object
- .fetch_batch_user_metadata_by_emails(emails, include_orgs: false) ⇒ Object
- .fetch_batch_user_metadata_by_user_ids(user_ids, include_orgs: false) ⇒ Object
- .fetch_batch_user_metadata_by_usernames(usernames, include_orgs: false) ⇒ Object
- .fetch_org(org_id) ⇒ Object
- .fetch_orgs_by_query(page_size: 10, page_number: 0, order_by: OrgOrderBy::CREATED_AT_ASC) ⇒ Object
- .fetch_user_metadata_by_email(email, include_orgs: false) ⇒ Object
- .fetch_user_metadata_by_user_id(user_id, include_orgs: false) ⇒ Object
- .fetch_user_metadata_by_username(username, include_orgs: false) ⇒ Object
- .fetch_users_by_query(page_size: 10, page_number: 0, order_by: UserOrderBy::CREATED_AT_ASC, email_or_username: nil, include_orgs: false) ⇒ Object
- .fetch_users_in_org(org_id, page_size: 10, page_number: 0, include_orgs: false) ⇒ Object
Class Method Details
.create_user(email, email_confirmed: false, send_email_to_confirm_email_address: false, password: nil, username: nil, first_name: nil, last_name: nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/propelauth/client.rb', line 111 def create_user(email, email_confirmed: false, send_email_to_confirm_email_address: false, password: nil, username: nil, first_name: nil, last_name: nil) json_body = { email: email, email_confirmed: email_confirmed, send_email_to_confirm_email_address: send_email_to_confirm_email_address, password: password, username: username, first_name: first_name, last_name: last_name, }.to_json response = connection.post "/api/backend/v1/user/", json_body, { "Authorization" => "Bearer #{api_key}", "Content-Type" => "application/json", } if response.status >= 200 && response.status < 300 response.body elsif response.status == 400 raise PropelAuth::BadRequest.new response.body elsif response.status == 401 raise PropelAuth::InvalidApiKey.new else raise PropelAuth::UnexpectedError.new end end |
.fetch_batch_user_metadata_by_emails(emails, include_orgs: false) ⇒ Object
23 24 25 |
# File 'lib/propelauth/client.rb', line 23 def (emails, include_orgs: false) ("emails", emails, -> (x) { x["email"] }, include_orgs) end |
.fetch_batch_user_metadata_by_user_ids(user_ids, include_orgs: false) ⇒ Object
19 20 21 |
# File 'lib/propelauth/client.rb', line 19 def (user_ids, include_orgs: false) ("user_ids", user_ids, -> (x) { x["user_id"] }, include_orgs) end |
.fetch_batch_user_metadata_by_usernames(usernames, include_orgs: false) ⇒ Object
27 28 29 |
# File 'lib/propelauth/client.rb', line 27 def (usernames, include_orgs: false) ("usernames", usernames, -> (x) { x["username"] }, include_orgs) end |
.fetch_org(org_id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/propelauth/client.rb', line 31 def fetch_org(org_id) response = connection.get("/api/backend/v1/org/#{org_id}", {}, { "Authorization" => "Bearer #{api_key}" }) if response.status == 200 response.body elsif response.status == 404 nil elsif response.status == 401 raise PropelAuth::InvalidApiKey.new elsif response.status == 426 raise PropelAuth::B2BSupportDisabled.new else raise PropelAuth::UnexpectedError.new end end |
.fetch_orgs_by_query(page_size: 10, page_number: 0, order_by: OrgOrderBy::CREATED_AT_ASC) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/propelauth/client.rb', line 46 def fetch_orgs_by_query(page_size: 10, page_number: 0, order_by: OrgOrderBy::CREATED_AT_ASC) json_body = { page_size: page_size, page_number: page_number, order_by: order_by, }.to_json response = connection.post "/api/backend/v1/org/query", json_body, { "Authorization" => "Bearer #{api_key}", "Content-Type" => "application/json", } if response.status == 200 response.body elsif response.status == 400 raise PropelAuth::BadRequest.new response.body elsif response.status == 401 raise PropelAuth::InvalidApiKey.new elsif response.status == 426 raise PropelAuth::B2BSupportDisabled.new else raise PropelAuth::UnexpectedError.new end end |
.fetch_user_metadata_by_email(email, include_orgs: false) ⇒ Object
11 12 13 |
# File 'lib/propelauth/client.rb', line 11 def (email, include_orgs: false) ("email", { email: email, include_orgs: include_orgs }) end |
.fetch_user_metadata_by_user_id(user_id, include_orgs: false) ⇒ Object
7 8 9 |
# File 'lib/propelauth/client.rb', line 7 def (user_id, include_orgs: false) (user_id, { include_orgs: include_orgs }) end |
.fetch_user_metadata_by_username(username, include_orgs: false) ⇒ Object
15 16 17 |
# File 'lib/propelauth/client.rb', line 15 def (username, include_orgs: false) ("username", { username: username, include_orgs: include_orgs }) end |
.fetch_users_by_query(page_size: 10, page_number: 0, order_by: UserOrderBy::CREATED_AT_ASC, email_or_username: nil, include_orgs: false) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/propelauth/client.rb', line 69 def fetch_users_by_query(page_size: 10, page_number: 0, order_by: UserOrderBy::CREATED_AT_ASC, email_or_username: nil, include_orgs: false) params = { page_size: page_size, page_number: page_number, order_by: order_by, email_or_username: email_or_username, include_orgs: include_orgs, } response = connection.get "/api/backend/v1/user/query", params, { "Authorization" => "Bearer #{api_key}" } if response.status == 200 response.body elsif response.status == 400 raise PropelAuth::BadRequest.new response.body elsif response.status == 401 raise PropelAuth::InvalidApiKey.new elsif response.status == 426 raise PropelAuth::B2BSupportDisabled.new else raise PropelAuth::UnexpectedError.new end end |
.fetch_users_in_org(org_id, page_size: 10, page_number: 0, include_orgs: false) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/propelauth/client.rb', line 91 def fetch_users_in_org(org_id, page_size: 10, page_number: 0, include_orgs: false) params = { page_size: page_size, page_number: page_number, include_orgs: include_orgs, } response = connection.get "/api/backend/v1/user/org/#{org_id}", params, { "Authorization" => "Bearer #{api_key}" } if response.status == 200 response.body elsif response.status == 400 raise PropelAuth::BadRequest.new response.body elsif response.status == 401 raise PropelAuth::InvalidApiKey.new elsif response.status == 426 raise PropelAuth::B2BSupportDisabled.new else raise PropelAuth::UnexpectedError.new end end |