onepost 0.1.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: be36691d446ee82c3d1d5cefdb7fa6219ecab52999d32017372fcb32223824c0
4
+ data.tar.gz: bc4c1e3e114bb1b98a947c2c05ed2b0109771e0f7f4edb7739441110a1936a48
5
+ SHA512:
6
+ metadata.gz: b2a0b0b1e2e88c36dd2bb3ed4bbefa2f677f242590e048aea0258a8ac7ed866f69dcd4de82947ec357cb57535921c26687cc54e54506e1e4efa563adbdc915a2
7
+ data.tar.gz: '059361224757edc3aa132d350549d6881f528a078898000f2ce355562a104916f099114548c00942ba2298fb2a933bbdd49f2fe5ad2188bff8c4d1ffe497169c'
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at piremies@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in onepost.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "activesupport"
8
+ gem "httparty"
9
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ onepost (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.1.3)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ zeitwerk (~> 2.3)
15
+ addressable (2.7.0)
16
+ public_suffix (>= 2.0.2, < 5.0)
17
+ coderay (1.1.3)
18
+ concurrent-ruby (1.1.8)
19
+ crack (0.4.5)
20
+ rexml
21
+ hashdiff (1.0.1)
22
+ httparty (0.18.1)
23
+ mime-types (~> 3.0)
24
+ multi_xml (>= 0.5.2)
25
+ i18n (1.8.9)
26
+ concurrent-ruby (~> 1.0)
27
+ method_source (1.0.0)
28
+ mime-types (3.3.1)
29
+ mime-types-data (~> 3.2015)
30
+ mime-types-data (3.2021.0212)
31
+ minitest (5.14.3)
32
+ minitest-focus (1.2.1)
33
+ minitest (>= 4, < 6)
34
+ mocha (1.12.0)
35
+ multi_xml (0.6.0)
36
+ pry (0.14.0)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
39
+ public_suffix (4.0.6)
40
+ rake (12.3.3)
41
+ rexml (3.2.4)
42
+ tzinfo (2.0.4)
43
+ concurrent-ruby (~> 1.0)
44
+ webmock (3.11.2)
45
+ addressable (>= 2.3.6)
46
+ crack (>= 0.3.2)
47
+ hashdiff (>= 0.4.0, < 2.0.0)
48
+ zeitwerk (2.4.2)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ activesupport
55
+ httparty
56
+ minitest (~> 5.0)
57
+ minitest-focus
58
+ mocha
59
+ onepost!
60
+ pry
61
+ rake (~> 12.0)
62
+ webmock
63
+
64
+ BUNDLED WITH
65
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Adam Darrah
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,214 @@
1
+ # Onepost
2
+
3
+ OnePost is social media management infrastructure for the internet. Companies use our API to create, post, and manage their social presence via programmatic communication. You can think of it like a headless Hootsuite built for developers.
4
+
5
+ Use OnePost to quickly integrate your application with Twitter, Facebook, and Instagram.
6
+
7
+ 1. Start by registering for the developer applications that you'll need for your application, such as Twitter and Facebook.
8
+ 2. Then, use OnePost to allow your application's users to log in to each service through their web browser, thereby giving your application permission to post on their behalf.
9
+ 3. Finally, post to one (or many) social pages owned by the user with a single API call. Use OnePost to track the performance of each post over time.
10
+
11
+ Learn more at [https://www.getonepost.com/](https://www.getonepost.com/).
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'onepost'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install onepost
28
+
29
+ ## Usage
30
+
31
+ ### Obtain Credentials
32
+
33
+ To use the OnePost Ruby Gem, you must first obtain the required credentials:
34
+
35
+ 1. Create a user account on [OnePost](https://api.getonepost.com/) to get your `secret_key`, which will be a required parameter for all requests.
36
+ 2. OnePost uses the RapidAPI infrastructure to manage API requests. You will need to find your `X-RapidAPI-Key` value from [RapidAPI](https://rapidapi.com/onepost/api/onepost1).
37
+
38
+ ### Create Developer Applications
39
+
40
+ Now that you have the required credentials, the next step is to register a developer application with Providers you would like to integrate with, such as Twitter and Facebook. For the purpose of these instructions, we'll be using Twitter. Use the [Twitter Developer Portal](https://developer.twitter.com/en) to register a new Developer Application. Once you have created your developer application, take note of your `API key` and `API secret key`.
41
+
42
+ ### Using the OnePost Ruby Gem
43
+
44
+ All interactions with the OnePost API is done using a `Onepost::Client` instance. You can create your instance by passing your credentials:
45
+
46
+ ```ruby
47
+ client = Onepost::Client.new(
48
+ secret_key: "sk-7a0...",
49
+ rapid_api_key: "9d0..."
50
+ )
51
+ ```
52
+
53
+ Once we have a `Onepost::Client` instance, let's use the instance to create a Provider record for our Twitter Developer Application. Provider records are used to store the `API key` and `API secret key` from any social provider, such as Twitter, Facebook, etc.
54
+
55
+ ```ruby
56
+ client.create_provider(body: {
57
+ provider: {
58
+ type: "Providers::Twitter",
59
+ api_key: "edw...",
60
+ api_secret_key: "XVI..."
61
+ }
62
+ })
63
+ # => {"id"=>5, "type"=>"Providers::Twitter", "api_key"=>"edw...", "created_at"=>"2021-02-19T10:04:23.692-05:00", "updated_at"=>"2021-02-19T10:04:23.692-05:00", "callback_url"=>nil, "api_secret_key"=>"XVI..."}
64
+ ```
65
+
66
+ Now that we have created a Provider record, we can use our client to read the data back.
67
+
68
+ ```ruby
69
+ client.get_provider(5)
70
+ # => {"id"=>5, "type"=>"Providers::Twitter", "api_key"=>"edw...", "created_at"=>"2021-02-19T10:04:23.692-05:00", "updated_at"=>"2021-02-19T10:04:23.692-05:00", "callback_url"=>nil, "api_secret_key"=>"XVI..."}
71
+ ```
72
+
73
+ Or you can fetch all providers registered to the API user.
74
+
75
+ ```ruby
76
+ client.get_providers
77
+ # => {"current_page"=>1, "per_page"=>30, "total_entries"=>1, "collection"=>[{"id"=>5, "type"=>"Providers::Twitter", "api_key"=>"edw...", "created_at"=>"2021-02-19T10:04:23.692-05:00", "updated_at"=>"2021-02-19T10:04:23.692-05:00", "callback_url"=>nil, "api_secret_key"=>"XVI..."}]}
78
+ ```
79
+
80
+ As you can see, the OnePost API will paginate results for endpoints that can return many records. You can pass additional parameters to your API call to navigate your results (`per_page` has a maximum value of 100):
81
+
82
+ ```ruby
83
+ client.get_providers(query: {page: 2, per_page: 50})
84
+ => {"current_page"=>2, "per_page"=>50, "total_entries"=>2, "collection"=>[]}
85
+ ```
86
+
87
+ Now that we have registered our Twitter Developer Application with OnePost by creating a `Provider` record, the next step is for us to authorize a Twitter account by creating an `Authorization` record. This is a step that must be done in the web browser, but you can get instructions by using the `create_authorization` API endpoint.
88
+
89
+ ```ruby
90
+ client.create_authorization(body: {authorization: {provider_id: 5}})
91
+ # => {"instructions"=>["Perform the following steps to complete the authorization process:", " 1. In your web browser, navigate to the provided URL.", " 2. Sign in to Twitter.", " 3. You will be redirected back to the original application."], "url"=>"https://api.getonepost.com/users/auth/twitter?provider_id=5&public_key=pk-7a0..."}
92
+ ```
93
+
94
+ In your web browser, navigate to the `url` value. You will be prompted to log in to your Twitter account, which will give your Twitter Developer Application access. Once you log in, you will be redirected back to the OnePost website. The URL to redirect the user to after a successful authorization can be customized by the `callback_url` value on the Provider record.
95
+
96
+ <img width="1000" alt="twitter-browser" src="https://user-images.githubusercontent.com/69064/108530520-aea1b100-72a3-11eb-94f8-123e9e256e44.png">
97
+
98
+ Once you've authorized your Twitter account, the Authorization record is available on the OnePost API. (Note: In addition to finding the `Authorization` record via the API, look for the `X-OnePost-Authorization-Id`, `X-OnePost-Provider-Id`, and `X-OnePost-Public-Key` header values in the request sent to your `callback_url`)
99
+
100
+ ```ruby
101
+ client.get_authorizations
102
+ # => {"current_page"=>1, "per_page"=>30, "total_entries"=>1, "collection"=>[{"id"=>5, "created_at"=>"2021-02-19T10:18:36.384-05:00", "updated_at"=>"2021-02-19T10:18:36.384-05:00", "provider_id"=>5, "type"=>"Authorizations::Twitter", "consumer_key"=>"815...", "consumer_secret"=>"HLh...", "authorized_pages"=>[]}]}
103
+ ```
104
+
105
+ When an Authorization is created in OnePost, OnePost will automatically create `AuthorizedPage` records for the `Authorization` that represent social pages the user is allowed to post to. In the case of Twitter, this will be a single `AuthorizedPage`. Let's use the API to find our `AuthorizedPage` record:
106
+
107
+ ```ruby
108
+ client.get_authorized_pages
109
+ # => {"current_page"=>1, "per_page"=>30, "total_entries"=>1, "collection"=>[{"id"=>6, "authorization_id"=>5, "name"=>"1bertlol", "service_id"=>"81534513", "type"=>"AuthorizedPages::Twitter", "info"=>{...}]}
110
+ ```
111
+
112
+ Now that we have an `AuthorizedPage` id, we are ready to create our first post!
113
+
114
+ ```ruby
115
+ client.create_post(body: {
116
+ post: {
117
+ "body": "My first post using the OnePost Ruby Gem https://github.com/akdarrah/onepost-gem",
118
+ "authorized_page_ids": [6],
119
+ "image_url": "https://img1.looper.com/img/gallery/the-real-reason-futurama-was-canceled/intro-1567514049.jpg"
120
+ }
121
+ })
122
+ # => {"id"=>7, "body"=>"My first post using the OnePost Ruby Gem https://github.com/akdarrah/onepost-gem", "created_at"=>"2021-02-19T10:49:37.633-05:00", "updated_at"=>"2021-02-19T10:49:37.656-05:00", "state"=>"draft", "publish_at"=>nil, "authorized_page_ids"=>[6], "image_url"=>"https://onepost-aws-assets.s3.amazonaws.com/g5smw81h3oudjpri1sj66dp...", "social_posts"=>[{"id"=>7, "post_id"=>7, "created_at"=>"2021-02-19T10:49:37.642-05:00", "updated_at"=>"2021-02-19T10:49:37.642-05:00", "type"=>"SocialPosts::Twitter", "state"=>"unsent", "authorized_page_id"=>6}]}
123
+ ```
124
+
125
+ Posts are created in a "draft" state and can be updated until it is published. Notice that a `SocialPost` record is automatically created for the AuthorizedPage you provided. As you alter the `authorized_page_ids`, these `SocialPost` records will be automatically created or destroyed for each page you are posting to.
126
+
127
+ Additionally, you can use the `publish_at` field to specify a time for OnePost to automatically publish the post. Since we didn't schedule this post to be published automatically, let's publish it using the API:
128
+
129
+ ```ruby
130
+ client.publish_post(7)
131
+ # => {"id"=>7, "body"=>"My first post using the OnePost Ruby Gem https://github.com/akdarrah/onepost-gem", "created_at"=>"2021-02-19T10:49:37.633-05:00", "updated_at"=>"2021-02-19T10:56:23.977-05:00", "state"=>"publishing", "publish_at"=>nil, "authorized_page_ids"=>[6], "image_url"=>"https://onepost-aws-assets.s3.amazonaws.com/g5smw81h3oud...", "social_posts"=>[{"id"=>7, "post_id"=>7, "created_at"=>"2021-02-19T10:49:37.642-05:00", "updated_at"=>"2021-02-19T10:49:37.642-05:00", "type"=>"SocialPosts::Twitter", "state"=>"unsent", "authorized_page_id"=>6}]}
132
+ ```
133
+
134
+ A few moments later, and you will see your published Tweet!
135
+
136
+ <img width="668" alt="published-tweet" src="https://user-images.githubusercontent.com/69064/108529332-5cac5b80-72a2-11eb-8166-9565d2d35f72.png">
137
+
138
+ Once published, OnePost will track the performance of your `SocialPost` over time. Simply get the SocialPost record to see the most up-to-date data available.
139
+
140
+ ```ruby
141
+ client.get_social_post(7)
142
+ # => {"id"=>7, "post_id"=>7, "created_at"=>"2021-02-19T10:49:37.642-05:00", "updated_at"=>"2021-02-19T10:56:24.019-05:00", "type"=>"SocialPosts::Twitter", "state"=>"sent", "authorized_page_id"=>6, "service_data"=>{"id"=>1362793165137313792, "geo"=>nil, "lang"=>"en", "text"=>"My first post using the OnePost Ruby Gem https://t.co/K0nlM9qLWx https://t.co/owC53ZJuDO", "user"=>{"id"=>81534513, "url"=>"https://t.co/23KYmkQZJB", "lang"=>nil, "name"=>"Adam Darrah", "id_str"=>"81534513", "entities"=>{"url"=>{"urls"=>[{"url"=>"https://t.co/23KYmkQZJB", "indices"=>[0, 23], "display_url"=>"dropkiq.com", "expanded_url"=>"https://www.dropkiq.com/"}]}, "description"=>{"urls"=>[]}}, "location"=>"Keystone, Indiana", "verified"=>false, "following"=>false, "protected"=>false, "time_zone"=>nil, "created_at"=>"Sun Oct 11 06:36:24 +0000 2009", "utc_offset"=>nil, "description"=>"I like futurama, websites, and code. Founder of Dropkiq 🥊", "geo_enabled"=>false, "screen_name"=>"1bertlol", "listed_count"=>4, "friends_count"=>266, "is_translator"=>false, "notifications"=>false, "statuses_count"=>1693, "default_profile"=>false, "followers_count"=>175, "translator_type"=>"none", "favourites_count"=>771, "profile_image_url"=>"http://pbs.twimg.com/profile_images/1266163001532518400/K41HOU0Y_normal.jpg", "profile_link_color"=>"0084B4", "profile_text_color"=>"333333", "follow_request_sent"=>false, "contributors_enabled"=>false, "has_extended_profile"=>false, "default_profile_image"=>false, "is_translation_enabled"=>false, "profile_background_tile"=>true, "profile_image_url_https"=>"https://pbs.twimg.com/profile_images/1266163001532518400/K41HOU0Y_normal.jpg", "profile_background_color"=>"C0DEED", "profile_sidebar_fill_color"=>"DDEEF6", "profile_background_image_url"=>"http://abs.twimg.com/images/themes/theme18/bg.gif", "profile_sidebar_border_color"=>"000000", "profile_use_background_image"=>true, "profile_background_image_url_https"=>"https://abs.twimg.com/images/themes/theme18/bg.gif"}, "place"=>nil, "id_str"=>"1362793165137313792", "source"=>"<a href=\"https://www.getonepost.com/\" rel=\"nofollow\">GetOnepost</a>", "entities"=>{"urls"=>[{"url"=>"https://t.co/K0nlM9qLWx", "indices"=>[41, 64], "display_url"=>"github.com/akdarrah/onepo…", "expanded_url"=>"https://github.com/akdarrah/onepost-gem"}], "media"=>[{"id"=>1362793163627384833, "url"=>"https://t.co/owC53ZJuDO", "type"=>"photo", "sizes"=>{"large"=>{"h"=>438, "w"=>780, "resize"=>"fit"}, "small"=>{"h"=>382, "w"=>680, "resize"=>"fit"}, "thumb"=>{"h"=>150, "w"=>150, "resize"=>"crop"}, "medium"=>{"h"=>438, "w"=>780, "resize"=>"fit"}}, "id_str"=>"1362793163627384833", "indices"=>[65, 88], "media_url"=>"http://pbs.twimg.com/media/EumdKXRXUAETYvz.jpg", "display_url"=>"pic.twitter.com/owC53ZJuDO", "expanded_url"=>"https://twitter.com/1bertlol/status/1362793165137313792/photo/1", "media_url_https"=>"https://pbs.twimg.com/media/EumdKXRXUAETYvz.jpg"}], "symbols"=>[], "hashtags"=>[], "user_mentions"=>[]}, "favorited"=>false, "retweeted"=>false, "truncated"=>false, "created_at"=>"Fri Feb 19 15:56:24 +0000 2021", "coordinates"=>nil, "contributors"=>nil, "retweet_count"=>0, "favorite_count"=>1, "is_quote_status"=>false, "extended_entities"=>{"media"=>[{"id"=>1362793163627384833, "url"=>"https://t.co/owC53ZJuDO", "type"=>"photo", "sizes"=>{"large"=>{"h"=>438, "w"=>780, "resize"=>"fit"}, "small"=>{"h"=>382, "w"=>680, "resize"=>"fit"}, "thumb"=>{"h"=>150, "w"=>150, "resize"=>"crop"}, "medium"=>{"h"=>438, "w"=>780, "resize"=>"fit"}}, "id_str"=>"1362793163627384833", "indices"=>[65, 88], "media_url"=>"http://pbs.twimg.com/media/EumdKXRXUAETYvz.jpg", "display_url"=>"pic.twitter.com/owC53ZJuDO", "expanded_url"=>"https://twitter.com/1bertlol/status/1362793165137313792/photo/1", "media_url_https"=>"https://pbs.twimg.com/media/EumdKXRXUAETYvz.jpg"}]}, "possibly_sensitive"=>false, "in_reply_to_user_id"=>nil, "in_reply_to_status_id"=>nil, "in_reply_to_screen_name"=>nil, "in_reply_to_user_id_str"=>nil, "in_reply_to_status_id_str"=>nil, "possibly_sensitive_appealable"=>false}, "service_data_updated_at"=>"2021-02-19T11:00:18.465-05:00"}
143
+ ```
144
+
145
+ ### Webhooks
146
+
147
+ You may have noticed while reading over the documentation that several key records are created for you automatically, such as `AuthorizedPage` records. This can be problematic in the event that you go to look for your records and they haven't been created yet.
148
+
149
+ Luckily, OnePost solves this need by providing a Webhook system. This system allows you to specify an HTTP endpoint in your application for OnePost to send `POST` requests to. When key events happen in the OnePost system, the event data will be sent to your endpoint where your application can do the necessary processing without polling for updates.
150
+
151
+ To test this system, we can get a new test endpoint quickly using [Webhook.site](https://webhook.site/). Navigating to this page will give you a "unique URL" that you can use as your test endpoint. Let's use the Gem to register this endpoint:
152
+
153
+ ```ruby
154
+ client.create_webhook(body:{
155
+ webhook: {
156
+ endpoint_url: "https://webhook.site/3f338283-10b0-492a-a97e-d891d538ab79"
157
+ }
158
+ })
159
+ # => {"id"=>4, "endpoint_url"=>"https://webhook.site/3f338283-10b0-492a-a97e-d891d538ab79", "created_at"=>"2021-02-19T11:45:15.652-05:00", "updated_at"=>"2021-02-19T11:45:15.652-05:00"}
160
+ ```
161
+
162
+ Now that we have our endpoint, let's create a test event to make sure it's working.
163
+
164
+ ```ruby
165
+ client.create_test_event
166
+ # => {"id"=>16, "name"=>"events.test", "data"=>{"object"=>{"ping"=>"pong"}}, "created_at"=>"2021-02-19T11:48:26.546-05:00", "updated_at"=>"2021-02-19T11:48:26.546-05:00", "webhook_attempts"=>[{"id"=>11, "state"=>"new", "created_at"=>"2021-02-19T11:48:26.561-05:00", "updated_at"=>"2021-02-19T11:48:26.561-05:00", "number_of_attempted_requests"=>0, "webhook"=>{"id"=>4, "endpoint_url"=>"https://webhook.site/3f338283-10b0-492a-a97e-d891d538ab79", "created_at"=>"2021-02-19T11:45:15.652-05:00", "updated_at"=>"2021-02-19T11:45:15.652-05:00"}}]}
167
+ ```
168
+
169
+ You should now see your test event appear in Webhook.site.
170
+
171
+ <img width="1275" alt="success" src="https://user-images.githubusercontent.com/69064/108535592-7dc47a80-72a9-11eb-8d21-17885442570e.png">
172
+
173
+ OnePost will continue to attempt to send the request to notify your application of events using an exponential backoff algorithm in the case we receive a non-200 response.
174
+
175
+ At the time of writing, OnePost has just a handful of events (check back later for more):
176
+
177
+ Name | Description
178
+ ------------ | -------------
179
+ events.test | Created manually by the API user to test Webhook endpoints are configured correctly
180
+ authorized_page.created | Created automatically when a new AuthorizedPage is created (after an Authorization is created)
181
+ social_post.updated | Created automatically for each SocialPost after a Post has been published. Listen for this event if you want to track performance (such as number of likes, retweets, etc).
182
+
183
+ ### Reference
184
+
185
+ For full documentation, please use the [OnePost RapidAPI Page](https://rapidapi.com/onepost/api/onepost1) as the ultimate source of truth. Additionally, the tests included in this gem are a great way to see what is possible using the Gem:
186
+
187
+ Resource | Test File
188
+ ------------ | -------------
189
+ Providers | [Provider Tests](https://github.com/akdarrah/onepost-gem/blob/master/test/onepost_provider_test.rb)
190
+ Authorizations | [Authorization Tests](https://github.com/akdarrah/onepost-gem/blob/master/test/onepost_authorization_test.rb)
191
+ Authorized Pages | [Authorized Page Tests](https://github.com/akdarrah/onepost-gem/blob/master/test/onepost_authorized_page_test.rb)
192
+ Posts | [Post Tests](https://github.com/akdarrah/onepost-gem/blob/master/test/onepost_post_test.rb)
193
+ Social Posts | [Social Post Tests](https://github.com/akdarrah/onepost-gem/blob/master/test/onepost_social_post_test.rb)
194
+ Webhooks | [Webhook Tests](https://github.com/akdarrah/onepost-gem/blob/master/test/onepost_webhook_test.rb)
195
+ Events | [Event Tests](https://github.com/akdarrah/onepost-gem/blob/master/test/onepost_event_test.rb)
196
+
197
+ ## Development
198
+
199
+ 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.
200
+
201
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
202
+
203
+ ## Contributing
204
+
205
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/onepost. 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/[USERNAME]/onepost/blob/master/CODE_OF_CONDUCT.md).
206
+
207
+
208
+ ## License
209
+
210
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
211
+
212
+ ## Code of Conduct
213
+
214
+ Everyone interacting in the Onepost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/onepost/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "onepost"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/onepost.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "active_support"
2
+ require "httparty"
3
+
4
+ require "onepost/version"
5
+
6
+ require 'onepost/provider'
7
+ require 'onepost/authorization'
8
+ require 'onepost/authorized_page'
9
+ require 'onepost/post'
10
+ require 'onepost/social_post'
11
+ require 'onepost/webhook'
12
+ require 'onepost/event'
13
+
14
+ require "onepost/client"
@@ -0,0 +1,71 @@
1
+ module Onepost
2
+ module Authorization
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def get_authorizations(options={})
7
+ url = construct_url("api/v1/authorizations")
8
+ query = default_query.merge(options.fetch(:query, {}))
9
+ body = default_body.merge(options.fetch(:body, {}))
10
+ headers = default_headers.merge(options.fetch(:headers, {}))
11
+
12
+ response = HTTParty.get(url, {
13
+ query: query,
14
+ body: body.to_json,
15
+ headers: headers,
16
+ timeout: Onepost::Client::TIMEOUT
17
+ })
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def get_authorization(id, options={})
23
+ url = construct_url("api/v1/authorizations/#{id}")
24
+ query = default_query.merge(options.fetch(:query, {}))
25
+ body = default_body.merge(options.fetch(:body, {}))
26
+ headers = default_headers.merge(options.fetch(:headers, {}))
27
+
28
+ response = HTTParty.get(url, {
29
+ query: query,
30
+ body: body.to_json,
31
+ headers: headers,
32
+ timeout: Onepost::Client::TIMEOUT
33
+ })
34
+
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+ def create_authorization(options={})
39
+ url = construct_url("api/v1/authorizations")
40
+ query = default_query.merge(options.fetch(:query, {}))
41
+ body = default_body.merge(options.fetch(:body, {}))
42
+ headers = default_headers.merge(options.fetch(:headers, {}))
43
+
44
+ response = HTTParty.post(url, {
45
+ query: query,
46
+ body: body.to_json,
47
+ headers: headers,
48
+ timeout: Onepost::Client::TIMEOUT
49
+ })
50
+
51
+ JSON.parse(response.body)
52
+ end
53
+
54
+ def delete_authorization(id, options={})
55
+ url = construct_url("api/v1/authorizations/#{id}")
56
+ query = default_query.merge(options.fetch(:query, {}))
57
+ body = default_body.merge(options.fetch(:body, {}))
58
+ headers = default_headers.merge(options.fetch(:headers, {}))
59
+
60
+ response = HTTParty.delete(url, {
61
+ query: query,
62
+ body: body.to_json,
63
+ headers: headers,
64
+ timeout: Onepost::Client::TIMEOUT
65
+ })
66
+
67
+ JSON.parse(response.body)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,39 @@
1
+ module Onepost
2
+ module AuthorizedPage
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def get_authorized_pages(options={})
7
+ url = construct_url("api/v1/authorized_pages")
8
+ query = default_query.merge(options.fetch(:query, {}))
9
+ body = default_body.merge(options.fetch(:body, {}))
10
+ headers = default_headers.merge(options.fetch(:headers, {}))
11
+
12
+ response = HTTParty.get(url, {
13
+ query: query,
14
+ body: body.to_json,
15
+ headers: headers,
16
+ timeout: Onepost::Client::TIMEOUT
17
+ })
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def get_authorized_page(id, options={})
23
+ url = construct_url("api/v1/authorized_pages/#{id}")
24
+ query = default_query.merge(options.fetch(:query, {}))
25
+ body = default_body.merge(options.fetch(:body, {}))
26
+ headers = default_headers.merge(options.fetch(:headers, {}))
27
+
28
+ response = HTTParty.get(url, {
29
+ query: query,
30
+ body: body.to_json,
31
+ headers: headers,
32
+ timeout: Onepost::Client::TIMEOUT
33
+ })
34
+
35
+ JSON.parse(response.body)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,45 @@
1
+ module Onepost
2
+ class Client
3
+ include Onepost::Provider
4
+ include Onepost::Authorization
5
+ include Onepost::AuthorizedPage
6
+ include Onepost::Post
7
+ include Onepost::SocialPost
8
+ include Onepost::Webhook
9
+ include Onepost::Event
10
+
11
+ RAPID_API_HOST = "onepost1.p.rapidapi.com"
12
+ TIMEOUT = 180
13
+
14
+ attr_accessor :rapid_api_key, :secret_key
15
+
16
+ def initialize(data={})
17
+ self.rapid_api_key = data.fetch(:rapid_api_key)
18
+ self.secret_key = data.fetch(:secret_key)
19
+ end
20
+
21
+ private
22
+
23
+ def default_query
24
+ {
25
+ "secret_key" => secret_key
26
+ }
27
+ end
28
+
29
+ def default_body
30
+ {}
31
+ end
32
+
33
+ def default_headers
34
+ {
35
+ "Content-Type" => "application/json",
36
+ "x-rapidapi-key" => rapid_api_key,
37
+ "x-rapidapi-host" => Onepost::Client::RAPID_API_HOST
38
+ }
39
+ end
40
+
41
+ def construct_url(endpoint)
42
+ "https://#{RAPID_API_HOST}/#{endpoint}"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,55 @@
1
+ module Onepost
2
+ module Event
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def get_events(options={})
7
+ url = construct_url("api/v1/events")
8
+ query = default_query.merge(options.fetch(:query, {}))
9
+ body = default_body.merge(options.fetch(:body, {}))
10
+ headers = default_headers.merge(options.fetch(:headers, {}))
11
+
12
+ response = HTTParty.get(url, {
13
+ query: query,
14
+ body: body.to_json,
15
+ headers: headers,
16
+ timeout: Onepost::Client::TIMEOUT
17
+ })
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def get_event(id, options={})
23
+ url = construct_url("api/v1/events/#{id}")
24
+ query = default_query.merge(options.fetch(:query, {}))
25
+ body = default_body.merge(options.fetch(:body, {}))
26
+ headers = default_headers.merge(options.fetch(:headers, {}))
27
+
28
+ response = HTTParty.get(url, {
29
+ query: query,
30
+ body: body.to_json,
31
+ headers: headers,
32
+ timeout: Onepost::Client::TIMEOUT
33
+ })
34
+
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+ def create_test_event(options={})
39
+ url = construct_url("api/v1/events/test")
40
+ query = default_query.merge(options.fetch(:query, {}))
41
+ body = default_body.merge(options.fetch(:body, {}))
42
+ headers = default_headers.merge(options.fetch(:headers, {}))
43
+
44
+ response = HTTParty.post(url, {
45
+ query: query,
46
+ body: body.to_json,
47
+ headers: headers,
48
+ timeout: Onepost::Client::TIMEOUT
49
+ })
50
+
51
+ JSON.parse(response.body)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,103 @@
1
+ module Onepost
2
+ module Post
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def get_posts(options={})
7
+ url = construct_url("api/v1/posts")
8
+ query = default_query.merge(options.fetch(:query, {}))
9
+ body = default_body.merge(options.fetch(:body, {}))
10
+ headers = default_headers.merge(options.fetch(:headers, {}))
11
+
12
+ response = HTTParty.get(url, {
13
+ query: query,
14
+ body: body.to_json,
15
+ headers: headers,
16
+ timeout: Onepost::Client::TIMEOUT
17
+ })
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def get_post(id, options={})
23
+ url = construct_url("api/v1/posts/#{id}")
24
+ query = default_query.merge(options.fetch(:query, {}))
25
+ body = default_body.merge(options.fetch(:body, {}))
26
+ headers = default_headers.merge(options.fetch(:headers, {}))
27
+
28
+ response = HTTParty.get(url, {
29
+ query: query,
30
+ body: body.to_json,
31
+ headers: headers,
32
+ timeout: Onepost::Client::TIMEOUT
33
+ })
34
+
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+ def create_post(options={})
39
+ url = construct_url("api/v1/posts")
40
+ query = default_query.merge(options.fetch(:query, {}))
41
+ body = default_body.merge(options.fetch(:body, {}))
42
+ headers = default_headers.merge(options.fetch(:headers, {}))
43
+
44
+ response = HTTParty.post(url, {
45
+ query: query,
46
+ body: body.to_json,
47
+ headers: headers,
48
+ timeout: Onepost::Client::TIMEOUT
49
+ })
50
+
51
+ JSON.parse(response.body)
52
+ end
53
+
54
+ def update_post(id, options={})
55
+ url = construct_url("api/v1/posts/#{id}")
56
+ query = default_query.merge(options.fetch(:query, {}))
57
+ body = default_body.merge(options.fetch(:body, {}))
58
+ headers = default_headers.merge(options.fetch(:headers, {}))
59
+
60
+ response = HTTParty.put(url, {
61
+ query: query,
62
+ body: body.to_json,
63
+ headers: headers,
64
+ timeout: Onepost::Client::TIMEOUT
65
+ })
66
+
67
+ JSON.parse(response.body)
68
+ end
69
+
70
+ def delete_post(id, options={})
71
+ url = construct_url("api/v1/posts/#{id}")
72
+ query = default_query.merge(options.fetch(:query, {}))
73
+ body = default_body.merge(options.fetch(:body, {}))
74
+ headers = default_headers.merge(options.fetch(:headers, {}))
75
+
76
+ response = HTTParty.delete(url, {
77
+ query: query,
78
+ body: body.to_json,
79
+ headers: headers,
80
+ timeout: Onepost::Client::TIMEOUT
81
+ })
82
+
83
+ JSON.parse(response.body)
84
+ end
85
+
86
+ def publish_post(id, options={})
87
+ url = construct_url("api/v1/posts/#{id}/publish")
88
+ query = default_query.merge(options.fetch(:query, {}))
89
+ body = default_body.merge(options.fetch(:body, {}))
90
+ headers = default_headers.merge(options.fetch(:headers, {}))
91
+
92
+ response = HTTParty.post(url, {
93
+ query: query,
94
+ body: body.to_json,
95
+ headers: headers,
96
+ timeout: Onepost::Client::TIMEOUT
97
+ })
98
+
99
+ JSON.parse(response.body)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,87 @@
1
+ module Onepost
2
+ module Provider
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def get_providers(options={})
7
+ url = construct_url("api/v1/providers")
8
+ query = default_query.merge(options.fetch(:query, {}))
9
+ body = default_body.merge(options.fetch(:body, {}))
10
+ headers = default_headers.merge(options.fetch(:headers, {}))
11
+
12
+ response = HTTParty.get(url, {
13
+ query: query,
14
+ body: body.to_json,
15
+ headers: headers,
16
+ timeout: Onepost::Client::TIMEOUT
17
+ })
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def get_provider(id, options={})
23
+ url = construct_url("api/v1/providers/#{id}")
24
+ query = default_query.merge(options.fetch(:query, {}))
25
+ body = default_body.merge(options.fetch(:body, {}))
26
+ headers = default_headers.merge(options.fetch(:headers, {}))
27
+
28
+ response = HTTParty.get(url, {
29
+ query: query,
30
+ body: body.to_json,
31
+ headers: headers,
32
+ timeout: Onepost::Client::TIMEOUT
33
+ })
34
+
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+ def create_provider(options={})
39
+ url = construct_url("api/v1/providers")
40
+ query = default_query.merge(options.fetch(:query, {}))
41
+ body = default_body.merge(options.fetch(:body, {}))
42
+ headers = default_headers.merge(options.fetch(:headers, {}))
43
+
44
+ response = HTTParty.post(url, {
45
+ query: query,
46
+ body: body.to_json,
47
+ headers: headers,
48
+ timeout: Onepost::Client::TIMEOUT
49
+ })
50
+
51
+ JSON.parse(response.body)
52
+ end
53
+
54
+ def update_provider(id, options={})
55
+ url = construct_url("api/v1/providers/#{id}")
56
+ query = default_query.merge(options.fetch(:query, {}))
57
+ body = default_body.merge(options.fetch(:body, {}))
58
+ headers = default_headers.merge(options.fetch(:headers, {}))
59
+
60
+ response = HTTParty.put(url, {
61
+ query: query,
62
+ body: body.to_json,
63
+ headers: headers,
64
+ timeout: Onepost::Client::TIMEOUT
65
+ })
66
+
67
+ JSON.parse(response.body)
68
+ end
69
+
70
+ def delete_provider(id, options={})
71
+ url = construct_url("api/v1/providers/#{id}")
72
+ query = default_query.merge(options.fetch(:query, {}))
73
+ body = default_body.merge(options.fetch(:body, {}))
74
+ headers = default_headers.merge(options.fetch(:headers, {}))
75
+
76
+ response = HTTParty.delete(url, {
77
+ query: query,
78
+ body: body.to_json,
79
+ headers: headers,
80
+ timeout: Onepost::Client::TIMEOUT
81
+ })
82
+
83
+ JSON.parse(response.body)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,39 @@
1
+ module Onepost
2
+ module SocialPost
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def get_social_posts(options={})
7
+ url = construct_url("api/v1/social_posts")
8
+ query = default_query.merge(options.fetch(:query, {}))
9
+ body = default_body.merge(options.fetch(:body, {}))
10
+ headers = default_headers.merge(options.fetch(:headers, {}))
11
+
12
+ response = HTTParty.get(url, {
13
+ query: query,
14
+ body: body.to_json,
15
+ headers: headers,
16
+ timeout: Onepost::Client::TIMEOUT
17
+ })
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def get_social_post(id, options={})
23
+ url = construct_url("api/v1/social_posts/#{id}")
24
+ query = default_query.merge(options.fetch(:query, {}))
25
+ body = default_body.merge(options.fetch(:body, {}))
26
+ headers = default_headers.merge(options.fetch(:headers, {}))
27
+
28
+ response = HTTParty.get(url, {
29
+ query: query,
30
+ body: body.to_json,
31
+ headers: headers,
32
+ timeout: Onepost::Client::TIMEOUT
33
+ })
34
+
35
+ JSON.parse(response.body)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Onepost
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,87 @@
1
+ module Onepost
2
+ module Webhook
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def get_webhooks(options={})
7
+ url = construct_url("api/v1/webhooks")
8
+ query = default_query.merge(options.fetch(:query, {}))
9
+ body = default_body.merge(options.fetch(:body, {}))
10
+ headers = default_headers.merge(options.fetch(:headers, {}))
11
+
12
+ response = HTTParty.get(url, {
13
+ query: query,
14
+ body: body.to_json,
15
+ headers: headers,
16
+ timeout: Onepost::Client::TIMEOUT
17
+ })
18
+
19
+ JSON.parse(response.body)
20
+ end
21
+
22
+ def get_webhook(id, options={})
23
+ url = construct_url("api/v1/webhooks/#{id}")
24
+ query = default_query.merge(options.fetch(:query, {}))
25
+ body = default_body.merge(options.fetch(:body, {}))
26
+ headers = default_headers.merge(options.fetch(:headers, {}))
27
+
28
+ response = HTTParty.get(url, {
29
+ query: query,
30
+ body: body.to_json,
31
+ headers: headers,
32
+ timeout: Onepost::Client::TIMEOUT
33
+ })
34
+
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+ def create_webhook(options={})
39
+ url = construct_url("api/v1/webhooks")
40
+ query = default_query.merge(options.fetch(:query, {}))
41
+ body = default_body.merge(options.fetch(:body, {}))
42
+ headers = default_headers.merge(options.fetch(:headers, {}))
43
+
44
+ response = HTTParty.post(url, {
45
+ query: query,
46
+ body: body.to_json,
47
+ headers: headers,
48
+ timeout: Onepost::Client::TIMEOUT
49
+ })
50
+
51
+ JSON.parse(response.body)
52
+ end
53
+
54
+ def update_webhook(id, options={})
55
+ url = construct_url("api/v1/webhooks/#{id}")
56
+ query = default_query.merge(options.fetch(:query, {}))
57
+ body = default_body.merge(options.fetch(:body, {}))
58
+ headers = default_headers.merge(options.fetch(:headers, {}))
59
+
60
+ response = HTTParty.put(url, {
61
+ query: query,
62
+ body: body.to_json,
63
+ headers: headers,
64
+ timeout: Onepost::Client::TIMEOUT
65
+ })
66
+
67
+ JSON.parse(response.body)
68
+ end
69
+
70
+ def delete_webhook(id, options={})
71
+ url = construct_url("api/v1/webhooks/#{id}")
72
+ query = default_query.merge(options.fetch(:query, {}))
73
+ body = default_body.merge(options.fetch(:body, {}))
74
+ headers = default_headers.merge(options.fetch(:headers, {}))
75
+
76
+ response = HTTParty.delete(url, {
77
+ query: query,
78
+ body: body.to_json,
79
+ headers: headers,
80
+ timeout: Onepost::Client::TIMEOUT
81
+ })
82
+
83
+ JSON.parse(response.body)
84
+ end
85
+ end
86
+ end
87
+ end
data/onepost.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ require_relative 'lib/onepost/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "onepost"
5
+ spec.version = Onepost::VERSION
6
+ spec.authors = ["Adam Darrah"]
7
+ spec.email = ["adam@getonepost.com"]
8
+
9
+ spec.summary = %q{A Ruby interface to the OnePost API.}
10
+ spec.homepage = "https://www.getonepost.com/"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/akdarrah/onepost-gem"
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "minitest-focus"
31
+ spec.add_development_dependency "mocha"
32
+ spec.add_development_dependency "webmock"
33
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onepost
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Darrah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-focus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - adam@getonepost.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/onepost.rb
87
+ - lib/onepost/authorization.rb
88
+ - lib/onepost/authorized_page.rb
89
+ - lib/onepost/client.rb
90
+ - lib/onepost/event.rb
91
+ - lib/onepost/post.rb
92
+ - lib/onepost/provider.rb
93
+ - lib/onepost/social_post.rb
94
+ - lib/onepost/version.rb
95
+ - lib/onepost/webhook.rb
96
+ - onepost.gemspec
97
+ homepage: https://www.getonepost.com/
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ homepage_uri: https://www.getonepost.com/
102
+ source_code_uri: https://github.com/akdarrah/onepost-gem
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 2.3.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.0.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: A Ruby interface to the OnePost API.
122
+ test_files: []