twiddla 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -0
- data/lib/twiddla.rb +1 -0
- data/lib/twiddla/api.rb +61 -0
- data/lib/twiddla/base.rb +9 -0
- data/lib/twiddla/version.rb +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/twiddla_spec.rb +60 -0
- data/twiddla.gemspec +22 -0
- metadata +71 -0
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
Twiddla
|
2
|
+
## Installation
|
3
|
+
|
4
|
+
http://rubygems.org/gems/twiddla
|
5
|
+
|
6
|
+
gem install twiddla
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Set up API key
|
11
|
+
|
12
|
+
require 'twiddla'
|
13
|
+
Twiddla.auth!('username', 'password') # set your own API key here
|
14
|
+
|
15
|
+
Create user
|
16
|
+
|
17
|
+
options = {
|
18
|
+
newusername: 'john_doe',
|
19
|
+
newpassword: 'password',
|
20
|
+
displayname: 'John Doe'
|
21
|
+
}
|
22
|
+
user_name = Twiddla::API.create_user(options)
|
23
|
+
|
24
|
+
Create meeting
|
25
|
+
|
26
|
+
options = { meetingtitle: 'Title', meetingpassword: 'password' }
|
27
|
+
session_id = Twiddla::API.create_meeting(options)
|
28
|
+
|
29
|
+
Embeddable meeting url
|
30
|
+
|
31
|
+
meeting_url = Twiddla::API.meeting_url(session_id)
|
32
|
+
|
33
|
+
List active meetings
|
34
|
+
|
35
|
+
meetings = Twiddla::API.active_meetings
|
36
|
+
|
37
|
+
List snapshots
|
38
|
+
|
39
|
+
snapshots = Twiddla::API.snapshots
|
40
|
+
|
41
|
+
Delete meeting
|
42
|
+
|
43
|
+
Twiddla::API.delete(session_id)
|
44
|
+
|
45
|
+
## Twiddla API References
|
46
|
+
|
47
|
+
http://www.twiddla.com/API/Reference.aspx
|
data/lib/twiddla.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'twiddla/base'
|
data/lib/twiddla/api.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Twiddla
|
2
|
+
class API
|
3
|
+
class << self
|
4
|
+
attr_accessor :username, :password
|
5
|
+
|
6
|
+
def create_user(options)
|
7
|
+
api_call('CreateUser', options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_meeting(options={})
|
11
|
+
call('new', options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def meeting_url(session_id, options = {})
|
15
|
+
params = { sessionid: session_id }.merge(options)
|
16
|
+
"#{twiddla_url('api/Start')}?#{URI.encode_www_form(params)}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def active_meetings
|
20
|
+
api_call('ListActive').split(',')
|
21
|
+
end
|
22
|
+
|
23
|
+
def snapshots(session_id = nil)
|
24
|
+
params = session_id ? { sessionid: session_id } : {}
|
25
|
+
api_call('ListSnapshots', params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_meeting(session_id)
|
29
|
+
api_call('DeleteSession', { sessionid: session_id })
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def api_call(path, params = {})
|
35
|
+
call("api/#{path}", params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def call(path, params = {})
|
39
|
+
uri = URI.parse(twiddla_url(path))
|
40
|
+
response = Net::HTTP.post_form(uri, auth_params.merge(params))
|
41
|
+
check_for_errors_and_return response.body.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def twiddla_url(path)
|
45
|
+
"http://www.twiddla.com/#{path}.aspx"
|
46
|
+
end
|
47
|
+
|
48
|
+
def auth_params
|
49
|
+
{ username: username, password: password }
|
50
|
+
end
|
51
|
+
|
52
|
+
LEADING_NEGATIVE_INTEGER = /-\d/
|
53
|
+
def check_for_errors_and_return(response_body)
|
54
|
+
raise APIError.new(response_body) if response_body.match(LEADING_NEGATIVE_INTEGER)
|
55
|
+
response_body
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Twiddla::APIError < Exception; end
|
61
|
+
end
|
data/lib/twiddla/base.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Twiddla::API do
|
4
|
+
before :each do
|
5
|
+
Twiddla.auth!('username', 'password')
|
6
|
+
@response = mock()
|
7
|
+
@response.stub(:body).and_return('')
|
8
|
+
Net::HTTP.stub(:post_form).and_return(@response)
|
9
|
+
@session_id = rand(1000)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.create_user' do
|
13
|
+
it 'calls "CreateUser"' do
|
14
|
+
options = {
|
15
|
+
newusername: 'foo',
|
16
|
+
newpassword: 'bar',
|
17
|
+
displayname: 'foo bar',
|
18
|
+
email: 'foo@example.com',
|
19
|
+
}
|
20
|
+
Twiddla::API.should_receive(:api_call).with('CreateUser', options).and_return(options[:displayname])
|
21
|
+
Twiddla::API.create_user(options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.create_meeting' do
|
26
|
+
it 'calls "new"' do
|
27
|
+
Twiddla::API.should_receive(:call).with('new', {}).and_return(@session_id)
|
28
|
+
Twiddla::API.create_meeting
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.meeting_url' do
|
33
|
+
it 'creates embeddable url' do
|
34
|
+
regex = /api\/Start\.aspx\?sessionid=#{@session_id}$/
|
35
|
+
Twiddla::API.meeting_url(@session_id).should match(regex)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.active_meetings' do
|
40
|
+
it 'calls "ListActive"' do
|
41
|
+
session_ids = [@session_id, @session_id + 1].map(&:to_s)
|
42
|
+
Twiddla::API.should_receive(:api_call).with('ListActive').and_return(session_ids.join(','))
|
43
|
+
Twiddla::API.active_meetings.should == session_ids
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.snapshots' do
|
48
|
+
it 'calls "ListSnapshots"' do
|
49
|
+
Twiddla::API.should_receive(:call).with('api/ListSnapshots', { sessionid: @session_id })
|
50
|
+
Twiddla::API.snapshots(@session_id)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.delete_meeting' do
|
55
|
+
it 'calls "DeleteSession"' do
|
56
|
+
Twiddla::API.should_receive(:call).with('api/DeleteSession', { sessionid: @session_id }).and_return('1')
|
57
|
+
Twiddla::API.delete_meeting(@session_id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/twiddla.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "twiddla/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "twiddla"
|
7
|
+
s.version = Twiddla::VERSION
|
8
|
+
s.date = "2013-02-17"
|
9
|
+
s.authors = ["Hwan-Joon Choi"]
|
10
|
+
s.email = ["hc5duke@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/hc5duke/twiddla"
|
12
|
+
|
13
|
+
s.summary = "Twiddla API ruby wrapper."
|
14
|
+
s.description = "Twiddla API in ruby."
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec", "~>2.5"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twiddla
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hwan-Joon Choi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.5'
|
30
|
+
description: Twiddla API in ruby.
|
31
|
+
email:
|
32
|
+
- hc5duke@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- README.md
|
38
|
+
- lib/twiddla.rb
|
39
|
+
- lib/twiddla/api.rb
|
40
|
+
- lib/twiddla/base.rb
|
41
|
+
- lib/twiddla/version.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- spec/twiddla_spec.rb
|
44
|
+
- twiddla.gemspec
|
45
|
+
homepage: https://github.com/hc5duke/twiddla
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Twiddla API ruby wrapper.
|
69
|
+
test_files:
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
- spec/twiddla_spec.rb
|