peach-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/Rakefile +12 -0
- data/lib/peach/app/request.rb +91 -0
- data/lib/peach/app/response.rb +79 -0
- data/lib/peach/app.rb +4 -0
- data/lib/peach/app_message.rb +26 -0
- data/lib/peach/client.rb +27 -0
- data/lib/peach/configuration.rb +19 -0
- data/lib/peach/message.rb +4 -0
- data/lib/peach/stream/request.rb +69 -0
- data/lib/peach/stream/response.rb +109 -0
- data/lib/peach/stream.rb +4 -0
- data/lib/peach/template_message.rb +26 -0
- data/lib/peach/version.rb +5 -0
- data/lib/peach-ruby.rb +22 -0
- data/sig/peach/version.rbs +4 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6bbf4a34a9d69b838e5a2a0e5562ad0f598ceae6521c5a0738d8966afdebba2
|
4
|
+
data.tar.gz: 5a789324350150dd3a0dfd1e9ad04655fbcd87701f365d4d51998ee40a5cb370
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49263d5ee3c1089f55ee635afcb843a7779db1c3d1ad024f902018474143b3ea1d68cf3caf8ae72f9db6455463432cae8729e330eb699e4e9f7da783c78c1eaa
|
7
|
+
data.tar.gz: 9732144b1e654ae41a4f886ae08841d5bb97a37ccd2dba69664258722340b6c45651278f57d79888630a844a5827dff6ac87b7a59b8b0829082677b5fffbfbd0
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
- rubocop-factory_bot
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
TargetRubyVersion: '2.7.4'
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: single_quotes
|
12
|
+
|
13
|
+
Style/StringLiteralsInInterpolation:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: double_quotes
|
16
|
+
|
17
|
+
Layout/LineLength:
|
18
|
+
Max: 120
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.4
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 trypeach-io
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# peach-ruby
|
2
|
+
|
3
|
+
Ruby library for Peach API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Configure the SDK with your API Token:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Peach.configure do |config|
|
23
|
+
config.api_token = '<YOUR API TOKEN>'
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
And then use it:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
contact = {
|
31
|
+
id: 1,
|
32
|
+
name: 'John Doe',
|
33
|
+
language: 'en',
|
34
|
+
last_name: 'Doe',
|
35
|
+
account_id: 1,
|
36
|
+
first_name: 'John',
|
37
|
+
country_code: '91',
|
38
|
+
phone_number: '+919988776655'
|
39
|
+
}
|
40
|
+
# you may pass in an OpenStruct as well, if needed
|
41
|
+
Peach::TemplateMessage.deliver('wat_1234abcd', { foo: 'bar' }, contact)
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
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).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/peach-ruby.
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Peach
|
6
|
+
module App
|
7
|
+
class Request # :nodoc:
|
8
|
+
attr_reader :current_screen, :params, :context, :contact
|
9
|
+
|
10
|
+
APP_EXECUTION_TYPES = {
|
11
|
+
init: 'app_execution.init',
|
12
|
+
in_progress: 'app_execution.in_progress'
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def initialize(raw_params)
|
16
|
+
params = parse_params raw_params
|
17
|
+
validate_params params
|
18
|
+
instantiate_instance_variables_from params
|
19
|
+
end
|
20
|
+
|
21
|
+
def init?
|
22
|
+
init_request? @type
|
23
|
+
end
|
24
|
+
|
25
|
+
def in_progress?
|
26
|
+
in_progress_request? @type
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_params(raw_params)
|
32
|
+
case raw_params
|
33
|
+
when String
|
34
|
+
hash = JSON.parse(raw_params, symbolize_names: true)
|
35
|
+
deep_symbolize_keys hash
|
36
|
+
when Hash
|
37
|
+
deep_symbolize_keys raw_params
|
38
|
+
else
|
39
|
+
raise ArgumentError, "Invalid params: #{raw_params}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate_params(params)
|
44
|
+
validate_type_field params
|
45
|
+
validate_screen_field params
|
46
|
+
validate_request_field params
|
47
|
+
end
|
48
|
+
|
49
|
+
def instantiate_instance_variables_from(params)
|
50
|
+
@type = params[:type]
|
51
|
+
@current_screen = params[:screen] if in_progress_request?(@type)
|
52
|
+
@params = params.dig(:request, :params) || {}
|
53
|
+
@context = params.dig(:request, :context) || {}
|
54
|
+
@contact = OpenStruct.new(params.dig(:request, :contact) || {})
|
55
|
+
end
|
56
|
+
|
57
|
+
def deep_symbolize_keys(hash)
|
58
|
+
hash.each_with_object({}) do |(key, value), memo|
|
59
|
+
memo[key.to_sym] = value.is_a?(Hash) ? deep_symbolize_keys(value) : value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate_type_field(params)
|
64
|
+
raise Peach::BadRequestError, 'Field `type` is blank' unless params[:type]
|
65
|
+
end
|
66
|
+
|
67
|
+
def validate_screen_field(params)
|
68
|
+
if !in_progress_request?(params[:type]) && params[:screen]
|
69
|
+
raise Peach::BadRequestError,
|
70
|
+
"Field `screen` is present for `type` '#{params[:type]}'"
|
71
|
+
end
|
72
|
+
return unless in_progress_request?(params[:type]) && !params[:screen]
|
73
|
+
|
74
|
+
raise Peach::BadRequestError,
|
75
|
+
"Field `screen` is blank for `type` 'app_execution.in_progress'"
|
76
|
+
end
|
77
|
+
|
78
|
+
def validate_request_field(params)
|
79
|
+
raise Peach::BadRequestError, 'Field `request` is blank' unless params[:request]
|
80
|
+
end
|
81
|
+
|
82
|
+
def init_request?(type)
|
83
|
+
type == APP_EXECUTION_TYPES[:init]
|
84
|
+
end
|
85
|
+
|
86
|
+
def in_progress_request?(type)
|
87
|
+
type == APP_EXECUTION_TYPES[:in_progress]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Peach
|
6
|
+
module App
|
7
|
+
class Response # :nodoc:
|
8
|
+
SUPPORTED_ACTIONS = %w[navigate send_prompt end].freeze
|
9
|
+
attr_accessor :action, :screen, :data, :context
|
10
|
+
|
11
|
+
def initialize(**args)
|
12
|
+
args = set_defaults_for args
|
13
|
+
validate_arguments args
|
14
|
+
instantiate_instance_variables_from args
|
15
|
+
end
|
16
|
+
|
17
|
+
def body
|
18
|
+
body = { action: @action,
|
19
|
+
screen: @screen,
|
20
|
+
data: @data,
|
21
|
+
context: @context }
|
22
|
+
validate_arguments body
|
23
|
+
body.delete(:screen) if @action == 'end'
|
24
|
+
JSON.generate body
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def set_defaults_for(args)
|
30
|
+
args[:action] ||= 'navigate'
|
31
|
+
args[:screen] ||= nil
|
32
|
+
args[:data] ||= {}
|
33
|
+
args[:context] ||= {}
|
34
|
+
args
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_arguments(args)
|
38
|
+
validate_action args
|
39
|
+
validate_screen args
|
40
|
+
validate_data args
|
41
|
+
validate_context args
|
42
|
+
end
|
43
|
+
|
44
|
+
def instantiate_instance_variables_from(args)
|
45
|
+
@action = args[:action]
|
46
|
+
@screen = args[:screen]
|
47
|
+
@data = args[:data]
|
48
|
+
@context = args[:context]
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate_action(args)
|
52
|
+
return if SUPPORTED_ACTIONS.include? args[:action]
|
53
|
+
|
54
|
+
raise Peach::BadResponseError,
|
55
|
+
"Field `action` '#{args[:action]}' is not supported"
|
56
|
+
end
|
57
|
+
|
58
|
+
def validate_screen(args)
|
59
|
+
if args[:action] == 'navigate' && !args[:screen]
|
60
|
+
raise Peach::BadResponseError, "Field `screen` is blank for `action` 'navigate'"
|
61
|
+
end
|
62
|
+
return unless args[:action] == 'end' && args[:screen]
|
63
|
+
|
64
|
+
raise Peach::BadResponseError, "Field `screen` is present for `action` 'end'"
|
65
|
+
end
|
66
|
+
|
67
|
+
def validate_data(args)
|
68
|
+
raise Peach::BadResponseError, 'Field `data` is not a Hash' unless args[:data].is_a? Hash
|
69
|
+
return unless args[:action] == 'end' && args[:data].any?
|
70
|
+
|
71
|
+
raise Peach::BadResponseError, "Field `data` is present for `action` 'end'"
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate_context(args)
|
75
|
+
raise Peach::BadResponseError, 'Field `context` is not a Hash' unless args[:context].is_a? Hash
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/peach/app.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require_relative 'client'
|
5
|
+
|
6
|
+
module Peach
|
7
|
+
class AppMessage # :nodoc:
|
8
|
+
include Peach::Client
|
9
|
+
|
10
|
+
def self.deliver(template_id, liquid_values, contact)
|
11
|
+
body = {
|
12
|
+
event_type: 'send_flow',
|
13
|
+
contact: contact.to_h,
|
14
|
+
flow: {
|
15
|
+
whats_app_template_id: template_id,
|
16
|
+
liquid_values: liquid_values
|
17
|
+
}
|
18
|
+
}
|
19
|
+
post(body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.endpoint
|
23
|
+
URI.join(Peach.configuration.base_url, 'api/v1/events').to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/peach/client.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Peach
|
7
|
+
module Client # :nodoc:
|
8
|
+
def self.included(klass)
|
9
|
+
klass.extend ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods # :nodoc:
|
13
|
+
private
|
14
|
+
|
15
|
+
def post(body)
|
16
|
+
uri = URI(endpoint)
|
17
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
http.use_ssl = true
|
19
|
+
request = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json',
|
20
|
+
'Authorization' => Peach.configuration.api_token })
|
21
|
+
request.body = body.to_json
|
22
|
+
response = http.request(request)
|
23
|
+
response.body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Peach
|
6
|
+
class Configuration # :nodoc:
|
7
|
+
attr_accessor :api_token
|
8
|
+
attr_reader :base_url
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@api_token = nil
|
12
|
+
@base_url = 'https://app.trypeach.io/'
|
13
|
+
end
|
14
|
+
|
15
|
+
def base_url=(url)
|
16
|
+
@base_url = URI.parse(url).to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peach
|
4
|
+
module Stream
|
5
|
+
class Request # :nodoc:
|
6
|
+
attr_reader :params, :context, :contact, :prompt
|
7
|
+
|
8
|
+
STREAM_TYPES = {
|
9
|
+
init: 'stream.init',
|
10
|
+
in_progress: 'stream.in_progress'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def initialize(raw_params)
|
14
|
+
params = parse_params raw_params
|
15
|
+
validate_params params
|
16
|
+
instantiate_instance_variables_from params
|
17
|
+
end
|
18
|
+
|
19
|
+
def init?
|
20
|
+
@type == STREAM_TYPES[:init]
|
21
|
+
end
|
22
|
+
|
23
|
+
def in_progress?
|
24
|
+
@type == STREAM_TYPES[:in_progress]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse_params(raw_params)
|
30
|
+
case raw_params
|
31
|
+
when String
|
32
|
+
hash = JSON.parse(raw_params, symbolize_names: true)
|
33
|
+
deep_symbolize_keys hash
|
34
|
+
when Hash
|
35
|
+
deep_symbolize_keys raw_params
|
36
|
+
else
|
37
|
+
raise ArgumentError, "Invalid params: #{raw_params}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_params(params)
|
42
|
+
validate_type_field params
|
43
|
+
validate_request_field params
|
44
|
+
end
|
45
|
+
|
46
|
+
def instantiate_instance_variables_from(params)
|
47
|
+
@type = params[:type]
|
48
|
+
@params = params.dig(:request, :params) || {}
|
49
|
+
@context = params.dig(:request, :context) || {}
|
50
|
+
@contact = OpenStruct.new(params.dig(:request, :contact) || {})
|
51
|
+
@prompt = params.dig(:request, :prompt)
|
52
|
+
end
|
53
|
+
|
54
|
+
def deep_symbolize_keys(hash)
|
55
|
+
hash.each_with_object({}) do |(key, value), memo|
|
56
|
+
memo[key.to_sym] = value.is_a?(Hash) ? deep_symbolize_keys(value) : value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_type_field(params)
|
61
|
+
raise Peach::BadRequestError, 'Field `type` is blank' unless params[:type]
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_request_field(params)
|
65
|
+
raise Peach::BadRequestError, 'Field `request` is blank' unless params[:request]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peach
|
4
|
+
module Stream
|
5
|
+
class Response # :nodoc:
|
6
|
+
attr_reader :changes
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@changes = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_action(action, *args)
|
13
|
+
raise Peach::BadResponseError, "Action '#{action}' is not supported" unless respond_to?(action, true)
|
14
|
+
|
15
|
+
change = { action: action }
|
16
|
+
change.merge! send(action, *args)
|
17
|
+
@changes << change
|
18
|
+
end
|
19
|
+
|
20
|
+
def body
|
21
|
+
body = { changes: changes }
|
22
|
+
JSON.generate(body)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def send_message(text, header_media: {})
|
28
|
+
message = { text: text }
|
29
|
+
message[:header_media] = header_media unless header_media.empty?
|
30
|
+
validate_message(message)
|
31
|
+
{ message: message }
|
32
|
+
end
|
33
|
+
|
34
|
+
def send_prompt(key, data: {}, options: [])
|
35
|
+
prompt = { key: key }
|
36
|
+
prompt[:data] = data unless data.empty?
|
37
|
+
prompt[:options] = options unless options.empty?
|
38
|
+
validate_prompt(prompt)
|
39
|
+
{ prompt: prompt }
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_context(data)
|
43
|
+
validate_context data
|
44
|
+
{ context: data }
|
45
|
+
end
|
46
|
+
|
47
|
+
def close_stream
|
48
|
+
{}
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate_message(message)
|
52
|
+
raise Peach::BadResponseError, 'Field `message` does not have a `text`' if (message[:text] || '').empty?
|
53
|
+
|
54
|
+
return unless message.key?(:header_media)
|
55
|
+
|
56
|
+
if !message[:header_media].is_a?(Hash)
|
57
|
+
raise Peach::BadResponseError,
|
58
|
+
'Field `message.header_media` is not a Hash'
|
59
|
+
else
|
60
|
+
raise Peach::BadResponseError, 'Field `message.header_media` does not have a `type`' if message.dig(
|
61
|
+
:header_media, :type
|
62
|
+
).nil?
|
63
|
+
|
64
|
+
type = message.dig(:header_media, :type)
|
65
|
+
if message.dig(:header_media, type,
|
66
|
+
:url).nil?
|
67
|
+
raise Peach::BadResponseError,
|
68
|
+
"Field `message.header_media` does not have a `#{type}.url`"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def validate_prompt(prompt)
|
74
|
+
raise Peach::BadResponseError, 'Field `prompt` does not have a `key`' if (prompt[:key] || '').empty?
|
75
|
+
|
76
|
+
if prompt.key?(:data) && !prompt[:data].is_a?(Hash)
|
77
|
+
raise Peach::BadResponseError,
|
78
|
+
'Field `prompt.data` is not a Hash'
|
79
|
+
end
|
80
|
+
|
81
|
+
return unless prompt.key?(:options)
|
82
|
+
|
83
|
+
if !prompt[:options].is_a?(Array)
|
84
|
+
raise Peach::BadResponseError,
|
85
|
+
'Field `prompt.options` is not an Array'
|
86
|
+
else
|
87
|
+
prompt[:options].each do |option|
|
88
|
+
unless option.is_a?(Hash)
|
89
|
+
raise Peach::BadResponseError,
|
90
|
+
"Field `prompt.options`'s item #{option} is not a Hash"
|
91
|
+
end
|
92
|
+
if (option[:title] || '').empty?
|
93
|
+
raise Peach::BadResponseError,
|
94
|
+
"Field `prompt.options`'s item #{option} does not have a `title`"
|
95
|
+
end
|
96
|
+
if (option[:value] || '').empty?
|
97
|
+
raise Peach::BadResponseError,
|
98
|
+
"Field `prompt.options`'s item #{option} does not have a `value`"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def validate_context(context)
|
105
|
+
raise Peach::BadResponseError, 'Field `context` is not a Hash' unless context.is_a?(Hash)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/peach/stream.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require_relative 'client'
|
5
|
+
|
6
|
+
module Peach
|
7
|
+
class TemplateMessage # :nodoc:
|
8
|
+
include Peach::Client
|
9
|
+
|
10
|
+
def self.deliver(template_id, liquid_values, contact)
|
11
|
+
body = {
|
12
|
+
event_type: 'send_template_message',
|
13
|
+
contact: contact.to_h,
|
14
|
+
template_message: {
|
15
|
+
whats_app_template_id: template_id,
|
16
|
+
liquid_values: liquid_values
|
17
|
+
}
|
18
|
+
}
|
19
|
+
post(body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.endpoint
|
23
|
+
URI.join(Peach.configuration.base_url, 'api/v1/events').to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/peach-ruby.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'peach/app'
|
4
|
+
require_relative 'peach/stream'
|
5
|
+
require_relative 'peach/message'
|
6
|
+
require_relative 'peach/configuration'
|
7
|
+
require_relative 'peach/version'
|
8
|
+
|
9
|
+
module Peach # :nodoc:
|
10
|
+
class BadRequestError < StandardError; end
|
11
|
+
class BadResponseError < StandardError; end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peach-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peach Developers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: debug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: factory_bot
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.21'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-factory_bot
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.25'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.25'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.6.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.6.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.29'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.29'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.22.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.22.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.23'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.23'
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- dev@trypeach.io
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".rspec"
|
161
|
+
- ".rubocop.yml"
|
162
|
+
- ".ruby-version"
|
163
|
+
- ".tool-versions"
|
164
|
+
- LICENSE
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- lib/peach-ruby.rb
|
168
|
+
- lib/peach/app.rb
|
169
|
+
- lib/peach/app/request.rb
|
170
|
+
- lib/peach/app/response.rb
|
171
|
+
- lib/peach/app_message.rb
|
172
|
+
- lib/peach/client.rb
|
173
|
+
- lib/peach/configuration.rb
|
174
|
+
- lib/peach/message.rb
|
175
|
+
- lib/peach/stream.rb
|
176
|
+
- lib/peach/stream/request.rb
|
177
|
+
- lib/peach/stream/response.rb
|
178
|
+
- lib/peach/template_message.rb
|
179
|
+
- lib/peach/version.rb
|
180
|
+
- sig/peach/version.rbs
|
181
|
+
homepage: https://github.com/trypeach-io/peach-ruby
|
182
|
+
licenses: []
|
183
|
+
metadata:
|
184
|
+
homepage_uri: https://github.com/trypeach-io/peach-ruby
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: 2.7.4
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
requirements: []
|
200
|
+
rubygems_version: 3.1.6
|
201
|
+
signing_key:
|
202
|
+
specification_version: 4
|
203
|
+
summary: Ruby library for Peach API
|
204
|
+
test_files: []
|