twilio_ruby_wrapper 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/twilio_ruby_wrapper/call.rb +55 -0
- data/lib/twilio_ruby_wrapper/call_condition.rb +77 -0
- data/lib/twilio_ruby_wrapper/queue.rb +1 -1
- data/lib/twilio_ruby_wrapper/{condition.rb → queue_condition.rb} +2 -2
- data/lib/twilio_ruby_wrapper/version.rb +1 -1
- data/lib/twilio_ruby_wrapper.rb +3 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e0bc866e19e937a0b77a7a986ff6ce8c26b0912
|
4
|
+
data.tar.gz: dbf3419849f64de81490dd047f9b2589e6de1d7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10ed80d3ec6f160597c2e8cfdeda9e4d2b0dde13c778d42b655d535ae07be9dde0106a106b1e5d255f4225635b3aca53abd26d547843e905be5e37c52d2a4a92
|
7
|
+
data.tar.gz: 77867963cd72df0e966c84f0bed2a6cf9ab646e0586863567c99a1de1b3215439de4e3b92a4990175b7a412a73964b41557546b03c4b845839cf4237354a4a25
|
data/README.md
CHANGED
@@ -29,6 +29,9 @@ queues.find_by(friendly_name: "Queue friendly name") # return <Twilio::REST::Que
|
|
29
29
|
queues.condition(:gt).where(date_updated: "2017-05-31 0:0:0") # [<Twilio::REST::Queue>] array object
|
30
30
|
# The following is an error.
|
31
31
|
# queues.condition(:lt).where(date_updated: "2017-05-31 0:0:0").condition(:gt).where(date_updated: "2017-05-31 23:59:59")
|
32
|
+
|
33
|
+
calls = TwilioRubyWrapper::Call.new(account_sid: "Twilio ACCOUNT SID", auth_token: "Twilio AUTH TOKEN")
|
34
|
+
calls.filter(:"start_time>" => "2017-05-32").condition(:eq).where(from: "PHONE NUMBER")
|
32
35
|
```
|
33
36
|
|
34
37
|
## Development
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module TwilioRubyWrapper
|
2
|
+
class Call
|
3
|
+
attr_accessor :page_number, :page_size, :calls
|
4
|
+
|
5
|
+
def initialize(account_sid:, auth_token:)
|
6
|
+
client = Twilio::REST::Client.new(account_sid, auth_token)
|
7
|
+
@calls = client.account.calls
|
8
|
+
@filter = {}
|
9
|
+
@page_number = 0
|
10
|
+
@page_size = 50
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_by(*args)
|
14
|
+
hash = args.first
|
15
|
+
|
16
|
+
if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
|
17
|
+
raise
|
18
|
+
end
|
19
|
+
|
20
|
+
condition = self.condition(:eq)
|
21
|
+
condition.find_by(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def filter(*args)
|
25
|
+
hash = args.first
|
26
|
+
@filter = hash
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def condition(value, filter: { page: @page_number, page_size: @page_size })
|
31
|
+
if !(Symbol === value)
|
32
|
+
raise
|
33
|
+
end
|
34
|
+
|
35
|
+
condition = nil
|
36
|
+
case value
|
37
|
+
when :eq
|
38
|
+
condition = -> (x) { -> (y) { y == x }}
|
39
|
+
when :lt
|
40
|
+
condition = -> (x) { -> (y) { y < x }}
|
41
|
+
when :lteq
|
42
|
+
condition = -> (x) { -> (y) { y <= x }}
|
43
|
+
when :gt
|
44
|
+
condition = -> (x) { -> (y) { y > x }}
|
45
|
+
when :gteq
|
46
|
+
condition = -> (x) { -> (y) { y >= x }}
|
47
|
+
else
|
48
|
+
raise
|
49
|
+
end
|
50
|
+
|
51
|
+
filter = @filter unless @filter.empty?
|
52
|
+
CallCondition.new(calls: @calls, condition: condition, filter: filter)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module TwilioRubyWrapper
|
2
|
+
class CallCondition
|
3
|
+
attr_accessor :page_number, :page_size, :calls
|
4
|
+
|
5
|
+
def initialize(calls:, condition:, filter: {})
|
6
|
+
@calls = calls
|
7
|
+
@condition = condition
|
8
|
+
@filter = filter
|
9
|
+
@page_number = 0
|
10
|
+
@page_size = 50
|
11
|
+
end
|
12
|
+
|
13
|
+
def where(*args)
|
14
|
+
hash = args.first
|
15
|
+
|
16
|
+
if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
|
17
|
+
raise
|
18
|
+
end
|
19
|
+
|
20
|
+
key = hash.keys.first
|
21
|
+
value = build_value(hash[key], key)
|
22
|
+
|
23
|
+
calls = []
|
24
|
+
params = {page: @page_number, page_size: @page_size}
|
25
|
+
params.merge!(@filter) unless @filter.empty?
|
26
|
+
queue_set = @calls.list(params)
|
27
|
+
until queue_set.empty? do
|
28
|
+
t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }
|
29
|
+
calls.concat(t) unless t.empty?
|
30
|
+
queue_set = queue_set.next_page
|
31
|
+
end
|
32
|
+
|
33
|
+
calls
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_by(*args)
|
37
|
+
hash = args.first
|
38
|
+
|
39
|
+
if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
|
40
|
+
raise
|
41
|
+
end
|
42
|
+
|
43
|
+
key = hash.keys.first
|
44
|
+
value = build_value(hash[key], key)
|
45
|
+
|
46
|
+
params = {page: @page_number, page_size: @page_size}
|
47
|
+
params.merge!(@filter) unless @filter.empty?
|
48
|
+
queue_set = @calls.list(params)
|
49
|
+
t = nil
|
50
|
+
until queue_set.empty? do
|
51
|
+
t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }.first
|
52
|
+
break unless t.nil?
|
53
|
+
queue_set = queue_set.next_page
|
54
|
+
end
|
55
|
+
|
56
|
+
t
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def build_value(target, key)
|
61
|
+
value = nil
|
62
|
+
case key
|
63
|
+
when :sid, :parent_call_sid, :account_sid, :to, :from, :phone_number_sid, :status, :price_unit, :direction, :answered_by, :forwarded_from, :to_formatted, :from_formatted, :caller_name
|
64
|
+
value = target
|
65
|
+
when :duration, :price
|
66
|
+
value = target.to_i
|
67
|
+
when :date_created, :date_updated, :start_time, :end_time
|
68
|
+
value = DateTime.parse(target)
|
69
|
+
else
|
70
|
+
raise
|
71
|
+
end
|
72
|
+
|
73
|
+
value
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
data/lib/twilio_ruby_wrapper.rb
CHANGED
@@ -2,6 +2,8 @@ require "twilio_ruby_wrapper/version"
|
|
2
2
|
require "twilio-ruby"
|
3
3
|
|
4
4
|
module TwilioRubyWrapper
|
5
|
+
require 'twilio_ruby_wrapper/call'
|
6
|
+
require 'twilio_ruby_wrapper/call_condition'
|
5
7
|
require 'twilio_ruby_wrapper/queue'
|
6
|
-
require 'twilio_ruby_wrapper/
|
8
|
+
require 'twilio_ruby_wrapper/queue_condition'
|
7
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twilio_ruby_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FUNABARA Masao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twilio-ruby
|
@@ -83,8 +83,10 @@ files:
|
|
83
83
|
- bin/console
|
84
84
|
- bin/setup
|
85
85
|
- lib/twilio_ruby_wrapper.rb
|
86
|
-
- lib/twilio_ruby_wrapper/
|
86
|
+
- lib/twilio_ruby_wrapper/call.rb
|
87
|
+
- lib/twilio_ruby_wrapper/call_condition.rb
|
87
88
|
- lib/twilio_ruby_wrapper/queue.rb
|
89
|
+
- lib/twilio_ruby_wrapper/queue_condition.rb
|
88
90
|
- lib/twilio_ruby_wrapper/version.rb
|
89
91
|
- twilio_ruby_wrapper.gemspec
|
90
92
|
homepage: https://github.com/masoo/twilio_ruby_wrapper
|