huginn_mastodon_publish_agent 0.1
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: c475df82b48cabc746a3e19aac8494f2f811f41e26c22e8bdf55c28fa24ea5c3
|
4
|
+
data.tar.gz: 1562b2eaaa9cb6559a6619e82faef68204359b43056966f27ac449f0f8815c34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78bff76a459732a26211ba3cb92b8c6462448d4376484d5b2772320b9cacac85d299201c18cfce784d3ed281e45b31e7db4eb71336da3601512e828e72841114
|
7
|
+
data.tar.gz: f27fc9a849f9d76073f6bd562e2474114538d2b32daa48b7ea956ebdb20921045374816e0d3ae3aed6d595cd9091da251faadb9a96727293d20af4a057c2f7f2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2022 Nicolas Germain
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Agents
|
2
|
+
class MastodonPublishAgent < Agent
|
3
|
+
include FormConfigurable
|
4
|
+
|
5
|
+
cannot_be_scheduled!
|
6
|
+
|
7
|
+
description do
|
8
|
+
<<-MD
|
9
|
+
The Mastodon Publish Agent publishes status from the events it receives.
|
10
|
+
|
11
|
+
To be able to use this Agent you need to authenticate with Mastodon in the [Applications](https://mastodon.social/settings/applications) section first.
|
12
|
+
|
13
|
+
You must also specify a `status` parameter, you can use [Liquid](https://github.com/huginn/huginn/wiki/Formatting-Events-using-Liquid) to format the status.
|
14
|
+
Additional parameters can be passed via `parameters`.
|
15
|
+
|
16
|
+
Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
|
17
|
+
|
18
|
+
If `output_mode` is set to `merge`, the emitted Event will be merged into the original contents of the received Event.
|
19
|
+
MD
|
20
|
+
end
|
21
|
+
|
22
|
+
event_description <<-MD
|
23
|
+
Events look like this:
|
24
|
+
|
25
|
+
{
|
26
|
+
"id": "XXXXXXXXXXXXXXXXXX",
|
27
|
+
"created_at": "2022-04-30T10:43:17.130Z",
|
28
|
+
"in_reply_to_id": null,
|
29
|
+
"in_reply_to_account_id": null,
|
30
|
+
"sensitive": false,
|
31
|
+
"spoiler_text": "",
|
32
|
+
"visibility": "public",
|
33
|
+
"language": "fr",
|
34
|
+
"uri": "https://mastodon.social/users/toto/statuses/XXXXXXXXXXXXXXXXXX",
|
35
|
+
"url": "https://mastodon.social/@toto/XXXXXXXXXXXXXXXXXX",
|
36
|
+
"replies_count": 0,
|
37
|
+
"reblogs_count": 0,
|
38
|
+
"favourites_count": 0,
|
39
|
+
"edited_at": null,
|
40
|
+
"favourited": false,
|
41
|
+
"reblogged": false,
|
42
|
+
"muted": false,
|
43
|
+
"bookmarked": false,
|
44
|
+
"pinned": false,
|
45
|
+
"content": "<p>test</p>",
|
46
|
+
"reblog": null,
|
47
|
+
"application": {
|
48
|
+
"name": "huginn",
|
49
|
+
"website": "https://toto.com"
|
50
|
+
},
|
51
|
+
"account": {
|
52
|
+
"id": "XXXXXXXXXXXXXXXXXX",
|
53
|
+
"username": "toto",
|
54
|
+
"acct": "toto",
|
55
|
+
"display_name": "toto",
|
56
|
+
"locked": false,
|
57
|
+
"bot": false,
|
58
|
+
"discoverable": false,
|
59
|
+
"group": false,
|
60
|
+
"created_at": "2022-04-29T00:00:00.000Z",
|
61
|
+
"note": "",
|
62
|
+
"url": "https://mastodon.social/@toto",
|
63
|
+
"avatar": "https://mastodon.social/avatars/original/missing.png",
|
64
|
+
"avatar_static": "https://mastodon.social/avatars/original/missing.png",
|
65
|
+
"header": "https://mastodon.social/headers/original/missing.png",
|
66
|
+
"header_static": "https://mastodon.social/headers/original/missing.png",
|
67
|
+
"followers_count": 0,
|
68
|
+
"following_count": 0,
|
69
|
+
"statuses_count": 1,
|
70
|
+
"last_status_at": "2022-04-30",
|
71
|
+
"emojis": [],
|
72
|
+
"fields": []
|
73
|
+
},
|
74
|
+
"media_attachments": [],
|
75
|
+
"mentions": [],
|
76
|
+
"tags": [],
|
77
|
+
"emojis": [],
|
78
|
+
"card": null,
|
79
|
+
"poll": null
|
80
|
+
}
|
81
|
+
MD
|
82
|
+
|
83
|
+
def default_options
|
84
|
+
{
|
85
|
+
'status' => '',
|
86
|
+
'access_token' => '',
|
87
|
+
'debug' => 'false',
|
88
|
+
'emit_events' => 'false',
|
89
|
+
'expected_receive_period_in_days' => '2',
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
form_configurable :access_token, type: :string
|
94
|
+
form_configurable :status, type: :string
|
95
|
+
form_configurable :debug, type: :boolean
|
96
|
+
form_configurable :emit_events, type: :boolean
|
97
|
+
form_configurable :expected_receive_period_in_days, type: :string
|
98
|
+
def validate_options
|
99
|
+
|
100
|
+
unless options['access_token'].present?
|
101
|
+
errors.add(:base, "access_token is a required field")
|
102
|
+
end
|
103
|
+
|
104
|
+
unless options['status'].present?
|
105
|
+
errors.add(:base, "status is a required field")
|
106
|
+
end
|
107
|
+
|
108
|
+
if options.has_key?('emit_events') && boolify(options['emit_events']).nil?
|
109
|
+
errors.add(:base, "if provided, emit_events must be true or false")
|
110
|
+
end
|
111
|
+
|
112
|
+
if options.has_key?('debug') && boolify(options['debug']).nil?
|
113
|
+
errors.add(:base, "if provided, debug must be true or false")
|
114
|
+
end
|
115
|
+
|
116
|
+
unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
|
117
|
+
errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def working?
|
122
|
+
event_created_within?(interpolated['expected_update_period_in_days']) && most_recent_event && most_recent_event.payload['success'] == true && !recent_error_logs?
|
123
|
+
end
|
124
|
+
|
125
|
+
def receive(incoming_events)
|
126
|
+
incoming_events.each do |event|
|
127
|
+
interpolate_with(event) do
|
128
|
+
log event
|
129
|
+
publish
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def check
|
135
|
+
publish
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def publish
|
141
|
+
|
142
|
+
uri = URI.parse("https://mastodon.social/api/v1/statuses")
|
143
|
+
request = Net::HTTP::Post.new(uri)
|
144
|
+
request.set_form_data(
|
145
|
+
"status" => "#{interpolated['status']}",
|
146
|
+
)
|
147
|
+
request["Authorization"] = "Bearer #{interpolated['access_token']}"
|
148
|
+
|
149
|
+
req_options = {
|
150
|
+
use_ssl: uri.scheme == "https",
|
151
|
+
}
|
152
|
+
|
153
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
154
|
+
http.request(request)
|
155
|
+
end
|
156
|
+
|
157
|
+
if interpolated['debug'] == 'true'
|
158
|
+
log "response.body"
|
159
|
+
log response.body
|
160
|
+
end
|
161
|
+
|
162
|
+
log "fetch status request status : #{response.code}"
|
163
|
+
if interpolated['emit_events'] == 'true'
|
164
|
+
create_event payload: response.body
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::MastodonPublishAgent do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::MastodonPublishAgent.new.default_options
|
7
|
+
@checker = Agents::MastodonPublishAgent.new(:name => "MastodonPublishAgent", :options => @valid_options)
|
8
|
+
@checker.user = users(:bob)
|
9
|
+
@checker.save!
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "add specs here"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_mastodon_publish_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Germain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: huginn_agent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Write a longer description or delete this line.
|
56
|
+
email:
|
57
|
+
- ngermain@hihouhou.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- lib/huginn_mastodon_publish_agent.rb
|
64
|
+
- lib/huginn_mastodon_publish_agent/mastodon_publish_agent.rb
|
65
|
+
- spec/mastodon_publish_agent_spec.rb
|
66
|
+
homepage: https://github.com/hihouhou/huginn_mastodon_publish_agent
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.1.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Write a short summary, because Rubygems requires one.
|
89
|
+
test_files:
|
90
|
+
- spec/mastodon_publish_agent_spec.rb
|