yuntongxun_sdk 0.1.0 → 0.1.1
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 +4 -4
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/README.md +4 -1
- data/lib/yuntongxun_sdk/api.rb +65 -0
- data/lib/yuntongxun_sdk/configuration.rb +24 -0
- data/lib/yuntongxun_sdk/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aa6bd4783ceb34dfaecf704e23a5a5e09622887
|
4
|
+
data.tar.gz: 5b1bffd5329385f5ae534c00d2e110130f3849f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3965086d2e9efbfe35904e8ecc9301ffe2f6afd4e799432d5e8f992b18978599dfba423301b6b2d498fb63ed0060b132097212dc1988062f9e2557b5d40f014
|
7
|
+
data.tar.gz: 5f9105c29c5346b219d1a51e348cf08c60b1629fabd2181a6dc086ff26e144d35896da0319ce1ee7685f132b08c00e21fd0aa88254f3d9b03a978e8ecddefe34
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# YuntongxunSdk
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/yuntongxun_sdk)
|
4
|
+
[](https://travis-ci.org/FX-HAO/yuntongxun_sdk)
|
5
|
+
|
6
|
+
YuntongxunSdk is a [云通讯](http://www.yuntongxun.com/doc.html) library for Ruby.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module YuntongxunSdk
|
2
|
+
class API
|
3
|
+
def initialize(account_sid = YuntongxunSdk.config.account_sid, auth_token = YuntongxunSdk.config.auth_token, app_id = YuntongxunSdk.config.app_id)
|
4
|
+
@account_sid = account_sid
|
5
|
+
@auth_token = auth_token
|
6
|
+
@app_id = app_id
|
7
|
+
end
|
8
|
+
|
9
|
+
class RequestFailureError < StandardError
|
10
|
+
attr_reader :response, :status_code
|
11
|
+
|
12
|
+
def initialize(response, status_code)
|
13
|
+
@response = response
|
14
|
+
@status_code = status_code
|
15
|
+
end
|
16
|
+
|
17
|
+
def message
|
18
|
+
@response.to_json
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Makes a request to the appropriate YuntongxunSdk API.
|
27
|
+
# @note You'll rarely need to call this method directly.
|
28
|
+
#
|
29
|
+
# @param path the server path for this request (leading / is prepended if not present)
|
30
|
+
# @param args arguments to be sent to YuntongxunSdk
|
31
|
+
# @param verb the HTTP method to use
|
32
|
+
# @param options request-related options
|
33
|
+
def api(path, args = {}, verb = "post", options = {})
|
34
|
+
args = {
|
35
|
+
appId: @app_id
|
36
|
+
}.merge(args)
|
37
|
+
|
38
|
+
batch = DateTime.now.strftime("%Y%m%d%H%M%S")
|
39
|
+
signature = "#{@account_sid}#{@auth_token}#{batch}"
|
40
|
+
sig = Digest::MD5.hexdigest(signature).upcase
|
41
|
+
|
42
|
+
gateway = options.delete(:gateway) || YuntongxunSdk.config.gateway
|
43
|
+
# add a leading / if needed...
|
44
|
+
path = "/#{path}" unless path =~ /^\//
|
45
|
+
url = "#{gateway}/2013-12-26/Accounts/#{@account_sid}#{path}?sig=#{sig}"
|
46
|
+
|
47
|
+
headers = {
|
48
|
+
"Accept" => "application/json",
|
49
|
+
"Content-Type" => "application/json;charset=utf-8",
|
50
|
+
"Authorization" => Base64.strict_encode64("#{@account_sid}:#{batch}")
|
51
|
+
}
|
52
|
+
|
53
|
+
response = YuntongxunSdk.make_request(url, verb, args, headers)
|
54
|
+
build_reponse(response)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def build_reponse(response)
|
60
|
+
body = JSON.parse(response.body)
|
61
|
+
raise RequestFailureError.new(body, body["statusCode"]) if body["statusCode"] != "000000"
|
62
|
+
body
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Global configuration for YuntongxunSdk.
|
2
|
+
class YuntongxunSdk::Configuration
|
3
|
+
# The gateway to use for API requests
|
4
|
+
attr_accessor :gateway
|
5
|
+
|
6
|
+
# The default Account ID and token to be used
|
7
|
+
attr_accessor :account_sid, :auth_token
|
8
|
+
|
9
|
+
# The default App ID
|
10
|
+
attr_accessor :app_id
|
11
|
+
|
12
|
+
# Default server information for Yuntongxun. These can be overridden by setting config values.
|
13
|
+
# See YuntongxunSdk.config.
|
14
|
+
DEFAULT_SERVERS = {
|
15
|
+
gateway: 'https://app.cloopen.com:8883',
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
# Default to our default values.
|
20
|
+
DEFAULT_SERVERS.each_pair do |key, value|
|
21
|
+
self.public_send("#{key}=", value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yuntongxun_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fuxin Hao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -74,6 +74,8 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
77
79
|
- CODE_OF_CONDUCT.md
|
78
80
|
- Gemfile
|
79
81
|
- LICENSE.txt
|
@@ -82,6 +84,8 @@ files:
|
|
82
84
|
- bin/console
|
83
85
|
- bin/setup
|
84
86
|
- lib/yuntongxun_sdk.rb
|
87
|
+
- lib/yuntongxun_sdk/api.rb
|
88
|
+
- lib/yuntongxun_sdk/configuration.rb
|
85
89
|
- lib/yuntongxun_sdk/version.rb
|
86
90
|
- yuntongxun_sdk.gemspec
|
87
91
|
homepage: https://github.com/FX-HAO/yuntongxun_sdk
|