circuit_client 0.0.3 → 0.0.4
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 +4 -4
- data/lib/circuit_client/client.rb +12 -1
- data/lib/circuit_client/errors.rb +1 -1
- data/lib/circuit_client/send_message_cli.rb +34 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8ede2c67d6007b81a374d34013c55ecb6031aca0aabd1cbd15685882dbc10a7
|
4
|
+
data.tar.gz: c750950b29ed485c4c662ac2593b07ac005271b42103d640c2cb71a0fd72900f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6dea096242a5d412dbe09773b2e31135bbd98e31d375475eb7b4f337d2cebe0c242dae5a7bfd401bee00ec969d6383e636ed0ebb10957e00e6916516a3a7543
|
7
|
+
data.tar.gz: cd95a588cd1f2a65e0a22838f12183e2e281bf3fb0a8e080c6d8095d8e4d2654ecd0d50d46dca0c3a0d2bb4ebea534c6c91b93f5866d4e2bd940a2e285ba316e
|
@@ -10,15 +10,19 @@ module CircuitClient
|
|
10
10
|
# client for accessing circuit API
|
11
11
|
class Client
|
12
12
|
# Set the hostname of the circuit system
|
13
|
+
# Default: eu.yourcircuit.com
|
13
14
|
attr_accessor :host
|
14
15
|
|
15
16
|
# The base path of the API
|
17
|
+
# Default: /rest/v2
|
16
18
|
attr_accessor :base_path
|
17
19
|
|
18
20
|
# The protocol to use 'http' or 'https'
|
21
|
+
# Default: 'https'
|
19
22
|
attr_accessor :protocol
|
20
23
|
|
21
24
|
# Timeout for http requests
|
25
|
+
# Default: 60
|
22
26
|
attr_accessor :timeout
|
23
27
|
|
24
28
|
# The client_id for authentication
|
@@ -30,7 +34,13 @@ module CircuitClient
|
|
30
34
|
# The authentication method to use (currently only :client_credentials supported)
|
31
35
|
attr_accessor :auth_method
|
32
36
|
|
37
|
+
# Comma-delimited set of permissions that the application requests
|
38
|
+
# ALL, READ_USER_PROFILE, WRITE_USER_PROFILE, READ_CONVERSATIONS, WRITE_CONVERSATIONS, READ_USER, CALLS
|
39
|
+
# Default: ALL
|
40
|
+
attr_accessor :auth_scope
|
41
|
+
|
33
42
|
# Enable tracing (outputs http requests to STDOUT)
|
43
|
+
# Default: false (disabled)
|
34
44
|
attr_accessor :trace
|
35
45
|
|
36
46
|
# Initialize a new client
|
@@ -48,6 +58,7 @@ module CircuitClient
|
|
48
58
|
@base_path = '/rest/v2'
|
49
59
|
@protocol = 'https'
|
50
60
|
@auth_method = :client_credentials
|
61
|
+
@auth_scope = 'ALL'
|
51
62
|
@timeout = 60
|
52
63
|
@trace = false
|
53
64
|
yield self
|
@@ -81,7 +92,7 @@ module CircuitClient
|
|
81
92
|
client_id: @client_id,
|
82
93
|
client_secret: @client_secret,
|
83
94
|
grant_type: 'client_credentials',
|
84
|
-
scope:
|
95
|
+
scope: @auth_scope,
|
85
96
|
} )
|
86
97
|
data = JSON.parse(response.body)
|
87
98
|
data['access_token']
|
@@ -7,7 +7,7 @@ module CircuitClient
|
|
7
7
|
if !content_type.nil? && content_type.match(/application\/json/)
|
8
8
|
begin
|
9
9
|
error = JSON.parse(ex[:body])
|
10
|
-
super("server response: #{error['errorDescription']} (status: #{ex[:status]})")
|
10
|
+
super("server response: #{error['errorDescription'] || error} (status: #{ex[:status]})")
|
11
11
|
rescue JSON::ParserError
|
12
12
|
super("server response with status #{ex[:status]} and malformed JSON")
|
13
13
|
end
|
@@ -4,17 +4,19 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
module CircuitClient
|
6
6
|
class SendMessageCli
|
7
|
-
|
8
7
|
class Config
|
9
8
|
DEFAULTS = {
|
10
9
|
timeout: 60,
|
11
10
|
host: 'eu.yourcircuit.com',
|
12
11
|
client_id: nil,
|
13
12
|
client_secret: nil,
|
13
|
+
auth_scope: 'ALL'
|
14
14
|
}
|
15
|
+
|
15
16
|
def self.load_config(path)
|
16
17
|
@@data = YAML.load_file(path)
|
17
18
|
end
|
19
|
+
|
18
20
|
def self.method_missing(method_name)
|
19
21
|
if DEFAULTS.has_key?(method_name)
|
20
22
|
@@data[method_name.to_s] || DEFAULTS[method_name]
|
@@ -61,37 +63,37 @@ END_USAGE
|
|
61
63
|
|
62
64
|
def getopts
|
63
65
|
opts = GetoptLong.new(
|
64
|
-
[
|
65
|
-
[
|
66
|
-
[
|
67
|
-
[
|
68
|
-
[
|
69
|
-
[
|
70
|
-
[
|
71
|
-
[
|
72
|
-
[
|
66
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
67
|
+
['--conversation', '-c', GetoptLong::REQUIRED_ARGUMENT],
|
68
|
+
['--subject', '-s', GetoptLong::REQUIRED_ARGUMENT],
|
69
|
+
['--topic', '-t', GetoptLong::REQUIRED_ARGUMENT],
|
70
|
+
['--trace', GetoptLong::NO_ARGUMENT],
|
71
|
+
['--list', '-l', GetoptLong::NO_ARGUMENT],
|
72
|
+
['--new', '-n', GetoptLong::NO_ARGUMENT],
|
73
|
+
['--participant', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
74
|
+
['--config', '-f', GetoptLong::REQUIRED_ARGUMENT],
|
73
75
|
)
|
74
76
|
opts.each do |opt, arg|
|
75
77
|
case opt
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
when '--help'
|
79
|
+
usage
|
80
|
+
exit 0
|
81
|
+
when '--conversation'
|
82
|
+
@conversation = arg.to_s
|
83
|
+
when '--subject'
|
84
|
+
@subject = arg.to_s
|
85
|
+
when '--trace'
|
86
|
+
@trace = true
|
87
|
+
when '--list'
|
88
|
+
@list = true
|
89
|
+
when '--new'
|
90
|
+
@new = true
|
91
|
+
when '--participant'
|
92
|
+
@participants << arg.to_s
|
93
|
+
when '--config'
|
94
|
+
@config_file = arg.to_s
|
95
|
+
when '--topic'
|
96
|
+
@topic = arg.to_s
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
@@ -109,7 +111,7 @@ END_USAGE
|
|
109
111
|
body = $stdin.readlines.join
|
110
112
|
|
111
113
|
if @new == true
|
112
|
-
puts
|
114
|
+
puts 'creating new group conversation...'
|
113
115
|
conv = client.create_group_conversation(@participants, @topic)['convId']
|
114
116
|
else
|
115
117
|
conv = @conversation
|
@@ -119,7 +121,7 @@ END_USAGE
|
|
119
121
|
options[:subject] = @subject unless @subject.nil?
|
120
122
|
puts "sending message to #{conv}..."
|
121
123
|
begin
|
122
|
-
client.create_message(
|
124
|
+
client.create_message(conv, body, **options)
|
123
125
|
rescue CircuitClient::ClientError => e
|
124
126
|
puts "Could not send message: #{e.message}"
|
125
127
|
exit 1
|
@@ -131,6 +133,7 @@ END_USAGE
|
|
131
133
|
c.host = Config.host
|
132
134
|
c.client_id = Config.client_id
|
133
135
|
c.client_secret = Config.client_secret
|
136
|
+
c.auth_scope = Config.auth_scope
|
134
137
|
c.trace = @trace
|
135
138
|
c.timeout = Config.timeout
|
136
139
|
end
|
@@ -141,7 +144,5 @@ END_USAGE
|
|
141
144
|
puts "- #{c['topic']} (#{c['convId']})"
|
142
145
|
end
|
143
146
|
end
|
144
|
-
|
145
147
|
end
|
146
148
|
end
|
147
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuit_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Benning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|