Sha256: 9db103aef26420e7bb8627d3631ec2b721f97d0dbe7498c84758137248a155a3

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module NightcrawlerSwift
  class Command

    def connection
      NightcrawlerSwift.connection.tap do |conn|
        conn.connect! unless conn.connected?
      end
    end

    def options
      NightcrawlerSwift.options
    end

    # :nocov:
    def execute
      raise NotImplemented.new
    end
    # :nocov:

    protected

    [
      :get,
      :head,
      :delete
    ].each do |http_verb|
      define_method http_verb do |*method_args|
        url = method_args[0]
        args = method_args[1] || {}

        prepare_args args
        Gateway.new(url).request {|r| r.send(http_verb, headers_and_params(args))}
      end
    end

    def put url, args = {}
      prepare_args args
      Gateway.new(url).request {|r| r.put args[:body], headers_and_params(args)}
    end

    private
    def prepare_args args
      args[:headers] ||= {}
      args[:headers]["X-Storage-Token"] = connection.token_id
      args[:params] ||= {}
    end

    def headers_and_params args
      args[:headers].merge(params: args[:params])
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nightcrawler_swift-1.0.0 lib/nightcrawler_swift/command.rb
nightcrawler_swift-0.11.1 lib/nightcrawler_swift/command.rb
nightcrawler_swift-0.11.0 lib/nightcrawler_swift/command.rb
nightcrawler_swift-0.10.0 lib/nightcrawler_swift/command.rb
nightcrawler_swift-0.9.0 lib/nightcrawler_swift/command.rb
nightcrawler_swift-0.8.1 lib/nightcrawler_swift/command.rb
nightcrawler_swift-0.8.0 lib/nightcrawler_swift/command.rb