Sha256: 38c097a136214ca3a1e333c1f48e49782ead4f0c051339819ee24d0935bd50d9

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

module MarketoApi
  module Concerns
    module Verbs
      # Internal: Define methods to handle a verb.
      #
      # verbs - A list of verbs to define methods for.
      #
      # Examples
      #
      #   define_verbs :get, :post
      #
      # Returns nil.
      def define_verbs(*verbs)
        verbs.each do |verb|
          define_verb(verb)
          define_api_verb(verb)
        end
      end

      # Internal: Defines a method to handle HTTP requests with the passed in
      # verb.
      #
      # verb - Symbol name of the verb (e.g. :get).
      #
      # Examples
      #
      #   define_verb :get
      #   # => get '/rest/v1/leads'
      #
      # Returns nil.
      def define_verb(verb)
        define_method verb do |*args, &block|
          begin
            connection.send(verb, *args, &block)
          rescue MarketoApi::UnauthorizedError
            raise
          end
        end
      end

      # Internal: Defines a method to handle HTTP requests with the passed in
      # verb to a marketo api endpoint.
      #
      # verb - Symbol name of the verb (e.g. :get).
      #
      # Examples
      #
      #   define_api_verb :get
      #   # => api_get 'leads'
      #
      # Returns nil.
      def define_api_verb(verb)
        define_method :"api_#{verb}" do |*args, &block|
          args[0] = api_path(args[0])
          send(verb, *args, &block)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
marketo_api-0.3.0.pre.alpha lib/marketo_api/concerns/verbs.rb
marketo_api-0.1.1.pre.alpha lib/marketo_api/concerns/verbs.rb
marketo_api-0.0.7.pre.alpha lib/marketo_api/concerns/verbs.rb