class Uktt::Heading
A Chapter
object for dealing with an API resource
Attributes
config[RW]
heading_id[RW]
response[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/uktt/heading.rb, line 6 def initialize(opts = {}) @heading_id = opts[:heading_id] || nil Uktt.configure(opts) @config = Uktt.config @response = nil end
Public Instance Methods
changes()
click to toggle source
# File lib/uktt/heading.rb, line 29 def changes return '@chapter_id cannot be nil' if @heading_id.nil? fetch "#{HEADING}/#{@heading_id}/changes.json" end
config=(new_opts = {})
click to toggle source
# File lib/uktt/heading.rb, line 35 def config=(new_opts = {}) merged_opts = Uktt.config.merge(new_opts) Uktt.configure merged_opts @heading_id = merged_opts[:heading_id] || @heading_id @config = Uktt.config end
find(id)
click to toggle source
# File lib/uktt/heading.rb, line 42 def find(id) return '@response is nil, run #retrieve first' unless @response response = @response.included.select do |obj| obj.id === id || obj.type === id end response.length == 1 ? response.first : response end
goods_nomenclatures()
click to toggle source
# File lib/uktt/heading.rb, line 19 def goods_nomenclatures return '@chapter_id cannot be nil' if @heading_id.nil? fetch "#{GOODS_NOMENCLATURE}/heading/#{@heading_id}.json" end
note()
click to toggle source
# File lib/uktt/heading.rb, line 25 def note 'a heading cannot have a note' end
retrieve()
click to toggle source
# File lib/uktt/heading.rb, line 13 def retrieve return '@chapter_id cannot be nil' if @heading_id.nil? fetch "#{HEADING}/#{@heading_id}.json" end
Private Instance Methods
fetch(resource)
click to toggle source
# File lib/uktt/heading.rb, line 53 def fetch(resource) @response = Uktt::Http.new( @config[:host], @config[:version], @config[:debug]) .retrieve(resource, @config[:return_json]) end