yuntongxun_sdk 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bfd10101cc5d5e03a0ca00017541422e5d46f81
4
- data.tar.gz: d892dcafa7e7977a45ac1e205544717ad2d1823b
3
+ metadata.gz: 9aa6bd4783ceb34dfaecf704e23a5a5e09622887
4
+ data.tar.gz: 5b1bffd5329385f5ae534c00d2e110130f3849f2
5
5
  SHA512:
6
- metadata.gz: 6a1f7c92b47ebb918b86a48793a3d42f38b9f660086e6fa87ec49bc76230613bbd182c4282d494738080d3e0c94cbf4f56777251b0650085499613055fcddbe3
7
- data.tar.gz: dfd6d739606fb3abb4e835af235fb503d0ebdcb826e182af86dab01f785095c4ccb8fd4dfec8f9d5c62b30d53247aefa5224cf022f82a36a6622c4ed05f9a48c
6
+ metadata.gz: f3965086d2e9efbfe35904e8ecc9301ffe2f6afd4e799432d5e8f992b18978599dfba423301b6b2d498fb63ed0060b132097212dc1988062f9e2557b5d40f014
7
+ data.tar.gz: 5f9105c29c5346b219d1a51e348cf08c60b1629fabd2181a6dc086ff26e144d35896da0319ce1ee7685f132b08c00e21fd0aa88254f3d9b03a978e8ecddefe34
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: required
2
+ language: ruby
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ install: "bundle install"
9
+ script:
10
+ - bundle exec rspec
11
+ cache: bundler
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # YuntongxunSdk
2
2
 
3
- YuntongxunSdk is a [Yuntongxun](http://www.yuntongxun.com/doc.html) library for Ruby.
3
+ [![Gem Version](https://badge.fury.io/rb/yuntongxun_sdk.svg)](https://badge.fury.io/rb/yuntongxun_sdk)
4
+ [![Build Status](https://travis-ci.org/FX-HAO/yuntongxun_sdk.svg?branch=master)](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
@@ -1,3 +1,3 @@
1
1
  module YuntongxunSdk
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
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: 2017-12-25 00:00:00.000000000 Z
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