Class: SnapchatApi::Resources::Organization

Inherits:
Base
  • Object
show all
Defined in:
lib/snapchat_api/resources/organization.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SnapchatApi::Resources::Base

Instance Method Details

#get(organization_id:) ⇒ Object



21
22
23
24
# File 'lib/snapchat_api/resources/organization.rb', line 21

def get(organization_id:)
  response = client.request(:get, "organizations/#{organization_id}")
  response.body["organizations"].first["organization"]
end

#list_all(params: {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/snapchat_api/resources/organization.rb', line 4

def list_all(params: {})
  params[:limit] ||= 50

  organizations = []
  query = URI.encode_www_form(params.compact)
  next_link = "me/organizations?#{query}"

  loop do
    response = client.request(:get, next_link)
    next_link = response.body.dig("paging", "next_link")
    organizations.concat(response.body["organizations"].map { |el| el["organization"] })
    break if next_link.nil?
  end

  organizations
end