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
-
#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.
36 37 38 |
# File 'lib/nexus/invision/client.rb', line 36 def initialize(connection) @connection = connection end |
Class Method Details
.build(base_url:, api_key:, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nexus/invision/client.rb', line 50 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
114 115 116 117 118 119 120 121 |
# File 'lib/nexus/invision/client.rb', line 114 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
145 146 147 148 149 150 151 152 |
# File 'lib/nexus/invision/client.rb', line 145 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
93 94 95 96 97 98 99 100 101 |
# File 'lib/nexus/invision/client.rb', line 93 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
82 83 84 85 86 87 88 89 90 |
# File 'lib/nexus/invision/client.rb', line 82 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
134 135 136 137 138 139 140 141 142 |
# File 'lib/nexus/invision/client.rb', line 134 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 |
#list_forum_topics(request) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nexus/invision/client.rb', line 63 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
104 105 106 107 108 109 110 111 |
# File 'lib/nexus/invision/client.rb', line 104 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
124 125 126 127 128 129 130 131 |
# File 'lib/nexus/invision/client.rb', line 124 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
155 156 157 158 159 160 161 162 |
# File 'lib/nexus/invision/client.rb', line 155 def unban_member(member_id) response = request( http_method: HTTPMethod::DELETE, endpoint: URI("core/bans/#{member_id}"), ) Resources::User.from_hash(response.body) end |