Class: SonyCiAdmin::Lister

Inherits:
SonyCiClient show all
Includes:
Enumerable
Defined in:
lib/sony_ci_api/sony_ci_admin.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from SonyCiClient

#add_headers, #handle_errors

Constructor Details

#initialize(ci) ⇒ Lister



86
87
88
# File 'lib/sony_ci_api/sony_ci_admin.rb', line 86

def initialize(ci)
  @ci = ci
end

Instance Method Details

#eachObject



99
100
101
102
103
104
105
106
107
108
# File 'lib/sony_ci_api/sony_ci_admin.rb', line 99

def each
  limit = 5 # Small chunks so it's easy to spot windowing problems
  offset = 0
  loop do
    assets = list(limit, offset)
    break if assets.empty?
    assets.each { |asset| yield asset }
    offset += limit
  end
end

#list(limit, offset) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/sony_ci_api/sony_ci_admin.rb', line 90

def list(limit, offset)
  curl = Curl::Easy.http_get('https:''//api.cimediacloud.com/workspaces/' \
                             "#{@ci.workspace_id}/contents?limit=#{limit}&offset=#{offset}") do |c|
    add_headers(c)
  end
  handle_errors(curl)
  JSON.parse(curl.body_str)['items']
end