Class: Lockstep::User
- Defined in:
- app/models/lockstep/user.rb
Constant Summary
Constants inherited from ApiRecord
ApiRecord::HashWithIndifferentAccess
Instance Attribute Summary
Attributes inherited from ApiRecord
Class Method Summary collapse
Methods inherited from ApiRecord
#==, #_read_attribute, additional_query_params, alias_attribute, #as_json, #attributes, #attributes=, #attributes_for_saving, belongs_to, #belongs_to_relations, belongs_to_relations, bulk_import, chunk, class_attributes, #clean?, config, #create, create, #create_getters!, #create_setters!, #create_setters_and_getters!, #created_at, #destroy, destroy_all, #dirty?, enum, enum_config, #enum_config, execute, field, fields, find, find_by, #get_attribute, has_many, #has_many_relations, has_many_relations, #id, #id_ref, included, #initialize, #instance_resource, #load_association, load_schema, lockstep_belongs_to_relations, lockstep_has_many_relations, merge_all_attributes, #merge_attributes, #merge_relations, #method_missing, method_missing, #model_base_uri, model_base_uri, #new?, #objectId, #persisted?, #pointerize, #post_result, #primary_key, primary_key, #relations_for_saving, #reload, #resource, resource, #save, schema, #schema, #set_attribute, single_record!, to_date_object, #to_json, #to_pointer, #update, #update_attribute, #update_attributes, #updated_at, valid_attribute?, #validate_enum, where
Methods included from QueryMethods
Constructor Details
This class inherits a constructor from Lockstep::ApiRecord
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Lockstep::ApiRecord
Class Method Details
.invite(email_addresses) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/lockstep/user.rb', line 11 def self.invite(email_addresses) emails = email_addresses.map { |email| { email: email } } resp = resource.post('/invite', body: emails, params: {}) parsed_response = JSON.parse(resp.body) case resp.code.to_s when '401' raise Lockstep::Exceptions::UnauthorizedError, parsed_response['title'] when '400' raise Lockstep::Exceptions::BadRequestError, parsed_response['title'] when '404' raise Lockstep::Exceptions::RecordNotFound, parsed_response['title'] when '200' snake_case_parsed_response = parsed_response.map { |response| response.transform_keys { |key| key.underscore } } result = snake_case_parsed_response&.map do |user| if user['success'] invited_user_in_snake_case = user['invited_user'].transform_keys { |key| key.underscore } Lockstep::User.new(invited_user_in_snake_case) else invited_user = Lockstep::User.new(email: user['email']) invited_user.errors.add "email", "#{user['error_message']}" invited_user end end else raise Lockstep::Exceptions::BadRequestError, parsed_response end end |