Class: Dotloop::Folder
- Inherits:
-
Object
- Object
- Dotloop::Folder
- Defined in:
- lib/dotloop/folder.rb
Constant Summary collapse
- FOLDER_FIELDS =
%w[name].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #all(profile_id:, loop_id:) ⇒ Object
- #create(profile_id:, loop_id:, params: {}) ⇒ Object
- #find(profile_id:, loop_id:, folder_id:) ⇒ Object
-
#initialize(client:) ⇒ Folder
constructor
A new instance of Folder.
- #update(profile_id:, loop_id:, folder_id:, params: {}) ⇒ Object
Constructor Details
#initialize(client:) ⇒ Folder
Returns a new instance of Folder.
9 10 11 |
# File 'lib/dotloop/folder.rb', line 9 def initialize(client:) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/dotloop/folder.rb', line 5 def client @client end |
Instance Method Details
#all(profile_id:, loop_id:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dotloop/folder.rb', line 13 def all(profile_id:, loop_id:) url = "/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder" @client.get(url)[:data].map do |folder_attrs| folder = Dotloop::Models::Folder.new(folder_attrs) folder.client = client folder.profile_id = profile_id.to_i folder.loop_id = loop_id.to_i folder end end |
#create(profile_id:, loop_id:, params: {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dotloop/folder.rb', line 33 def create(profile_id:, loop_id:, params: {}) data = { name: params['name'] } folder_data = @client.post("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder", data)[:data] folder = Dotloop::Models::Folder.new(folder_data) folder.client = client folder.profile_id = profile_id.to_i folder end |
#find(profile_id:, loop_id:, folder_id:) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/dotloop/folder.rb', line 24 def find(profile_id:, loop_id:, folder_id:) folder_data = @client.get("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder/#{folder_id.to_i}")[:data] folder = Dotloop::Models::Folder.new(folder_data) folder.client = client folder.profile_id = profile_id.to_i folder.loop_id = loop_id.to_i folder end |
#update(profile_id:, loop_id:, folder_id:, params: {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dotloop/folder.rb', line 45 def update(profile_id:, loop_id:, folder_id:, params: {}) data = {} params.each do |key, value| FOLDER_FIELDS.include?(key.to_s) || next data[key] = value.to_s end folder_data = @client.patch("/profile/#{profile_id.to_i}/loop/#{loop_id.to_i}/folder/#{folder_id.to_i}", data)[:data] folder = Dotloop::Models::Folder.new(folder_data) folder.client = client folder.profile_id = profile_id.to_i folder.loop_id = loop_id.to_i folder end |