gridspace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gridspace.gemspec +34 -0
- data/lib/gridspace/capability.rb +74 -0
- data/lib/gridspace/commands.rb +81 -0
- data/lib/gridspace/gridspace.rb +20 -0
- data/lib/gridspace/version.rb +3 -0
- data/lib/gridspace.rb +8 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2fe50bf83a2edd12b4dfc7983fa4d090aab27133
|
4
|
+
data.tar.gz: dbd67387e01074068bf04276a1e90cb99de99364
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d645017263619c6ce36e9b16e3e574d7e72b6f8913a886dfaf524c6fc27f1bc11957e1cc707548b7a0b234ecc9a579c0188eab8519d689158068ebb5ee2663fd
|
7
|
+
data.tar.gz: 703a182c79ff94408bee918536e506a6179411bab2375de1f76878163360d7f325ee71ec188b089d128296ef59345a8c2608c4f7cb06fa055e97fe1bc1488f37
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Gridspace
|
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/gridspace`. 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 'gridspace'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gridspace
|
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 `rake spec` to run the tests. You can also 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`, which will 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
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gridspace.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gridspace"
|
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
data/gridspace.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gridspace/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gridspace"
|
8
|
+
spec.version = Gridspace::VERSION
|
9
|
+
spec.authors = ["Gridspace"]
|
10
|
+
spec.email = ["inquiries@gridspace.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Ruby client library to access the Gridspace API.}
|
13
|
+
spec.homepage = "https://www.gridspace.com/"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = "none"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency "httparty"
|
29
|
+
spec.add_dependency "jwt"
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'jwt'
|
2
|
+
|
3
|
+
module Gridspace
|
4
|
+
module Util
|
5
|
+
def url_encode(hash)
|
6
|
+
hash.to_a.map {|p| p.map {|e| CGI.escape get_string(e)}.join '='}.join '&'
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_string(obj)
|
10
|
+
if obj.respond_to?(:strftime)
|
11
|
+
obj.strftime('%Y-%m-%d')
|
12
|
+
else
|
13
|
+
obj.to_s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Capability
|
18
|
+
include Gridspace::Util
|
19
|
+
|
20
|
+
def initialize(account_sid, auth_token)
|
21
|
+
@account_sid = account_sid
|
22
|
+
@auth_token = auth_token
|
23
|
+
if @account_sid.nil? || @auth_token.nil?
|
24
|
+
raise ArgumentError, 'Account SID and auth token are required'
|
25
|
+
end
|
26
|
+
@capabilities = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def allow_client_incoming(client_name)
|
30
|
+
@client_name = client_name # stash for use in outgoing
|
31
|
+
scope_params = { 'clientName' => client_name }
|
32
|
+
@capabilities << scope_uri_for('client', 'incoming', scope_params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def allow_client_outgoing(app_sid, params = {})
|
36
|
+
@allow_client_outgoing = true
|
37
|
+
@outgoing_scope_params = { 'appSid' => app_sid }
|
38
|
+
unless params.empty?
|
39
|
+
@outgoing_scope_params['appParams'] = url_encode params
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def allow_event_stream(filters = {})
|
44
|
+
scope_params = { 'path' => '/2010-04-01/Events' }
|
45
|
+
scope_params['params'] = filters unless filters.empty?
|
46
|
+
@capabilities << scope_uri_for('stream', 'subscribe', scope_params)
|
47
|
+
end
|
48
|
+
|
49
|
+
def scope_uri_for(service, privilege, params = {})
|
50
|
+
scope_uri = "scope:#{service}:#{privilege}"
|
51
|
+
scope_uri << "?#{url_encode(params)}" unless params.empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate(ttl = 3600)
|
55
|
+
capabilities = @capabilities.clone # we need a local copy to work on
|
56
|
+
|
57
|
+
# build the outgoing scope lazily so that we can use @client_name
|
58
|
+
if @allow_client_outgoing
|
59
|
+
params = @outgoing_scope_params
|
60
|
+
params.merge!('clientName' => @client_name) if @client_name
|
61
|
+
capabilities << scope_uri_for('client', 'outgoing', params)
|
62
|
+
end
|
63
|
+
|
64
|
+
payload = {
|
65
|
+
'scope' => capabilities.join(' '),
|
66
|
+
'iss' => @account_sid,
|
67
|
+
'exp' => (Time.now.to_i + ttl),
|
68
|
+
}
|
69
|
+
|
70
|
+
JWT.encode payload, @auth_token
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Gridspace
|
2
|
+
class JSONable
|
3
|
+
def to_json options = nil
|
4
|
+
hash = {}
|
5
|
+
self.instance_variables.each do |var|
|
6
|
+
# remove @
|
7
|
+
base = var[1..-1]
|
8
|
+
hash[base] = self.instance_variable_get(var)
|
9
|
+
end
|
10
|
+
hash.to_json
|
11
|
+
end
|
12
|
+
def from_json! string
|
13
|
+
JSON.load(string).each do |var, val|
|
14
|
+
self.instance_variable_set var, val
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class BaseCommand < JSONable
|
20
|
+
def class_name
|
21
|
+
self.class.name.split('::').last
|
22
|
+
end
|
23
|
+
def to_json options = nil
|
24
|
+
@name = class_name()
|
25
|
+
super(options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Play < BaseCommand
|
30
|
+
attr_accessor :sound
|
31
|
+
def initialize sound
|
32
|
+
@sound = sound
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Say < BaseCommand
|
37
|
+
attr_accessor :text
|
38
|
+
def initialize text
|
39
|
+
@text = text
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class GetDigits < BaseCommand
|
44
|
+
attr_accessor :count, :prompt, :url
|
45
|
+
def initialize count, prompt, url
|
46
|
+
@count = count
|
47
|
+
@prompt = prompt
|
48
|
+
@url = url
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class JoinConference < BaseCommand
|
53
|
+
attr_accessor :conference_name, :hold_music, :on_done, :on_talk_time, :on_transcript
|
54
|
+
def initialize conference_name, on_done = nil, hold_music = nil, on_talk_time = nil, on_transcript = nil
|
55
|
+
@conference_name = conference_name
|
56
|
+
@hold_music = hold_music
|
57
|
+
@on_done = on_done
|
58
|
+
@on_talk_time = on_talk_time
|
59
|
+
@on_transcript = on_transcript
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# CallClient is a command to call a client id with a specific transcription URL.
|
64
|
+
class CallClient < BaseCommand
|
65
|
+
attr_accessor :client_name, :on_transcript
|
66
|
+
def initialize client_name, on_transcript = nil
|
67
|
+
@client_name = client_name
|
68
|
+
@on_transcript = on_transcript unless on_transcript.nil?
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class CallPhone < BaseCommand
|
73
|
+
attr_accessor :phone_number, :on_transcript
|
74
|
+
def initialize phone_number, on_transcript = nil
|
75
|
+
@phone_number = phone_number
|
76
|
+
@on_transcript = on_transcript unless on_transcript.nil?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Hangup < BaseCommand; end
|
81
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
# A stub GridSpace client library.
|
4
|
+
|
5
|
+
|
6
|
+
class GridSpace
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
# TODO(d4l3k): Change to point to actual endpoint.
|
10
|
+
base_uri 'zenapi.gridspace.com'
|
11
|
+
|
12
|
+
def initialize(token)
|
13
|
+
@options = { query: {token: token} }
|
14
|
+
end
|
15
|
+
|
16
|
+
# calls returns all currently running calls
|
17
|
+
def calls
|
18
|
+
self.class.get('/calls', @options)
|
19
|
+
end
|
20
|
+
end
|
data/lib/gridspace.rb
ADDED
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gridspace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gridspace
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jwt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- inquiries@gridspace.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- gridspace.gemspec
|
99
|
+
- lib/gridspace.rb
|
100
|
+
- lib/gridspace/capability.rb
|
101
|
+
- lib/gridspace/commands.rb
|
102
|
+
- lib/gridspace/gridspace.rb
|
103
|
+
- lib/gridspace/version.rb
|
104
|
+
homepage: https://www.gridspace.com/
|
105
|
+
licenses: []
|
106
|
+
metadata:
|
107
|
+
allowed_push_host: none
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.0.14
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: A Ruby client library to access the Gridspace API.
|
128
|
+
test_files: []
|