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
- #create_message(request) ⇒ Object
- #delete_member(request) ⇒ Object
- #delete_post(post_id) ⇒ Object
- #delete_topic(topic_id) ⇒ Object
- #edit_member(request) ⇒ Object
- #edit_member_primary_group(request) ⇒ Object
- #ensure_member(request) ⇒ Object
- #get_member(nexusmods_member_id) ⇒ Object
- #get_post(post_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
- #unread_count(request) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Client
Returns a new instance of Client.
46 47 48 |
# File 'lib/nexus/invision/client.rb', line 46 def initialize(connection) @connection = connection end |
Class Method Details
.build(base_url:, api_key:, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nexus/invision/client.rb', line 60 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
200 201 202 203 204 205 206 207 |
# File 'lib/nexus/invision/client.rb', line 200 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
231 232 233 234 235 236 237 238 |
# File 'lib/nexus/invision/client.rb', line 231 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
129 130 131 132 133 134 135 136 137 |
# File 'lib/nexus/invision/client.rb', line 129 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
118 119 120 121 122 123 124 125 126 |
# File 'lib/nexus/invision/client.rb', line 118 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
220 221 222 223 224 225 226 227 228 |
# File 'lib/nexus/invision/client.rb', line 220 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 |
#create_message(request) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/nexus/invision/client.rb', line 171 def (request) request( http_method: HTTPMethod::POST, endpoint: URI("core/messages"), params: request.serialize, ) end |
#delete_member(request) ⇒ Object
251 252 253 254 255 256 257 258 259 |
# File 'lib/nexus/invision/client.rb', line 251 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 |
#delete_post(post_id) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/nexus/invision/client.rb', line 73 def delete_post(post_id) request( http_method: HTTPMethod::DELETE, endpoint: URI("forums/posts/#{post_id}"), ) end |
#delete_topic(topic_id) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/nexus/invision/client.rb', line 81 def delete_topic(topic_id) request( http_method: HTTPMethod::DELETE, endpoint: URI("forums/topics/#{topic_id}"), ) end |
#edit_member(request) ⇒ Object
262 263 264 265 266 267 268 269 |
# File 'lib/nexus/invision/client.rb', line 262 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
190 191 192 193 194 195 196 197 |
# File 'lib/nexus/invision/client.rb', line 190 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 |
#ensure_member(request) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/nexus/invision/client.rb', line 160 def ensure_member(request) response = request( http_method: HTTPMethod::POST, endpoint: URI("core/ensuremember/#{request.id}"), params: request.serialize.except("id"), ) Resources::EnsureMember.from_hash(response.body) end |
#get_member(nexusmods_member_id) ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/nexus/invision/client.rb', line 150 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 |
#get_post(post_id) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/nexus/invision/client.rb', line 89 def get_post(post_id) response = request( http_method: HTTPMethod::GET, endpoint: URI("forums/posts/#{post_id}"), ) Resources::Post.from_hash(response.body) end |
#list_forum_topics(request) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/nexus/invision/client.rb', line 99 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
140 141 142 143 144 145 146 147 |
# File 'lib/nexus/invision/client.rb', line 140 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
210 211 212 213 214 215 216 217 |
# File 'lib/nexus/invision/client.rb', line 210 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
241 242 243 244 245 246 247 248 |
# File 'lib/nexus/invision/client.rb', line 241 def unban_member(member_id) response = request( http_method: HTTPMethod::DELETE, endpoint: URI("core/bans/#{member_id}"), ) Resources::User.from_hash(response.body) end |
#unread_count(request) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/nexus/invision/client.rb', line 180 def unread_count(request) response = request( http_method: HTTPMethod::GET, endpoint: URI("core/unreadcount/#{request.id}"), ) Resources::UnreadCount.from_hash(response.body) end |