Class: Nexus::Invision::Client
- Inherits:
-
Object
- Object
- Nexus::Invision::Client
- Extended by:
- T::Sig
- Defined in:
- lib/nexus/invision/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_member_to_secondary_group(request) ⇒ Object
- #ban_member(member_id) ⇒ Object
- #create_forum_post(request) ⇒ Object
- #create_forum_topic(request) ⇒ Object
- #create_member_warning(request) ⇒ Object
- #delete_member(request) ⇒ Object
- #edit_member(request) ⇒ Object
- #edit_member_primary_group(request) ⇒ Object
- #get_member(nexusmods_member_id) ⇒ Object
-
#initialize(connection) ⇒ Client
constructor
A new instance of Client.
- #list_forum_topics(request) ⇒ Object
- #login_link(nexusmods_member_id) ⇒ Object
- #remove_member_from_secondary_group(request) ⇒ Object
- #unban_member(member_id) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Client
Returns a new instance of Client.
41 42 43 |
# File 'lib/nexus/invision/client.rb', line 41 def initialize(connection) @connection = connection end |
Class Method Details
.build(base_url:, api_key:, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nexus/invision/client.rb', line 55 def build(base_url:, api_key:, &block) new( Faraday.new(url: base_url.to_s, headers: { "Accept" => "application/json" }) do |builder| builder.request(:authorization, :basic, api_key, "") builder.request(:url_encoded) builder.response(:json) block&.call(builder) end, ) end |
Instance Method Details
#add_member_to_secondary_group(request) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/nexus/invision/client.rb', line 139 def add_member_to_secondary_group(request) response = request( http_method: HTTPMethod::POST, endpoint: URI("core/members/#{request.member_id}/secgroup/#{request.group_id}"), ) Resources::User.from_hash(response.body) end |
#ban_member(member_id) ⇒ Object
170 171 172 173 174 175 176 177 |
# File 'lib/nexus/invision/client.rb', line 170 def ban_member(member_id) response = request( http_method: HTTPMethod::POST, endpoint: URI("core/bans/#{member_id}"), ) Resources::User.from_hash(response.body) end |
#create_forum_post(request) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/nexus/invision/client.rb', line 98 def create_forum_post(request) response = request( http_method: HTTPMethod::POST, endpoint: URI("forums/posts"), params: request.serialize, ) Resources::Post.from_hash(response.body) end |
#create_forum_topic(request) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/nexus/invision/client.rb', line 87 def create_forum_topic(request) response = request( http_method: HTTPMethod::POST, endpoint: URI("forums/topics"), params: request.serialize, ) Resources::Topic.from_hash(response.body) end |
#create_member_warning(request) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/nexus/invision/client.rb', line 159 def create_member_warning(request) response = request( http_method: HTTPMethod::POST, endpoint: URI("core/members/#{request.member_id}/warnings"), params: request.serialize.except("member_id"), ) Resources::Warning.from_hash(response.body) end |
#delete_member(request) ⇒ Object
190 191 192 193 194 195 196 197 198 |
# File 'lib/nexus/invision/client.rb', line 190 def delete_member(request) # 1 is keep member name, 0 is anonymize content values = request.serialize.except("member_id").merge({ "contentAnonymize" => request.keep_member_name ? 1 : 0 }) request( http_method: HTTPMethod::DELETE, endpoint: URI("core/members/#{request.member_id}"), params: values, ) end |
#edit_member(request) ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/nexus/invision/client.rb', line 201 def edit_member(request) response = request( http_method: HTTPMethod::POST, endpoint: URI("core/members/#{request.member_id}"), params: request.serialize.except("member_id"), ) Resources::User.from_hash(response.body) end |
#edit_member_primary_group(request) ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/nexus/invision/client.rb', line 129 def edit_member_primary_group(request) response = request( http_method: HTTPMethod::POST, endpoint: URI("core/members/#{request.member_id}"), params: request.serialize.except("member_id"), ) Resources::Member.from_hash(response.body) end |
#get_member(nexusmods_member_id) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/nexus/invision/client.rb', line 119 def get_member(nexusmods_member_id) response = request( http_method: HTTPMethod::GET, endpoint: URI("core/members/#{nexusmods_member_id}"), ) Resources::Member.from_hash(response.body) end |
#list_forum_topics(request) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nexus/invision/client.rb', line 68 def list_forum_topics(request) response = request( http_method: HTTPMethod::GET, endpoint: URI("forums/topics"), params: request.serialize, ) body = response.body Resources::Page[Resources::Topic].new( page: body.fetch("page"), per_page: body.fetch("perPage"), total_results: body.fetch("totalResults"), total_pages: body.fetch("totalPages"), results: body.fetch("results").map { |result| Resources::Topic.from_hash(result) }, ) end |
#login_link(nexusmods_member_id) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/nexus/invision/client.rb', line 109 def login_link(nexusmods_member_id) response = request( http_method: HTTPMethod::GET, endpoint: URI("core/loginlinks/#{nexusmods_member_id}"), ) Resources::LoginLink.from_hash(response.body) end |
#remove_member_from_secondary_group(request) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/nexus/invision/client.rb', line 149 def remove_member_from_secondary_group(request) response = request( http_method: HTTPMethod::DELETE, endpoint: URI("core/members/#{request.member_id}/secgroup/#{request.group_id}"), ) Resources::User.from_hash(response.body) end |
#unban_member(member_id) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/nexus/invision/client.rb', line 180 def unban_member(member_id) response = request( http_method: HTTPMethod::DELETE, endpoint: URI("core/bans/#{member_id}"), ) Resources::User.from_hash(response.body) end |