bulutfon_sdk 1.1.3 → 1.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 +59 -2
- data/examples/examples.rb +60 -0
- data/lib/bulutfon_sdk/hash.rb +5 -0
- data/lib/bulutfon_sdk/helpers/data_helper.rb +45 -0
- data/lib/bulutfon_sdk/rest/base_request.rb +85 -82
- data/lib/bulutfon_sdk/version.rb +1 -1
- data/lib/bulutfon_sdk.rb +5 -0
- 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: 46ed35e55bb3d1d1063cb1f02147df007c7ad8fa
|
4
|
+
data.tar.gz: 08466339da1fb22dcd8b1afd95b9091a3daf0a21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2cfd79af389d4f9a20b633e2f7c67e69f94e51d6951be99fd246296da0723bcdb1f5c1fdccd55583f493292d32a29e84e29cdace9a91fae26a6c0e90e22ba0e
|
7
|
+
data.tar.gz: 3c534bacb65306dcf85a958fced31864a814dd7c8f95cd458a072a897a9e7a1606c349febc4e969a51c864ae5178a866c16f2223ed50783cdcd2054aba089787
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Bulutfon Ruby SDK
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/bulutfon_sdk.svg)](https://badge.fury.io/rb/bulutfon_sdk)
|
4
|
+
|
3
5
|
* [API Dokümantasyonu](https://github.com/bulutfon/documents/tree/master/API)
|
4
6
|
* [Örnek Kodlar](https://github.com/bulutfon/ruby-sdk/tree/master/examples)
|
5
7
|
|
@@ -272,8 +274,63 @@ puts bulutfon.messages.create(params)
|
|
272
274
|
methodlarını kullanabilirsiniz.
|
273
275
|
|
274
276
|
Örnek kullanımları görmek için ve erişebileceğiniz değişkenler için [örnek kodlarımızı](https://github.com/bulutfon/ruby-sdk/tree/master/examples) inceleyebilirsiniz.
|
275
|
-
|
277
|
+
|
278
|
+
## Hash cevapları OpenStruct objesine dönüştürme
|
279
|
+
|
280
|
+
### Hesap
|
281
|
+
```ruby
|
282
|
+
bulutfon = BulutfonSDK::REST::Bulutfon.new(token)
|
283
|
+
# Hesap detaylarını hash olarak gösterir
|
284
|
+
puts bulutfon.details
|
285
|
+
# Örnek bir hesap detayları sonucu
|
286
|
+
details = {
|
287
|
+
'user' =>{
|
288
|
+
'email' => 'test@bulutfon.com', 'name' => 'BULUTFON', 'gsm' => 'XXXXXXXXXXXX'
|
289
|
+
},
|
290
|
+
'pbx' =>{
|
291
|
+
'name' => 'test', 'url' => 'test.com', 'state' => 'CONFIRMED', 'package' => 'ENTERPRISE', 'customer_type' => 'CORPORATE'
|
292
|
+
},
|
293
|
+
'credit' =>{
|
294
|
+
'balance' => '10.00', 'sms_credit' => 0
|
295
|
+
}
|
296
|
+
}
|
297
|
+
# to_obj bizim hash sonuçları için tanımladığımız yardımcı metodumuz
|
298
|
+
detail_object = bulutfon.details.to_obj
|
299
|
+
puts detail_object
|
300
|
+
# Object örneği
|
301
|
+
=begin
|
302
|
+
#<OpenStruct
|
303
|
+
user=#<OpenStruct email="test@bulutfon.com", name="BULUTFON", gsm="XXXXXXXXXXXX">,
|
304
|
+
pbx=#<OpenStruct name="test", url="test.com", state="CONFIRMED", package="ENTERPRISE", customer_type="CORPORATE">,
|
305
|
+
credit=#<OpenStruct balance="10.00", sms_credit=0>>
|
306
|
+
=end
|
307
|
+
# Obje üzerinden alanlara şu şekilde ulaşabilirsiniz
|
308
|
+
puts detail_object.user.email
|
309
|
+
puts detail_object.user.name
|
310
|
+
puts detail_object.pbx.name
|
311
|
+
puts detail_object.pbx.url
|
312
|
+
puts detail_object.credit.balance
|
313
|
+
puts detail_object.credit.sms_credit
|
314
|
+
```
|
315
|
+
|
316
|
+
### Gruplar için örnek
|
317
|
+
```ruby
|
318
|
+
group_sdk = BulutfonSDK::REST::Group.new(token)
|
319
|
+
obj_result = group_sdk.all.to_obj
|
320
|
+
=begin
|
321
|
+
#<OpenStruct
|
322
|
+
groups=[
|
323
|
+
#<OpenStruct id=1, number=11, name="Ofis - İstanbul", timeout=30>,
|
324
|
+
#<OpenStruct id=2, number=22, name="Ofis - Denizli", timeout=30>,
|
325
|
+
#<OpenStruct id=3, number=33, name="İngilizce", timeout=30>
|
326
|
+
]>
|
327
|
+
=end
|
328
|
+
obj_result.groups.each do |group|
|
329
|
+
puts group.name
|
330
|
+
end
|
331
|
+
```
|
332
|
+
|
276
333
|
##Credits
|
277
334
|
* ruby_sdk is maintained by [Lab2023](http://lab2023.com/) & [Bulutfon](https://www.bulutfon.com/)
|
278
335
|
* Thank you to all the contributors!
|
279
|
-
* The names and logos for Bulutfon are trademarks of Bulutfon
|
336
|
+
* The names and logos for Bulutfon are trademarks of Bulutfon
|
data/examples/examples.rb
CHANGED
@@ -214,3 +214,63 @@ params = {
|
|
214
214
|
}
|
215
215
|
puts message.create(params)
|
216
216
|
|
217
|
+
##############################################
|
218
|
+
# Create OpenStruct object from hash
|
219
|
+
##############################################
|
220
|
+
|
221
|
+
# Account
|
222
|
+
# -------------------------------------------------------------
|
223
|
+
bulutfon = BulutfonSDK::REST::Bulutfon.new(token)
|
224
|
+
# Get account details
|
225
|
+
puts bulutfon.details
|
226
|
+
|
227
|
+
# Details result is like below
|
228
|
+
=begin
|
229
|
+
details = {
|
230
|
+
'user' =>{
|
231
|
+
'email' => 'test@bulutfon.com', 'name' => 'BULUTFON', 'gsm' => 'XXXXXXXXXXXX'
|
232
|
+
},
|
233
|
+
'pbx' =>{
|
234
|
+
'name' => 'test', 'url' => 'test.com', 'state' => 'CONFIRMED', 'package' => 'ENTERPRISE', 'customer_type' => 'CORPORATE'
|
235
|
+
},
|
236
|
+
'credit' =>{
|
237
|
+
'balance' => '10.00', 'sms_credit' => 0
|
238
|
+
}
|
239
|
+
}
|
240
|
+
=end
|
241
|
+
|
242
|
+
# to_obj is our helper method for hashes
|
243
|
+
detail_object = bulutfon.details.to_obj
|
244
|
+
puts detail_object
|
245
|
+
|
246
|
+
# Object Example
|
247
|
+
=begin
|
248
|
+
#<OpenStruct
|
249
|
+
user=#<OpenStruct email="test@bulutfon.com", name="BULUTFON", gsm="XXXXXXXXXXXX">,
|
250
|
+
pbx=#<OpenStruct name="test", url="test.com", state="CONFIRMED", package="ENTERPRISE", customer_type="CORPORATE">,
|
251
|
+
credit=#<OpenStruct balance="10.00", sms_credit=0>>
|
252
|
+
=end
|
253
|
+
|
254
|
+
# You can access fields
|
255
|
+
puts detail_object.user.email
|
256
|
+
puts detail_object.user.name
|
257
|
+
puts detail_object.pbx.name
|
258
|
+
puts detail_object.pbx.url
|
259
|
+
puts detail_object.credit.balance
|
260
|
+
puts detail_object.credit.sms_credit
|
261
|
+
|
262
|
+
# Groups
|
263
|
+
# -------------------------------------------------------------
|
264
|
+
group_sdk = BulutfonSDK::REST::Group.new(token)
|
265
|
+
obj_result = group_sdk.all.to_obj
|
266
|
+
=begin
|
267
|
+
#<OpenStruct
|
268
|
+
groups=[
|
269
|
+
#<OpenStruct id=1, number=11, name="Ofis - İstanbul", timeout=30>,
|
270
|
+
#<OpenStruct id=2, number=22, name="Ofis - Denizli", timeout=30>,
|
271
|
+
#<OpenStruct id=3, number=33, name="İngilizce", timeout=30>
|
272
|
+
]>
|
273
|
+
=end
|
274
|
+
obj_result.groups.each do |group|
|
275
|
+
puts group.name
|
276
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module BulutfonSDK
|
2
|
+
module Helpers
|
3
|
+
module DataHelper
|
4
|
+
|
5
|
+
##
|
6
|
+
# Convert hash to object
|
7
|
+
def convert_to_obj(hash)
|
8
|
+
open_struct = OpenStruct.new
|
9
|
+
set_open_struct_variables( open_struct, hash )
|
10
|
+
open_struct
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Set hash variable to open_struct
|
15
|
+
# Recursive method for hash values
|
16
|
+
def set_open_struct_variables(open_struct, hash)
|
17
|
+
hash.each do |key,value|
|
18
|
+
if value.is_a? Hash
|
19
|
+
# create new open struct value
|
20
|
+
new_open_struct = OpenStruct.new
|
21
|
+
open_struct.send("#{key}=", new_open_struct)
|
22
|
+
set_open_struct_variables(new_open_struct, value)
|
23
|
+
elsif value.is_a? Array
|
24
|
+
open_struct.send("#{key}=", value)
|
25
|
+
value.each_with_index do |val, index|
|
26
|
+
if val.is_a? Hash
|
27
|
+
# create new open struct value
|
28
|
+
new_open_struct = OpenStruct.new
|
29
|
+
# set array index value variable
|
30
|
+
value[index] = new_open_struct
|
31
|
+
set_open_struct_variables(new_open_struct, val)
|
32
|
+
else
|
33
|
+
# Do nothing
|
34
|
+
# value[index] = val
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
open_struct.send("#{key}=", value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -17,100 +17,103 @@ module BulutfonSDK
|
|
17
17
|
end
|
18
18
|
|
19
19
|
protected
|
20
|
+
##
|
21
|
+
# Prepare URI object for file path
|
22
|
+
def prepare_uri(path, params = {})
|
23
|
+
uri = uri_parse(params, path)
|
24
|
+
uri.query = URI.encode_www_form(params)
|
25
|
+
uri
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
##
|
32
|
-
# Prepare http request
|
33
|
-
def prepare_request(method, path, params = {})
|
34
|
-
request_path = "#{@config.host}/#{path}"
|
35
|
-
uri = URI.parse(request_path)
|
36
|
-
params[:access_token] = @token
|
37
|
-
uri.query = URI.encode_www_form(params) if ['get', 'delete'].include?(method)
|
38
|
-
method_class = Net::HTTP.const_get method.to_s.capitalize
|
39
|
-
request = method_class.new(uri.to_s, HTTP_HEADERS)
|
40
|
-
request.form_data = params if ['post', 'put'].include?(method)
|
41
|
-
connect_and_send(request)
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
# Prepare http request for file saving
|
46
|
-
def save_file(method, path, save_path)
|
47
|
-
uri = prepare_uri(path)
|
48
|
-
method_class = Net::HTTP.const_get method.to_s.capitalize
|
49
|
-
request = method_class.new(uri.to_s, HTTP_HEADERS)
|
50
|
-
response = connect_and_send(request, is_file: true )
|
51
|
-
begin
|
52
|
-
file = File.open(save_path, 'w')
|
53
|
-
file.write(response)
|
54
|
-
rescue => error
|
55
|
-
raise BulutfonSDK::REST::SDKError.new error
|
56
|
-
ensure
|
57
|
-
file.close unless file.nil?
|
28
|
+
##
|
29
|
+
# Prepare http request
|
30
|
+
def prepare_request(method, path, params = {})
|
31
|
+
uri = uri_parse(params, path)
|
32
|
+
uri.query = URI.encode_www_form(params) if ['get', 'delete'].include?(method)
|
33
|
+
method_class = Net::HTTP.const_get method.to_s.capitalize
|
34
|
+
request = method_class.new(uri.to_s, HTTP_HEADERS)
|
35
|
+
request.form_data = params if ['post', 'put'].include?(method)
|
36
|
+
connect_and_send(request)
|
58
37
|
end
|
59
|
-
{ file: file, save_path: save_path }
|
60
|
-
end
|
61
38
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@http.use_ssl = @config.use_ssl
|
70
|
-
if @config.ssl_verify_peer
|
71
|
-
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
72
|
-
@http.ca_file = @config.ssl_ca_file
|
73
|
-
else
|
74
|
-
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
39
|
+
##
|
40
|
+
# URI parse for params
|
41
|
+
def uri_parse(params, path)
|
42
|
+
request_path = "#{@config.host}/#{path}"
|
43
|
+
uri = URI.parse(request_path)
|
44
|
+
params[:access_token] = @token
|
45
|
+
uri
|
75
46
|
end
|
76
|
-
@http.open_timeout = @config.timeout
|
77
|
-
@http.read_timeout = @config.timeout
|
78
|
-
end
|
79
47
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
48
|
+
##
|
49
|
+
# Prepare http request for file saving
|
50
|
+
def save_file(method, path, save_path)
|
51
|
+
uri = prepare_uri(path)
|
52
|
+
method_class = Net::HTTP.const_get method.to_s.capitalize
|
53
|
+
request = method_class.new(uri.to_s, HTTP_HEADERS)
|
54
|
+
response = connect_and_send(request, is_file: true )
|
55
|
+
begin
|
56
|
+
file = File.open(save_path, 'w')
|
57
|
+
file.write(response)
|
58
|
+
rescue => error
|
59
|
+
raise BulutfonSDK::REST::SDKError.new error
|
60
|
+
ensure
|
61
|
+
file.close unless file.nil?
|
94
62
|
end
|
95
|
-
|
96
|
-
raise if request.class == Net::HTTP::Post
|
97
|
-
if retries_left > 0 then retries_left -= 1; retry else raise end
|
63
|
+
{ file: file, save_path: save_path }
|
98
64
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
65
|
+
|
66
|
+
##
|
67
|
+
# Set up and cache a Net::HTTP object to use when making requests.
|
68
|
+
def set_up_connection # :doc:
|
69
|
+
uri = URI.parse(@config.host)
|
70
|
+
@http = Net::HTTP.new(uri.host, uri.port, p_user = @config.proxy_user, p_pass = @config.proxy_pass)
|
71
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
72
|
+
@http.use_ssl = @config.use_ssl
|
73
|
+
if @config.ssl_verify_peer
|
74
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
75
|
+
@http.ca_file = @config.ssl_ca_file
|
102
76
|
else
|
103
|
-
|
77
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
104
78
|
end
|
105
|
-
|
106
|
-
|
79
|
+
@http.open_timeout = @config.timeout
|
80
|
+
@http.read_timeout = @config.timeout
|
107
81
|
end
|
108
82
|
|
109
|
-
|
110
|
-
|
83
|
+
##
|
84
|
+
# Send an HTTP request using the cached <tt>@http</tt> object and
|
85
|
+
# return the JSON response body parsed into a hash. Also save the raw
|
86
|
+
# Net::HTTP::Request and Net::HTTP::Response objects as
|
87
|
+
# <tt>@last_request</tt> and <tt>@last_response</tt> to allow for
|
88
|
+
# inspection later.
|
89
|
+
def connect_and_send(request, is_file = false ) # :doc:
|
90
|
+
@last_request = request
|
91
|
+
retries_left = @config.retry_limit
|
92
|
+
begin
|
93
|
+
response = @http.request request
|
94
|
+
@last_response = response
|
95
|
+
if response.kind_of? Net::HTTPServerError
|
96
|
+
raise BulutfonSDK::REST::ServerError
|
97
|
+
end
|
98
|
+
rescue
|
99
|
+
raise if request.class == Net::HTTP::Post
|
100
|
+
if retries_left > 0 then retries_left -= 1; retry else raise end
|
101
|
+
end
|
102
|
+
if response.body and !response.body.empty?
|
103
|
+
if is_file
|
104
|
+
object = response.body
|
105
|
+
else
|
106
|
+
object = MultiJson.load response.body
|
107
|
+
end
|
108
|
+
elsif response.kind_of? Net::HTTPBadRequest
|
109
|
+
object = { message: 'Bad request', code: 400 }
|
110
|
+
end
|
111
|
+
|
112
|
+
if response.kind_of? Net::HTTPClientError
|
113
|
+
raise BulutfonSDK::REST::RequestError.new object['error'], object['code']
|
114
|
+
end
|
115
|
+
object
|
111
116
|
end
|
112
|
-
object
|
113
|
-
end
|
114
117
|
|
115
118
|
end
|
116
119
|
end
|
data/lib/bulutfon_sdk/version.rb
CHANGED
data/lib/bulutfon_sdk.rb
CHANGED
@@ -6,9 +6,12 @@ require 'openssl'
|
|
6
6
|
require 'open3'
|
7
7
|
require 'mime/types'
|
8
8
|
require 'base64'
|
9
|
+
require 'ostruct'
|
9
10
|
|
10
11
|
require 'bulutfon_sdk/version' unless defined?(BulutfonSDK::VERSION)
|
11
12
|
require 'bulutfon_sdk/util'
|
13
|
+
require 'bulutfon_sdk/helpers/data_helper'
|
14
|
+
require 'bulutfon_sdk/hash'
|
12
15
|
require 'bulutfon_sdk/rest/bulutfon'
|
13
16
|
require 'bulutfon_sdk/rest/message'
|
14
17
|
require 'bulutfon_sdk/rest/did'
|
@@ -24,6 +27,8 @@ require 'bulutfon_sdk/rest/message_title'
|
|
24
27
|
require 'bulutfon_sdk/util/client_config'
|
25
28
|
require 'bulutfon_sdk/rest/errors'
|
26
29
|
|
30
|
+
include BulutfonSDK::Helpers::DataHelper
|
31
|
+
|
27
32
|
module BulutfonSDK
|
28
33
|
# Your code goes here...
|
29
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bulutfon_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismail Akbudak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -106,6 +106,8 @@ files:
|
|
106
106
|
- examples/pdf-sample.pdf
|
107
107
|
- examples/test.wav
|
108
108
|
- lib/bulutfon_sdk.rb
|
109
|
+
- lib/bulutfon_sdk/hash.rb
|
110
|
+
- lib/bulutfon_sdk/helpers/data_helper.rb
|
109
111
|
- lib/bulutfon_sdk/rest/announcement.rb
|
110
112
|
- lib/bulutfon_sdk/rest/automatic_call.rb
|
111
113
|
- lib/bulutfon_sdk/rest/base_request.rb
|
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
145
|
version: '0'
|
144
146
|
requirements: []
|
145
147
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.4
|
148
|
+
rubygems_version: 2.6.4
|
147
149
|
signing_key:
|
148
150
|
specification_version: 4
|
149
151
|
summary: Bulutfon Ruby SDK.
|