minxing_ruby_sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e2d8b03747ba56947b2c575ba047d107054d2dc
4
+ data.tar.gz: b938a3d8147f9481087d982d8591e07965c5eccb
5
+ SHA512:
6
+ metadata.gz: 4a278d0fbc8394b052d1e3265544ae80dab246e7b857f7f2bc54bd964653201d67807864b476567bbf1f7c04929722343d3fd955c099670909bf05974a923b9e
7
+ data.tar.gz: c620968012cf2bf8116fad1d4edbf51905b0de39eba538eb25a90579b81d3b25bc75c3e07b61394dc5c3c2a39a8f03be38d73de62b70d20baa258b61a36571e1
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://ruby.taobao.org/'
2
+
3
+ gem 'faraday', '~>0.9.0'
4
+ gem 'settingslogic', '~> 2.0.9'
5
+ gem 'pry', '~>0.9.12.4'
6
+ gem 'pry-nav', '~>0.2.3'
7
+ gem 'rspec'
8
+ gem 'json'
9
+
10
+
11
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ minxing_ruby_sdk (0.0.1)
5
+ faraday (~> 0.9.0)
6
+ json
7
+ settingslogic (~> 2.0.9)
8
+
9
+ GEM
10
+ remote: http://ruby.taobao.org/
11
+ specs:
12
+ coderay (1.1.0)
13
+ diff-lcs (1.2.5)
14
+ faraday (0.9.0)
15
+ multipart-post (>= 1.2, < 3)
16
+ json (1.7.7)
17
+ method_source (0.8.2)
18
+ multipart-post (2.0.0)
19
+ pry (0.9.12.6)
20
+ coderay (~> 1.0)
21
+ method_source (~> 0.8)
22
+ slop (~> 3.4)
23
+ pry-nav (0.2.3)
24
+ pry (~> 0.9.10)
25
+ rake (0.9.6)
26
+ rspec (3.0.0)
27
+ rspec-core (~> 3.0.0)
28
+ rspec-expectations (~> 3.0.0)
29
+ rspec-mocks (~> 3.0.0)
30
+ rspec-core (3.0.1)
31
+ rspec-support (~> 3.0.0)
32
+ rspec-expectations (3.0.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.0.0)
35
+ rspec-mocks (3.0.1)
36
+ rspec-support (~> 3.0.0)
37
+ rspec-support (3.0.0)
38
+ settingslogic (2.0.9)
39
+ slop (3.5.0)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.5)
46
+ faraday (~> 0.9.0)
47
+ json
48
+ minxing_ruby_sdk!
49
+ pry (~> 0.9.12.4)
50
+ pry-nav (~> 0.2.3)
51
+ rake
52
+ rspec
53
+ settingslogic (~> 2.0.9)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 bsktbl
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MinxingRubySdk
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'minxing_ruby_sdk'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install minxing_ruby_sdk
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/minxing_ruby_sdk/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+ ##运行测试,当前目录,执行。
32
+ 修改配置文件信息,然后执行测试
33
+ rspec spec/ocu_text_spec.rb
34
+
35
+ ##debug模式
36
+ #加断点
37
+ binding.pry
38
+ #调试
39
+ debug: s/n/c (step/next/continue)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ require 'logger'
2
+ require "minxing_ruby_sdk/version"
3
+
4
+ module MinxingRubySdk
5
+ # Your code goes here...
6
+
7
+ class << self
8
+ # Public: Gets or sets the root path that Faraday is being loaded from.
9
+ # This is the root from where the libraries are auto-loaded from.
10
+ attr_accessor :root_path
11
+
12
+ # Public: Gets or sets the path that the Faraday libs are loaded from.
13
+ attr_accessor :lib_path
14
+
15
+
16
+ end
17
+
18
+ self.root_path = File.expand_path "../..", __FILE__
19
+ self.lib_path = File.expand_path "../minxing_ruby_sdk", __FILE__
20
+
21
+ LOGGER = Logger.new(STDOUT)
22
+ SETTINGS = YAML.load_file(root_path + '/settings.yml')
23
+
24
+ end
@@ -0,0 +1,49 @@
1
+ module MinxingRubySdk
2
+ class Account
3
+
4
+ attr_accessor :connection
5
+
6
+ def get(url, withTokenHeader=true, headers, params)
7
+ apiForResponse('get', url, withTokenHeader, headers, params)
8
+ end
9
+
10
+ def post(url, withTokenHeader=true, headers, params)
11
+ apiForResponse('post', url, withTokenHeader, headers, params)
12
+ end
13
+
14
+ def put(url, withTokenHeader=true, headers, params)
15
+ apiForResponse('put', url, withTokenHeader, headers, params)
16
+ end
17
+
18
+ def delete(url, withTokenHeader=true, headers, params)
19
+ apiForResponse('delete', url, withTokenHeader, headers, params)
20
+ end
21
+
22
+
23
+ def apiForResponse(method, url, withTokenHeader, headers, params)
24
+ method = 'get' if method.empty?
25
+ method = method.downcase
26
+ if withTokenHeader
27
+ @connection.tokenType = "Bearer" if @connection.tokenType.empty?
28
+
29
+ headers['Authorization'] = @connection.tokenType + " " + @connection.token
30
+ # headers["API-RemoteIP"] = ipaddr.getHostAddress()
31
+ # client.getHostConfiguration().getParams()
32
+ # .setParameter("http.default-headers", headers);
33
+ end
34
+ response = @connection.connection.send(method) do |req|
35
+ LOGGER.debug(url)
36
+ LOGGER.debug(headers)
37
+ LOGGER.debug(params)
38
+
39
+ req.url url
40
+ req.headers = headers
41
+ req.body = params
42
+ end
43
+
44
+ response.body
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+
2
+ module MinxingRubySdk
3
+ module Api
4
+ class Login
5
+ attr_reader :connection, :root_url, :token
6
+
7
+ def initialize(root_url)
8
+ @root_url = root_url
9
+ @connection = MinxingRubySdk::Connection.new root_url
10
+ end
11
+
12
+ def get_token_json (args)
13
+ response = @connection.connection.post do |req|
14
+ req.url @root_url + MinxingRubySdk::SETTINGS['api']['access_token_url']
15
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
16
+ req.body = args
17
+ end
18
+
19
+ @token = JSON response.body
20
+ end
21
+
22
+ def from_last_seen
23
+ response = @connection.connection.get do |req|
24
+ req.url @root_url + MinxingRubySdk::SETTINGS['api']['api_prefix'] + MinxingRubySdk::SETTINGS['api']['from_last_seen']
25
+ req.headers['AUTHORIZATION'] = 'bearer ' + @token['access_token']
26
+ end
27
+ JSON response.body
28
+ end
29
+
30
+ def subscriptions_ocus(ocu_id)
31
+ response = @connection.connection.post do |req|
32
+ req.url @root_url + MinxingRubySdk::SETTINGS['api']['api_prefix'] + MinxingRubySdk::SETTINGS['api']['subscriptions_ocus'] + '/' + ocu_id
33
+ req.headers['AUTHORIZATION'] = 'bearer ' + @token['access_token']
34
+ end
35
+ puts response.body
36
+ end
37
+
38
+ def post_conversations_messages(conversation_id,message_content)
39
+ params = {}
40
+ params['body'] = message_content
41
+ response = @connection.connection.post do |req|
42
+ req.url @root_url + MinxingRubySdk::SETTINGS['api']['api_prefix'] + MinxingRubySdk::SETTINGS['api']['post_conversations_messages'].sub('id',conversation_id)
43
+ req.headers['AUTHORIZATION'] = 'bearer ' + @token['access_token']
44
+ req.body = params
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ module MinxingRubySdk
2
+ module COMPONENT
3
+ class PostParameter
4
+ attr_accessor :name, :value
5
+
6
+ def initialize (name, value)
7
+ @name = name
8
+ @value = value
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'faraday'
2
+
3
+ module MinxingRubySdk
4
+ class Connection
5
+
6
+ attr_accessor :tokenType, :token, :connection
7
+
8
+ def initialize root_url
9
+ @connection = Faraday.new(:url => root_url) do |faraday|
10
+ faraday.request :url_encoded # form-encode POST params
11
+ faraday.response :logger # log requests to STDOUT
12
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ # Dir[File.join(File.dirname(__FILE__),'../*.rb')].each{|f| require f; puts f}
2
+ # Dir[File.join(File.dirname(__FILE__),'module/*.rb')].each{|f| require f; puts f}
3
+ # Dir[File.join(File.dirname(__FILE__),'ocu/*.rb')].each{|f| require f; puts f}
4
+ # Dir[File.join(File.dirname(__FILE__),'util/*.rb')].each{|f| require f; puts f}
@@ -0,0 +1,4 @@
1
+ module MinxingRubySdk
2
+ class Message
3
+ end
4
+ end
@@ -0,0 +1,23 @@
1
+ module MinxingRubySdk
2
+ module Ocu
3
+ class Article
4
+ attr_accessor :title, :description, :pic_url, :url, :app_url, :resource_id, :type, :resource
5
+
6
+ def initialize(args, *resource)
7
+ @title = args['title']
8
+ @description = args['description']
9
+ @pic_url = args['pic_url']
10
+ @url = args['url']
11
+ @app_url = args['app_url']
12
+
13
+
14
+ @resource = resource
15
+ if resource.size > 0
16
+ @type = 'resource'
17
+ @resource_id = args['resource_id']
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ module MinxingRubySdk
2
+ module Ocu
3
+ class ArticleMessage < Message
4
+ attr_accessor :articles
5
+
6
+ def initialize
7
+ @articles = []
8
+ end
9
+
10
+ def body
11
+ size = @articles.size
12
+ if size > 0
13
+ json = '{"article_count":' + size.to_s + ',"articles":['
14
+ for i in 0...size
15
+ if i>0
16
+ json += ','
17
+ end
18
+ json += '{'
19
+ if articles[i].type == 'resource'
20
+ json += resource_article_json(articles[i])
21
+ else
22
+ json += common_article_json(articles[i])
23
+ end
24
+ json += '}'
25
+
26
+ end
27
+ json +=']}'
28
+ end
29
+ json
30
+ end
31
+
32
+ def common_article_json(article)
33
+ json = ""
34
+ json += '"title":"' + article.title + '"' unless article.title.nil?
35
+ json += ',"description":"' + article.description + '"' unless article.description.nil?
36
+ json += ',"pic_url":"' + article.pic_url + '"' unless article.pic_url.nil?
37
+ json += ',"url":"' + article.url + '"' unless article.url.nil?
38
+ json += ',"app_url":"' + article.app_url + '"' unless article.app_url.nil?
39
+ json
40
+ end
41
+ def resource_article_json(article)
42
+ json = ""
43
+ json += '"type":"' + article.type + '"' unless article.type.nil?
44
+ json += ',"resource_id":"' + article.resource_id.to_s + '"' unless article.resource_id.nil?
45
+ json
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,117 @@
1
+
2
+ require 'minxing_ruby_sdk/connection'
3
+ require 'minxing_ruby_sdk/account'
4
+ require 'minxing_ruby_sdk/util/util'
5
+ module MinxingRubySdk
6
+ module Ocu
7
+ TEXT = 0
8
+ ARTICLE = 1
9
+
10
+ class OcuAccount < MinxingRubySdk::Account
11
+
12
+ attr_accessor :root_url, :ocuId, :ocuSecret, :api_prefix, :api_ocu_messages, :api_ocu_resources, :api_user_info
13
+
14
+ def initialize(args={})
15
+ config = YAML.load_file(MinxingRubySdk.root_path + '/settings.yml')
16
+
17
+ defaults = {
18
+ :api_prefix => config['api']['api_prefix'],
19
+ :api_ocu_messages => config['api']['ocu_messages'],
20
+ :api_ocu_resources => config['api']['ocu_resources'],
21
+ :api_user_info => config['api']['user_info']
22
+ }
23
+ args.merge(defaults).each do |attr,val|
24
+ instance_variable_set("@#{attr}", val) unless val.nil?
25
+ end if args
26
+
27
+ init_connection
28
+ end
29
+
30
+ def init_connection
31
+ @connection = MinxingRubySdk::Connection.new @root_url
32
+ @connection.tokenType = 'MAC'
33
+ @connection.token = ''
34
+ end
35
+
36
+ def send_to_post (message, type, *userStr)
37
+ headers = {}
38
+ params = {}
39
+
40
+ save_resource_and_get_id(message) if message.is_a? ArticleMessage
41
+
42
+ params['body'] = message.body
43
+ params['direct_to_user_ids'] = userStr[0] unless userStr.nil?
44
+ params['content_type'] = type
45
+
46
+ url = @root_url + @api_prefix + @api_ocu_messages
47
+
48
+ beforeRequest(url, headers, params)
49
+ post(url, true, headers, params)
50
+ end
51
+
52
+ def beforeRequest(url, headers, params)
53
+ time = Time.new.to_i.to_s
54
+ @connection.token = CGI::escape(@ocuId + ":" + Util.hmac_sha1(url + "?timestamp=" + time, @ocuSecret))
55
+ headers["timestamp"] = time
56
+ end
57
+
58
+ def save_resource_and_get_id(articleMessage)
59
+ url = @root_url + @api_prefix + @api_ocu_resources
60
+ params = {}
61
+ headers = {}
62
+ articles = articleMessage.articles
63
+ if articles.size > 0
64
+ for i in 0...articles.size
65
+ if articles[i].type == 'resource'
66
+ resource = articles[i].resource[0]
67
+ params['title'] = resource.title
68
+ params['sub_title'] = resource.sub_title
69
+ params['author'] = resource.author
70
+ params['create_time'] = resource.create_time
71
+ params['pic_url'] = resource.pic_url
72
+ params['content'] = resource.description
73
+ beforeRequest(url, headers, params)
74
+ response_body = JSON post(url, true, headers, params)
75
+ articles[i].resource_id = response_body['resource_id']
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ def send_message_to_users(message, type, users)
82
+ usersStr = users
83
+ if users.is_a?(Array)
84
+ usersStr = users.join(',')
85
+ end
86
+ send_to_post(message, type, usersStr)
87
+ end
88
+ def send_message_to_public(message, type)
89
+ send_to_post(message, type)
90
+ end
91
+ def check_signature(request,params)
92
+
93
+ if request.get?
94
+ token = MinxingRubySdk::Util.url_param_decode params['token']
95
+ timestamp = MinxingRubySdk::Util.url_param_decode params['timestamp']
96
+ nonce = MinxingRubySdk::Util.url_param_decode params['nonce']
97
+ open_id = MinxingRubySdk::Util.url_param_decode params['open_id']
98
+ elsif request.post?
99
+ token = request.headers['token']
100
+ timestamp = request.headers['timestamp']
101
+ nonce = request.headers['nonce']
102
+ open_id = request.headers['open_id']
103
+ end
104
+ sign = MinxingRubySdk::Util.hmac_sha1(timestamp + nonce, @ocuSecret)
105
+
106
+ open_id if CGI::escape(@ocuId + ":" +sign) == token
107
+ end
108
+ def get_user_info(open_id)
109
+ headers = {}
110
+ params = {}
111
+ url = @root_url + @api_prefix + @api_user_info + "/" + open_id
112
+ beforeRequest(url, headers, params)
113
+ get(url,true,headers,params)
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,16 @@
1
+ module MinxingRubySdk
2
+ module Ocu
3
+ class Resource
4
+ attr_accessor :title, :sub_title, :author, :create_time, :pic_url, :description
5
+
6
+ def initialize(args)
7
+ @title = args['title']
8
+ @sub_title = args['sub_title']
9
+ @author = args['author']
10
+ @create_time = args['create_time']
11
+ @pic_url = args['pic_url']
12
+ @description = args['description']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module MinxingRubySdk
2
+ module Ocu
3
+ class TextMessage < Message
4
+ attr_accessor :body
5
+ def initialize (body)
6
+ @body = body
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module MinxingRubySdk
2
+ module Ocu
3
+ class User
4
+ attr_accessor :email, :cellPhone, :empCode
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ #{\"access_token\":\"110ad26dc04f1fce49415f2a1b966be1\",
2
+ #\"token_type\":\"bearer\",
3
+ #\"expires_in\":2591999,
4
+ #\"refresh_token\":\"4a1d64faa7cddee3b3bc08e55f29f969\",
5
+ #\"default_network_id\":2}"
6
+ module MinxingRubySdk
7
+ class Token
8
+ attr_accessor :access_token, :token_type, :expires_in, :refresh_token, :default_network_id
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module MinxingRubySdk
2
+ module Util
3
+ def self.hmac_sha1(data, secret)
4
+ require 'base64'
5
+ require 'cgi'
6
+ require 'openssl'
7
+ Base64.encode64(OpenSSL::HMAC.digest('sha1',secret, data)).strip!
8
+ end
9
+
10
+ def self.url_param_decode(param)
11
+ param.gsub! '+', '%2b'
12
+ CGI::unescape param
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module MinxingRubySdk
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minxing_ruby_sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "minxing_ruby_sdk"
8
+ spec.version = MinxingRubySdk::VERSION
9
+ spec.authors = ["bsktbl"]
10
+ spec.email = ["bsktbll@qq.com"]
11
+ spec.summary = %q{minxing_ruby_sdk}
12
+ spec.description = %q{minxing_ruby_sdk}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency(%q<faraday>, "~> 0.9.0")
25
+ spec.add_dependency(%q<settingslogic>, "~> 2.0.9")
26
+ spec.add_dependency(%q<json>)
27
+ end
Binary file
data/settings.yml ADDED
@@ -0,0 +1,13 @@
1
+ api:
2
+ api_prefix: /api/v1
3
+ access_token_url: /oauth2/token
4
+ authorize_url: /oauth2/authorize
5
+ from_last_seen: /conversations2/from_last_seen
6
+
7
+ ocu_messages: /conversations/ocu_messages
8
+ ocu_resources: /conversations/ocu_resources
9
+ user_info: /oauth/user_info
10
+ subscriptions_ocus: /subscriptions/ocus
11
+ post_conversations_messages: /conversations/id/messages
12
+
13
+
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe 'login test' do
4
+ before (:all) do
5
+ @test_api_data = YAML.load_file(File.expand_path(File.dirname(__FILE__)+'/test_api_data.yml'))
6
+ @login = MinxingRubySdk::Api::Login.new @test_api_data['root_url']
7
+ @login.get_token_json(@test_api_data)
8
+ end
9
+
10
+ it 'send messages to conversation' do
11
+ i = 0
12
+ while i < 50 do
13
+ sleep 0.2
14
+ i = i + 1
15
+ @login.post_conversations_messages('469',"1111conversation_body #{i}")
16
+ end
17
+ end
18
+ # it 'login to system by login_name/password' do
19
+ # @token_json = @login.get_token_json(@test_api_data)
20
+ # expect(@token_json['token_type']).to eq 'bearer'
21
+ # end
22
+
23
+ # it 'call from_last_seen' do
24
+ # from_last_seen = @login.from_last_seen
25
+ # expect(from_last_seen.has_key?('items')).to be_truthy
26
+ # end
27
+
28
+ # it 'subscribe 23 友情链接' do
29
+ # @login.subscriptions_ocus '22'
30
+ # end
31
+ # it 'subscribe 24 CRM' do
32
+ # @login.subscriptions_ocus '24'
33
+ # end
34
+ # it 'subscribe 42 政务动态' do
35
+ # @login.subscriptions_ocus '42'
36
+ # end
37
+ # it 'subscribe 43 党建信息' do
38
+ # @login.subscriptions_ocus '43'
39
+ # end
40
+ # it 'subscribe 44 党刊精品' do
41
+ # @login.subscriptions_ocus '44'
42
+ # end
43
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'test article ocu' do
4
+ before (:all) do
5
+ @test_data = YAML.load_file(File.expand_path(File.dirname(__FILE__)+'/test_ocu_data.yml'))
6
+ @to_users = @test_data['to_users']
7
+ @ocu = MinxingRubySdk::Ocu::OcuAccount.new ({:root_url => @test_data['root_url'], :ocuId => @test_data['ocuId'], :ocuSecret =>@test_data['ocuSecret']})
8
+ end
9
+
10
+
11
+ it 'test POST /api/v1/conversations/ocu_messages, send a articlemessage to users.' do
12
+ articles = @test_data['articles']
13
+ articlemessage = MinxingRubySdk::Ocu::ArticleMessage.new
14
+ for i in 0...articles.size
15
+ args={}
16
+ args['title'] = articles[i]['title']
17
+ args['description'] = articles[i]['description']
18
+ args['pic_url'] = articles[i]['pic_url']
19
+ args['url'] = articles[i]['url']
20
+ args['app_url'] = articles[i]['app_url']
21
+
22
+ article = MinxingRubySdk::Ocu::Article.new(args)
23
+ articlemessage.articles[i] = article
24
+ end
25
+
26
+ # @ocu.send_message_to_users(articlemessage, MinxingRubySdk::Ocu::ARTICLE, @to_users)
27
+ @ocu.send_message_to_public(articlemessage, MinxingRubySdk::Ocu::ARTICLE)
28
+ MinxingRubySdk::LOGGER.debug("sended ok: " + articles.size.to_s)
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'test resource ocu' do
4
+ before (:all) do
5
+ @test_data = YAML.load_file(File.expand_path(File.dirname(__FILE__)+'/test_ocu_data.yml'))
6
+ @to_users = @test_data['to_users']
7
+ @ocu = MinxingRubySdk::Ocu::OcuAccount.new ({:root_url => @test_data['root_url'], :ocuId => @test_data['ocuId'], :ocuSecret =>@test_data['ocuSecret']})
8
+ end
9
+
10
+ it 'test POST /api/v1/conversations/ocu_messages, send a article resource message to users.' do
11
+ resources = @test_data['resources']
12
+ articlemessage = MinxingRubySdk::Ocu::ArticleMessage.new
13
+ for i in 0...resources.size
14
+ args = {}
15
+ args['title'] = resources[i]['title']
16
+ args['sub_title'] = resources[i]['sub_title']
17
+ args['author'] = resources[i]['author']
18
+ args['create_time'] = resources[i]['create_time']
19
+ args['pic_url'] = resources[i]['pic_url']
20
+ args['description'] = resources[i]['description']
21
+ resource = MinxingRubySdk::Ocu::Resource.new(args)
22
+ article = MinxingRubySdk::Ocu::Article.new({}, resource)
23
+ articlemessage.articles[i] = article
24
+ end
25
+
26
+ @ocu.send_message_to_users(articlemessage, MinxingRubySdk::Ocu::ARTICLE, @to_users)
27
+ # @ocu.send_message_to_public(articlemessage, MinxingRubySdk::Ocu::ARTICLE)
28
+ MinxingRubySdk::LOGGER.debug("sended ok: " + resources.size.to_s)
29
+ end
30
+
31
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'test test ocu' do
4
+
5
+ before (:all) do
6
+ @test_data = YAML.load_file(File.expand_path(File.dirname(__FILE__)+'/test_ocu_data.yml'))
7
+ @to_users = @test_data['to_users']
8
+ @ocu = MinxingRubySdk::Ocu::OcuAccount.new ({:root_url => @test_data['root_url'], :ocuId => @test_data['ocuId'], :ocuSecret =>@test_data['ocuSecret']})
9
+ end
10
+
11
+ it 'test POST /api/v1/conversations/ocu_messages, send a textmessage to users. ' do
12
+ @body = @test_data['textmessage']['body']
13
+ message = MinxingRubySdk::Ocu::TextMessage.new @body
14
+ @ocu.send_message_to_users(message, MinxingRubySdk::Ocu::TEXT, @to_users)
15
+ # @ocu.send_message_to_public(message,MinxingRubySdk::Ocu::TEXT)
16
+ MinxingRubySdk::LOGGER.debug("sended ok: 1")
17
+ end
18
+
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'rspec'
2
+ require 'pry'
3
+ require 'json'
4
+ require 'yaml'
5
+ # $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib','sdk'))
8
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib','sdk', 'module'))
9
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib','sdk', 'ocu'))
10
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib','sdk', 'util'))
11
+
12
+ Dir[File.join(File.dirname(__FILE__),'../lib/*.rb')].each{|f| require f}
13
+ Dir[File.join(File.dirname(__FILE__),'../lib/minxing_ruby_sdk/*.rb')].each{|f| require f}
14
+ Dir[File.join(File.dirname(__FILE__),'../lib/minxing_ruby_sdk/component/*.rb')].each{|f| require f}
15
+ Dir[File.join(File.dirname(__FILE__),'../lib/minxing_ruby_sdk/ocu/*.rb')].each{|f| require f}
16
+ Dir[File.join(File.dirname(__FILE__),'../lib/minxing_ruby_sdk/util/*.rb')].each{|f| require f}
17
+ Dir[File.join(File.dirname(__FILE__),'../lib/minxing_ruby_sdk/api/*.rb')].each{|f| require f}
18
+
19
+ Dir[File.join(File.dirname(__FILE__),'support/*.rb')].each{|f| require f}
20
+
21
+
22
+
23
+ RSpec.configure do |config|
24
+ config.include LoginMacros
25
+ config.include ConnectionMacros
26
+ end
@@ -0,0 +1,5 @@
1
+ module ConnectionMacros
2
+ def get_connection
3
+ MinxingRubySdk::Connection.new
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module LoginMacros
2
+ def set_user_access_token (access_token)
3
+ access_token
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ root_url: http://intg.dehuinet.com:8060
2
+ login_name: 1033
3
+ password: 111111
4
+ grant_type: password
5
+ app_id: 1001
6
+ app_secret: 2440ddcaf784ef540fc78433cda5ed26
@@ -0,0 +1,57 @@
1
+ root_url: http://192.168.200.242:3000
2
+ ocuId: 9d563bcaea630ffa3e294edfdc133d18
3
+ ocuSecret: 4aa1892f68215c0a8331907de1f5ce6f
4
+ to_users:
5
+ - admin@t.cn
6
+ textmessage:
7
+ body: testbody
8
+ articles:
9
+ - title: 1我国月户均移动互联网接入流量
10
+ description: 1月户均移动互联网接入流量超130M
11
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
12
+ url: http://ocu.dehuinet.com:8029/mx-test4dev/ocu/microsoft.html
13
+ app_url:
14
+
15
+ - title: 2月户均移动互联网接入流量
16
+ description: 2均移动互联网接入流量超130M
17
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
18
+ url: http://ocu.dehuinet.com:8029/mx-test4dev/ocu/microsoft.html
19
+ app_url:
20
+
21
+ - title: 3月户均移动互联网接入流量
22
+ description: 3均移动互联网接入流量超130M
23
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
24
+ url: http://ocu.dehuinet.com:8029/mx-test4dev/ocu/microsoft.html
25
+ app_url:
26
+
27
+ - title: 4月户均移动互联网接入流量
28
+ description: 4均移动互联网接入流量超130M
29
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
30
+ url: http://ocu.dehuinet.com:8029/mx-test4dev/ocu/microsoft.html
31
+ app_url:
32
+ resources:
33
+ - title: 1康师傅没了
34
+ sub_title: 1大老虎
35
+ author: 1大苍蝇
36
+ create_time: 2013-3-4
37
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
38
+ description: 1月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M
39
+ - title: 2康师傅没了
40
+ sub_title: 2大老虎
41
+ author: 2大苍蝇
42
+ create_time: 2013-3-4
43
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
44
+ description: 2月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M
45
+ - title: 3康师傅没了
46
+ sub_title: 3大老虎
47
+ author: 3大苍蝇
48
+ create_time: 2013-3-4
49
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
50
+ description: 3月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M
51
+ - title: 4康师傅没了
52
+ sub_title: 4大老虎
53
+ author: 4大苍蝇
54
+ create_time: 2013-3-4
55
+ pic_url: http://ocu.dehuinet.com:8029/mx-test4dev/image/microsoft.jpg
56
+ description: 4月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M月户均移动互联网接入流量超130M
57
+
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minxing_ruby_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - bsktbl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: settingslogic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.9
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.9
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: minxing_ruby_sdk
84
+ email:
85
+ - bsktbll@qq.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/minxing_ruby_sdk.rb
96
+ - lib/minxing_ruby_sdk/account.rb
97
+ - lib/minxing_ruby_sdk/api/login.rb
98
+ - lib/minxing_ruby_sdk/component/post_parameter.rb
99
+ - lib/minxing_ruby_sdk/connection.rb
100
+ - lib/minxing_ruby_sdk/helper.rb
101
+ - lib/minxing_ruby_sdk/message.rb
102
+ - lib/minxing_ruby_sdk/ocu/article.rb
103
+ - lib/minxing_ruby_sdk/ocu/article_message.rb
104
+ - lib/minxing_ruby_sdk/ocu/ocu_account.rb
105
+ - lib/minxing_ruby_sdk/ocu/resource.rb
106
+ - lib/minxing_ruby_sdk/ocu/text_message.rb
107
+ - lib/minxing_ruby_sdk/ocu/user.rb
108
+ - lib/minxing_ruby_sdk/token.rb
109
+ - lib/minxing_ruby_sdk/util/util.rb
110
+ - lib/minxing_ruby_sdk/version.rb
111
+ - minxing_ruby_sdk.gemspec
112
+ - pkg/minxing_ruby_sdk-0.0.1.gem
113
+ - settings.yml
114
+ - spec/login_spec.rb
115
+ - spec/ocu_article_spec.rb
116
+ - spec/ocu_resource_spec.rb
117
+ - spec/ocu_text_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/support/connection_macros.rb
120
+ - spec/support/login_macros.rb
121
+ - spec/test_api_data.yml
122
+ - spec/test_ocu_data.yml
123
+ homepage: ''
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.8
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: minxing_ruby_sdk
147
+ test_files:
148
+ - spec/login_spec.rb
149
+ - spec/ocu_article_spec.rb
150
+ - spec/ocu_resource_spec.rb
151
+ - spec/ocu_text_spec.rb
152
+ - spec/spec_helper.rb
153
+ - spec/support/connection_macros.rb
154
+ - spec/support/login_macros.rb
155
+ - spec/test_api_data.yml
156
+ - spec/test_ocu_data.yml
157
+ has_rdoc: