signalcloud 1.0.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 +34 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +9 -0
- data/lib/signalcloud/conversation.rb +34 -0
- data/lib/signalcloud/message.rb +0 -0
- data/lib/signalcloud/organization.rb +11 -0
- data/lib/signalcloud/stencil.rb +27 -0
- data/lib/signalcloud/time_transformer.rb +16 -0
- data/lib/signalcloud/version.rb +3 -0
- data/lib/signalcloud.rb +190 -0
- data/signalcloud.gemspec +25 -0
- data/spec/integration/authentication_spec.rb +34 -0
- data/spec/integration/conversation_spec.rb +44 -0
- data/spec/integration/organizations_spec.rb +23 -0
- data/spec/integration/stencils_spec.rb +24 -0
- data/spec/models/client_spec.rb +103 -0
- data/spec/spec_helper.rb +29 -0
- data/tasks/brutes.rb +1 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42bd443dc46ac29a9ad55a6dec7f387d623930b1
|
4
|
+
data.tar.gz: 00167f4ef5da067225e727f8afb5eaf38047df3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f0c8bf7e9cd3a8d9413edc0bb2c9b4728339dc4eba6a06d4e6521ec8f5fcd4d3e7172e93b0ed633b9b3d119fbaca656cfb00e1f89d3697b20ce4622da027c27
|
7
|
+
data.tar.gz: b76fea285c932bf37d5d1572233662cb501f39d44759e1765f9f4bf31ca8962128368f0a122aec853ac89681a14f1324c023bd5613ef8956c6ea89b6611d6941
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Gemfile.lock
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
coverage
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
coverage
|
16
|
+
.env
|
17
|
+
|
18
|
+
# YARD artifacts
|
19
|
+
.yardoc
|
20
|
+
_yardoc
|
21
|
+
doc/
|
22
|
+
|
23
|
+
.DS_Store
|
24
|
+
.AppleDouble
|
25
|
+
.LSOverride
|
26
|
+
Icon
|
27
|
+
|
28
|
+
|
29
|
+
# Thumbnails
|
30
|
+
._*
|
31
|
+
|
32
|
+
# Files that might appear on external disk
|
33
|
+
.Spotlight-V100
|
34
|
+
.Trashes
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ian Lloyd
|
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,29 @@
|
|
1
|
+
# Signalcloud
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'signalcloud'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install signalcloud
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module SignalCloud
|
2
|
+
|
3
|
+
class Conversation < ::APISmith::Smash
|
4
|
+
property :id, transformer: :to_i
|
5
|
+
property :stencil_id, transformer: :to_i
|
6
|
+
property :customer_number
|
7
|
+
property :internal_number
|
8
|
+
|
9
|
+
property :status
|
10
|
+
property :status_text
|
11
|
+
|
12
|
+
property :challenge_status
|
13
|
+
property :challenge_status_text
|
14
|
+
|
15
|
+
property :reply_status
|
16
|
+
property :reply_status_text
|
17
|
+
|
18
|
+
property :webhook_uri
|
19
|
+
|
20
|
+
property :question
|
21
|
+
property :confirmed_reply
|
22
|
+
property :denied_reply
|
23
|
+
property :expired_reply
|
24
|
+
property :failed_reply
|
25
|
+
|
26
|
+
property :created_at, transformer: TimeTransformer
|
27
|
+
property :updated_at, transformer: TimeTransformer
|
28
|
+
property :expires_at, transformer: TimeTransformer
|
29
|
+
property :challenge_sent_at, transformer: TimeTransformer
|
30
|
+
property :response_received_at, transformer: TimeTransformer
|
31
|
+
property :reply_received_at, transformer: TimeTransformer
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SignalCloud
|
2
|
+
|
3
|
+
class Stencil < ::APISmith::Smash
|
4
|
+
|
5
|
+
property :id, transformer: :to_i
|
6
|
+
property :phone_directory_id, transformer: :to_i
|
7
|
+
|
8
|
+
property :label
|
9
|
+
property :description
|
10
|
+
property :primary
|
11
|
+
|
12
|
+
property :webhook_uri
|
13
|
+
property :seconds_to_live
|
14
|
+
|
15
|
+
property :question
|
16
|
+
property :expected_confirmed_answer
|
17
|
+
property :expected_denied_answer
|
18
|
+
property :confirmed_reply
|
19
|
+
property :denied_reply
|
20
|
+
property :failed_reply
|
21
|
+
property :expired_reply
|
22
|
+
|
23
|
+
property :created_at, transformer: TimeTransformer
|
24
|
+
property :updated_at, transformer: TimeTransformer
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/signalcloud.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
require "signalcloud/version"
|
2
|
+
require 'api_smith'
|
3
|
+
|
4
|
+
require 'signalcloud/time_transformer'
|
5
|
+
require 'signalcloud/organization'
|
6
|
+
require 'signalcloud/stencil'
|
7
|
+
require 'signalcloud/message'
|
8
|
+
require 'signalcloud/conversation'
|
9
|
+
|
10
|
+
##
|
11
|
+
# A helper library for working with the SignalCloud service.
|
12
|
+
module SignalCloud
|
13
|
+
|
14
|
+
##
|
15
|
+
# US service URI.
|
16
|
+
US_BASE_URI = 'https://us.signalcloudapp.com'
|
17
|
+
|
18
|
+
##
|
19
|
+
# EU service URI.
|
20
|
+
EU_BASE_URI = 'https://eu.signalcloudapp.com'
|
21
|
+
|
22
|
+
##
|
23
|
+
# The default service URI; currently defaults to the EU service.
|
24
|
+
DEFAULT_BASE_URI = EU_BASE_URI
|
25
|
+
|
26
|
+
##
|
27
|
+
# Standard SignalCloud error. All errors produced by the SignalCloud library or service will be raised as this Error class.
|
28
|
+
class SignalCloudError < StandardError; end
|
29
|
+
|
30
|
+
##
|
31
|
+
# A SignalCloudError raised whenever the service cannot authenticate the provided user credentials.
|
32
|
+
class InvalidCredentialError < SignalCloudError; end
|
33
|
+
|
34
|
+
##
|
35
|
+
# A SignalCloudError rasied whenever a requested object could not be found.
|
36
|
+
class ObjectNotFoundError < SignalCloudError; end
|
37
|
+
|
38
|
+
##
|
39
|
+
# The primary Client for using the SignalCloud service. Either sub-class this object to make your own client or use it directly.
|
40
|
+
#
|
41
|
+
# The Client uses several environment variables to automagically set defaults.
|
42
|
+
# [SIGNALCLOUD_URI] The service URI. May be either a fully qualified URI, or US or EU to use the respective region-specific service. Defaults to the EU service URI.
|
43
|
+
# [SIGNALCLOUD_USERNAME] A valid SignalCloud username
|
44
|
+
# [SIGNALCLOUD_PASSWORD] A valid SignalCloud password
|
45
|
+
class Client
|
46
|
+
include ::APISmith::Client
|
47
|
+
|
48
|
+
##
|
49
|
+
# The BASIC AUTH username for the SignalCloud service.
|
50
|
+
attr_reader :username
|
51
|
+
|
52
|
+
##
|
53
|
+
# The BASIC AUTH password for the SignalCloud service.
|
54
|
+
attr_reader :password
|
55
|
+
|
56
|
+
##
|
57
|
+
# Create a new Client
|
58
|
+
# [username] A SignalCloud username, or nil to use the SIGNALCLOUD_USERNAME environment variable
|
59
|
+
# [password] A SignalCloud password, or nil to use the SIGNALCLOUD_PASSWORD environment variable
|
60
|
+
# [options] A Hash of options to pass to the Client. Keys may be any method which the Client understands, while the value must be in a format the method can understand.
|
61
|
+
def initialize( username=nil, password=nil, options={} )
|
62
|
+
@username = username || ENV['SIGNALCLOUD_USERNAME']
|
63
|
+
@password = password || ENV['SIGNALCLOUD_PASSWORD']
|
64
|
+
|
65
|
+
raise SignalCloudError.new( 'Username or Password was nil. Define your credentials either through parameters or through the SIGNALCLOUD_USERNAME and SIGNALCLOUD_PASSWORD environment variables.' ) if ( @username.nil? or @password.nil? )
|
66
|
+
|
67
|
+
# Assign base URI by parameters
|
68
|
+
self.class.base_uri self.class.pick_base_uri
|
69
|
+
|
70
|
+
options.each do |key,value|
|
71
|
+
self.class.send(key, value) if self.class.respond_to? key
|
72
|
+
send(key, value) if respond_to? key
|
73
|
+
end
|
74
|
+
|
75
|
+
#self.basic_auth(username, password)
|
76
|
+
add_request_options!( basic_auth: {username: self.username, password: self.password} )
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Request all organizations available to this user account.
|
81
|
+
# [options] A Hash of key-value pairs to be submitted with the request as a query (i.e. after a ? in the request URI).
|
82
|
+
# Returns an Array of Organization objects.
|
83
|
+
def organizations( options={} )
|
84
|
+
get "organizations.json", extra_query: options, response_container: %w( organizations ), transform: SignalCloud::Organization
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Request a specific organization by unique ID.
|
89
|
+
# [organization_id] The ID of the holding Organization
|
90
|
+
# [options] A Hash of key-value pairs to be submitted with the request as a query (i.e. after a ? in the request URI).
|
91
|
+
# Returns an Organization object.
|
92
|
+
def organization( organization_id, options={} )
|
93
|
+
get "organizations/#{organization_id}.json", extra_query: options, response_container: %w( organization ), transform: SignalCloud::Organization
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# Request all stencils available to this user account and the specified organization.
|
98
|
+
# [organization_id] The ID of the holding Organization
|
99
|
+
# [options] A Hash of key-value pairs to be submitted with the request as a query (i.e. after a ? in the request URI).
|
100
|
+
# Returns an Array of Stencil objects.
|
101
|
+
def stencils( organization_id, options={} )
|
102
|
+
get "organizations/#{organization_id}/stencils.json", extra_query: options, response_container: %w( stencils ), transform: SignalCloud::Stencil
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# Request a specific Stencil by Organization and Stencil IDs.
|
107
|
+
# [organization_id] The ID of the holding Organization
|
108
|
+
# [stencil_id] The ID of the requested Stencil
|
109
|
+
# [options] A Hash of key-value pairs to be submitted with the request as a query (i.e. after a ? in the request URI).
|
110
|
+
# Returns an Organization object.
|
111
|
+
def stencil( organization_id, stencil_id, options={} )
|
112
|
+
get "organizations/#{organization_id}/stencils/#{stencil_id}.json", extra_query: options, response_container: %w( stencil ), transform: SignalCloud::Stencil
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Request all Stencils available to this user account and the specified organization.
|
117
|
+
# [organization_id] The ID of the holding Organization
|
118
|
+
# [options] A Hash of key-value pairs to be submitted with the request as a query (i.e. after a ? in the request URI).
|
119
|
+
# Returns an Array of Conversation objects.
|
120
|
+
def conversations( organization_id, options={} )
|
121
|
+
get "organizations/#{organization_id}/conversations.json", extra_query: options, response_container: %w( conversations ), transform: SignalCloud::Conversation
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Request a specific Conversation by Organization and Conversation IDs.
|
126
|
+
# [organization_id] The ID of the holding Organization
|
127
|
+
# [conversation_id] The ID of the requested Conversation
|
128
|
+
# [options] A Hash of key-value pairs to be submitted with the request as a query (i.e. after a ? in the request URI).
|
129
|
+
# Returns a Conversation object.
|
130
|
+
def conversation( organization_id, conversation_id, options={} )
|
131
|
+
get "organizations/#{organization_id}/conversations/#{conversation_id}.json", extra_query: options, response_container: %w( conversation ), transform: SignalCloud::Conversation
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# Start a new Conversation for the given Organization.
|
136
|
+
# [organization_id] The ID of the holding Organization
|
137
|
+
# [options] A Hash of key-value pairs to be submitted with the request. Please see http://www.signalcloudapp.com/dev for details on accepted parameters.
|
138
|
+
# Returns a Conversation object.
|
139
|
+
def start_conversation( organization_id, params={} )
|
140
|
+
conversation_uri = 'conversations.json'
|
141
|
+
conversation_uri = "stencils/#{params[:stencil_id]}/#{conversation_uri}" if params.include? :stencil_id
|
142
|
+
conversation_uri = "organizations/#{organization_id}/#{conversation_uri}"
|
143
|
+
post conversation_uri, extra_query: { conversation: params }, response_container: %w( conversation ), transform: SignalCloud::Conversation
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# Pick the appropriate base URI to use based on environment variables.
|
148
|
+
# Uses the +SIGNALCLOUD_URI+ environment variable to select the URI.
|
149
|
+
# Accepts one either a fully qualified URI, or country short-cuts as follows:
|
150
|
+
# * +EU+ for the European version.
|
151
|
+
# * +US+ for the United States version.
|
152
|
+
# If the parameter is blank or is not one of the country codes, will default to the EU version.
|
153
|
+
def self.pick_base_uri(uri = nil)
|
154
|
+
uri ||= ENV['SIGNALCLOUD_URI']
|
155
|
+
case uri.to_s.strip.downcase
|
156
|
+
when 'eu'
|
157
|
+
EU_BASE_URI
|
158
|
+
when 'us'
|
159
|
+
US_BASE_URI
|
160
|
+
when nil, ''
|
161
|
+
DEFAULT_BASE_URI
|
162
|
+
else
|
163
|
+
uri
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
##
|
170
|
+
# Always make requests as JSON.
|
171
|
+
def base_query_options
|
172
|
+
{ :format => 'json' }
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Peform error checking on responses.
|
177
|
+
def check_response_errors(response)
|
178
|
+
# Raise specific errors
|
179
|
+
raise InvalidCredentialError.new(response['error']) if response.code == 401
|
180
|
+
raise ObjectNotFoundError if response.code == 404
|
181
|
+
|
182
|
+
# Raise a general error
|
183
|
+
if response.is_a?(Hash) and (error = response['error'] || response['errors'])
|
184
|
+
raise SignalCloudError.new(error)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
data/signalcloud.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'signalcloud/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "signalcloud"
|
8
|
+
gem.version = SignalCloud::VERSION
|
9
|
+
gem.authors = ["Ian Lloyd"]
|
10
|
+
gem.email = ["ian@signalcloudapp.com"]
|
11
|
+
gem.description = %q{Access the SignalCloud API to manage tickets.}
|
12
|
+
gem.summary = %q{Tap into the SignalCloud API.}
|
13
|
+
gem.homepage = "http://www.signalcloudapp.com/api"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'api_smith', '~> 1.3.0'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
gem.add_development_dependency 'rspec-its'
|
24
|
+
gem.add_development_dependency 'simplecov'
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SignalCloud::Client do
|
4
|
+
let(:service_uri) { 'http://localhost:5000' }
|
5
|
+
let(:client) { SignalCloud::Client.new( username, password, base_uri: service_uri) }
|
6
|
+
|
7
|
+
context 'when valid' do
|
8
|
+
let(:username) { ENV['SIGNALCLOUD_TEST_USERNAME'] }
|
9
|
+
let(:password) { ENV['SIGNALCLOUD_TEST_PASSWORD'] }
|
10
|
+
it 'does not raise an error' do
|
11
|
+
expect{ client.organizations }.not_to raise_error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when invalid' do
|
16
|
+
let(:username) { 'bad' }
|
17
|
+
let(:password) { 'credential' }
|
18
|
+
it 'raises invalid credential error' do
|
19
|
+
expect{ client.organizations }.to raise_error(SignalCloud::InvalidCredentialError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when providing bogus organization options' do
|
24
|
+
let(:client) { test_client }
|
25
|
+
it 'raises not found' do
|
26
|
+
expect{ client.organization(-1) }.to raise_error(SignalCloud::ObjectNotFoundError)
|
27
|
+
end
|
28
|
+
it 'raises misc error' do
|
29
|
+
pending('Need to configure server to not redirect when format is JSON.')
|
30
|
+
expect{ client.organization(2) }.to raise_error(SignalCloud::SignalCloudError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SignalCloud::Client do
|
4
|
+
let(:client) { test_client }
|
5
|
+
let!(:organization_id) { client.organizations.first.id }
|
6
|
+
|
7
|
+
describe '#conversations' do
|
8
|
+
it 'returns a list of conversations' do
|
9
|
+
expect( client.conversations(organization_id) ).not_to be_empty
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#conversation' do
|
14
|
+
let!(:conversation_id) { client.conversations(organization_id).first.id }
|
15
|
+
|
16
|
+
it 'returns a conversation object' do
|
17
|
+
client.conversation(organization_id, conversation_id).should be_a( SignalCloud::Conversation )
|
18
|
+
end
|
19
|
+
it 'returns the requested conversation' do
|
20
|
+
client.conversation(organization_id, conversation_id).id.should == conversation_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#start_conversation' do
|
25
|
+
let(:stencil_id) { 2 }
|
26
|
+
# let(:stencil_id) { client.stencils(organization_id).first.id }
|
27
|
+
let(:number) { ENV['TEST_NUMBER'] }
|
28
|
+
let(:options) do
|
29
|
+
{
|
30
|
+
stencil_id: stencil_id,
|
31
|
+
customer_number: number
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'starts a new conversation from a stencil' do
|
36
|
+
conversation = nil
|
37
|
+
expect{ conversation = client.start_conversation( organization_id, options ) }.not_to raise_error
|
38
|
+
expect( conversation.id).not_to be_nil
|
39
|
+
expect( conversation.customer_number ).to eq( number )
|
40
|
+
expect( conversation.internal_number ).not_to be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SignalCloud::Client do
|
4
|
+
let(:client) { test_client }
|
5
|
+
|
6
|
+
describe '#organizations' do
|
7
|
+
it 'returns a list of organizations' do
|
8
|
+
expect( client.organizations ).not_to be_empty
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#organization' do
|
13
|
+
let!(:organization_id) { client.organizations.first.id }
|
14
|
+
|
15
|
+
it 'returns an organization object' do
|
16
|
+
client.organization(organization_id).should be_a( SignalCloud::Organization )
|
17
|
+
end
|
18
|
+
it 'returns the requested organization' do
|
19
|
+
client.organization(organization_id).id.should == organization_id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SignalCloud::Client do
|
4
|
+
let(:client) { test_client }
|
5
|
+
let!(:organization_id) { client.organizations.first.id }
|
6
|
+
|
7
|
+
describe '#stencils' do
|
8
|
+
it 'returns a list of stencils' do
|
9
|
+
expect( client.stencils(organization_id) ).not_to be_empty
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#stencil' do
|
14
|
+
let(:stencil_id) { client.stencils(organization_id).first.id }
|
15
|
+
|
16
|
+
it 'returns a stencil object' do
|
17
|
+
client.stencil(organization_id, stencil_id).should be_a( SignalCloud::Stencil )
|
18
|
+
end
|
19
|
+
it 'returns the requested stencil' do
|
20
|
+
client.stencil(organization_id, stencil_id).id.should == stencil_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SignalCloud::Client do
|
4
|
+
|
5
|
+
describe '.new' do
|
6
|
+
let(:username) { 'user' }
|
7
|
+
let(:password) { 'pass' }
|
8
|
+
|
9
|
+
context 'when using explicit credentials' do
|
10
|
+
subject { SignalCloud::Client.new( username, password ) }
|
11
|
+
its(:username) { should == username }
|
12
|
+
its(:password) { should == password }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when using environment credentials' do
|
16
|
+
before(:each) do # Set environment variables
|
17
|
+
ENV['SIGNALCLOUD_USERNAME'] = username
|
18
|
+
ENV['SIGNALCLOUD_PASSWORD'] = password
|
19
|
+
end
|
20
|
+
after(:each) do # Purge environment variables
|
21
|
+
ENV.delete 'SIGNALCLOUD_USERNAME'
|
22
|
+
ENV.delete 'SIGNALCLOUD_PASSWORD'
|
23
|
+
end
|
24
|
+
subject { SignalCloud::Client.new() }
|
25
|
+
its(:username) { should == username }
|
26
|
+
its(:password) { should == password }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when missing credentials' do
|
30
|
+
before(:each) do # Purge environment variables
|
31
|
+
ENV.delete 'SIGNALCLOUD_USERNAME'
|
32
|
+
ENV.delete 'SIGNALCLOUD_PASSWORD'
|
33
|
+
end
|
34
|
+
it 'raises error on nil username' do
|
35
|
+
expect { SignalCloud::Client.new( nil, password ) }.to raise_error
|
36
|
+
end
|
37
|
+
it 'raises error on nil password' do
|
38
|
+
expect { SignalCloud::Client.new( username, nil ) }.to raise_error
|
39
|
+
end
|
40
|
+
it 'raises error on missing password' do
|
41
|
+
expect { SignalCloud::Client.new( username ) }.to raise_error
|
42
|
+
end
|
43
|
+
it 'raises error on missing username and password' do
|
44
|
+
expect { SignalCloud::Client.new() }.to raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when providing options' do
|
49
|
+
let(:base_uri) { 'http://localhost:5000' }
|
50
|
+
let(:options) {
|
51
|
+
{ base_uri: base_uri }
|
52
|
+
}
|
53
|
+
subject { SignalCloud::Client.new( username, password, options ) }
|
54
|
+
|
55
|
+
its('class.base_uri') { should == base_uri }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when using environment URI' do
|
59
|
+
before(:each) do # Set environment variables
|
60
|
+
ENV['SIGNALCLOUD_USERNAME'] = username
|
61
|
+
ENV['SIGNALCLOUD_PASSWORD'] = password
|
62
|
+
ENV['SIGNALCLOUD_URI'] = uri_or_region
|
63
|
+
end
|
64
|
+
after(:each) do # Purge environment variables
|
65
|
+
ENV.delete 'SIGNALCLOUD_USERNAME'
|
66
|
+
ENV.delete 'SIGNALCLOUD_PASSWORD'
|
67
|
+
ENV.delete 'SIGNALCLOUD_URI'
|
68
|
+
end
|
69
|
+
subject { SignalCloud::Client.new }
|
70
|
+
|
71
|
+
context 'when using US region' do
|
72
|
+
let(:uri_or_region) { 'US' }
|
73
|
+
let(:expected_uri) { SignalCloud::US_BASE_URI }
|
74
|
+
|
75
|
+
its('class.base_uri') { should == expected_uri }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when using EU region' do
|
79
|
+
let(:uri_or_region) { 'EU' }
|
80
|
+
let(:expected_uri) { SignalCloud::EU_BASE_URI }
|
81
|
+
|
82
|
+
its('class.base_uri') { should == expected_uri }
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when using default region' do
|
86
|
+
let(:uri_or_region) { nil }
|
87
|
+
let(:expected_uri) { SignalCloud::DEFAULT_BASE_URI }
|
88
|
+
|
89
|
+
its('class.base_uri') { should == expected_uri }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when using custom URI' do
|
93
|
+
let(:uri_or_region) { 'http://localhost:80' }
|
94
|
+
let(:expected_uri) { uri_or_region }
|
95
|
+
|
96
|
+
its('class.base_uri') { should == expected_uri }
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rspec/its'
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start 'rails'
|
4
|
+
|
5
|
+
require 'signalcloud'
|
6
|
+
|
7
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
8
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
9
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
10
|
+
# loaded once.
|
11
|
+
#
|
12
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_client
|
25
|
+
username = ENV['SIGNALCLOUD_TEST_USERNAME']
|
26
|
+
password = ENV['SIGNALCLOUD_TEST_PASSWORD']
|
27
|
+
service_uri = 'http://localhost:5000'
|
28
|
+
SignalCloud::Client.new( username, password, base_uri: service_uri)
|
29
|
+
end
|
data/tasks/brutes.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# I'm just an empty file to hold open the tasks directory!
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: signalcloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian Lloyd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: api_smith
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
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: rspec-its
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
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: Access the SignalCloud API to manage tickets.
|
70
|
+
email:
|
71
|
+
- ian@signalcloudapp.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/signalcloud.rb
|
83
|
+
- lib/signalcloud/conversation.rb
|
84
|
+
- lib/signalcloud/message.rb
|
85
|
+
- lib/signalcloud/organization.rb
|
86
|
+
- lib/signalcloud/stencil.rb
|
87
|
+
- lib/signalcloud/time_transformer.rb
|
88
|
+
- lib/signalcloud/version.rb
|
89
|
+
- signalcloud.gemspec
|
90
|
+
- spec/integration/authentication_spec.rb
|
91
|
+
- spec/integration/conversation_spec.rb
|
92
|
+
- spec/integration/organizations_spec.rb
|
93
|
+
- spec/integration/stencils_spec.rb
|
94
|
+
- spec/models/client_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- tasks/brutes.rb
|
97
|
+
homepage: http://www.signalcloudapp.com/api
|
98
|
+
licenses: []
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.6
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Tap into the SignalCloud API.
|
120
|
+
test_files:
|
121
|
+
- spec/integration/authentication_spec.rb
|
122
|
+
- spec/integration/conversation_spec.rb
|
123
|
+
- spec/integration/organizations_spec.rb
|
124
|
+
- spec/integration/stencils_spec.rb
|
125
|
+
- spec/models/client_spec.rb
|
126
|
+
- spec/spec_helper.rb
|