Class: CanvasApi::Render

Inherits:
Object
  • Object
show all
Includes:
CanvasApi, GoHelpers, GraphQLHelpers, JsHelpers, RubyHelpers
Defined in:
lib/canvas_api/render.rb

Constant Summary

Constants included from GoHelpers

GoHelpers::QuizSubmissionOverrides

Constants included from GraphQLHelpers

GraphQLHelpers::CONFLICTING_NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GoHelpers

#go_api_url, #go_comments, #go_declaration, #go_do_final_return_statement, #go_do_return_statement, #go_do_return_value, #go_field_validation, #go_form_params, #go_name, #go_param_empty_value, #go_param_kind, #go_param_path, #go_param_to_field, #go_parameter_doc, #go_path_params, #go_primitive, #go_property_type, #go_query_params, #go_ref_property_type, #go_render_child_structs, #go_render_params, #go_require_models, #go_return_type, #go_struct_fields, #go_to_tree, #go_type, #is_array, #is_nested?, #is_paged?, #is_required_field, #is_x_param?, #next_param, #select_params, #split_nested, #struct_fields, #struct_name, #time_required?

Methods included from RubyHelpers

#ruby_api_url

Methods included from JsHelpers

#js_args, #js_url_parts, #key_args, #parameters_doc, #reducer_key

Methods included from GraphQLHelpers

#argument_format, #canvas_name, #enum_class_name, #field_format, #field_resolver_format, #graphql_field_enums, #graphql_fields, #graphql_primitive, #graphql_resolve, #graphql_resolver_class, #graphql_type, #is_basic_type, #make_bespoke_file_name, #make_file_name, #name_from_operation, #no_brackets_period, #params_as_string, #require_from_operation, #require_from_properties, #safe_js, #safe_rb, #type_from_operation

Methods included from CanvasApi

#nested_arg

Constructor Details

#initialize(template, api, resource, resource_api, operation, parameters, content, model, api_path) ⇒ Render

Returns a new instance of Render.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
66
67
68
69
70
# File 'lib/canvas_api/render.rb', line 21

def initialize(template, api, resource, resource_api, operation, parameters, content, model, api_path)
  @template = File.read(File.expand_path(template, __dir__))
  @api_path = api_path
  if api
    @api         = api
    @name        = @api["path"].gsub("/", "").gsub(".json", "")
    @description = @api["description"]
  end
  if resource
    @resource      = resource
    @resource_name = resource["resourcePath"].gsub("/", "")
  end
  if resource_api
    @resource_api = resource_api
    @api_url      = resource_api["path"].gsub("/v1/", "")
    @args         = args(@api_url)
  end
  if operation
    nickname = operation["nickname"]

    if nickname == "save_enabled_account_calendars_creates_and_updates_enabled_account_calendars_and_mark_feature_as_seen_user_preferences_argument_mark_feature_as_seen_optional_boolean_flag_to_mark_account_calendars_feature_as_seen_argument_enabled_account_calendars_optional_array_array_of_account_ids_to_remember_in_calendars_list_of_user_curl_https_canvas_api_v_calendar_events_save_enabled_account_calendars_x_post_f_mark_feature_as_seen_true_f_enabled_account_calendars_f_enabled_account_calendars_h_authorization_bearer_token"
      nickname = "save_enabled_account_calendars"
    end

    nickname = "#{@name}_#{nickname}" if [
      "upload_file",
      "query_by_course",
      "preview_processed_html",
      "create_peer_review_courses",
      "create_peer_review_sections",
      "set_extensions_for_student_quiz_submissions"
    ].include?(nickname)

    @method    = operation["method"]
    @operation = operation
    @nickname  = nickname
    @notes     = operation["notes"].gsub("\n", "\n// ")
    @summary   = operation["summary"]
  end
  if parameters
    # Keep a copy of full parameters for code that will include the description
    @full_parameters = Marshal.load Marshal::dump(parameters)
    # Strip description from parameters so that canvas_urls.rb
    # doesn't error out on bad chars in the descriptions
    tmp_params = Marshal.load Marshal::dump(parameters)
    @parameters = tmp_params.map { |p| p.delete("description"); p }
  end
  @content = content
  @model = model
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def api
  @api
end

#api_urlObject

Returns the value of attribute api_url.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def api_url
  @api_url
end

#args(api_url) ⇒ Object

Returns the value of attribute args.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def args
  @args
end

#contentObject

Returns the value of attribute content.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def content
  @content
end

#descriptionObject

Returns the value of attribute description.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def description
  @description
end

#methodObject

Returns the value of attribute method.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def method
  @method
end

#modelObject

Returns the value of attribute model.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def model
  @model
end

#model_nameObject

Returns the value of attribute model_name.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def model_name
  @model_name
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def name
  @name
end

#nicknameObject

Returns the value of attribute nickname.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def nickname
  @nickname
end

#notesObject

Returns the value of attribute notes.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def notes
  @notes
end

#operationObject

Returns the value of attribute operation.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def operation
  @operation
end

#resourceObject

Returns the value of attribute resource.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def resource
  @resource
end

#resource_apiObject

Returns the value of attribute resource_api.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def resource_api
  @resource_api
end

#resource_nameObject

Returns the value of attribute resource_name.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def resource_name
  @resource_name
end

#summaryObject

Returns the value of attribute summary.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def summary
  @summary
end

#templateObject

Returns the value of attribute template.



17
18
19
# File 'lib/canvas_api/render.rb', line 17

def template
  @template
end

Instance Method Details

#renderObject



80
81
82
# File 'lib/canvas_api/render.rb', line 80

def render
  ERB.new(@template, nil, "-").result(binding).strip
end

#save(file) ⇒ Object



84
85
86
# File 'lib/canvas_api/render.rb', line 84

def save(file)
  File.write(file, render)
end