peach-ruby 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 557e13610afe3709ca022ada06e2bcf2ed02ad9b6da78023fd08c5a4d6fdf47a
4
- data.tar.gz: 5d5035d2b1015a81489b061a40597d6285d601c11e0774610ecb8b5efbe0f684
3
+ metadata.gz: 22044ce025121dc6f98a9b9847815caff80ef0f16089368616b048f02e145d37
4
+ data.tar.gz: ead484f3c4c9427e918fe819d5d128f0c900104b8dbfa1d6a12f03942b68715e
5
5
  SHA512:
6
- metadata.gz: c517fe6adc838a1996438b5026f0694316081c26811b7afd3316df50e4e22ef55437ad200c7d3df0efb30fc70a22778fb1b81011e44a412db09428275ad15a1a
7
- data.tar.gz: 8d205177f57f5776664d0923b297275aebfcec11769b971ab3294c470a2e523d6820903b086db0965ffa7384ff54defe24e71c89a33854032095a55919014328
6
+ metadata.gz: f2a7f243046a6c61cf7ef62f5ebe3d321f2b0491a3460620f3940592e99593624388e46b5513ff6297777085554030e9cedcdf61ec9720c655291fea2a07ab80
7
+ data.tar.gz: 5ba357f84e83d4d638fe3cadea472a08275b2b6d1eda30fc4b133a76dfa3edc181cfb3fb1995912c40891a3a37764650d165464ba71dc141d0e4fb7cbfa3ac08
@@ -3,11 +3,12 @@
3
3
  module Peach
4
4
  module Stream
5
5
  class Request # :nodoc:
6
- attr_reader :contact, :prompt, :params, :message, :context
6
+ attr_reader :contact, :params, :prompt, :message, :payload, :context
7
7
 
8
8
  STREAM_TYPES = {
9
9
  init: 'stream.init',
10
- in_progress: 'stream.in_progress'
10
+ in_progress: 'stream.in_progress',
11
+ event_received: 'stream.event_received'
11
12
  }.freeze
12
13
 
13
14
  def initialize(raw_params)
@@ -24,6 +25,10 @@ module Peach
24
25
  @type == STREAM_TYPES[:in_progress]
25
26
  end
26
27
 
28
+ def event_received?
29
+ @type == STREAM_TYPES[:event_received]
30
+ end
31
+
27
32
  private
28
33
 
29
34
  def parse_params(raw_params)
@@ -46,9 +51,10 @@ module Peach
46
51
  def instantiate_instance_variables_from(params)
47
52
  @type = params[:type]
48
53
  @contact = OpenStruct.new(params.dig(:request, :contact) || {})
49
- @prompt = params.dig(:request, :prompt)
50
54
  @params = params.dig(:request, :params) || {}
55
+ @prompt = params.dig(:request, :prompt)
51
56
  @message = OpenStruct.new(params.dig(:request, :message) || {})
57
+ @payload = params.dig(:request, :payload) || {}
52
58
  @context = params.dig(:request, :context) || {}
53
59
  end
54
60
 
@@ -95,8 +95,8 @@ module Peach
95
95
  def validate_prompt(prompt)
96
96
  validate_key(prompt)
97
97
  validate_data(prompt)
98
- validate_button(prompt) if prompt.key?(:button)
99
- validate_options(prompt) if prompt.key?(:options)
98
+ validate_button(prompt)
99
+ validate_options(prompt)
100
100
  end
101
101
 
102
102
  def validate_key(prompt)
@@ -110,11 +110,15 @@ module Peach
110
110
  end
111
111
 
112
112
  def validate_button(prompt)
113
+ return unless prompt.key?(:button)
114
+
113
115
  raise Peach::BadResponseError, 'Field `prompt.button` is not a String' unless prompt[:button].is_a?(String)
114
116
  raise Peach::BadResponseError, 'Field `prompt.button` is empty' if prompt[:button].empty?
115
117
  end
116
118
 
117
119
  def validate_options(prompt)
120
+ return unless prompt.key?(:options)
121
+
118
122
  raise Peach::BadResponseError, 'Field `prompt.options` is not an Array' unless prompt[:options].is_a?(Array)
119
123
 
120
124
  validate_each_option(prompt)
@@ -123,7 +127,7 @@ module Peach
123
127
  def validate_each_option(prompt)
124
128
  prompt[:options].each_with_index do |option, idx|
125
129
  validate_option_is_hash(option, idx)
126
- validate_option_title(option, idx)
130
+ # validate_option_title(option, idx)
127
131
  validate_option_value_or_values(prompt, option, idx)
128
132
  end
129
133
  end
@@ -144,7 +148,7 @@ module Peach
144
148
  if prompt.key?(:button)
145
149
  validate_option_values(option, idx)
146
150
  else
147
- validate_option_value(option, idx)
151
+ # validate_option_value(option, idx)
148
152
  end
149
153
  end
150
154
 
@@ -160,7 +164,7 @@ module Peach
160
164
  end
161
165
 
162
166
  validate_values_are_array(option, idx)
163
- validate_each_value(option, idx)
167
+ # validate_each_value(option, idx)
164
168
  end
165
169
 
166
170
  def validate_values_are_array(option, idx)
data/lib/peach/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peach
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peach-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peach Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
11
+ date: 2024-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debug