Class: Nexus::Invision::Client

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/nexus/invision/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Client

Returns a new instance of Client.



38
39
40
# File 'lib/nexus/invision/client.rb', line 38

def initialize(connection)
  @connection = connection
end

Class Method Details

.build(base_url:, api_key:, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/nexus/invision/client.rb', line 52

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



116
117
118
119
120
121
122
123
# File 'lib/nexus/invision/client.rb', line 116

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



147
148
149
150
151
152
153
154
# File 'lib/nexus/invision/client.rb', line 147

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



95
96
97
98
99
100
101
102
103
# File 'lib/nexus/invision/client.rb', line 95

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



84
85
86
87
88
89
90
91
92
# File 'lib/nexus/invision/client.rb', line 84

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



136
137
138
139
140
141
142
143
144
# File 'lib/nexus/invision/client.rb', line 136

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



167
168
169
170
171
172
173
174
175
176
# File 'lib/nexus/invision/client.rb', line 167

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



179
180
181
182
183
184
185
186
# File 'lib/nexus/invision/client.rb', line 179

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

#list_forum_topics(request) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nexus/invision/client.rb', line 65

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


106
107
108
109
110
111
112
113
# File 'lib/nexus/invision/client.rb', line 106

def (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



126
127
128
129
130
131
132
133
# File 'lib/nexus/invision/client.rb', line 126

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



157
158
159
160
161
162
163
164
# File 'lib/nexus/invision/client.rb', line 157

def unban_member(member_id)
  response = request(
    http_method: HTTPMethod::DELETE,
    endpoint: URI("core/bans/#{member_id}"),
  )

  Resources::User.from_hash(response.body)
end