mock-bandwidth 1.0.0 → 1.1.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +14 -1
- data/lib/mock/bandwidth/decorators/messaging_v2/message_create.rb +12 -3
- data/lib/mock/bandwidth/util/configuration.rb +15 -0
- data/lib/mock/bandwidth/util/error_handler.rb +15 -0
- data/lib/mock/bandwidth/version.rb +1 -1
- data/lib/mock/bandwidth/webhook_client.rb +21 -0
- data/lib/mock/bandwidth/webhooks/base.rb +21 -0
- data/lib/mock/bandwidth/webhooks/messages.rb +50 -0
- data/lib/mock/bandwidth.rb +22 -1
- metadata +51 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 989459f85a1c15c28e62e5e384bf2e3916a820bc2199ca664a92de1f8eeaecd7
|
4
|
+
data.tar.gz: fca644ad717de699e1efc07378a2736f2006f8c310866534568b22f72657ce68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32cc04ecce4ed6a5bcffd2b3cd1de835dabb959312d0b972c70502f2305007b3750a7ec8a5041c367b2e4b9de1693f1b70cc7471a0b8127172becef64bd813d1
|
7
|
+
data.tar.gz: 3d01d3a8fcae079ce7da0cd74ec786a00087e39be68d8a257e70512088352102b353da28d0fdb52985728e097917db8f0049996e235116444fb88265947a1d4d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Mock::Bandwidth
|
2
|
+
[](https://badge.fury.io/rb/mock-bandwidth)
|
3
|
+

|
2
4
|
|
3
|
-
This is a SchoolStatus implementation to mock Bandwidth to perform requests to [bandwidth-oai](https://docs.stoplight.io/docs/prism/83dbbd75532cf-http-mocking)
|
5
|
+
This is a SchoolStatus implementation to mock Bandwidth-sdk to perform requests to [bandwidth-oai](https://docs.stoplight.io/docs/prism/83dbbd75532cf-http-mocking)
|
4
6
|
|
5
7
|
|
6
8
|
# Installation
|
@@ -13,6 +15,7 @@ gem install mock-bandwidth
|
|
13
15
|
|
14
16
|
## Requirements
|
15
17
|
- [Bandwidth-oai](https://docs.stoplight.io/docs/prism/83dbbd75532cf-http-mocking)
|
18
|
+
- [Bandwidth-sdk](https://github.com/Bandwidth/ruby-sdk)
|
16
19
|
|
17
20
|
## Defaults Prism
|
18
21
|
|
@@ -26,6 +29,12 @@ gem install mock-bandwidth
|
|
26
29
|
| ------------- | ------------- |
|
27
30
|
| :white_check_mark: | `Bandwidth::MessagesApi.new.create_message(account_id, body)` |
|
28
31
|
|
32
|
+
## Trigger resources updates
|
33
|
+
|
34
|
+
| Mock::Bandwidth::Webhooks | Support |
|
35
|
+
| ------------- | ------------- |
|
36
|
+
| `Webhooks::Messages` | :white_check_mark: |
|
37
|
+
|
29
38
|
|
30
39
|
## How to use
|
31
40
|
Initializer sample
|
@@ -39,6 +48,10 @@ Bandwidth.configure do |config| # Configure Basic Auth
|
|
39
48
|
connection.use Mock::Bandwidth::Middleware::Proxy
|
40
49
|
end
|
41
50
|
end
|
51
|
+
|
52
|
+
Mock::Bandwidth.configure do |config|
|
53
|
+
config.webhook_message_status_url = "http://my-server.com/webhooks/bandwidth/messages_updates"
|
54
|
+
end
|
42
55
|
```
|
43
56
|
|
44
57
|
Example
|
@@ -15,15 +15,24 @@ module Mock
|
|
15
15
|
body["text"] = data["text"] if body["text"]
|
16
16
|
body["applicationId"] = data["applicationId"] if body["applicationId"]
|
17
17
|
|
18
|
-
body["id"] = message_id if body["id"]
|
18
|
+
body["id"] = message_id(body) if body["id"]
|
19
19
|
|
20
20
|
body.to_json
|
21
21
|
end
|
22
22
|
|
23
|
-
def message_id
|
23
|
+
def message_id(body)
|
24
24
|
timestamp = (Time.now.to_f * 1000).to_i.to_s[0..12]
|
25
25
|
random_part = SecureRandom.alphanumeric(15).downcase
|
26
|
-
"#{timestamp}#{random_part}"
|
26
|
+
id = "#{timestamp}#{random_part}"
|
27
|
+
scheduler = Rufus::Scheduler.new
|
28
|
+
scheduler.in '2s' do
|
29
|
+
begin
|
30
|
+
Mock::Bandwidth::Webhooks::Messages.trigger(id, body)
|
31
|
+
rescue => e
|
32
|
+
puts e
|
33
|
+
end
|
34
|
+
end
|
35
|
+
id
|
27
36
|
end
|
28
37
|
end
|
29
38
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Bandwidth
|
5
|
+
module Util
|
6
|
+
class Configuration
|
7
|
+
attr_accessor :webhook_message_status_url
|
8
|
+
|
9
|
+
def webhook_message_status_url=(value)
|
10
|
+
@webhook_message_status_url = value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Bandwidth
|
5
|
+
class WebhookClient
|
6
|
+
attr_reader :url, :params, :headers
|
7
|
+
|
8
|
+
def initialize(url:, params: nil, headers: {})
|
9
|
+
@url = url
|
10
|
+
@params = params
|
11
|
+
@headers = headers
|
12
|
+
end
|
13
|
+
|
14
|
+
def post
|
15
|
+
arguments = { body: params, headers: headers }
|
16
|
+
|
17
|
+
::HTTParty.post(url, **arguments)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Bandwidth
|
5
|
+
module Webhooks
|
6
|
+
class RestError < StandardError
|
7
|
+
end
|
8
|
+
class Base
|
9
|
+
DELAY = [0.5, 0.8]
|
10
|
+
|
11
|
+
def self.webhook_client
|
12
|
+
Mock::Bandwidth::WebhookClient
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.headers
|
16
|
+
{ "Content-Type" => "application/json" }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
module Bandwidth
|
5
|
+
module Webhooks
|
6
|
+
class Messages < Base
|
7
|
+
def self.trigger(id, body)
|
8
|
+
# Wait simulation from twilio
|
9
|
+
sleep DELAY.sample
|
10
|
+
|
11
|
+
url = Mock::Bandwidth.webhook_message_status_url
|
12
|
+
|
13
|
+
params = {
|
14
|
+
_json: [
|
15
|
+
{
|
16
|
+
time: Time.current.rfc2822,
|
17
|
+
type: "message-delivered",
|
18
|
+
to: body["to"],
|
19
|
+
description: "Message delivered to carrier.",
|
20
|
+
message: {
|
21
|
+
id: id,
|
22
|
+
owner: body["from"],
|
23
|
+
applicationId: "12341234",
|
24
|
+
time: Time.current.rfc2822,
|
25
|
+
segmentCount: 1,
|
26
|
+
direction: "out",
|
27
|
+
to: [
|
28
|
+
body["to"]
|
29
|
+
],
|
30
|
+
from: body["from"],
|
31
|
+
text: body["text"],
|
32
|
+
tag: "",
|
33
|
+
},
|
34
|
+
}
|
35
|
+
],
|
36
|
+
}.to_json
|
37
|
+
|
38
|
+
response = webhook_client.new(url: url, params: params, headers: headers).post
|
39
|
+
|
40
|
+
case response.code.to_i
|
41
|
+
when 200..204
|
42
|
+
response
|
43
|
+
when 400..600
|
44
|
+
raise Webhooks::RestError, Mock::Twilio::ErrorHandler.new(response).raise
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/mock/bandwidth.rb
CHANGED
@@ -1,12 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "rufus-scheduler"
|
4
|
+
require "active_support"
|
5
|
+
require "active_support/core_ext/time"
|
6
|
+
require "httparty"
|
3
7
|
require_relative "bandwidth/version"
|
4
8
|
require_relative "bandwidth/middleware/proxy"
|
5
9
|
require_relative "bandwidth/response"
|
6
10
|
require_relative "bandwidth/decorator"
|
11
|
+
require_relative "bandwidth/webhook_client"
|
12
|
+
require_relative "bandwidth/webhooks/base"
|
13
|
+
require_relative "bandwidth/webhooks/messages"
|
14
|
+
require_relative "bandwidth/util/error_handler"
|
15
|
+
require_relative "bandwidth/util/configuration"
|
7
16
|
|
8
17
|
module Mock
|
9
18
|
module Bandwidth
|
10
|
-
|
19
|
+
extend SingleForwardable
|
20
|
+
|
21
|
+
def_delegators :configuration, :webhook_message_status_url
|
22
|
+
|
23
|
+
def self.configure(&block)
|
24
|
+
yield configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configuration
|
28
|
+
@configuration ||= Util::Configuration.new
|
29
|
+
end
|
30
|
+
|
31
|
+
private_class_method :configuration
|
11
32
|
end
|
12
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock-bandwidth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- SchoolStatus Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -44,6 +44,48 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '14.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rufus-scheduler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.9.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.9.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: activesupport
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '5.2'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.2'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: httparty
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.22.0
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.22.0
|
47
89
|
description: This repository contains Mock::Bandwidth for Bandwidth's API.
|
48
90
|
email:
|
49
91
|
- meemocol@gmail.com
|
@@ -61,7 +103,12 @@ files:
|
|
61
103
|
- lib/mock/bandwidth/middleware/proxy.rb
|
62
104
|
- lib/mock/bandwidth/response.rb
|
63
105
|
- lib/mock/bandwidth/schemas/messaging_v2.rb
|
106
|
+
- lib/mock/bandwidth/util/configuration.rb
|
107
|
+
- lib/mock/bandwidth/util/error_handler.rb
|
64
108
|
- lib/mock/bandwidth/version.rb
|
109
|
+
- lib/mock/bandwidth/webhook_client.rb
|
110
|
+
- lib/mock/bandwidth/webhooks/base.rb
|
111
|
+
- lib/mock/bandwidth/webhooks/messages.rb
|
65
112
|
- sig/mock/bandwidth.rbs
|
66
113
|
homepage: https://github.com/schoolstatus/mock-bandwidth
|
67
114
|
licenses:
|
@@ -85,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
132
|
- !ruby/object:Gem::Version
|
86
133
|
version: '0'
|
87
134
|
requirements: []
|
88
|
-
rubygems_version: 3.1.
|
135
|
+
rubygems_version: 3.1.6
|
89
136
|
signing_key:
|
90
137
|
specification_version: 4
|
91
138
|
summary: This repository contains Mock::Bandwidth and Webhooks for Bandwidth's API.
|