Using the ruby-trello gem, how can I determine whether an organization is public or not?

此生再无相见时 提交于 2019-12-25 02:27:08

问题


This question was prompted by this one:

  • Using the ruby-trello gem, how can I determine whether a board is public or not?

In the Trello API, I see both boards and organizations offer a prefs object with a permissionLevel values.

However, it appears the gem only returns these prefs values for the board:

> board = Trello::Member.find('me').boards.first
> board.prefs['permissionLevel']
=> "org"
> org = Trello::Member.find('me').organizations.first
> org.prefs['permissionLevel']
Traceback (most recent call last):
        1: from (irb):11
NoMethodError (undefined method `prefs' for #<Trello::Organization:0x00007feb54459fd8>)

Is there any way to get the organization's permission level using the gem?


回答1:


Here's a workaround using the gem:

> org = Trello::Member.find('me').organizations.first
> path = "/organizations/#{org.id}/prefs"
> response = org.client.get(path)
> org_prefs = JSON.parse(response.body)
=> {"permissionLevel"=>"public", "orgInviteRestrict"=>[], "externalMembersDisabled"=>false, "associatedDomain"=>nil, "googleAppsVersion"=>1, "boardVisibilityRestrict"=>{"private"=>"org", "org"=>"org", "public"=>"org"}}
> org_prefs['permissionLevel']
=> "public"



回答2:


The gem you are using does not support prefs in organization objects, you can verify that here but the actual Trello API does have that field so you can either look for other gems that provide you that data or call the API directly without using the gem



来源:https://stackoverflow.com/questions/50980722/using-the-ruby-trello-gem-how-can-i-determine-whether-an-organization-is-public

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!