class Theguardian::Api::Tag
Public Class Methods
process(params = {})
click to toggle source
# File lib/theguardian/api/tag.rb, line 4 def self.process(params = {}) connection = Theguardian::Connection.new(resource: "tags") params = self.process_params(params) response = connection.get(params) response["results"].map do |tag_params| self.new(tag_params, recurse_over_arrays: true) end end
process_params(params)
click to toggle source
# File lib/theguardian/api/tag.rb, line 30 def self.process_params(params) # Query string and tag type theguardian_api_params = { q: params[:q], type: params[:type] } # Pagination theguardian_api_params.merge!({ "page" => params[:page] }) if params.has_key?(:page) theguardian_api_params.merge!({ "page-size" => params[:per_page] }) if params.has_key?(:per_page) theguardian_api_params.reject{ |_, value| value.nil? } end
Public Instance Methods
fetch()
click to toggle source
# File lib/theguardian/api/tag.rb, line 14 def fetch connection = Theguardian::Connection.new(resource: URI(self.apiUrl).path) self.class.new(connection.get, recurse_over_arrays: true) end
items()
click to toggle source
# File lib/theguardian/api/tag.rb, line 20 def items self.results.map do |item_params| Theguardian::Api::Item.new(item_params, recurse_over_arrays: true) end end
section()
click to toggle source
# File lib/theguardian/api/tag.rb, line 26 def section Theguardian::Api::Section.process(id: self.tag.sectionId) end