orbit_members 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e25eb88141341498fa1b4cc0d656c9891f298f5162a3398bd06c6eac25297698
4
+ data.tar.gz: ced3e08ae5b98ada767c0777e998b729b835f7e6ceab2c3ba50499dfd5aff22e
5
+ SHA512:
6
+ metadata.gz: 72961b079fd1fd5f5190c4b39b287c005d6b58608fefc04dccb37b41c4c1b3b72c4af406bc6f898f456c5b4de12d526dea016e0ac905aed0e00f3429601c5465
7
+ data.tar.gz: a290cf46b0209edfb6b03e7b640732e7358d7e021ca490593ac28176a4699c6241bce5375b20acd0c0ccb9bd6237e959b8f0c88bb0eb668da8bae29ab1a2cbc6
data/.byebug_history ADDED
@@ -0,0 +1,4 @@
1
+ exit
2
+ body
3
+ req.body
4
+ n
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ matrix:
13
+ os: [ubuntu-latest, macos-latest]
14
+ ruby: [2.7, 3.0]
15
+ runs-on: ${{ matrix.os }}
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Install dependencies
23
+ run: bundle install
24
+ - name: Run tests
25
+ run: bundle exec rspec
data/.gitignore ADDED
File without changes
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ Exclude:
4
+ - 'spec/**/*'
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: false
19
+
20
+ Style/GuardClause:
21
+ Enabled: false
22
+
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ Metrics/AbcSize:
27
+ Enabled: false
28
+
29
+ Naming/AccessorMethodName:
30
+ Enabled: false
@@ -0,0 +1,132 @@
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ team@orbit.love.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
126
+ at [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,67 @@
1
+ # Contributing Guidelines
2
+
3
+ We 💜 contributions from everyone! 🎉
4
+
5
+ It is a good idea to [talk to us on Discord](https://discord.orbit.love/) first if you plan to add any new functionality. Otherwise, bug reports, bug fixes and feedback on this project is always appreciated.
6
+
7
+ ![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat "Contributions Welcome")
8
+
9
+ The following is a set of guidelines for contributing to this project, which are hosted on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
10
+
11
+ Please take the time to review the [Code of Conduct](CODE_OF_CONDUCT.md), which all contributors are subject to on this project.
12
+
13
+ **Table of Contents**
14
+
15
+ - [Reporting Bugs](#reporting-bugs)
16
+ - [Suggesting Enhancements](#suggesting-enhancements)
17
+ - [Pull Requests](#pull-requests)
18
+
19
+ ## Reporting Bugs
20
+
21
+ This section guides you through submitting a bug report. Following these guidelines helps maintainers and the community understand your report , reproduce the behavior, and find related reports.
22
+
23
+ Before creating bug reports, please do a quick search of existing issues as you might find out that you don't need to create one.
24
+
25
+ When you are creating a bug report, please include as many details as possible. Fill out the required template, the information it asks for helps us resolve issues faster.
26
+
27
+ ### How Do I Submit A (Good) Bug Report?
28
+
29
+ Bugs are tracked as GitHub issues. Create an issue and provide the following information by filling in the provided template which appears when you try and open an issue.
30
+
31
+ Explain the problem and include additional details to help maintainers reproduce the problem:
32
+
33
+ * **Use a clear and descriptive title** for the issue to identify the problem.
34
+ * **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining how you started. When listing steps, **don't just say what you did, but explain how you did it**.
35
+ * **Provide specific examples to demonstrate the steps**. Include links to files or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use Markdown code blocks.
36
+ * **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
37
+ * **Explain which behavior you expected to see instead and why.**
38
+ * **Include screenshots and animated GIFs** where possible. Show how you follow the described steps and clearly demonstrate the problem.
39
+ * **If the problem wasn't triggered by a specific action**, describe what you were doing before the problem happened and share more information using the guidelines below.
40
+ * **Can you reliably reproduce the issue?** If not, provide details about how often the problem happens and under which conditions it normally happens.
41
+ Include details about your configuration and environment:
42
+
43
+ ## Suggesting Enhancements
44
+
45
+ This section guides you through submitting a suggestion, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related suggestions.
46
+
47
+ Before creating a suggestion, please do a quick search of existing issues as you might find out that you don't need to create one.
48
+
49
+ ### How Do I Submit A (Good) Enhancement Suggestion?
50
+
51
+ Enhancement suggestions are tracked as GitHub issues. Create an issue and provide the following information by filling in the provided template which appears when you try and open an issue.
52
+
53
+ * **Use a clear and descriptive title** for the issue to identify the suggestion.
54
+ * **Provide a step-by-step description of the suggested enhancement** in as many details as possible.
55
+ * **Provide specific examples to demonstrate the steps**. Include copy/pasteable snippets which you use in those examples, as Markdown code blocks.
56
+ * **Describe the current behavior** and **explain which behavior you expected to see instead** and why.
57
+ * **Explain why this enhancement would be useful** to most users.
58
+
59
+ ## Pull Requests
60
+
61
+ Please follow these steps to have your contribution considered by the maintainers:
62
+
63
+ 1. Follow all instructions in the template.
64
+ 2. Adhear the Code of Conduct.
65
+ 3. After you submit your pull request, verify that all [status checks](https://help.github.com/articles/about-status-checks/) are passing.
66
+
67
+ While the prerequisites above must be satisfied prior to having your pull request reviewed, the reviewer(s) may ask you to complete additional design work, tests, or other changes before your pull request can be ultimately accepted.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ orbit_members (0.0.1)
5
+ http (~> 4.4)
6
+ json (~> 2.5)
7
+ rake (~> 13.0)
8
+ zeitwerk (~> 2.4)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.7.0)
14
+ public_suffix (>= 2.0.2, < 5.0)
15
+ ast (2.4.2)
16
+ byebug (11.1.3)
17
+ crack (0.4.5)
18
+ rexml
19
+ diff-lcs (1.4.4)
20
+ domain_name (0.5.20190701)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ ffi (1.15.1)
23
+ ffi-compiler (1.0.1)
24
+ ffi (>= 1.0.0)
25
+ rake
26
+ hashdiff (1.0.1)
27
+ http (4.4.1)
28
+ addressable (~> 2.3)
29
+ http-cookie (~> 1.0)
30
+ http-form_data (~> 2.2)
31
+ http-parser (~> 1.2.0)
32
+ http-cookie (1.0.3)
33
+ domain_name (~> 0.5)
34
+ http-form_data (2.3.0)
35
+ http-parser (1.2.3)
36
+ ffi-compiler (>= 1.0, < 2.0)
37
+ json (2.5.1)
38
+ parallel (1.20.1)
39
+ parser (3.0.1.1)
40
+ ast (~> 2.4.1)
41
+ public_suffix (4.0.6)
42
+ rainbow (3.0.0)
43
+ rake (13.0.3)
44
+ regexp_parser (2.1.1)
45
+ rexml (3.2.5)
46
+ rspec (3.10.0)
47
+ rspec-core (~> 3.10.0)
48
+ rspec-expectations (~> 3.10.0)
49
+ rspec-mocks (~> 3.10.0)
50
+ rspec-core (3.10.1)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-expectations (3.10.1)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.10.0)
55
+ rspec-mocks (3.10.2)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.10.0)
58
+ rspec-support (3.10.2)
59
+ rubocop (1.15.0)
60
+ parallel (~> 1.10)
61
+ parser (>= 3.0.0.0)
62
+ rainbow (>= 2.2.2, < 4.0)
63
+ regexp_parser (>= 1.8, < 3.0)
64
+ rexml
65
+ rubocop-ast (>= 1.5.0, < 2.0)
66
+ ruby-progressbar (~> 1.7)
67
+ unicode-display_width (>= 1.4.0, < 3.0)
68
+ rubocop-ast (1.7.0)
69
+ parser (>= 3.0.1.1)
70
+ ruby-progressbar (1.11.0)
71
+ unf (0.1.4)
72
+ unf_ext
73
+ unf_ext (0.0.7.7)
74
+ unicode-display_width (2.0.0)
75
+ webmock (3.13.0)
76
+ addressable (>= 2.3.6)
77
+ crack (>= 0.3.2)
78
+ hashdiff (>= 0.4.0, < 2.0.0)
79
+ zeitwerk (2.4.2)
80
+
81
+ PLATFORMS
82
+ arm64-darwin-20
83
+
84
+ DEPENDENCIES
85
+ byebug
86
+ orbit_members!
87
+ rspec (~> 3.4)
88
+ rubocop (~> 1.7)
89
+ webmock (~> 3.12)
90
+
91
+ BUNDLED WITH
92
+ 2.2.16
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Orbit Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # Orbit Members Helper Library for Ruby
2
+
3
+ ![Build Status](https://github.com/orbit-love/ruby-orbit-members/workflows/CI/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/orbit_members.svg)](https://badge.fury.io/rb/orbit_members)
5
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md)
6
+
7
+ > Orbit API helper library for Ruby. <br>This client can create, read, update and delete members and their identities in your Orbit workspace.
8
+
9
+ <img src="https://github.com/orbit-love/js-orbit-activities/blob/bc4ce38a34af95e40b2c3e54ba44d3df6b3d3aac/.github/logo.png" alt="Orbit" style="max-width: 300px; margin: 2em 0;">
10
+
11
+ ## Package Usage
12
+
13
+ ### Installation
14
+
15
+ To install this integration in a standalone app, add the gem to your `Gemfile`:
16
+
17
+ ```ruby
18
+ gem "orbit_members"
19
+ ```
20
+
21
+ Then, run `bundle install` from your terminal.
22
+
23
+ ### Usage
24
+
25
+ #### Create a Member
26
+
27
+ To create amember:
28
+
29
+ ```ruby
30
+ OrbitMembers::Request.new(
31
+ api_key: # Your Orbit API key,
32
+ workspace_id: # Your Orbit workspace ID,
33
+ action: "create_member",
34
+ body: # The custom activity object in JSON format, see Orbit API docs for reference
35
+ )
36
+ ```
37
+ #### Update a Member
38
+
39
+ To update a member:
40
+
41
+ ```ruby
42
+ OrbitMembers::Request.new(
43
+ api_key: # Your Orbit API key,
44
+ workspace_id: # Your Orbit workspace ID,
45
+ action: "update_member",
46
+ member_id: # The ID of the member,
47
+ body: # The custom activity object in JSON format, see Orbit API docs for reference
48
+ )
49
+ ```
50
+ #### Delete a Member
51
+
52
+ To delete a member:
53
+
54
+ ```ruby
55
+ OrbitMembers::Request.new(
56
+ api_key: # Your Orbit API key,
57
+ workspace_id: # Your Orbit workspace ID,
58
+ action: "delete_member",
59
+ member_id: # The ID of the member
60
+ )
61
+ ```
62
+ #### List Members in a Workspace
63
+
64
+ To list members in a workspace:
65
+
66
+ ```ruby
67
+ OrbitMembers::Request.new(
68
+ api_key: # Your Orbit API key,
69
+ workspace_id: # Your Orbit workspace ID,
70
+ action: "list_members",
71
+ filters: # Any filters on the request in JSON format, see Orbit API docs for reference
72
+ )
73
+ ```
74
+ #### Get Specific Member
75
+
76
+ To get a specific member:
77
+
78
+ ```ruby
79
+ OrbitMembers::Request.new(
80
+ api_key: # Your Orbit API key,
81
+ workspace_id: # Your Orbit workspace ID,
82
+ action: "get_member",
83
+ member_id: # The ID of the member
84
+ )
85
+ ```
86
+ #### Get Member by an Identity
87
+
88
+ To find a member by an identity:
89
+
90
+ ```ruby
91
+ OrbitMembers::Request.new(
92
+ api_key: # Your Orbit API key,
93
+ workspace_id: # Your Orbit workspace ID,
94
+ action: "find_member_by_identity",
95
+ member_id: # The ID of the member,
96
+ filters: # Identity filter to find by, see Orbit API docs for reference
97
+ )
98
+ ```
99
+
100
+ #### Add an Identity to a Member
101
+
102
+ To add an identity to a member:
103
+
104
+ ```ruby
105
+ OrbitMembers::Request.new(
106
+ api_key: # Your Orbit API key,
107
+ workspace_id: # Your Orbit workspace ID,
108
+ action: "add_identity",
109
+ member_id: # The ID of the member,
110
+ filters: # The new identity body in JSON format, see Orbit API docs for reference
111
+ )
112
+ ```
113
+
114
+ #### Remove an Identity from a Member
115
+
116
+ To remove an identity from a member:
117
+
118
+ ```ruby
119
+ OrbitMembers::Request.new(
120
+ api_key: # Your Orbit API key,
121
+ workspace_id: # Your Orbit workspace ID,
122
+ action: "remove_identity",
123
+ member_id: # The ID of the member,
124
+ filters: # The identity to remove in JSON format, see Orbit API docs for reference
125
+ )
126
+ ```
127
+
128
+
129
+ For details on the data structures the Orbit API expects, refer to the [Orbit API Documentation](https://docs.orbit.love/reference).
130
+
131
+ ## Contributing
132
+
133
+ We 💜 contributions from everyone! Check out the [Contributing Guidelines](CONTRIBUTING.md) for more information.
134
+
135
+ ## License
136
+
137
+ This is available as open source under the terms of the [MIT License](LICENSE).
138
+
139
+ ## Code of Conduct
140
+
141
+ This project uses the [Contributor Code of Conduct](CODE_OF_CONDUCT.md). We ask everyone to please adhere by its guidelines.
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zeitwerk"
4
+ require_relative "orbit_members/version"
5
+
6
+ module OrbitMembers
7
+ loader = Zeitwerk::Loader.new
8
+ loader.tag = File.basename(__FILE__, ".rb")
9
+ loader.push_dir(__dir__)
10
+ loader.setup
11
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require_relative "utils"
6
+
7
+ module OrbitMembers
8
+ class HTTP
9
+ def self.post(url:, user_agent:, api_key:, body:)
10
+ url = URI(url)
11
+
12
+ http = Net::HTTP.new(url.host, url.port)
13
+ http.use_ssl = true
14
+ req = Net::HTTP::Post.new(url)
15
+ req["Accept"] = "application/json"
16
+ req["Content-Type"] = "application/json"
17
+ req["Authorization"] = "Bearer #{api_key}"
18
+ req["User-Agent"] = user_agent
19
+
20
+ req.body = body
21
+
22
+ response = http.request(req)
23
+
24
+ validate_payload(response.body)
25
+ end
26
+
27
+ def self.get(url:, user_agent:, api_key:, filters: nil)
28
+ url = URI(url)
29
+ url.query = URI.encode_www_form(filters) if filters
30
+
31
+ http = Net::HTTP.new(url.host, url.port)
32
+ http.use_ssl = true
33
+ req = Net::HTTP::Get.new(url)
34
+ req["Accept"] = "application/json"
35
+ req["Authorization"] = "Bearer #{api_key}"
36
+ req["User-Agent"] = user_agent
37
+
38
+ response = http.request(req)
39
+
40
+ validate_payload(response.body)
41
+ end
42
+
43
+ def self.delete(url:, user_agent:, api_key:, body: nil)
44
+ url = URI(url)
45
+
46
+ http = Net::HTTP.new(url.host, url.port)
47
+ http.use_ssl = true
48
+
49
+ req = Net::HTTP::Delete.new(url)
50
+ req["Authorization"] = "Bearer #{api_key}"
51
+ req["User-Agent"] = user_agent
52
+
53
+ req.body = body if body
54
+
55
+ response = http.request(req)
56
+
57
+ return "Deletion successful" if response.code == "204" || response.code == "200"
58
+
59
+ raise ArgumentError, response.message if response.code != "204" || response.code != "200"
60
+ end
61
+
62
+ def self.put(url:, user_agent:, api_key:, body:)
63
+ url = URI(url)
64
+
65
+ http = Net::HTTP.new(url.host, url.port)
66
+ http.use_ssl = true
67
+ req = Net::HTTP::Put.new(url)
68
+ req["Accept"] = "application/json"
69
+ req["Content-Type"] = "application/json"
70
+ req["Authorization"] = "Bearer #{api_key}"
71
+ req["User-Agent"] = user_agent
72
+
73
+ req.body = body
74
+
75
+ response = http.request(req)
76
+
77
+ return "Update successful" if response.code == "204" || response.code == "200"
78
+
79
+ raise ArgumentError, response.message if response.code != "204" || response.code != "200"
80
+ end
81
+
82
+ def self.validate_payload(payload)
83
+ JSON.parse(payload) if OrbitMembers::Utils.valid_json?(payload)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "http"
4
+
5
+ module OrbitMembers
6
+ class Request
7
+ attr_reader :api_key, :workspace_id, :user_agent, :action, :body, :filters, :member_id
8
+
9
+ def initialize(params = {})
10
+ @action = params.fetch(:action)
11
+ @api_key = params.fetch(:api_key)
12
+ @workspace_id = params.fetch(:workspace_id)
13
+ @user_agent = params.fetch(:user_agent, "ruby-orbit-members/#{OrbitMembers::VERSION}")
14
+ @body = params.fetch(:body, nil)
15
+ @filters = params.fetch(:filters, nil)
16
+ @member_id = params.fetch(:member_id, nil)
17
+ @activity_id = params.fetch(:activity_id, nil)
18
+
19
+ after_initialize!
20
+ end
21
+
22
+ def after_initialize!
23
+ case @action
24
+ when "create_member"
25
+ create_member
26
+ when "get_member"
27
+ get_member
28
+ when "list_members"
29
+ list_members
30
+ when "add_identity"
31
+ add_identity
32
+ when "remove_identity"
33
+ remove_identity
34
+ when "update_member"
35
+ update_member
36
+ when "delete_member"
37
+ delete_member
38
+ when "find_member_by_identity"
39
+ find_member_by_identity
40
+ else
41
+ raise ArgumentError,
42
+ "Activity type is unrecognized. Must be one of: create_member, update_member, get_member, list_members, add_identity, remove_identity, update_member, delete_member, find_member_by_identity"
43
+ end
44
+ end
45
+
46
+ def create_member
47
+ OrbitMembers::HTTP.post(
48
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members",
49
+ user_agent: @user_agent,
50
+ api_key: @api_key,
51
+ body: @body
52
+ )
53
+ end
54
+
55
+ def get_member
56
+ OrbitMembers::HTTP.get(
57
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}",
58
+ user_agent: @user_agent,
59
+ api_key: @api_key
60
+ )
61
+ end
62
+
63
+ def list_members
64
+ OrbitMembers::HTTP.get(
65
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members",
66
+ user_agent: @user_agent,
67
+ api_key: @api_key,
68
+ filters: @filters
69
+ )
70
+ end
71
+
72
+ def add_identity
73
+ OrbitMembers::HTTP.post(
74
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/identities",
75
+ user_agent: @user_agent,
76
+ api_key: @api_key,
77
+ body: @body
78
+ )
79
+ end
80
+
81
+ def remove_identity
82
+ OrbitMembers::HTTP.delete(
83
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/identities",
84
+ user_agent: @user_agent,
85
+ api_key: @api_key,
86
+ body: @body
87
+ )
88
+ end
89
+
90
+ def update_member
91
+ OrbitMembers::HTTP.put(
92
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}",
93
+ user_agent: @user_agent,
94
+ api_key: @api_key,
95
+ body: @body
96
+ )
97
+ end
98
+
99
+ def delete_member
100
+ OrbitMembers::HTTP.delete(
101
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}",
102
+ user_agent: @user_agent,
103
+ api_key: @api_key
104
+ )
105
+ end
106
+
107
+ def find_member_by_identity
108
+ OrbitMembers::HTTP.get(
109
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/find",
110
+ user_agent: @user_agent,
111
+ api_key: @api_key,
112
+ filters: @filters
113
+ )
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OrbitMembers
4
+ class Utils
5
+ def self.valid_json?(string)
6
+ !JSON.parse(string).nil?
7
+ rescue JSON::ParserError
8
+ raise ArgumentError,
9
+ "Expected confirmation from the Orbit API, but received nothing. Please check your logs and try again."
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OrbitMembers
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/orbit_members/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "orbit_members"
7
+ spec.version = OrbitMembers::VERSION
8
+ spec.authors = ["Orbit DevRel", "Ben Greenberg"]
9
+ spec.email = ["devrel@orbit.love"]
10
+
11
+ spec.summary = "A helper library to work with members in the Orbit API"
12
+ spec.description = "This gem helps you work with members using the Orbit API"
13
+ spec.homepage = "https://github.com/orbit-love/ruby-orbit-members"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.2")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/orbit-love/ruby-orbit-members/blob/main/CHANGELOG.md"
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+
25
+ spec.bindir = "bin"
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "http", "~> 4.4"
30
+ spec.add_dependency "json", "~> 2.5"
31
+ spec.add_dependency "rake", "~> 13.0"
32
+ spec.add_dependency "zeitwerk", "~> 2.4"
33
+ spec.add_development_dependency "byebug"
34
+ spec.add_development_dependency "rspec", "~> 3.4"
35
+ spec.add_development_dependency "rubocop", "~> 1.7"
36
+ spec.add_development_dependency "webmock", "~> 3.12"
37
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orbit_members
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Orbit DevRel
8
+ - Ben Greenberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-05-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: http
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '4.4'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '4.4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.5'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '13.0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '13.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: zeitwerk
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.4'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.4'
70
+ - !ruby/object:Gem::Dependency
71
+ name: byebug
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.4'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.4'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.7'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.7'
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '3.12'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '3.12'
126
+ description: This gem helps you work with members using the Orbit API
127
+ email:
128
+ - devrel@orbit.love
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".byebug_history"
134
+ - ".github/workflows/CI.yml"
135
+ - ".gitignore"
136
+ - ".rubocop.yml"
137
+ - CODE_OF_CONDUCT.md
138
+ - CONTRIBUTING.md
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE
142
+ - README.md
143
+ - lib/orbit_members.rb
144
+ - lib/orbit_members/http.rb
145
+ - lib/orbit_members/request.rb
146
+ - lib/orbit_members/utils.rb
147
+ - lib/orbit_members/version.rb
148
+ - orbit_members.gemspec
149
+ homepage: https://github.com/orbit-love/ruby-orbit-members
150
+ licenses:
151
+ - MIT
152
+ metadata:
153
+ homepage_uri: https://github.com/orbit-love/ruby-orbit-members
154
+ source_code_uri: https://github.com/orbit-love/ruby-orbit-members
155
+ changelog_uri: https://github.com/orbit-love/ruby-orbit-members/blob/main/CHANGELOG.md
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 2.7.2
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubygems_version: 3.2.15
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: A helper library to work with members in the Orbit API
175
+ test_files: []