gensee 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 629ab6dea129507b506155bfb1817682beb048ae
4
+ data.tar.gz: 7274e69ae6b15227f75396e1eec1d3f25097e384
5
+ SHA512:
6
+ metadata.gz: 81ed3069aab3d3787c2520ebdb716f131c4afecde94a7a585b22e04a7e57fe1dc6cbbd1c43b97cdc5eff8a2a40ddcf90586bd715aa7dfbfe65cf9eb3efd7c833
7
+ data.tar.gz: 88dc378c2719a0c9bfdf80671e23669af6340b2a0651ca18f2040f01f19bce9d7c85e6311e3fc6bcca9ad53fed13377da29a461aa45b2a62657bce9071e5285a
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gensee.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuan He
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.
@@ -0,0 +1,63 @@
1
+ # Gensee
2
+
3
+ Gensee is Ruby wrapper for [Gensee API](http://www.gensee.com/document-technical.php),
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gensee'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gensee
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # Provide authentication credentials
25
+ Gensee.configure do |c|
26
+ c.endpoint = 'http://yoursubdomain.gensee.com'
27
+ c.login = 'loginname'
28
+ c.password = 'yourpassword'
29
+ end
30
+
31
+ # Create classroom
32
+ classroom = Gensee.client.create_classroom('AWESOME CLASSROOM', Time.now, rand(100_000..200_000), rand(100_000..2000_000))
33
+ puts classroom[:student_join_url] # http://youdomain.gensee.com/training/site/s/{classroom_number}
34
+ puts classroom[:teacher_join_url] # http://youdomain.gensee.com/training/site/s/{classroom_number}
35
+ puts classroom[:number] # 34154643
36
+ puts classroom[:id] # mquQf2
37
+ ```
38
+
39
+ or
40
+
41
+ ```ruby
42
+ # Provide authentication credentials
43
+ client = Gensee::Client.new(endpoint: 'http://yoursubdomain.gensee.com', login: 'gensee@username', password: 'yourpassword')
44
+ # create classroom
45
+ classroom = client.create_classroom('AWESOME CLASSROOM', Time.now, rand(100_000..200_000), rand(100_000..2000_000))
46
+ puts classroom[:student_join_url] # http://youdomain.gensee.com/training/site/s/{classroom_number}
47
+ puts classroom[:teacher_join_url] # http://youdomain.gensee.com/training/site/s/{classroom_number}
48
+ puts classroom[:number] # 34154643
49
+ puts classroom[:id] # mquQf2
50
+ ```
51
+
52
+ ## Testing
53
+
54
+ $export GENSEE_ENDPOINT='http://yoursubdomain.gensee.com' GENSEE_LOGIN=loginname GENSEE_PASSWORD=somelooogpassword
55
+ $ rake
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/[my-github-username]/gensee/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gensee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gensee'
8
+ spec.version = Gensee::VERSION
9
+ spec.authors = ['Yuan He']
10
+ spec.email = ['yuan@liulishuo.com']
11
+ spec.summary = %q{A Gensee API Wrapper in Ruby}
12
+ spec.description = %q{Using Gensee JSON API easily}
13
+ spec.homepage = 'https://git.llsapp.com/yuan/gensee/tree/master'
14
+ spec.license = 'MIT'
15
+
16
+ spec.add_runtime_dependency 'faraday', '~> 0.9'
17
+ spec.add_runtime_dependency 'oj', '~> 2.11'
18
+ spec.add_runtime_dependency 'activesupport', '~> 3.1'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.7'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.1'
28
+ spec.add_development_dependency 'pry', '~> 0.10'
29
+ end
@@ -0,0 +1,15 @@
1
+ require 'gensee/version'
2
+ require 'gensee/client'
3
+
4
+ module Gensee
5
+
6
+ class << self
7
+ include Gensee::Configurable
8
+
9
+ # @return [Gensee::Client] Gensee API Wrapper client
10
+ def client
11
+ @client = Gensee::Client.new(options)
12
+ @client
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,75 @@
1
+ require 'faraday'
2
+ require 'digest'
3
+ require 'oj'
4
+ require 'active_support/core_ext/string'
5
+ require 'active_support/core_ext/hash'
6
+ require 'gensee/client/training'
7
+ require 'gensee/configurable'
8
+
9
+ module Gensee
10
+ # Client for Gensee API
11
+ #
12
+ # @see http://www.gensee.com/document-technical.php
13
+ # @params: uri [String], the URI/endpoint which Gensee created for you
14
+ # username [String], Your Gensee login in name. might be an email address
15
+ # password [String], Your Gensee password
16
+ class Client
17
+ include Gensee::Client::Training
18
+
19
+ def initialize(options = {})
20
+ opts = options.dup
21
+ @endpoint = opts[:endpoint].start_with?('http://') ? opts[:endpoint] : "http://#{opts[:endpoint]}"
22
+ @username = opts[:login]
23
+ @password = Digest::MD5.hexdigest(opts[:password])
24
+ end
25
+
26
+ def default_options
27
+ { loginName: @username, password: @password, sec: 'true' }
28
+ end
29
+
30
+ def app_client
31
+ @client ||= Faraday.new(@endpoint) do |conn|
32
+ conn.params = default_options
33
+ conn.headers = {
34
+ content_type: 'application/json',
35
+ user_agent: Gensee::Configurable.user_agent
36
+ }
37
+ conn.request :url_encoded
38
+ # conn.response :logger
39
+ conn.adapter Faraday.default_adapter
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def request(method, path, params)
46
+ resp = app_client.send(method, path, params)
47
+ convert_result(resp)
48
+ end
49
+
50
+ %w(get post).each do |m|
51
+ define_method m do |path, params|
52
+ request(m, path, params)
53
+ end
54
+ end
55
+
56
+ ## Helper methods
57
+ def preform_path(path)
58
+ "/integration/site/#{path}"
59
+ end
60
+
61
+ def time_to_ms(time)
62
+ (time.to_f * 1000).to_i
63
+ end
64
+
65
+ def convert_result(resp)
66
+ if resp.success?
67
+ h = Oj.load(resp.body)
68
+ ary = h.inject([]) { |r, (k, v)| r << [k.to_s.underscore, v] }
69
+ Hash[ary].with_indifferent_access
70
+ else
71
+ resp
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,75 @@
1
+ module Gensee
2
+ class Client
3
+ # Gensee Training API
4
+ # @see http://www.gensee.com/document-technical.php
5
+ module Training
6
+ ##-------------------- CLASSROOM --------------------##
7
+ # Create an Training classroom
8
+ # @params: subject [String] *required*: classroom name/subject
9
+ # start_date [DateTime] *required*: Time which classroom will open.
10
+ # teacher_token [String/Integer] *required*: teacher token to login classroom(length: 6~15)
11
+ # assistant_token [String/Integer] *required*: assistant token to login classroom
12
+ # @notice subject is an unique field
13
+ # teacher_token and assistant_token should NOT be same value
14
+ def create_classroom(subject, start_date, teacher_token, assistant_token, options = {})
15
+ params = options.dup
16
+ params[:subject] = subject
17
+ params[:startDate] = time_to_ms(start_date)
18
+ params.merge!(teacherToken: teacher_token.to_s, assistantToken: assistant_token.to_s)
19
+ get preform_path('training/room/created'), params
20
+ end
21
+
22
+ # Modify Training classroom info
23
+ # @params: id [String] *required*: classroom id
24
+ def modify_classroom(id, subject, start_date, teacher_token, assistant_token, options = {})
25
+ params = options.dup
26
+ params[:id] = id
27
+ params[:subject] = subject
28
+ params[:startDate] = time_to_ms(start_date)
29
+ params.merge!(teacherToken: teacher_token.to_s, assistantToken: assistant_token.to_s)
30
+ get preform_path('training/room/modify'), params
31
+ end
32
+
33
+ def delete_classroom(room_id)
34
+ get preform_path('training/room/deleted'), roomId: room_id
35
+ end
36
+
37
+ def classroom_info(room_id)
38
+ get preform_path('training/room/info'), roomId: room_id
39
+ end
40
+
41
+ ##-------------------- COURSEWARE --------------------##
42
+
43
+ # List all classrooms courseware
44
+ def courseware_list(room_id)
45
+ get preform_path('training/courseware/list'), roomId: room_id
46
+ end
47
+
48
+ def courseware_info(id)
49
+ get preform_path('training/courseware/info'), coursewareId: id
50
+ end
51
+
52
+ # Modify courseware
53
+ # @params id [String]: courseware ID
54
+ def modify_courseware(id, subject, options = {})
55
+ params= options.dup
56
+ get preform_path('training/courseware/modify'), params.merge!(id: id, subject: subject)
57
+ end
58
+
59
+ def delete_courseware(id)
60
+ get preform_path('training/courseware/deleted'), coursewareId: id
61
+ end
62
+
63
+ ##-------------------- TEACHER --------------------##
64
+
65
+ # Register a teacher
66
+ # @params login [String]: teacher login name(email/mobile) (length: 1~40)
67
+ # password [String]: teacher login password (length: 6~15)
68
+ # name [String]: teacher name, (length: 1-40)
69
+ def create_teacher(name, login, password)
70
+ params = { name: name, teacherLoginName: login, teacherPassword: password }
71
+ get preform_path('training/teacher/created'), params
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,38 @@
1
+ module Gensee
2
+ module Configurable
3
+ attr_accessor :endpoint, :login, :password
4
+
5
+ class << self
6
+ USER_AGENT = "Gensee Ruby Gem #{Gensee::VERSION}".freeze
7
+ # List all keys
8
+ # @return [Array]
9
+ def keys
10
+ @keys ||= [:endpoint, :login, :password]
11
+ end
12
+
13
+ def default_options
14
+ {
15
+ endpoint: ENV['GENSEE_ENDPOINT'],
16
+ login: ENV['GENSEE_LOGIN'],
17
+ password: ENV['GENSEE_PASSWORD']
18
+ }
19
+ end
20
+
21
+ def user_agent
22
+ ENV['GENSEE_USER_AGENT'] || USER_AGENT
23
+ end
24
+ end
25
+
26
+ def options
27
+ ary = Gensee::Configurable.keys.map do |key|
28
+ [key, send(key) || Gensee::Configurable.default_options[key]]
29
+ end
30
+ Hash[ary]
31
+ end
32
+
33
+ # Set configuration options using a block
34
+ def configure
35
+ yield self
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Gensee
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gensee::Client::Training do
4
+ ## NOTICE: Below tests need a read Gensee account,
5
+ ## please set then var ENV, for example:
6
+ ## export GENSEE_ENDPOINT='http://yoursubdomain.gensee.com' GENSEE_LOGIN='loginname' GENSEE_PASSWORD='somelooogpassword'
7
+
8
+ let(:client) { Gensee.client }
9
+ let(:classroom) { client.create_classroom("[TEST] a funny topic #{rand(100)}", Time.now, rand(100_000..200_000).to_s, rand(100_000..200_000).to_s) }
10
+ context 'classroom' do
11
+ after(:each) do
12
+ expect(client.delete_classroom(classroom[:id])[:code]).to eq '0'
13
+ end
14
+
15
+ it 'create' do
16
+ expect(classroom).to be_kind_of Hash
17
+ expect(classroom[:code]).to eq '0'
18
+ end
19
+
20
+ it 'modify and delete' do
21
+ new_subject = '[Test] NEW classroom subject'
22
+ t = Time.now + 600 * 60
23
+ room = client.modify_classroom(classroom[:id], new_subject, t, classroom[:teacher_token], classroom[:assistant_token])
24
+ expect(room[:code]).to eq '0'
25
+ end
26
+
27
+ it 'query and delete' do
28
+ info = client.classroom_info(classroom[:id])
29
+ expect(info[:id]).to eq info[:id]
30
+ end
31
+ end
32
+
33
+ context 'classware' do
34
+ it 'should list all' do
35
+ list = client.courseware_list classroom[:id]
36
+ expect(list[:code]).to eq '0'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gensee::Client do
4
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gensee::Configurable do
4
+ let(:uri) { 'http://www.example.com' }
5
+ let(:login) { 'username' }
6
+ let(:password) { 'password' }
7
+
8
+ it '.configure' do
9
+ Gensee.configure do |c|
10
+ c.endpoint = uri
11
+ c.login = login
12
+ c.password = password
13
+ end
14
+ expect(Gensee.options).to be_kind_of Hash
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gensee do
4
+ let(:uri) { 'http://example.gensee.com' }
5
+ let(:uri_without_schema) { 'example.gensee.com' }
6
+
7
+ context '.client' do
8
+
9
+ before(:all) do
10
+ Gensee.configure do |c|
11
+ c.endpoint = 'http://example.gensee.com'
12
+ c.login = 'hello'
13
+ c.password = 'hello'
14
+ end
15
+ end
16
+
17
+ it 'should accept as uri without schema' do
18
+ @client = Gensee.client
19
+ expect(@client.app_client.build_url.to_s).to match %r{http://}
20
+ end
21
+
22
+ it 'create an Gensee::Client' do
23
+ expect(Gensee.client).to be_kind_of Gensee::Client
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+ require 'gensee'
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |expectations|
7
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gensee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuan He
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ description: Using Gensee JSON API easily
112
+ email:
113
+ - yuan@liulishuo.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - gensee.gemspec
125
+ - lib/gensee.rb
126
+ - lib/gensee/client.rb
127
+ - lib/gensee/client/training.rb
128
+ - lib/gensee/configurable.rb
129
+ - lib/gensee/version.rb
130
+ - spec/gensee/client/training_spec.rb
131
+ - spec/gensee/client_spec.rb
132
+ - spec/gensee/configurable_spec.rb
133
+ - spec/gensee_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: https://git.llsapp.com/yuan/gensee/tree/master
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.2.2
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: A Gensee API Wrapper in Ruby
159
+ test_files:
160
+ - spec/gensee/client/training_spec.rb
161
+ - spec/gensee/client_spec.rb
162
+ - spec/gensee/configurable_spec.rb
163
+ - spec/gensee_spec.rb
164
+ - spec/spec_helper.rb
165
+ has_rdoc: