talkbox_api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: acb6f1a33be16c907191d9c0a6e1f7cdeee5abe68b315b7d991e2930bd282b3c
4
+ data.tar.gz: d8f1531a7ac4cc00598e97c2cd9b683919e8cf188bdb016faa05d17e325ef272
5
+ SHA512:
6
+ metadata.gz: 4c3e11a7e36945c6c37c6e8dd9bb9364f65ab84196cc2184fae46db13396304cd882e3d0e658cf46556412c673daa60d4de8779f99a9b8ffddb4c1cdad0607f7
7
+ data.tar.gz: 80db3b60f5aa91e7de8377bd87ffee8744181351248f7494cf3ac38de3f17574589b155265a3225adca3194b8aa6431278d6bd754cdf2785d343c88cb80288e0
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-06-07
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant 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
10
+ identity 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 overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ 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 address,
35
+ 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 email 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
+ [INSERT CONTACT METHOD].
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 of
86
+ 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 permanent
93
+ 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 the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
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 at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Glenn Trigg
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,54 @@
1
+ # TalkboxApi
2
+
3
+ This is a Ruby gem for interacting with the Talkbox API.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add talkbox_api
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install talkbox_api
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ First create a connection using the API credentials created in Talkbox at https://talkbox.impactapp.com.au/account/api_credentials.
22
+
23
+ ```ruby
24
+ connection = TalkboxApi::Connection.new("username", "password")
25
+ ```
26
+
27
+ You can then access the API resources using the connection object. E.g.
28
+
29
+ ```ruby
30
+ connection.account.get
31
+ connection.fields.all
32
+ connection.tags.create "New Tag"
33
+ ```
34
+ etc.
35
+
36
+ See the full API documentation at https://talkbox.impactapp.com.au/api.html.
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ImpactData/talkbox_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ImpactData/talkbox_api/blob/master/CODE_OF_CONDUCT.md).
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+
52
+ ## Code of Conduct
53
+
54
+ Everyone interacting in the TalkboxApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ImpactData/talkbox_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Account resource class
5
+ # This class provides methods for interacting with the Talkbox API account resource.
6
+ class Account
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves the account details
12
+ # @return [Hash] The account details
13
+ def get
14
+ resp = @conn.get("#{PATH_PREFIX}/account")
15
+ resp.body
16
+ end
17
+
18
+ # Updates the account details
19
+ # @param details [Hash] The account details to update
20
+ # @return [Hash] The updated account details
21
+ def update(details = {})
22
+ @conn.put("#{PATH_PREFIX}/account", details.to_json, { "Content-Type" => "application/json" }).body
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Communications resource class
5
+ # This class provides methods for interacting with the Talkbox API communications resource.
6
+ class Communications
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all communications
12
+ # @return [Array] The list of communications
13
+ def all
14
+ @conn.get("#{PATH_PREFIX}/communications").body
15
+ end
16
+
17
+ # Retrieves a specific communication
18
+ # @param id [String] The ID of the communication to retrieve
19
+ # @return [Hash] The retrieved communication
20
+ def get(id)
21
+ @conn.get("#{PATH_PREFIX}/promotions/#{id}/communications").body
22
+ end
23
+
24
+ # Sends a communication
25
+ # @param id [String] The ID of the communication to send
26
+ # @param params [Hash] The parameters for the communication
27
+ # @return [Hash] The sent communication
28
+ def send(id, params)
29
+ @conn.post("#{PATH_PREFIX}/promotions/#{id}/communications", params.to_json,
30
+ { "Content-Type" => "application/json" }).body
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Contacts resource class
5
+ # This class provides methods for interacting with the Talkbox API contacts resource.
6
+ class Contacts
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all contacts
12
+ # @param params [Hash] Optional parameters for the request
13
+ # @return [Array] The list of contacts
14
+ def retrieve(params = { page: 1 })
15
+ @conn.get("#{PATH_PREFIX}/contact", params).body
16
+ end
17
+
18
+ # Retrieves a specific contact
19
+ # @param id [String] The ID of the contact to retrieve
20
+ # @return [Hash] The retrieved contact
21
+ def get(id)
22
+ @conn.get("#{PATH_PREFIX}/contacts/#{id}").body
23
+ end
24
+
25
+ # Creates a new contact
26
+ # @param details [Hash] The details of the contact to create
27
+ # @return [Hash] The created contact
28
+ def create(details = {})
29
+ @conn.post("#{PATH_PREFIX}/contacts", details.to_json, { "Content-Type" => "application/json" }).body
30
+ end
31
+
32
+ # Updates an existing contact
33
+ # @param id [String] The ID of the contact to update
34
+ # @param details [Hash] The details of the contact to update
35
+ # @return [Hash] The updated contact
36
+ def update(id, details = {})
37
+ @conn.put("#{PATH_PREFIX}/contacts/#{id}", details.to_json, { "Content-Type" => "application/json" }).body
38
+ end
39
+
40
+ # Deletes a contact
41
+ # @param id [String] The ID of the contact to delete
42
+ # @return [Hash] The deleted contact
43
+ def delete(id)
44
+ @conn.delete("#{PATH_PREFIX}/contacts/#{id}").body
45
+ end
46
+
47
+ # Creates or updates a contact
48
+ # @param details [Hash] The details of the contact to create or update
49
+ # @return [Hash] The created or updated contact
50
+ def create_or_update(details = {})
51
+ @conn.post("#{PATH_PREFIX}/contacts/create_or_update", details.to_json, { "Content-Type" => "application/json" })
52
+ .body
53
+ end
54
+
55
+ # Finds a contact by email or mobile number
56
+ # @param email [String] The email of the contact to find
57
+ # @param mobile_number [String] The mobile number of the contact to find
58
+ # @return [Hash] The found contact
59
+ def find_first(email: nil, mobile_number: nil)
60
+ @conn.get("#{PATH_PREFIX}/contact/find_first", { email: email, mobile_number: mobile_number }).body
61
+ end
62
+
63
+ # Sends a resubscription email to a contact
64
+ # @param id [String] The ID of the contact to send the email to
65
+ # @return [Hash] The sent email
66
+ def send_resubscription_email(id)
67
+ @conn.post("#{PATH_PREFIX}/contacts/#{id}/send_resubscription_email").body
68
+ end
69
+
70
+ # Sends a resubscription SMS to a contact
71
+ # @param id [String] The ID of the contact to send the SMS to
72
+ # @return [Hash] The sent SMS
73
+ def send_resubscription_sms(id)
74
+ @conn.post("#{PATH_PREFIX}/contacts/#{id}/send_resubscription_sms").body
75
+ end
76
+
77
+ # Retrieves all vouchers for a contact
78
+ # @param id [String] The ID of the contact to retrieve vouchers for
79
+ # @param status [String] Optional status of the vouchers to retrieve
80
+ # @return [Array] The list of vouchers
81
+ def vouchers(id, status = nil)
82
+ if status
83
+ @conn.get("#{PATH_PREFIX}/contacts/#{id}/vouchers", { status: status }).body
84
+ else
85
+ @conn.get("#{PATH_PREFIX}/contacts/#{id}/vouchers").body
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # EmailSenderDetails resource class
5
+ # This class provides methods for interacting with the Talkbox API email sender details resource.
6
+ class EmailSenderDetails
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all email sender details
12
+ # @return [Array] The list of email sender details
13
+ def all
14
+ @conn.get("#{PATH_PREFIX}/email_sender_details").body
15
+ end
16
+
17
+ # Creates a new email sender detail
18
+ # @param params [Hash] The parameters for the new email sender detail
19
+ # @return [Hash] The created email sender detail
20
+ def create(params)
21
+ @conn.post("#{PATH_PREFIX}/email_sender_details", params.to_json, { "Content-Type" => "application/json" }).body
22
+ end
23
+
24
+ # Updates an existing email sender detail
25
+ # @param id [String] The ID of the email sender detail to update
26
+ # @param params [Hash] The parameters for the updated email sender detail
27
+ # @return [Hash] The updated email sender detail
28
+ def update(id, params)
29
+ @conn.put("#{PATH_PREFIX}/email_sender_details/#{id}", params.to_json, { "Content-Type" => "application/json" })
30
+ .body
31
+ end
32
+
33
+ # Deletes an email sender detail
34
+ # @param id [String] The ID of the email sender detail to delete
35
+ # @return [Hash] The deleted email sender detail
36
+ def delete(id)
37
+ @conn.delete("#{PATH_PREFIX}/email_sender_details/#{id}").body
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Fields resource class
5
+ # This class provides methods for interacting with the Talkbox API fields resource.
6
+ class Fields
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all fields
12
+ # @return [Array] The list of fields
13
+ def all
14
+ @conn.get("#{PATH_PREFIX}/fields").body
15
+ end
16
+
17
+ # Creates a new field
18
+ # @param name [String] The name of the field
19
+ # @param field_type [String] The type of the field
20
+ # @param options [Hash] Optional additional options for the field
21
+ # @return [Hash] The created field
22
+ def create(name, field_type, options = nil)
23
+ @conn.post("#{PATH_PREFIX}/fields", { name: name, field_type: field_type, options: options }.to_json,
24
+ { "Content-Type" => "application/json" }).body
25
+ end
26
+
27
+ # Updates an existing field
28
+ # @param system_name [String] The system name of the field to update
29
+ # @param name [String] The new name of the field
30
+ # @param options [Hash] Optional additional options for the field
31
+ # @return [Hash] The updated field
32
+ def update(system_name, name, options = nil)
33
+ @conn.put("#{PATH_PREFIX}/fields/#{system_name}", { name: name, options: options }.to_json,
34
+ { "Content-Type" => "application/json" }).body
35
+ end
36
+
37
+ # Deletes a field
38
+ # @param system_name [String] The system name of the field to delete
39
+ # @return [Hash] The deleted field
40
+ def delete(system_name)
41
+ @conn.delete("#{PATH_PREFIX}/fields/#{system_name}").body
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Offers resource class
5
+ # This class provides methods for interacting with the Talkbox API offers resource.
6
+ class Offers
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all offers
12
+ # @return [Array] The list of offers
13
+ def all
14
+ @conn.get("#{PATH_PREFIX}/offers").body
15
+ end
16
+
17
+ # Retrieves a specific offer
18
+ # @param id [String] The ID of the offer to retrieve
19
+ # @return [Hash] The retrieved offer
20
+ def get(id)
21
+ @conn.get("#{PATH_PREFIX}/offers/#{id}").body
22
+ end
23
+
24
+ # Creates a new offer
25
+ # @param params [Hash] The parameters for the new offer
26
+ # @return [Hash] The created offer
27
+ def create(params)
28
+ @conn.post("#{PATH_PREFIX}/offers", params.to_json, { "Content-Type" => "application/json" }).body
29
+ end
30
+
31
+ # Updates an existing offer
32
+ # @param id [String] The ID of the offer to update
33
+ # @param params [Hash] The parameters for the updated offer
34
+ # @return [Hash] The updated offer
35
+ def update(id, params)
36
+ @conn.put("#{PATH_PREFIX}/offers/#{id}", params.to_json, { "Content-Type" => "application/json" }).body
37
+ end
38
+
39
+ # Deletes an offer
40
+ # @param id [String] The ID of the offer to delete
41
+ # @return [Hash] The deleted offer
42
+ def delete(id)
43
+ @conn.delete("#{PATH_PREFIX}/offers/#{id}").body
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Promotions resource class
5
+ # This class provides methods for interacting with the Talkbox API promotions resource.
6
+ class Promotions
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Creates a new promotion
12
+ # @param params [Hash] The parameters for the new promotion
13
+ # @return [Hash] The created promotion
14
+ def create(params)
15
+ @conn.post("#{PATH_PREFIX}/promotions", params.to_json, { "Content-Type" => "application/json" }).body
16
+ end
17
+
18
+ # Updates an existing promotion
19
+ # @param id [String] The ID of the promotion to update
20
+ # @param params [Hash] The parameters for the updated promotion
21
+ # @return [Hash] The updated promotion
22
+ def update(id, params)
23
+ @conn.put("#{PATH_PREFIX}/promotions/#{id}", params.to_json, { "Content-Type" => "application/json" }).body
24
+ end
25
+
26
+ # Deletes a promotion
27
+ # @param id [String] The ID of the promotion to delete
28
+ # @return [Hash] The deleted promotion
29
+ def delete(id)
30
+ @conn.delete("#{PATH_PREFIX}/promotions/#{id}").body
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Sections resource class
5
+ # This class provides methods for interacting with the Talkbox API sections resource.
6
+ class Sections
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all sections
12
+ # @return [Array] The list of sections
13
+ def all
14
+ @conn.get("#{PATH_PREFIX}/sections").body
15
+ end
16
+
17
+ # Retrieves a specific section
18
+ # @param id [String] The ID of the section to retrieve
19
+ # @return [Hash] The retrieved section
20
+ def get(id)
21
+ @conn.get("#{PATH_PREFIX}/sections/#{id}").body
22
+ end
23
+
24
+ # Creates a new section
25
+ # @param params [Hash] The parameters for the new section
26
+ # @return [Hash] The created section
27
+ def create(params)
28
+ @conn.post("#{PATH_PREFIX}/sections", params.to_json, { "Content-Type" => "application/json" }).body
29
+ end
30
+
31
+ # Updates an existing section
32
+ # @param id [String] The ID of the section to update
33
+ # @param params [Hash] The parameters for the updated section
34
+ # @return [Hash] The updated section
35
+ def update(id, params)
36
+ @conn.put("#{PATH_PREFIX}/sections/#{id}", params.to_json, { "Content-Type" => "application/json" }).body
37
+ end
38
+
39
+ # Deletes a section
40
+ # @param id [String] The ID of the section to delete
41
+ # @return [Hash] The deleted section
42
+ def delete(id)
43
+ @conn.delete("#{PATH_PREFIX}/sections/#{id}").body
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Subscriptions resource class
5
+ # This class provides methods for interacting with the Talkbox API subscriptions resource.
6
+ class Subscriptions
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all subscriptions
12
+ # @param params [Hash] Optional parameters for the request
13
+ # @return [Array] The list of subscriptions
14
+ def retrieve(params = { page: 1 })
15
+ @conn.get("#{PATH_PREFIX}/subscriptions", params).body
16
+ end
17
+
18
+ # Unsubscribes a contact
19
+ # @param params [Hash] The parameters for the unsubscribe request
20
+ # @return [Hash] The unsubscribed contact
21
+ def unsubscribe(params)
22
+ @conn.post("#{PATH_PREFIX}/unsubscriptions", params.to_json, { "Content-Type" => "application/json" }).body
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Surveys resource class
5
+ # This class provides methods for interacting with the Talkbox API surveys resource.
6
+ class Surveys
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all surveys
12
+ # @param params [Hash] Optional parameters for the request
13
+ # @return [Array] The list of surveys
14
+ def all(params = nil)
15
+ @conn.get("#{PATH_PREFIX}/surveys", params).body
16
+ end
17
+
18
+ # Retrieves the score of a survey
19
+ # @param params [Hash] Optional parameters for the request
20
+ # @return [Hash] The score of the survey
21
+ def score(params = nil)
22
+ @conn.get("#{PATH_PREFIX}/surveys/score", params).body
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Tags resource class
5
+ # This class provides methods for interacting with the Talkbox API tags resource.
6
+ class Tags
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all tags
12
+ # @return [Array] The list of tags
13
+ def all
14
+ @conn.get("#{PATH_PREFIX}/tags").body.map(&:values).to_h
15
+ end
16
+
17
+ # Retrieves a specific tag
18
+ # @param id [String] The ID of the tag to retrieve
19
+ # @return [Hash] The retrieved tag
20
+ def get(id)
21
+ @conn.get("#{PATH_PREFIX}/tags/#{id}").body
22
+ end
23
+
24
+ # Creates a new tag
25
+ # @param name [String] The name of the tag
26
+ # @return [Hash] The created tag
27
+ def create(name)
28
+ @conn.post("#{PATH_PREFIX}/tags", { name: name }.to_json, { "Content-Type" => "application/json" }).body
29
+ end
30
+
31
+ # Updates an existing tag
32
+ # @param id [String] The ID of the tag to update
33
+ # @param name [String] The new name of the tag
34
+ # @return [Hash] The updated tag
35
+ def update(id, name)
36
+ @conn.put("#{PATH_PREFIX}/tags/#{id}", { name: name }.to_json, { "Content-Type" => "application/json" }).body
37
+ end
38
+
39
+ # Deletes a tag
40
+ # @param id [String] The ID of the tag to delete
41
+ # @return [Hash] The deleted tag
42
+ def delete(id)
43
+ @conn.delete("#{PATH_PREFIX}/tags/#{id}").body
44
+ end
45
+
46
+ # Untags all contacts from a tag
47
+ # @param id [String] The ID of the tag to untag contacts from
48
+ # @return [Hash] The untagged tag
49
+ def untag_contacts(id)
50
+ @conn.put("#{PATH_PREFIX}/tags/#{id}/untag_contacts").body
51
+ end
52
+
53
+ # Retrieves all contacts for a tag
54
+ # @param id [String] The ID of the tag to retrieve contacts for
55
+ # @return [Array] The list of contacts
56
+ def contacts(id)
57
+ @conn.get("#{PATH_PREFIX}/tags/#{id}/contacts").body
58
+ end
59
+
60
+ # Adds a contact to a tag
61
+ # @param id [String] The ID of the tag to add the contact to
62
+ # @param contact_id [String] The ID of the contact to add
63
+ # @return [Hash] The added contact
64
+ def add_contact(id, contact_id)
65
+ @conn.post("#{PATH_PREFIX}/tags/#{id}/contacts/#{contact_id}").body
66
+ end
67
+
68
+ # Removes a contact from a tag
69
+ # @param id [String] The ID of the tag to remove the contact from
70
+ # @param contact_id [String] The ID of the contact to remove
71
+ # @return [Hash] The removed contact
72
+ def remove_contact(id, contact_id)
73
+ @conn.delete("#{PATH_PREFIX}/tags/#{id}/contacts/#{contact_id}").body
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TalkboxApi
4
+ # Vouchers resource class
5
+ # This class provides methods for interacting with the Talkbox API vouchers resource.
6
+ class Vouchers
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ # Retrieves all vouchers
12
+ # @param params [Hash] Optional parameters for the request
13
+ # @return [Array] The list of vouchers
14
+ def all(params = nil)
15
+ @conn.get("#{PATH_PREFIX}/vouchers", params).body
16
+ end
17
+
18
+ # Retrieves a specific voucher
19
+ # @param id [String] The ID of the voucher to retrieve
20
+ # @return [Hash] The retrieved voucher
21
+ def get(id)
22
+ @conn.get("#{PATH_PREFIX}/vouchers/#{id}").body
23
+ end
24
+
25
+ # Redeems a voucher
26
+ # @param id [String] The ID of the voucher to redeem
27
+ # @return [Hash] The redeemed voucher
28
+ def redeem(id)
29
+ @conn.put("#{PATH_PREFIX}/vouchers/#{id}").body
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require_relative "talkbox_api/account"
5
+ require_relative "talkbox_api/communications"
6
+ require_relative "talkbox_api/contacts"
7
+ require_relative "talkbox_api/email_sender_details"
8
+ require_relative "talkbox_api/fields"
9
+ require_relative "talkbox_api/offers"
10
+ require_relative "talkbox_api/promotions"
11
+ require_relative "talkbox_api/sections"
12
+ require_relative "talkbox_api/subscriptions"
13
+ require_relative "talkbox_api/surveys"
14
+ require_relative "talkbox_api/tags"
15
+ require_relative "talkbox_api/version"
16
+ require_relative "talkbox_api/vouchers"
17
+
18
+ module TalkboxApi
19
+ PATH_PREFIX = "/service/v1"
20
+
21
+ # Main connection class for Talkbox API
22
+ # This class handles authentication and provides access to all Talkbox API resources.
23
+ # It uses Faraday for HTTP requests and caches resource instances for efficiency.
24
+ class Connection
25
+ # Initializes a new Talkbox API connection
26
+ # @param username [String] The Talkbox API username
27
+ # @param password [String] The Talkbox API password
28
+ # @param base_url [String] Optional custom base URL for the API (defaults to Talkbox production)
29
+ # @raise [Faraday::Error] If authentication fails
30
+ def initialize(username, password, base_url: nil)
31
+ @base_url = base_url || "https://talkbox.impactapp.com.au/"
32
+ @conn = Faraday.new(url: @base_url) do |faraday|
33
+ faraday.request :authorization, "basic", username, password
34
+ faraday.response :json
35
+ faraday.response :raise_error
36
+ end
37
+ # Get account here to make sure credentials/base_url are all good.
38
+ account.get
39
+ end
40
+
41
+ # Returns a Fields resource instance
42
+ # @return [TalkboxApi::Fields] The Fields resource
43
+ def fields
44
+ @fields ||= Fields.new(@conn)
45
+ end
46
+
47
+ # Returns an Account resource instance
48
+ # @return [TalkboxApi::Account] The Account resource
49
+ def account
50
+ @account ||= Account.new(@conn)
51
+ end
52
+
53
+ # Returns a Tags resource instance
54
+ # @return [TalkboxApi::Tags] The Tags resource
55
+ def tags
56
+ @tags ||= Tags.new(@conn)
57
+ end
58
+
59
+ # Returns a Contacts resource instance
60
+ # @return [TalkboxApi::Contacts] The Contacts resource
61
+ def contacts
62
+ @contacts ||= Contacts.new(@conn)
63
+ end
64
+
65
+ # Returns a Subscriptions resource instance
66
+ # @return [TalkboxApi::Subscriptions] The Subscriptions resource
67
+ def subscriptions
68
+ @subscriptions ||= Subscriptions.new(@conn)
69
+ end
70
+
71
+ # Returns a Promotions resource instance
72
+ # @return [TalkboxApi::Promotions] The Promotions resource
73
+ def promotions
74
+ @promotions ||= Promotions.new(@conn)
75
+ end
76
+
77
+ # Returns a Communications resource instance
78
+ # @return [TalkboxApi::Communications] The Communications resource
79
+ def communications
80
+ @communications ||= Communications.new(@conn)
81
+ end
82
+
83
+ # Returns an EmailSenderDetails resource instance
84
+ # @return [TalkboxApi::EmailSenderDetails] The EmailSenderDetails resource
85
+ def email_sender_details
86
+ @email_sender_details ||= EmailSenderDetails.new(@conn)
87
+ end
88
+
89
+ # Returns a Surveys resource instance
90
+ # @return [TalkboxApi::Surveys] The Surveys resource
91
+ def surveys
92
+ @surveys ||= Surveys.new(@conn)
93
+ end
94
+
95
+ # Returns a Vouchers resource instance
96
+ # @return [TalkboxApi::Vouchers] The Vouchers resource
97
+ def vouchers
98
+ @vouchers ||= Vouchers.new(@conn)
99
+ end
100
+
101
+ # Returns an Offers resource instance
102
+ # @return [TalkboxApi::Offers] The Offers resource
103
+ def offers
104
+ @offers ||= Offers.new(@conn)
105
+ end
106
+
107
+ # Returns a Sections resource instance
108
+ # @return [TalkboxApi::Sections] The Sections resource
109
+ def sections
110
+ @sections ||= Sections.new(@conn)
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,4 @@
1
+ module TalkboxApi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: talkbox_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Glenn Trigg
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-06-10 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: A Ruby gem for interacting with the Talkbox API (see https://talkbox.impactapp.com.au/api.html)
27
+ email:
28
+ - ggt@glenntrigg.net
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".rubocop.yml"
34
+ - CHANGELOG.md
35
+ - CODE_OF_CONDUCT.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/talkbox_api.rb
40
+ - lib/talkbox_api/account.rb
41
+ - lib/talkbox_api/communications.rb
42
+ - lib/talkbox_api/contacts.rb
43
+ - lib/talkbox_api/email_sender_details.rb
44
+ - lib/talkbox_api/fields.rb
45
+ - lib/talkbox_api/offers.rb
46
+ - lib/talkbox_api/promotions.rb
47
+ - lib/talkbox_api/sections.rb
48
+ - lib/talkbox_api/subscriptions.rb
49
+ - lib/talkbox_api/surveys.rb
50
+ - lib/talkbox_api/tags.rb
51
+ - lib/talkbox_api/version.rb
52
+ - lib/talkbox_api/vouchers.rb
53
+ - sig/talkbox_api.rbs
54
+ homepage: https://github.com/ImpactData/talkbox_api
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ homepage_uri: https://github.com/ImpactData/talkbox_api
59
+ changelog_uri: https://github.com/ImpactData/talkbox_api/blob/main/CHANGELOG.md
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.0.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.6.3
75
+ specification_version: 4
76
+ summary: A Ruby gem for interacting with the Talkbox API.
77
+ test_files: []