Class: FetchResource

Inherits:
KOSapiInteractor show all
Defined in:
app/interactors/fetch_resource.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from KOSapiInteractor

#setup

Methods included from Interpipe::Interactor

included, #initialize, #setup

Class Attribute Details

.query_instanceObject

Returns the value of attribute query_instance


19
20
21
# File 'app/interactors/fetch_resource.rb', line 19

def query_instance
  @query_instance
end

.resourceObject

Returns the value of attribute resource


19
20
21
# File 'app/interactors/fetch_resource.rb', line 19

def resource
  @resource
end

Class Method Details

.[](resource, query_instance: FacultySemesterQuery.new) ⇒ Object


21
22
23
24
25
26
# File 'app/interactors/fetch_resource.rb', line 21

def [](resource, query_instance: FacultySemesterQuery.new)
  Class.new(self).tap do |cls|
    cls.resource = resource
    cls.query_instance = query_instance
  end
end

Instance Method Details

#perform(faculty_semester:, limit: 100, paginate: true) ⇒ Object


6
7
8
9
10
11
12
# File 'app/interactors/fetch_resource.rb', line 6

def perform(faculty_semester:, limit: 100, paginate: true)
  @faculty_semester = faculty_semester
  client = kosapi_client(faculty_semester)
  resource = client.send(resource_name)
  @data = query_instance.apply(resource, faculty_semester: faculty_semester).limit(limit)
  @data.auto_paginate = paginate
end

#query_instanceObject


33
34
35
# File 'app/interactors/fetch_resource.rb', line 33

def query_instance
  self.class.query_instance
end

#resource_nameObject


29
30
31
# File 'app/interactors/fetch_resource.rb', line 29

def resource_name
  self.class.resource
end

#resultsObject


14
15
16
# File 'app/interactors/fetch_resource.rb', line 14

def results
  { resource_name => @data, faculty_semester: @faculty_semester }
end