DEV: Adds method to retrieve invite (#230)

DEV: Adds method to retrieve invite (#230)

  • DEV: Adds method to retrieve invite

  • DEV: allows nil params

  • DEV: checks email in invite spec

diff --git a/examples/invite_users.rb b/examples/invite_users.rb
index 780700a..8d8ba7a 100644
--- a/examples/invite_users.rb
+++ b/examples/invite_users.rb
@@ -19,3 +19,6 @@ client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
 
 # if the user is an admin you may invite to a group as well
 client.invite_user_to_topic(email: "foo@bar.com", group_ids: "1,2,3", topic_id: 1)
+
+# retrieve invite
+puts client.retrieve_invite(email: "foo@bar.com")
diff --git a/lib/discourse_api/api/invite.rb b/lib/discourse_api/api/invite.rb
index c110e0f..20fd83e 100644
--- a/lib/discourse_api/api/invite.rb
+++ b/lib/discourse_api/api/invite.rb
@@ -35,6 +35,14 @@ module DiscourseApi
         post("/t/#{topic_id}/invite", args)
       end
 
+      def retrieve_invite(params = {})
+        args = API.params(params).required(:email).to_h
+
+        response = get("invites/retrieve.json", args)
+
+        response.body
+      end
+
       # requires this plugin => https://github.com/discourse/discourse-invite-tokens
       def disposable_tokens(params = {})
         post("/invite-token/generate", params)
diff --git a/spec/discourse_api/api/invite_spec.rb b/spec/discourse_api/api/invite_spec.rb
index 459cf2d..314c1a9 100644
--- a/spec/discourse_api/api/invite_spec.rb
+++ b/spec/discourse_api/api/invite_spec.rb
@@ -31,4 +31,26 @@ describe DiscourseApi::API::Invite do
       expect(a_put("#{host}/invites/27")).to have_been_made
     end
   end
+
+  describe "#retrieve_invite" do
+    before do
+      stub_get("#{host}/invites/retrieve.json?email=foo@bar.com").to_return(body: fixture("retrieve_invite.json"), headers: { content_type: "application/json" })
+    end
+
+    it "requests the correct resource" do
+      subject.retrieve_invite(email: "foo@bar.com")
+      expect(a_get("#{host}/invites/retrieve.json?email=foo@bar.com")).to have_been_made
+    end
+
+    it "returns the requested topics" do
+      invites = subject.retrieve_invite(email: "foo@bar.com")
+      expect(invites).to be_an Hash
+    end
+
+    it "returns the requested invite" do
+      invites = subject.retrieve_invite(email: "foo@bar.com")
+      expect(invites["email"]).to eq("foo@bar.com")
+      expect(invites).to have_key("invite_key")
+    end
+  end
 end
diff --git a/spec/fixtures/retrieve_invite.json b/spec/fixtures/retrieve_invite.json
new file mode 100644
index 0000000..6ffb8bb
--- /dev/null
+++ b/spec/fixtures/retrieve_invite.json
@@ -0,0 +1,116 @@
+{
+  "id": 26,
+  "invite_key": "CGUHjNC4Na",
+  "link": "http://localhost:3000/invites/CGUHjNC4Na",
+  "email": "foo@bar.com",
+  "emailed": true,
+  "custom_message": null,
+  "created_at": "2021-05-07T20:48:14.278Z",
+  "updated_at": "2021-05-07T20:48:14.278Z",
+  "expires_at": "2021-06-06T20:48:14.278Z",
+  "expired": false,
+  "topics": [
+    {
+      "id": 1,
+      "title": "About the Site Feedback category",
+      "fancy_title": "About the Site Feedback category",
+      "slug": "about-the-site-feedback-category",
+      "posts_count": 1
+    }
+  ],
+  "groups": [
+    {
+      "id": 1,
+      "automatic": true,
+      "name": "admins",
+      "display_name": "admins",
+      "user_count": 1,
+      "mentionable_level": 0,
+      "messageable_level": 0,
+      "visibility_level": 1,
+      "primary_group": false,
+      "title": null,
+      "grant_trust_level": null,
+      "incoming_email": null,
+      "has_messages": true,
+      "flair_url": null,
+      "flair_bg_color": null,
+      "flair_color": null,
+      "bio_raw": "",
+      "bio_cooked": null,
+      "bio_excerpt": null,
+      "public_admission": false,
+      "public_exit": false,
+      "allow_membership_requests": false,
+      "full_name": null,
+      "default_notification_level": 3,
+      "membership_request_template": null,
+      "members_visibility_level": 0,
+      "can_see_members": true,
+      "can_admin_group": true,
+      "publish_read_state": false
+    },
+    {
+      "id": 2,
+      "automatic": true,
+      "name": "moderators",
+      "display_name": "moderators",
+      "user_count": 1,
+      "mentionable_level": 0,
+      "messageable_level": 99,
+      "visibility_level": 1,
+      "primary_group": false,
+      "title": null,
+      "grant_trust_level": null,
+      "incoming_email": null,
+      "has_messages": true,
+      "flair_url": null,
+      "flair_bg_color": null,
+      "flair_color": null,
+      "bio_raw": null,
+      "bio_cooked": null,
+      "bio_excerpt": null,
+      "public_admission": false,
+      "public_exit": false,
+      "allow_membership_requests": false,
+      "full_name": null,
+      "default_notification_level": 2,
+      "membership_request_template": null,
+      "members_visibility_level": 0,
+      "can_see_members": true,
+      "can_admin_group": true,
+      "publish_read_state": false
+    },
+    {
+      "id": 3,
+      "automatic": true,
+      "name": "staff",
+      "display_name": "staff",
+      "user_count": 2,
+      "mentionable_level": 0,
+      "messageable_level": 0,
+      "visibility_level": 1,
+      "primary_group": false,
+      "title": null,
+      "grant_trust_level": null,
+      "incoming_email": null,
+      "has_messages": false,
+      "flair_url": null,
+      "flair_bg_color": null,
+      "flair_color": null,
+      "bio_raw": null,
+      "bio_cooked": null,
+      "bio_excerpt": null,
+      "public_admission": false,
+      "public_exit": false,
+      "allow_membership_requests": false,
+      "full_name": null,
+      "default_notification_level": 3,
+      "membership_request_template": null,
+      "members_visibility_level": 0,
+      "can_see_members": true,
+      "can_admin_group": true,
+      "publish_read_state": false
+    }
+  ]
+}

GitHub sha: 30686943

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