Sha256: 9703dde37b39fa9adef2ec18caf94a9bc04c4119d10d39bc159f1268e87acb2c

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module Shutterstock
  class Request

    attr_writer   :method,          # :post, :get etc
                  :path,            # request path /v2/images
                  :success_status,  # response code signifying success. Defaults to 200
                  :send_authorization, # default true. Set to false when requesting credentials
                  :content_type,    # default 'application/json'
                  :body,            # hash of parameters for request body (usually for :post)
                  :params           # hash of parameters for url params section (usually for :get or :delete)

    def initialize(&block)
      @success_status = 200
      @send_authorization = true
      @content_type = 'application/json'

      # Handle both forms of config:
      # Request.new { |r| r.method=... }
      # Request.new { method=... }
      if block_given?
        if block.arity == 1
          yield self
        else
          instance_eval(&block)

        end
      end
    end

    # DSL
    %w[method path success_status params body options send_authorization content_type].each do |method|
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{method}(new_value = nil)
          @#{method} = new_value unless new_value.nil?
          @#{method}
        end
      RUBY
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shutterstock-v2-0.0.1 lib/client/request.rb