File: get_shard_iterator.rb

package info (click to toggle)
ruby-fog-aws 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,092 kB
  • sloc: ruby: 72,795; javascript: 14; makefile: 9; sh: 4
file content (53 lines) | stat: -rw-r--r-- 2,078 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module Fog
  module AWS
    class Kinesis
      class Real
        # Gets a shard iterator.
        #
        # ==== Options
        # * ShardId<~String>: The shard ID of the shard to get the iterator for.
        # * ShardIteratorType<~String>: Determines how the shard iterator is used to start reading data records from the shard.
        # * StartingSequenceNumber<~String>: The sequence number of the data record in the shard from which to start reading from.
        # * StreamName<~String>: A name to identify the stream.
        # ==== Returns
        # * response<~Excon::Response>:
        #
        # ==== See Also
        # https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html
        #
        def get_shard_iterator(options={})
          body = {
            "ShardId" => options.delete("ShardId"),
            "ShardIteratorType" => options.delete("ShardIteratorType"),
            "StartingSequenceNumber" => options.delete("StartingSequenceNumber"),
            "StreamName" => options.delete("StreamName")
          }.reject{ |_,v| v.nil? }

          response = request({
                               'X-Amz-Target' => "Kinesis_#{@version}.GetShardIterator",
                               :body          => body,
                             }.merge(options))
          response.body = Fog::JSON.decode(response.body) unless response.body.nil?
          response
        end
      end

      class Mock
        def get_shard_iterator(options={})
          stream_name = options["StreamName"]

          unless stream = data[:kinesis_streams].detect{ |s| s["StreamName"] == stream_name }
            raise Fog::AWS::Kinesis::ResourceNotFound.new("Stream #{stream_name} under account #{@account_id} not found.")
          end

          response = Excon::Response.new
          response.status = 200
          response.body = {
            "ShardIterator" => Fog::JSON.encode(options) # just encode the options that were given, we decode them in get_records
          }
          response
        end
      end
    end
  end
end