Sha256: da8e13abe381eb3a4f0cd84380b75339046792a365c57330d9de29ace08f2b76

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'ostruct'
require 'json'
require 'httparty'
require 'hashie/mash'

require 'client/template/configuration'
require 'client/template/model'

module Mirage

  class Template

    include HTTParty
    include Model::InstanceMethods
    include Model::CommonMethods

    class << self
      alias_method :backedup_get, :get

      def get url
        response_hashie = Hashie::Mash.new backedup_get(url, :format => :json)

        response_config = response_hashie.response
        request_config = response_hashie.request

        template = new(response_hashie.endpoint, response_config.body)

        template.id response_hashie.id
        template.default response_config['default']
        template.delay response_config.delay
        template.content_type response_config.content_type
        template.status response_config.status
        template.headers response_config.headers

        template.required_parameters request_config.parameters
        template.required_body_content request_config.body_content
        template.http_method request_config.http_method
        template.url url
        template.requests_url response_hashie.requests_url
        template.required_headers request_config.headers

        template
      end
    end

    def initialize *args
      endpoint = args.first

      raise ArgumentError, "You must specify a string endpoint as the first argument" unless endpoint && endpoint.is_a?(String)
      super *args

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mirage-3.0.0.alpha.11 lib/mirage/client/template.rb
mirage-3.0.0.alpha.10 lib/mirage/client/template.rb
mirage-3.0.0.alpha.9 lib/mirage/client/template.rb
mirage-3.0.0.alpha.8 lib/mirage/client/template.rb
mirage-3.0.0.alpha.7 lib/mirage/client/template.rb