rong-auth-service-ruby 0.1.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 +7 -0
  2. data/lib/rong.rb +66 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb877101321489c9070f035b41008e2d97e1994b
4
+ data.tar.gz: 8e2fe429ae3188284170fbf83507c39685976d6b
5
+ SHA512:
6
+ metadata.gz: 96e45bfb6dbb1c99a2d84e32528fad6c5249085e6b629f230ed6e5ae42b10bc2b639021a50102029d0fd48b4267e83400637e2550f2defbfa1bd32017522c18a
7
+ data.tar.gz: 62a65a02aac3ebd62abc9d932e3520fb8d5d34d07bfb41aa75192fc46bb828111c5dcf2618fcafd689b48ff9d8c6d69287eca0f0a162f518dd3e35993a9d6bc9
@@ -0,0 +1,66 @@
1
+ class RongAuthService
2
+ def initialize(data={})
3
+ @format = 'json'
4
+ @url = 'https://api.cn.rong.io'
5
+ @appKey = 'df98wer'
6
+ @appSecret = 'de9ur4ijof9u8r'
7
+ @userId = ''
8
+ @name = ''
9
+ @portraitUri = ''
10
+ setOptions(data)
11
+ end
12
+ def request
13
+ url = @url + '/user/getToken.' + @format
14
+ params = {:userId => @userId,:format => @format,:name => @name, :portraitUri => @portraitUri}
15
+ httpHeader = {:appKey => @appKey, :appSecret => @appSecret}
16
+ curl url,params,httpHeader
17
+ end
18
+ class << self
19
+ def formatResponseData(arr,format='json')
20
+ if format == 'json'
21
+ JSON.parser(arr)
22
+ else
23
+ self.arrToXml(arr,true)
24
+ end
25
+ end
26
+ def arrToXml(data,flag=true,key='',type=0)
27
+ xml = ''
28
+ xml += '<result>\n' if flag == true
29
+ data.each do |k,v|
30
+ if v.is_a?(Hash)
31
+ xml += (k.is_a?(Numeric) ? "<item>" : "<#{k}>" ) + "\n" + self.arrToXml(v,false,k,type) + (k.is_a?(Numeric) ? '</item>' : "</#{k}>")+"\n"
32
+ else
33
+ xml += "<#{k}>" + (v.is_a?(Numeric)?v:"<![CDATA[#{v}]]>") + "</#{k}>\n"
34
+ end
35
+ end
36
+ xml += '</result>' if flag == true
37
+ return xml
38
+ end
39
+ end
40
+ private
41
+ def setOptions(data)
42
+ unless data.blank?
43
+ self.instance_variables.each do |k|
44
+ instance_variable_set(k,data[k]) if data[k] != nil
45
+ end
46
+ end
47
+ end
48
+ def curl(url,params,httpHeaders,method='post')
49
+ conn = Faraday.new(:url => url) do |faraday|
50
+ faraday.request :url_encoded
51
+ faraday.response :logger
52
+ faraday.adapter Faraday.default_adapter
53
+ end
54
+ # GET
55
+ if method.upcase == 'GET'
56
+ response = conn.get do |req|
57
+ req.url url
58
+ req.params = params
59
+ end
60
+ else
61
+ # POST
62
+ response = conn.post url,params,httpHeaders
63
+ end
64
+ {:httpInfo => 'httpInfo',:ret => response}
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rong-auth-service-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Megrez Lu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Well wrapped rong-auth-service interpreting with ruby. And which is my
14
+ first Gem Component
15
+ email: lujiajing1126@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/rong.rb
21
+ homepage: https://github.com/lujiajing1126/rong-auth-service-ruby
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: rong-auth-service sdk in ruby
45
+ test_files: []