class Kodmin::Consumers
Operations on consumer.
Public Instance Methods
create_consumer(attributes)
click to toggle source
Create a new consumer. @param attributes [Hash] attributes of the consumer. @return [Consumer] the created consumer.
# File lib/kodmin/consumers.rb, line 96 def create_consumer(attributes) resp = post('/consumers', attributes) Consumer.new(JSON.parse(resp)) end
create_consumer_hmac_credential(id)
click to toggle source
# File lib/kodmin/consumers.rb, line 126 def create_consumer_hmac_credential(id) access_key = SecureRandom.hex(16) secret_key = SecureRandom.hex(16) resp = post("/consumers/#{id}/hmac-auth", {username: access_key, secret: secret_key}) Consumer::HmacAuth.new(JSON.parse(resp)) end
delete_consumer(id)
click to toggle source
Delete a consumer. @param id [String] id of the consumer to be removed.
# File lib/kodmin/consumers.rb, line 103 def delete_consumer(id) delete("/consumers/#{id}") end
list_consumer_hmac_credentials(id, offset = '')
click to toggle source
Get a consumers's HMAC credentials. @param id [String] id of the consumer. @param offset [String] the offset token for pagination. An empty offset token refers to the first page. @return [Hash] a Hash with keys of :credentials and :offset.
# File lib/kodmin/consumers.rb, line 111 def list_consumer_hmac_credentials(id, offset = '') params = offset.empty? ? {} : { offset: offset } resp = get("/consumers/#{id}/hmac-auth", params) resp = JSON.parse(resp) credentials = [] resp['data'].each do |v| credentials << Consumer::HmacAuth.new(v) end offset_token = nil unless resp['next'].nil? || resp['next'].empty? offset_token = resp['next'].split('=')[1] end { credentials: credentials, offset: offset_token } end
list_consumers(offset = '')
click to toggle source
List a page of consumers. @param offset [String] the offset token for pagination. An empty offset token refers to the first page. @return [Hash] a Hash with keys of :consumers and :offset.
# File lib/kodmin/consumers.rb, line 78 def list_consumers(offset = '') params = offset.empty? ? {} : { offset: offset } resp = get('/consumers', params) resp = JSON.parse(resp) consumers = [] resp['data'].each do |v| consumers << Consumer.new(v) end offset_token = nil unless resp['next'].nil? || resp['next'].empty? offset_token = resp['next'].split('=')[1] end { consumers: consumers, offset: offset_token } end