Class: Umbreo::Models::Profile
- Inherits:
-
Object
- Object
- Umbreo::Models::Profile
- Defined in:
- lib/umbreo/models/profile.rb
Instance Method Summary collapse
- #all(filter = {}) ⇒ Object
-
#error ⇒ Object
Get first error.
-
#initialize(credentials = {}) ⇒ Profile
constructor
A new instance of Profile.
- #retrieve_data(filter = {}) ⇒ Object
-
#valid? ⇒ Boolean
Check no error from validation.
Constructor Details
#initialize(credentials = {}) ⇒ Profile
Returns a new instance of Profile.
5 6 7 8 9 10 11 |
# File 'lib/umbreo/models/profile.rb', line 5 def initialize(credentials = {}) if credentials.present? @email = credentials[:email] @api_key = credentials[:api_key] @endpoint = credentials[:end_point] || SERVER_END_POINT end end |
Instance Method Details
#all(filter = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/umbreo/models/profile.rb', line 28 def all(filter = {}) @errors << "Search keyword is required." if filter[:keyword].blank? && filter[:search] if valid? retrieve_data(filter) if @data['umbreo_profiles'].present? page = " | Page: #{filter[:page]} of #{@data['total_page']} pages" Helpers::Table.show_table(@data['umbreo_profiles'], "List Profile#{ page if @data['total_page'] > 1 }", ['ID', 'Name', 'Description']) else Helpers::AlertMessage.(@data["message"]) end else Helpers::AlertMessage.(error) end end |
#error ⇒ Object
Get first error
55 56 57 |
# File 'lib/umbreo/models/profile.rb', line 55 def error @errors.first end |
#retrieve_data(filter = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/umbreo/models/profile.rb', line 13 def retrieve_data(filter = {}) Helpers::ErrorException.rescue do data = Typhoeus.get( "#{@endpoint}/api/v1/profiles", body: { authenticate_token: @api_key, email: @email, filter: filter } ) @data = JSON.parse data.response_body end end |
#valid? ⇒ Boolean
Check no error from validation
48 49 50 |
# File 'lib/umbreo/models/profile.rb', line 48 def valid? @errors.blank? end |