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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44b59486d0af395164c4ba24986dbc36fb553aaf00b1d2621766d8227e820000
4
- data.tar.gz: 4fb9e02e4f19d42be8e62c0e1efed8c3eff8f49c3a7f904a8444a53131c02d82
3
+ metadata.gz: e8ede2c67d6007b81a374d34013c55ecb6031aca0aabd1cbd15685882dbc10a7
4
+ data.tar.gz: c750950b29ed485c4c662ac2593b07ac005271b42103d640c2cb71a0fd72900f
5
5
  SHA512:
6
- metadata.gz: '08180e655db091020cb66e6c4a8e2f0eb609c4ae14188615a912faaf4734223803bb1c6ec1bc236cb335c1c26fe6cb31da16c995f83c9e353862ad0548f0a953'
7
- data.tar.gz: d37e67f5acbe6096cb0c8434cdd6fe22beb947a3de2338f4d66c3f7794d2df9dfecee6b389c159363c8dc568bc4ad7858d24322495e3243367947c60f61cc0e3
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: 'ALL',
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
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
65
- [ '--conversation', '-c', GetoptLong::REQUIRED_ARGUMENT ],
66
- [ '--subject', '-s', GetoptLong::REQUIRED_ARGUMENT ],
67
- [ '--topic', '-t', GetoptLong::REQUIRED_ARGUMENT ],
68
- [ '--trace', GetoptLong::NO_ARGUMENT ],
69
- [ '--list', '-l', GetoptLong::NO_ARGUMENT ],
70
- [ '--new', '-n', GetoptLong::NO_ARGUMENT ],
71
- [ '--participant', '-p', GetoptLong::REQUIRED_ARGUMENT ],
72
- [ '--config', '-f', GetoptLong::REQUIRED_ARGUMENT ],
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
- when '--help'
77
- usage
78
- exit 0
79
- when '--conversation'
80
- @conversation = arg.to_s
81
- when '--subject'
82
- @subject = arg.to_s
83
- when '--trace'
84
- @trace = true
85
- when '--list'
86
- @list = true
87
- when '--new'
88
- @new = true
89
- when '--participant'
90
- @participants << arg.to_s
91
- when '--config'
92
- @config_file = arg.to_s
93
- when '--topic'
94
- @topic = arg.to_s
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 "creating new group conversation..."
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( conv, body, **options )
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.3
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-04-19 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake