rongcloud 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rongcloud/service/message.rb +83 -0
- data/lib/rongcloud/service/user.rb +20 -0
- data/lib/rongcloud/service.rb +74 -0
- data/lib/rongcloud/sign.rb +27 -0
- data/lib/rongcloud/version.rb +3 -0
- data/lib/rongcloud.rb +32 -0
- data/rongcloud.gemspec +33 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 920fe5224c48fcf81c32ecf86f334711f2d7aa07
|
4
|
+
data.tar.gz: 00af620ae05a89bdd23235959563784f75ef7b05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec966db23d109913411e135c96d3d1d686984e55764a0d303c04a74ba58a7aa779ef99f58acda7d31ba9a160e997a18fa73c6616c654b7dc2ed4444b285b6156
|
7
|
+
data.tar.gz: c9035676347c9783df4bb0a4d195ccad66416350e1123b3b7649a39affbbc84deb09fc358a775813c259d8ed3af39e1ed152c3ab6203f1ca8975660b576d67e4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 木卯溪
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Rongcloud
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rongcloud`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rongcloud'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rongcloud
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/rongcloud/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rongcloud"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
module Rongcloud
|
2
|
+
module Service
|
3
|
+
class Message < Rongcloud::Service::Model
|
4
|
+
attr_accessor :from_user_id
|
5
|
+
attr_accessor :to_user_id
|
6
|
+
attr_accessor :object_name #消息类型
|
7
|
+
|
8
|
+
def private_publish(rc_msg)
|
9
|
+
post = {uri: Rongcloud::Service::API_URI[:MSG_PRV_PUBLISH],
|
10
|
+
params: optional_params({fromUserId: self.from_user_id, toUserId: self.to_user_id,
|
11
|
+
objectName: self.object_name,
|
12
|
+
content: rc_msg.json_content})
|
13
|
+
}
|
14
|
+
res = Rongcloud::Service.req_post(post)
|
15
|
+
res[:code]==200
|
16
|
+
end
|
17
|
+
end
|
18
|
+
# 不同类型的消息
|
19
|
+
class RCMsg < Rongcloud::Service::Model
|
20
|
+
attr_accessor :content
|
21
|
+
attr_accessor :extra
|
22
|
+
|
23
|
+
def necessary_attrs
|
24
|
+
end
|
25
|
+
|
26
|
+
def json_content
|
27
|
+
necessary_attrs.to_json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class RCTxtMsg< Rongcloud::Service::RCMsg
|
32
|
+
def necessary_attrs
|
33
|
+
{content: self.content, extra: self.extra}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class RCImgMsg< Rongcloud::Service::RCMsg
|
38
|
+
attr_accessor :image_uri
|
39
|
+
|
40
|
+
def necessary_attrs
|
41
|
+
{content: self.content, imageUri: self.image_uri}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class RCVcMsg< Rongcloud::Service::RCMsg
|
46
|
+
attr_accessor :duration
|
47
|
+
|
48
|
+
def necessary_attrs
|
49
|
+
{content: self.content, duration: self.duration, extra: self.extra}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class RCImgTextMsg< Rongcloud::Service::RCMsg
|
54
|
+
attr_accessor :title
|
55
|
+
attr_accessor :image_uri
|
56
|
+
|
57
|
+
def necessary_attrs
|
58
|
+
{title: self.title, content: self.content, imageUri: self.image_uri, extra: self.extra}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class RCLBSMsg< Rongcloud::Service::RCMsg
|
63
|
+
attr_accessor :latitude
|
64
|
+
attr_accessor :longitude
|
65
|
+
attr_accessor :poi
|
66
|
+
|
67
|
+
def necessary_attrs
|
68
|
+
{content: self.content, latitude: self.latitude, longitude: self.longitude, poi: self.poi, extra: self.extra}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class RCContactNtf< Rongcloud::Service::RCMsg
|
73
|
+
attr_accessor :operation
|
74
|
+
attr_accessor :source_user_id
|
75
|
+
attr_accessor :target_user_id
|
76
|
+
attr_accessor :message
|
77
|
+
|
78
|
+
def necessary_attrs
|
79
|
+
{operation: self.operation, sourceUserId: self.source_user_id, targetUserId: self.target_user_id, message: self.message, extra: self.extra}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rongcloud
|
2
|
+
module Service
|
3
|
+
class User < Rongcloud::Service::Model
|
4
|
+
attr_accessor :user_id
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :portrait_uri
|
7
|
+
attr_accessor :token
|
8
|
+
|
9
|
+
#获取用户的token
|
10
|
+
def get_token
|
11
|
+
post = {uri: Rongcloud::Service::API_URI[:USER_GET_TOKEN],
|
12
|
+
params: optional_params({userId: self.user_id, name: self.name, portraitUri: self.portrait_uri})
|
13
|
+
}
|
14
|
+
res = Rongcloud::Service.req_post(post)
|
15
|
+
self.token = res[:token]
|
16
|
+
res[:token]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Rongcloud
|
2
|
+
module Service
|
3
|
+
|
4
|
+
API_URI = {
|
5
|
+
USER_GET_TOKEN: '/user/getToken.json',
|
6
|
+
MSG_PRV_PUBLISH: '/message/private/publish.json'
|
7
|
+
}
|
8
|
+
|
9
|
+
def self.req_get(config)
|
10
|
+
|
11
|
+
config = default_request_config(config)
|
12
|
+
|
13
|
+
conn = Faraday.new(:url => config[:host])
|
14
|
+
response = conn.get do |req|
|
15
|
+
req.url config[:uri]
|
16
|
+
config[:headers].each { |key, value| req.headers[key.to_s] = value.to_s }
|
17
|
+
config[:params] && config[:params].each { |key, value| req.params[key.to_s] = value.to_s }
|
18
|
+
end
|
19
|
+
|
20
|
+
response_body = response.body
|
21
|
+
warn("get response #{response_body}")
|
22
|
+
res_data(response_body)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.req_post(config, post_format='urlencode')
|
26
|
+
|
27
|
+
config = default_request_config(config)
|
28
|
+
|
29
|
+
conn = Faraday.new(:url => config[:host])
|
30
|
+
response = conn.post do |req|
|
31
|
+
req.url config[:uri]
|
32
|
+
config[:headers].each { |key, value| req.headers[key.to_s] = value.to_s }
|
33
|
+
if post_format.to_s == 'urlencode'
|
34
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
35
|
+
req.body = config[:params].collect { |key, value| "#{key}=#{value}" }.join('&')
|
36
|
+
elsif post_format.to_s == 'json'
|
37
|
+
req.headers['Content-Type'] = 'application/json'
|
38
|
+
req.body = config[:params].to_json
|
39
|
+
end
|
40
|
+
warn("post #{req.body}")
|
41
|
+
end
|
42
|
+
|
43
|
+
response_body = response.body
|
44
|
+
warn("post response #{response_body}")
|
45
|
+
res_data(response_body)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.res_data(response_body)
|
49
|
+
sym_keyed_hash(JSON.parse(response_body))
|
50
|
+
end
|
51
|
+
|
52
|
+
#返回key为sym的hash
|
53
|
+
def self.sym_keyed_hash(hash)
|
54
|
+
hash.inject({}) { |memo, (key, v)| memo[key.to_sym]=v; memo }
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.default_request_config(config)
|
58
|
+
config[:host] ||= Rongcloud.api_host
|
59
|
+
config[:uri] ||= nil
|
60
|
+
config[:params] ||= {}
|
61
|
+
config[:headers] ||= Rongcloud::Sign.gen_headers
|
62
|
+
config
|
63
|
+
end
|
64
|
+
|
65
|
+
# 所有数据类的父类
|
66
|
+
class Model
|
67
|
+
private
|
68
|
+
#返回可选参数(为空的参数不返回)
|
69
|
+
def optional_params(params)
|
70
|
+
params.select { |key, v| v }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rongcloud
|
2
|
+
module Sign
|
3
|
+
|
4
|
+
#生成header数据
|
5
|
+
def self.gen_headers
|
6
|
+
app_key = Rongcloud.app_key
|
7
|
+
app_secret = Rongcloud.app_secret
|
8
|
+
nonce = Rongcloud::Sign.random_str(32)
|
9
|
+
time_stamp = Time.now.to_i
|
10
|
+
signature = Digest::SHA1.hexdigest("#{app_secret}#{nonce}#{time_stamp}")
|
11
|
+
{
|
12
|
+
'App-Key' => app_key,
|
13
|
+
'Nonce' => nonce,
|
14
|
+
'Timestamp' => time_stamp,
|
15
|
+
'Signature' => signature
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
#生成随机字符串
|
20
|
+
def self.random_str(length)
|
21
|
+
seed = '0123456789abcdefjhijklmnopqrstuvwxyz'
|
22
|
+
length.times.inject('') { |acc, t|
|
23
|
+
acc+ seed[Random.rand(seed.length)]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/rongcloud.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'faraday'
|
4
|
+
require 'json'
|
5
|
+
require 'base64'
|
6
|
+
require 'rongcloud/version'
|
7
|
+
require 'rongcloud/sign'
|
8
|
+
require 'rongcloud/service'
|
9
|
+
require 'rongcloud/service/user'
|
10
|
+
require 'rongcloud/service/message'
|
11
|
+
|
12
|
+
module Rongcloud
|
13
|
+
class << self
|
14
|
+
API_HOST = 'https://api.cn.rong.io'
|
15
|
+
attr_accessor :app_key
|
16
|
+
attr_accessor :app_secret
|
17
|
+
attr_accessor :api_host
|
18
|
+
|
19
|
+
def api_host
|
20
|
+
unless @api_host
|
21
|
+
return API_HOST
|
22
|
+
end
|
23
|
+
@api_host
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_writer :debug_mode
|
27
|
+
|
28
|
+
def debug_mode?
|
29
|
+
@debug_mode.nil? ? true : !!@debug_mode
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/rongcloud.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rongcloud/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rongcloud"
|
8
|
+
spec.version = Rongcloud::VERSION
|
9
|
+
spec.authors = ["saxer"]
|
10
|
+
spec.email = ["15201280641@qq.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{融云及时通讯}
|
13
|
+
spec.description = %q{融云及时通讯}
|
14
|
+
spec.homepage = "https://github.com/mumaoxi/rongcloud"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "faraday"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rongcloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- saxer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: 融云及时通讯
|
70
|
+
email:
|
71
|
+
- 15201280641@qq.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/rongcloud.rb
|
85
|
+
- lib/rongcloud/service.rb
|
86
|
+
- lib/rongcloud/service/message.rb
|
87
|
+
- lib/rongcloud/service/user.rb
|
88
|
+
- lib/rongcloud/sign.rb
|
89
|
+
- lib/rongcloud/version.rb
|
90
|
+
- rongcloud.gemspec
|
91
|
+
homepage: https://github.com/mumaoxi/rongcloud
|
92
|
+
licenses: []
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.6
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: 融云及时通讯
|
115
|
+
test_files: []
|