voximplant_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/voximplant_api/client.rb +25 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6690d5560e90499ba2be773ffc4da8ec6f7ebba7
4
- data.tar.gz: 2630a669cf5678790777402614241404aff6cd60
3
+ metadata.gz: 05350c84c62797a2672f2fe02506d490b8b33c0a
4
+ data.tar.gz: 4202aa6409bbe2e17af8e5375377aca8e04a01bf
5
5
  SHA512:
6
- metadata.gz: 0e854c45065a6d95d335b4030588a400dccd98bfe1641fe06ec766fe29a8437b38dc3c63d8f3f0701009922e5e01c7792eb5359670c20711c07aea0b67804b5f
7
- data.tar.gz: 45ffa13e8073eeffa8b30ec5720745f2f62a8286826ff776729c9e0db1805c01a2756979bdf1782c270eb6dc4ab797a4c670a7dec437bcd4e660d336db5bfc6e
6
+ metadata.gz: 19fce76882a8b00c2f3cf35e6aa3882ad9d436475f6fbd22716ff229237fa361ad7e262273b3b2ed60f14dce19c767ff3607a9e1e33a13f8e4c0b365985eff98
7
+ data.tar.gz: 57877275c3f39df9427d4423238a4e11ff6c7b7058db8d4fd5e353677fbd438195dd630288992e2dadbf96e0e7bb9e880f8abd164b6b56b483f7e569f6594efe
@@ -24,9 +24,18 @@ module VoximplantApi
24
24
  end
25
25
 
26
26
  def method_missing(name, *args)
27
- method_name = name.to_s.split('_').collect(&:capitalize).join
28
27
  options = args.first || {}
29
- perform_request method_name, options
28
+ name_words = name.to_s.split('_')
29
+ if name_words.first == "each"
30
+ return enum_for(name, *args) unless block_given?
31
+ method_name = name_words[1..-1].collect(&:capitalize).join
32
+ perform_request_each method_name, options do |x|
33
+ yield x
34
+ end
35
+ else
36
+ method_name = name_words.collect(&:capitalize).join
37
+ perform_request method_name, options
38
+ end
30
39
 
31
40
  rescue VoximplantApi::Error => e
32
41
  if e.code == NO_METHOD_ERROR_CODE
@@ -53,6 +62,20 @@ module VoximplantApi
53
62
  self.class.perform_request(name, params)
54
63
  end
55
64
 
65
+ def perform_request_each(name, params = {})
66
+ offset = params[:offset] || 0
67
+ per_page = [params[:count] || 100, 100].min
68
+ begin
69
+ result = perform_request(name, params.merge(offset: offset, count: per_page))
70
+ count = result["count"]
71
+ offset += count
72
+ total_count = result["total_count"]
73
+ result["result"].each do |obj|
74
+ yield obj
75
+ end
76
+ end while offset < total_count
77
+ end
78
+
56
79
  def perform_request_as_parent(name, params = {})
57
80
  params = parent_auth_params.merge params
58
81
  self.class.perform_request(name, params)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voximplant_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Shushlin