Class: AcademicBenchmarks::Api::Standards
- Inherits:
-
Object
- Object
- AcademicBenchmarks::Api::Standards
- Defined in:
- lib/academic_benchmarks/api/standards.rb
Constant Summary collapse
- DEFAULT_PER_PAGE =
100
Instance Method Summary collapse
- #all ⇒ Object
- #authorities ⇒ Object
- #documents ⇒ Object
- #guid(guid, fields: []) ⇒ Object
-
#initialize(handle) ⇒ Standards
constructor
A new instance of Standards.
- #search(opts = {}) ⇒ Object (also: #where)
Constructor Details
#initialize(handle) ⇒ Standards
Returns a new instance of Standards.
11 12 13 |
# File 'lib/academic_benchmarks/api/standards.rb', line 11 def initialize(handle) @handle = handle end |
Instance Method Details
#all ⇒ Object
48 49 50 |
# File 'lib/academic_benchmarks/api/standards.rb', line 48 def all request_search_pages_and_concat_resources(auth_query_params) end |
#authorities ⇒ Object
52 53 54 |
# File 'lib/academic_benchmarks/api/standards.rb', line 52 def raw_search(list: "authority").map{|a| a["data"]["authority"]}.map{|a| AcademicBenchmarks::Standards::Authority.from_hash(a)} end |
#documents ⇒ Object
56 57 58 |
# File 'lib/academic_benchmarks/api/standards.rb', line 56 def documents raw_search(list: "document").map{|a| a["data"]["document"]}.map{|a| AcademicBenchmarks::Standards::Document.from_hash(a)} end |
#guid(guid, fields: []) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/academic_benchmarks/api/standards.rb', line 32 def guid(guid, fields: []) query_params = if fields.empty? auth_query_params else auth_query_params.merge({ fields: fields.join(",") }) end @handle.class.get( "/standards/#{guid}", query: query_params ).parsed_response["resources"].map do |r| AcademicBenchmarks::Standards::Standard.new(r["data"]) end end |
#search(opts = {}) ⇒ Object Also known as: where
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/academic_benchmarks/api/standards.rb', line 15 def search(opts = {}) # query: "", authority: "", subject: "", grade: "", subject_doc: "", course: "", # document: "", parent: "", deepest: "", limit: -1, offset: -1, list: "", fields: [] invalid_params = invalid_search_params(opts) if invalid_params.empty? raw_search(opts).map do |standard| AcademicBenchmarks::Standards::Standard.new(standard) end else raise ArgumentError.new( "Invalid search params: #{invalid_params.join(', ')}" ) end end |