huginn_sinch_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 +7 -0
- data/LICENSE.txt +7 -0
- data/lib/huginn_sinch_agent/sinch_agent.rb +138 -0
- data/lib/huginn_sinch_agent.rb +4 -0
- data/spec/sinch_agent_spec.rb +13 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3568210ef131f8865d1aa9f28f5d762f591d18d110af85fa2eaec12108cfcac1
|
4
|
+
data.tar.gz: afdf856e7eb87be230430abf3b6722642cfff18143042b014d76e8f66d3e03a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4410654d1ba27713fac54ebc8830c6e39fb41a72d5761ba45ddf72796f27a38698062d4788ed6df678973e83ffcce4f7daee7df2285b07a522101637278f7a49
|
7
|
+
data.tar.gz: 8a876676cf9a82bcafc151f9572332c91b4cfae016beb549325d93786f5a9112546e87efc5d8e049b94edcf9e0de85d82597f9cb469d1f99c9b05c37f53d913f
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2021 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,138 @@
|
|
1
|
+
module Agents
|
2
|
+
class SinchAgent < Agent
|
3
|
+
include FormConfigurable
|
4
|
+
can_dry_run!
|
5
|
+
no_bulk_receive!
|
6
|
+
default_schedule "never"
|
7
|
+
|
8
|
+
description do
|
9
|
+
<<-MD
|
10
|
+
The Sinch Agent sents sms with Sinch API..
|
11
|
+
|
12
|
+
`debug` is used for verbose mode.
|
13
|
+
|
14
|
+
`from_number` is the number of the sender.
|
15
|
+
|
16
|
+
`to_number` is the number of the recipient.
|
17
|
+
|
18
|
+
`token` is the bearer token for using the Sinch API.
|
19
|
+
|
20
|
+
If `emit_events` is set to `true`, the server response will be emitted as an Event. No data processing
|
21
|
+
will be attempted by this Agent, so the Event's "body" value will always be raw text.
|
22
|
+
|
23
|
+
`body` is the payload (message).
|
24
|
+
|
25
|
+
`service_plan_id` is for the auth.
|
26
|
+
|
27
|
+
MD
|
28
|
+
end
|
29
|
+
|
30
|
+
event_description <<-MD
|
31
|
+
Events look like this:
|
32
|
+
|
33
|
+
{
|
34
|
+
}
|
35
|
+
MD
|
36
|
+
|
37
|
+
def default_options
|
38
|
+
{
|
39
|
+
'from_number' => '',
|
40
|
+
'to_number' => '',
|
41
|
+
'service_plan_id' => '',
|
42
|
+
'token' => '',
|
43
|
+
'body' => '',
|
44
|
+
'debug' => 'false',
|
45
|
+
'emit_events' => 'false',
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
form_configurable :debug, type: :boolean
|
50
|
+
form_configurable :emit_events, type: :boolean
|
51
|
+
form_configurable :from_number, type: :string
|
52
|
+
form_configurable :to_number, type: :string
|
53
|
+
form_configurable :service_plan_id, type: :string
|
54
|
+
form_configurable :token, type: :string
|
55
|
+
form_configurable :body, type: :string
|
56
|
+
def validate_options
|
57
|
+
unless options['token'].present?
|
58
|
+
errors.add(:base, "token is a required field")
|
59
|
+
end
|
60
|
+
|
61
|
+
unless options['from_number'].present?
|
62
|
+
errors.add(:base, "from_number is a required field")
|
63
|
+
end
|
64
|
+
|
65
|
+
unless options['to_number'].present?
|
66
|
+
errors.add(:base, "to_number is a required field")
|
67
|
+
end
|
68
|
+
|
69
|
+
unless options['service_plan_id'].present?
|
70
|
+
errors.add(:base, "service_plan_id is a required field")
|
71
|
+
end
|
72
|
+
|
73
|
+
unless options['body'].present?
|
74
|
+
errors.add(:base, "body is a required field")
|
75
|
+
end
|
76
|
+
|
77
|
+
if options.has_key?('emit_events') && boolify(options['emit_events']).nil?
|
78
|
+
errors.add(:base, "if provided, emit_events must be true or false")
|
79
|
+
end
|
80
|
+
|
81
|
+
if options.has_key?('debug') && boolify(options['debug']).nil?
|
82
|
+
errors.add(:base, "if provided, debug must be true or false")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def working?
|
87
|
+
!recent_error_logs?
|
88
|
+
end
|
89
|
+
|
90
|
+
def receive(incoming_events)
|
91
|
+
incoming_events.each do |event|
|
92
|
+
interpolate_with(event) do
|
93
|
+
log event
|
94
|
+
trigger_event
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def check
|
100
|
+
trigger_event
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def trigger_event
|
106
|
+
uri = URI.parse("https://us.sms.api.sinch.com/xms/v1/#{interpolated['service_plan_id']}/batches")
|
107
|
+
request = Net::HTTP::Post.new(uri)
|
108
|
+
request.content_type = "application/json"
|
109
|
+
request["Authorization"] = "Bearer #{interpolated['token']}"
|
110
|
+
request.body = JSON.dump({
|
111
|
+
"from" => "#{interpolated['from_number']}",
|
112
|
+
"to" => [
|
113
|
+
"#{interpolated['to_number']}"
|
114
|
+
],
|
115
|
+
"body" => "#{interpolated['body']}"
|
116
|
+
})
|
117
|
+
|
118
|
+
req_options = {
|
119
|
+
use_ssl: uri.scheme == "https",
|
120
|
+
}
|
121
|
+
|
122
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
123
|
+
http.request(request)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
log "request status : #{response.code}"
|
128
|
+
|
129
|
+
if interpolated['debug'] == 'true'
|
130
|
+
log "response body : #{response.body}"
|
131
|
+
end
|
132
|
+
|
133
|
+
if interpolated['emit_events'] == 'true'
|
134
|
+
create_event :payload => response.body
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::SinchAgent do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::SinchAgent.new.default_options
|
7
|
+
@checker = Agents::SinchAgent.new(:name => "SinchAgent", :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_sinch_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-23 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_sinch_agent.rb
|
64
|
+
- lib/huginn_sinch_agent/sinch_agent.rb
|
65
|
+
- spec/sinch_agent_spec.rb
|
66
|
+
homepage: https://github.com/hihouhou/huginn_sinch_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/sinch_agent_spec.rb
|