Class: Agilix::Buzz::Api

Defined Under Namespace

Classes: AuthenticationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands::User

#create_users2, #delete_users, #get_active_user_count, #get_domain_activity, #get_profile_picture, #get_user2, #get_user_activity, #get_user_activity_stream, #list_users, #restore_user, #update_users

Methods included from Commands::Right

#create_role, #delete_role, #delete_subscriptions, #get_actor_rights, #get_effective_rights, #get_effective_subscription_list, #get_entity_rights, #get_entity_subscription_list, #get_personas, #get_rights, #get_rights_list, #get_role, #get_subscription_list, #list_roles, #restore_role, #right_flags, #right_flags_hex, #right_flags_lookup_value, #update_rights, #update_role, #update_subscriptions

Methods included from Commands::Resource

#copy_resources, #delete_documents, #delete_resources, #get_document, #get_document_info, #get_entity_resource_id, #get_resource, #get_resource_info2, #get_resource_list2, #list_restorable_documents, #list_restorable_resources, #put_resource, #put_resource_folders, #restore_documents, #restore_resources

Methods included from Commands::Report

#get_report_info, #get_report_list, #get_runnable_report_list, #run_report

Methods included from Commands::Manifest

#put_items, #update_manifest_data

Methods included from Commands::Library

#create_library_page, #get_library_page, #list_library_pages

Methods included from Commands::General

#echo, #get_basic_status, #get_command_list, #get_entity_type, #get_status, #get_upload_limits, #send_mail

Methods included from Commands::Enrollment

#create_enrollments, #delete_enrollments, #enrollment_status, #enrollment_status_lookup_value, #get_enrollment3, #get_enrollment_activity, #get_enrollment_gradebook2, #get_enrollment_group_list, #get_enrollment_metrics_report, #list_enrollments, #list_enrollments_by_teacher, #list_entity_enrollments, #list_user_enrollments, #put_self_assessment, #restore_enrollment, #update_enrollments

Methods included from Commands::Domain

#create_domains, #delete_domain, #get_domain2, #get_domain_content, #get_domain_enrollment_metrics, #get_domain_parent_list, #get_domain_settings, #get_domain_stats, #list_domains, #restore_domain, #update_domains

Methods included from Commands::Course

#copy_courses, #create_courses, #create_demo_course, #deactivate_course, #delete_courses, #get_course2, #get_course_history, #list_courses, #merge_courses, #restore_course, #update_courses

Methods included from Commands::Authentication

#compute_hmac, #extend_session, #force_password_change, #get_key, #get_password_login_attempt_history, #get_password_policy, #get_password_question, #login2, #logout, #proxy, #proxy_api, #proxy_sso_link, #put_key, #reset_lockout, #reset_password, #unproxy, #update_password, #update_password_question_answer

Constructor Details

#initialize(options = {}) ⇒ Api

Returns a new instance of Api.



20
21
22
23
24
25
26
27
# File 'lib/agilix/buzz/api.rb', line 20

def initialize(options = {})
  @username = options.fetch(:username, default_username)
  @password = options.fetch(:password, default_password)
  @domain = options.fetch(:domain, default_domain)
  @token = options.dig(:token)
  @token_expiration = options.dig(:token_expiration)
  @agilix_url_endpoint = options.fetch(:agilix_url_endpoint, default_agilix_url_endpoint)
end

Instance Attribute Details

#agilix_url_endpointObject

Returns the value of attribute agilix_url_endpoint.



18
19
20
# File 'lib/agilix/buzz/api.rb', line 18

def agilix_url_endpoint
  @agilix_url_endpoint
end

#domainObject

Returns the value of attribute domain.



18
19
20
# File 'lib/agilix/buzz/api.rb', line 18

def domain
  @domain
end

#passwordObject

Returns the value of attribute password.



18
19
20
# File 'lib/agilix/buzz/api.rb', line 18

def password
  @password
end

#tokenObject

Returns the value of attribute token.



18
19
20
# File 'lib/agilix/buzz/api.rb', line 18

def token
  @token
end

#token_expirationObject

Returns the value of attribute token_expiration.



18
19
20
# File 'lib/agilix/buzz/api.rb', line 18

def token_expiration
  @token_expiration
end

#usernameObject

Returns the value of attribute username.



18
19
20
# File 'lib/agilix/buzz/api.rb', line 18

def username
  @username
end

Instance Method Details

#authenticated_bulk_post(query = {}) ⇒ Object



44
45
46
47
# File 'lib/agilix/buzz/api.rb', line 44

def authenticated_bulk_post(query = {})
  check_authentication
  bulk_post query
end

#authenticated_get(query = {}) ⇒ Object



29
30
31
32
# File 'lib/agilix/buzz/api.rb', line 29

def authenticated_get(query = {})
  check_authentication
  get query
end

#authenticated_post(query = {}) ⇒ Object



34
35
36
37
# File 'lib/agilix/buzz/api.rb', line 34

def authenticated_post(query = {})
  check_authentication unless query.delete(:bypass_authentication_check)
  post query
end

#authenticated_query_post(query = {}) ⇒ Object



39
40
41
42
# File 'lib/agilix/buzz/api.rb', line 39

def authenticated_query_post(query = {})
  check_authentication unless query.delete(:bypass_authentication_check)
  query_post query
end

#bulk_post(query = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/agilix/buzz/api.rb', line 91

def bulk_post(query = {})
  cmd = query.delete(:cmd)
  url = agilix_url_base + "?cmd=#{cmd}&_token=#{token}"
  query_params = query.delete(:query_params)
  if query_params
    url += query_params.map {|k,v| "&#{k}=#{v}" }.join("")
  end
  response = self.class.post(url, body: modify_bulk_body(query), timeout: 60, headers: headers)
end

#check_authenticationObject



101
102
103
104
105
106
107
108
109
# File 'lib/agilix/buzz/api.rb', line 101

def check_authentication
  if token && token_expiration
    if token_expiration < Time.now
      extend_session
    end
  else
    authenticate!
  end
end

#get(query = {}) ⇒ Object



49
50
51
# File 'lib/agilix/buzz/api.rb', line 49

def get(query = {})
  response = self.class.get(agilix_url_base, query: modify_query(query), timeout: 60, headers: headers)
end

#post(query = {}) ⇒ Object



53
54
55
# File 'lib/agilix/buzz/api.rb', line 53

def post(query = {})
  response = self.class.post(agilix_url_base, body: modify_body(query), timeout: 60, headers: headers)
end

#query_post(query = {}) ⇒ Object

For when the api is super unconventional & you need to modify both query params & body params in a custom fashion, and upload a file even!



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/agilix/buzz/api.rb', line 75

def query_post(query = {})
  url = agilix_url_base
  query_params = query.delete(:query_params)
  if query_params
    url += "?&_token=#{token}" + query_params.map {|k,v| "&#{k}=#{v}" }.join("")
  end
  file = query.delete(:file)
  if file
    new_headers = headers
    new_headers["Content-Type"] = "multipart/form-data"
    response = self.class.post(url, multipart: true, body: {file: file}, timeout: 60, headers: new_headers)
  else
    response = self.class.post(url, body: query.to_json, timeout: 60, headers: headers)
  end
end