twilio_ruby_wrapper 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e0bc866e19e937a0b77a7a986ff6ce8c26b0912
4
- data.tar.gz: dbf3419849f64de81490dd047f9b2589e6de1d7f
3
+ metadata.gz: 924bffada1a1256c22c4945fac3d52c413bbc993
4
+ data.tar.gz: cf435476fa8f3046de7ccc2b54c37822c026ae9e
5
5
  SHA512:
6
- metadata.gz: 10ed80d3ec6f160597c2e8cfdeda9e4d2b0dde13c778d42b655d535ae07be9dde0106a106b1e5d255f4225635b3aca53abd26d547843e905be5e37c52d2a4a92
7
- data.tar.gz: 77867963cd72df0e966c84f0bed2a6cf9ab646e0586863567c99a1de1b3215439de4e3b92a4990175b7a412a73964b41557546b03c4b845839cf4237354a4a25
6
+ metadata.gz: eb25c23fec971709742d97fd5c429ae9acffcaad86c8fb4b04df43d902d720b9de34e34dabeffd6256d48092a09678c91de8e13e6e32492eaac2bb65b4f6f728
7
+ data.tar.gz: 04c7c9ff241abc11fdf5919105a8fd6d9e7b6497aee467799c386d59accfd707e454b7151f27e1a2a878959b9def919b0a2086a992c2c6f2e27b127e567e81e4
data/README.md CHANGED
@@ -23,15 +23,18 @@ Or install it yourself as:
23
23
  ## Usage
24
24
 
25
25
  ```ruby
26
- queues = TwilioRubyWrapper::Queue.new(account_sid: "Twilio ACCOUNT SID", auth_token: "Twilio AUTH TOKEN")
27
- queues.find_by(sid: "Queue SID") # return <Twilio::REST::Queue> object
28
- queues.find_by(friendly_name: "Queue friendly name") # return <Twilio::REST::Queue> object
29
- queues.condition(:gt).where(date_updated: "2017-05-31 0:0:0") # [<Twilio::REST::Queue>] array object
26
+ TwilioRubyWrapper::QueueCondition.set_twilio_params(account_sid: "Twilio ACCOUNT SID", auth_token: "Twilio AUTH TOKEN")
27
+ queue_condition = TwilioRubyWrapper::QueueCondition.new
28
+ queue = queue_condition.find_by(sid: "Queue SID") # return <TwilioRubyWrapper::Queue> object
29
+ queue = queue_condition.find_by(friendly_name: "Queue friendly name") # return <TwilioRubyWrapper::Queue> object
30
+ queues = queue_condition.condition(:gt).where(date_updated: "2017-05-31 0:0:0") # [<TwilioRubyWrapper::Queue>] array object
30
31
  # The following is an error.
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
+ # queue_condition.condition(:lt).where(date_updated: "2017-05-31 0:0:0").condition(:gt).where(date_updated: "2017-05-31 23:59:59")
32
33
 
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")
34
+ TwilioRubyWrapper::CallCondition.set_twilio_params(account_sid: Rails.application.secrets.twilio_account_sid, auth_token: Rails.application.secrets.twilio_auth_token)
35
+ call_condition = TwilioRubyWrapper::CallCondition.new
36
+ call = call_condition.find_by(from: "PHONE NUMBER")
37
+ calls = call_condition.filter(:"start_time>" => "2017-05-32").condition(:eq).where(from: "PHONE NUMBER")
35
38
  ```
36
39
 
37
40
  ## Development
@@ -1,55 +1,30 @@
1
1
  module TwilioRubyWrapper
2
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)
3
+ attr_reader :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, :duration, :price, :date_created, :date_updated, :start_time, :end_time
4
+ attr_reader :call_instance
5
+
6
+ def initialize(twilio_call_instance)
7
+ @call_instance = twilio_call_instance
8
+ @sid = @call_instance.sid
9
+ @parent_call_sid = @call_instance.parent_call_sid
10
+ @account_sid = @call_instance.account_sid
11
+ @to = @call_instance.to
12
+ @from = @call_instance.from
13
+ @phone_number_sid = @call_instance.phone_number_sid
14
+ @status = @call_instance.status
15
+ @price_unit = @call_instance.price_unit
16
+ @direction = @call_instance.direction
17
+ @answered_by = @call_instance.answered_by
18
+ @forwarded_from = @call_instance.forwarded_from
19
+ @to_formatted = @call_instance.to_formatted
20
+ @from_formatted = @call_instance.from_formatted
21
+ @caller_name = @call_instance.caller_name
22
+ @duration = @call_instance.duration
23
+ @price = @call_instance.price
24
+ @date_created = @call_instance.date_created
25
+ @date_updated = @call_instance.date_updated
26
+ @start_time = @call_instance.start_time
27
+ @end_time = @call_instance.end_time
53
28
  end
54
29
  end
55
30
  end
@@ -1,16 +1,24 @@
1
1
  module TwilioRubyWrapper
2
2
  class CallCondition
3
3
  attr_accessor :page_number, :page_size, :calls
4
+ @@account_sid = nil
5
+ @@auth_token = nil
4
6
 
5
- def initialize(calls:, condition:, filter: {})
6
- @calls = calls
7
+ def self.set_twilio_params(account_sid:, auth_token:)
8
+ @@account_sid = account_sid
9
+ @@auth_token = auth_token
10
+ true
11
+ end
12
+
13
+ def initialize(condition: nil, filter: {}, page_number: 0, page_size: 50)
7
14
  @condition = condition
8
15
  @filter = filter
9
- @page_number = 0
10
- @page_size = 50
16
+ @page_number = page_number
17
+ @page_size = page_size
11
18
  end
12
19
 
13
20
  def where(*args)
21
+ set_twilio_account()
14
22
  hash = args.first
15
23
 
16
24
  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
@@ -20,20 +28,22 @@ module TwilioRubyWrapper
20
28
  key = hash.keys.first
21
29
  value = build_value(hash[key], key)
22
30
 
23
- calls = []
24
31
  params = {page: @page_number, page_size: @page_size}
25
32
  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
33
+ twilio_calls = @twilio_call_list.list(params)
34
+ calls = []
35
+ until twilio_calls.empty? do
36
+ sub_calls = twilio_calls.select{|twilio_call| @condition[value][build_value(twilio_call.send(key), key)] }.map{|twilio_call| Call.new(twilio_call) }
37
+ calls.concat(sub_calls) unless sub_calls.empty?
38
+ twilio_calls = twilio_calls.next_page
31
39
  end
32
-
40
+
33
41
  calls
34
42
  end
35
43
 
36
44
  def find_by(*args)
45
+ set_twilio_account()
46
+ condition(:eq)
37
47
  hash = args.first
38
48
 
39
49
  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
@@ -45,15 +55,47 @@ module TwilioRubyWrapper
45
55
 
46
56
  params = {page: @page_number, page_size: @page_size}
47
57
  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
58
+ twilio_calls = @twilio_call_list.list(params)
59
+ call = nil
60
+ until twilio_calls.empty? do
61
+ call = twilio_calls.select {|twilio_call| @condition[value][build_value(twilio_call.send(key), key)] }.map{|twilio_call| Call.new(twilio_call) }.first
62
+ break call.nil?
63
+ twilio_calls = twilio_calls.next_page
64
+ end
65
+
66
+ call
67
+ end
68
+
69
+ def filter(*args)
70
+ hash = args.first
71
+ @filter = hash
72
+ self
73
+ end
74
+
75
+ def condition(value)
76
+ if !(Symbol === value)
77
+ raise
78
+ end
79
+
80
+ condition = nil
81
+ case value
82
+ when :eq
83
+ condition = -> (x) { -> (y) { y == x }}
84
+ when :lt
85
+ condition = -> (x) { -> (y) { y < x }}
86
+ when :lteq
87
+ condition = -> (x) { -> (y) { y <= x }}
88
+ when :gt
89
+ condition = -> (x) { -> (y) { y > x }}
90
+ when :gteq
91
+ condition = -> (x) { -> (y) { y >= x }}
92
+ else
93
+ raise
54
94
  end
55
-
56
- t
95
+
96
+ @condition = condition
97
+
98
+ self
57
99
  end
58
100
 
59
101
  private
@@ -73,5 +115,9 @@ module TwilioRubyWrapper
73
115
  value
74
116
  end
75
117
 
118
+ def set_twilio_account
119
+ @twilio_client = Twilio::REST::Client.new(@@account_sid, @@auth_token)
120
+ @twilio_call_list = @twilio_client.account.calls
121
+ end
76
122
  end
77
123
  end
@@ -1,47 +1,32 @@
1
1
  module TwilioRubyWrapper
2
2
  class Queue
3
- attr_accessor :page_number, :page_size, :queues
3
+ attr_reader :sid, :account_sid, :friendly_name, :uri, :current_size, :average_wait_time, :max_size, :date_created, :date_updated
4
+ attr_accessor :queue_instance
4
5
 
5
- def initialize(account_sid:, auth_token:)
6
- client = Twilio::REST::Client.new(account_sid, auth_token)
7
- @queues = client.account.queues
8
- @page_number = 0
9
- @page_size = 50
6
+ def self.set_twilio_params(account_sid:, auth_token:)
7
+ @@account_sid = account_sid
8
+ @@auth_token = auth_token
9
+ true
10
10
  end
11
11
 
12
- def find_by(*args)
13
- hash = args.first
14
-
15
- if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
16
- raise
17
- end
18
-
19
- condition = self.condition(:eq)
20
- condition.find_by(*args)
12
+ def initialize(twilio_queue_instance)
13
+ @twilio_client = Twilio::REST::Client.new(@@account_sid, @@auth_token)
14
+ @queue_instance = twilio_queue_instance
15
+ @sid = @queue_instance.sid
16
+ @account_sid = @queue_instance.account_sid
17
+ @friendly_name = @queue_instance.friendly_name
18
+ @uri = @queue_instance.uri
19
+ @current_size = @queue_instance.current_size
20
+ @average_wait_time = @queue_instance.average_wait_time
21
+ @max_size = @queue_instance.max_size
22
+ @date_created = @queue_instance.date_created
23
+ @date_updated = @queue_instance.date_updated
21
24
  end
22
25
 
23
- def condition(value)
24
- if !(Symbol === value)
25
- raise
26
+ def calls
27
+ @queue_instance.members.list().map do |member|
28
+ Call.new(@twilio_client.account.calls.get(member.call_sid))
26
29
  end
27
-
28
- condition = nil
29
- case value
30
- when :eq
31
- condition = -> (x) { -> (y) { y == x }}
32
- when :lt
33
- condition = -> (x) { -> (y) { y < x }}
34
- when :lteq
35
- condition = -> (x) { -> (y) { y <= x }}
36
- when :gt
37
- condition = -> (x) { -> (y) { y > x }}
38
- when :gteq
39
- condition = -> (x) { -> (y) { y >= x }}
40
- else
41
- raise
42
- end
43
-
44
- QueueCondition.new(queues: @queues, condition: condition)
45
30
  end
46
31
  end
47
32
  end
@@ -1,15 +1,23 @@
1
1
  module TwilioRubyWrapper
2
2
  class QueueCondition
3
3
  attr_accessor :page_number, :page_size, :queues
4
+ @@account_sid = nil
5
+ @@auth_token = nil
4
6
 
5
- def initialize(queues: , condition: )
7
+ def self.set_twilio_params(account_sid:, auth_token:)
8
+ @@account_sid = account_sid
9
+ @@auth_token = auth_token
10
+ true
11
+ end
12
+
13
+ def initialize(condition: nil, page_number: 0, page_size: 50)
6
14
  @condition = condition
7
- @page_number = 0
8
- @page_size = 50
9
- @queues = queues
15
+ @page_number = page_number
16
+ @page_size = page_size
10
17
  end
11
18
 
12
19
  def where(*args)
20
+ set_twilio_account()
13
21
  hash = args.first
14
22
 
15
23
  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
@@ -19,18 +27,21 @@ module TwilioRubyWrapper
19
27
  key = hash.keys.first
20
28
  value = build_value(hash[key], key)
21
29
 
30
+ params = {page: @page_number, page_size: @page_size}
31
+ twilio_queues = @twilio_queue_list.list(params)
22
32
  queues = []
23
- queue_set = @queues.list(page: @page_number, page_size: @page_size)
24
- until queue_set.empty? do
25
- t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }
26
- queues.concat(t) unless t.empty?
27
- queue_set = queue_set.next_page
33
+ until twilio_queues.empty? do
34
+ sub_queues = twilio_queues.select{|twilio_queue| @condition[value][build_value(twilio_queue.send(key), key)] }.map{|twilio_queue| Queue.new(twilio_queue) }
35
+ queues.concat(sub_queues) unless sub_queues.empty?
36
+ twilio_queues = twilio_queues.next_page
28
37
  end
29
-
38
+
30
39
  queues
31
40
  end
32
41
 
33
42
  def find_by(*args)
43
+ set_twilio_account()
44
+ condition(:eq)
34
45
  hash = args.first
35
46
 
36
47
  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
@@ -40,15 +51,42 @@ module TwilioRubyWrapper
40
51
  key = hash.keys.first
41
52
  value = build_value(hash[key], key)
42
53
 
43
- queue_set = @queues.list(page: @page_number, page_size: @page_size)
44
- t = nil
45
- until queue_set.empty? do
46
- t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }.first
47
- break unless t.nil?
48
- queue_set = queue_set.next_page
54
+ params = {page: @page_number, page_size: @page_size}
55
+ twilio_queues = @twilio_queue_list.list(params)
56
+ queue = nil
57
+ until twilio_queues.empty? do
58
+ queue = twilio_queues.select{|twilio_queue| @condition[value][build_value(twilio_queue.send(key), key)] }.map{|twilio_queue| Queue.new(twilio_queue) }.first
59
+ break queue.nil?
60
+ twilio_queues = twilio_queues.next_page
49
61
  end
50
-
51
- t
62
+
63
+ queue
64
+ end
65
+
66
+ def condition(value)
67
+ if !(Symbol === value)
68
+ raise
69
+ end
70
+
71
+ condition = nil
72
+ case value
73
+ when :eq
74
+ condition = -> (x) { -> (y) { y == x }}
75
+ when :lt
76
+ condition = -> (x) { -> (y) { y < x }}
77
+ when :lteq
78
+ condition = -> (x) { -> (y) { y <= x }}
79
+ when :gt
80
+ condition = -> (x) { -> (y) { y > x }}
81
+ when :gteq
82
+ condition = -> (x) { -> (y) { y >= x }}
83
+ else
84
+ raise
85
+ end
86
+
87
+ @condition = condition
88
+
89
+ self
52
90
  end
53
91
 
54
92
  private
@@ -68,5 +106,9 @@ module TwilioRubyWrapper
68
106
  value
69
107
  end
70
108
 
109
+ def set_twilio_account
110
+ @twilio_client = Twilio::REST::Client.new(@@account_sid, @@auth_token)
111
+ @twilio_queue_list = @twilio_client.account.queues
112
+ end
71
113
  end
72
114
  end
@@ -1,3 +1,3 @@
1
1
  module TwilioRubyWrapper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  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.2.0
4
+ version: 0.3.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-07-06 00:00:00.000000000 Z
11
+ date: 2017-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twilio-ruby
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 2.5.2
112
+ rubygems_version: 2.6.13
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: twilio-ruby wrapper