DEV: Adds method to update an invite (#229)

DEV: Adds method to update an invite (#229)

  • DEV: Adds method to update an invite

  • DEV: Adds rspec test for update_invite & invite_user method

diff --git a/examples/invite_users.rb b/examples/invite_users.rb
index 72c7f4d..780700a 100644
--- a/examples/invite_users.rb
+++ b/examples/invite_users.rb
@@ -9,7 +9,10 @@ client.api_key = config['api_key'] || "YOUR_API_KEY"
 client.api_username = config['api_username'] || "YOUR_USERNAME"
 
 # invite user
-client.invite_user(email: "name@example.com", group_ids: "41,42")
+invite = client.invite_user(email: "name@example.com", group_ids: "41,42")
+
+#update invite
+client.update_invite(invite["id"], email: "namee@example.com")
 
 # invite to a topic
 client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
diff --git a/lib/discourse_api/api/invite.rb b/lib/discourse_api/api/invite.rb
index 2660edc..c110e0f 100644
--- a/lib/discourse_api/api/invite.rb
+++ b/lib/discourse_api/api/invite.rb
@@ -39,6 +39,22 @@ module DiscourseApi
       def disposable_tokens(params = {})
         post("/invite-token/generate", params)
       end
+
+      def update_invite(invite_id, params = {})
+        args = API.params(params)
+          .optional(
+            :topic_id,
+            :group_ids,
+            :group_names,
+            :email,
+            :send_email,
+            :custom_message,
+            :max_redemptions_allowed,
+            :expires_at
+          ).to_h
+
+        put("invites/#{invite_id}", args)
+      end
     end
   end
 end
diff --git a/spec/discourse_api/api/invite_spec.rb b/spec/discourse_api/api/invite_spec.rb
new file mode 100644
index 0000000..459cf2d
--- /dev/null
+++ b/spec/discourse_api/api/invite_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+describe DiscourseApi::API::Invite do
+  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
+
+  describe "#invite_user" do
+    before do
+      stub_post("#{host}/invites").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
+    end
+
+    it "requests the correct resource" do
+      subject.invite_user(email: "fake_user@example.com", group_ids: "41,42")
+      expect(a_post("#{host}/invites")).to have_been_made
+    end
+
+    it "returns success" do
+      response = subject.invite_user(email: "fake_user@example.com", group_ids: "41,42")
+      expect(response).to be_a Hash
+      expect(response['success']).to be_truthy
+    end
+  end
+
+  describe "#update_invite" do
+    before do
+      stub_put("#{host}/invites/27").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
+    end
+
+    it "updates invite" do
+      subject.update_invite(27, email: "namee@example.com")
+      expect(a_put("#{host}/invites/27")).to have_been_made
+    end
+  end
+end

GitHub sha: 167f04ac

This commit appears in #229 which was approved by blake. It was merged by blake.