Sha256: f28bf36838efcdf66b92c85bb7e7438e8d57b0257031caffcfd39a4c75e3c6e4

Contents?: true

Size: 1.81 KB

Versions: 9

Compression:

Stored size: 1.81 KB

Contents

module FinApps
  module REST

    require 'erb'

    class Institutions < FinApps::REST::Resources
      include FinApps::REST::Defaults

      # @param [String] term
      # @return [Array<FinApps::REST::Institution>, Array<String>]
      def search(term)
        logger.debug "##{__method__.to_s} => Started"

        raise MissingArgumentsError.new 'Missing argument: term.' if term.blank?
        logger.debug "##{__method__.to_s} => term: #{term}"

        end_point = Defaults::END_POINTS[:institutions_search]
        logger.debug "##{__method__.to_s} => end_point: #{end_point}"

        path = end_point.sub ':search_term', ERB::Util.url_encode(term)
        logger.debug "##{__method__.to_s} => path: #{path}"

        institutions, error_messages = @client.get(path) do |r|
          r.body.each { |i| Institution.new(i) }
        end

        logger.debug "##{__method__.to_s} => Completed"
        return institutions, error_messages
      end

      # @param [Integer] site_id
      def form(site_id)
        logger.debug "##{__method__.to_s} => Started"

        raise MissingArgumentsError.new 'Missing argument: site_id.' if site_id.blank?
        logger.debug "##{__method__.to_s} => site_id: #{site_id}"

        end_point = Defaults::END_POINTS[:institutions_form]
        logger.debug "##{__method__.to_s} => end_point: #{end_point}"

        path = end_point.sub ':site_id', ERB::Util.url_encode(site_id)
        logger.debug "##{__method__.to_s} => path: #{path}"

        institution, error_messages = @client.get(path) { |r| Institution.new(r.body) }

        logger.debug "##{__method__.to_s} => Completed"
        return institution, error_messages
      end

    end

    class Institution < FinApps::REST::Resource
      attr_accessor :base_url, :display_name, :site_id, :org_display_name, :login_form_html
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
finapps-0.1.8.pre lib/finapps/rest/institutions.rb
finapps-0.1.7.pre lib/finapps/rest/institutions.rb
finapps-0.1.6.pre lib/finapps/rest/institutions.rb
finapps-0.1.5.pre lib/finapps/rest/institutions.rb
finapps-0.1.4.pre lib/finapps/rest/institutions.rb
finapps-0.1.3.pre lib/finapps/rest/institutions.rb
finapps-0.1.2.pre lib/finapps/rest/institutions.rb
finapps-0.1.1.pre lib/finapps/rest/institutions.rb
finapps-0.0.24.pre lib/finapps/rest/institutions.rb