circuit_client 0.0.4 → 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 +4 -4
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +25 -0
- data/lib/circuit_client/client.rb +40 -29
- data/lib/circuit_client/error_middleware.rb +5 -12
- data/lib/circuit_client/errors.rb +2 -2
- metadata +4 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21c82b46e11989d8d28d5f9ca959539eaf86417891312711c21aec8667f1dedb
|
4
|
+
data.tar.gz: ece2b2b67d64439021dbf0d8dd82e8593fab954cbde8782b973e40c8a5bc2963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 475b935dbd2d708664d3099ee15d8e0cbf411b30e6f289989f88dd22ea6309dc81d3b6cb4adba9fc049f3c66a7a0fca7f27d5becc83e6f9e92e092d4fed6476e
|
7
|
+
data.tar.gz: 90c7c822a5338db5eb240de788c66035bc7d07115887ba8d6f3aef3b08b5acfb9922d0df0d8df361366b8f83e84e066ac2975223e951cca20485f207731ca1b6
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
circuit_client (1.0.0)
|
5
|
+
faraday (~> 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
faraday (1.0.0)
|
11
|
+
multipart-post (>= 1.2, < 3)
|
12
|
+
multipart-post (2.1.1)
|
13
|
+
rake (12.3.3)
|
14
|
+
rdoc (6.2.1)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
circuit_client!
|
21
|
+
rake (~> 12)
|
22
|
+
rdoc (~> 6)
|
23
|
+
|
24
|
+
BUNDLED WITH
|
25
|
+
2.0.1
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require 'typhoeus'
|
3
|
-
require 'typhoeus/adapters/faraday'
|
4
2
|
require 'uri'
|
5
3
|
require 'json'
|
6
4
|
|
@@ -66,10 +64,10 @@ module CircuitClient
|
|
66
64
|
|
67
65
|
# The faraday http connection object
|
68
66
|
def connection
|
69
|
-
@connection ||= Faraday.new(url: base_uri.to_s) do |
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
@connection ||= Faraday.new(url: base_uri.to_s) do |c|
|
68
|
+
c.response :logger if @trace
|
69
|
+
c.use CircuitClient::ErrorMiddleware
|
70
|
+
c.adapter Faraday.default_adapter
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
@@ -86,14 +84,19 @@ module CircuitClient
|
|
86
84
|
|
87
85
|
# Authenticate using client_credentials method
|
88
86
|
def auth_client_credentials
|
89
|
-
raise
|
90
|
-
raise
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
87
|
+
raise 'client_id parameter required' if @client_id.nil?
|
88
|
+
raise 'client_secret parameter required' if @client_secret.nil?
|
89
|
+
|
90
|
+
response = connection.post(build_uri('/oauth/token')) do |req|
|
91
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
92
|
+
req.body = URI.encode_www_form(
|
93
|
+
client_id: @client_id,
|
94
|
+
client_secret: @client_secret,
|
95
|
+
grant_type: 'client_credentials',
|
96
|
+
scope: @auth_scope
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
97
100
|
data = JSON.parse(response.body)
|
98
101
|
data['access_token']
|
99
102
|
end
|
@@ -138,37 +141,45 @@ module CircuitClient
|
|
138
141
|
path = "/conversations/#{conv}/messages"
|
139
142
|
path += "/#{item_id}" unless item_id.nil?
|
140
143
|
options.delete(:item_id)
|
141
|
-
call(
|
142
|
-
|
143
|
-
|
144
|
-
|
144
|
+
call(
|
145
|
+
:post,
|
146
|
+
path,
|
147
|
+
content: text,
|
148
|
+
**options
|
149
|
+
)
|
145
150
|
end
|
146
151
|
|
147
152
|
# List all conversation of the user
|
148
153
|
def list_conversations
|
149
|
-
call(:get,
|
154
|
+
call(:get, '/conversations')
|
150
155
|
end
|
151
156
|
|
152
157
|
# Create a new group conversation
|
153
158
|
def create_group_conversation(participants, topic)
|
154
|
-
call(
|
159
|
+
call(
|
160
|
+
:post,
|
161
|
+
'/conversations/group',
|
155
162
|
participants: participants,
|
156
|
-
topic: topic
|
157
|
-
|
163
|
+
topic: topic
|
164
|
+
)
|
158
165
|
end
|
159
166
|
|
160
167
|
# Create a new 1:1 conversation
|
161
168
|
def create_direct_conversation(participant)
|
162
|
-
call(
|
163
|
-
|
164
|
-
|
169
|
+
call(
|
170
|
+
:post,
|
171
|
+
'/conversations/direct',
|
172
|
+
participant: participant
|
173
|
+
)
|
165
174
|
end
|
166
175
|
|
167
176
|
# Remove participants from a conversation
|
168
177
|
def delete_group_conversation_participants(conv, participants)
|
169
|
-
call(
|
170
|
-
|
171
|
-
|
178
|
+
call(
|
179
|
+
:delete,
|
180
|
+
"/conversations/group/#{conv}/participants",
|
181
|
+
participants: participants
|
182
|
+
)
|
172
183
|
end
|
173
184
|
|
174
185
|
# Remove the current_user from a conversation
|
@@ -178,7 +189,7 @@ module CircuitClient
|
|
178
189
|
|
179
190
|
# Get the profile of the connections user
|
180
191
|
def get_user_profile
|
181
|
-
call(:get,
|
192
|
+
call(:get, '/users/profile')
|
182
193
|
end
|
183
194
|
|
184
195
|
# A cached version of the current connections user profile
|
@@ -1,23 +1,16 @@
|
|
1
1
|
require 'circuit_client/errors'
|
2
2
|
|
3
3
|
module CircuitClient
|
4
|
-
class ErrorMiddleware < Faraday::Response::
|
5
|
-
|
4
|
+
class ErrorMiddleware < Faraday::Response::RaiseError
|
5
|
+
CLIENT_ERROR_STATUSES = (400...500).freeze
|
6
6
|
|
7
7
|
def on_complete(env)
|
8
8
|
case env[:status]
|
9
|
-
when
|
10
|
-
raise Faraday::Error::ResourceNotFound, response_values(env)
|
11
|
-
when 407
|
12
|
-
# mimic the behavior that we get with proxy requests with HTTPS
|
13
|
-
raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
14
|
-
when ClientErrorStatuses
|
9
|
+
when CLIENT_ERROR_STATUSES
|
15
10
|
raise CircuitClient::ClientError, response_values(env)
|
16
11
|
end
|
17
|
-
end
|
18
12
|
|
19
|
-
|
20
|
-
{:status => env.status, :headers => env.response_headers, :body => env.body}
|
13
|
+
super
|
21
14
|
end
|
22
|
-
end
|
15
|
+
end
|
23
16
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module CircuitClient
|
4
|
-
class ClientError < Faraday::
|
4
|
+
class ClientError < Faraday::ClientError
|
5
5
|
def initialize(ex, response = nil)
|
6
6
|
content_type = ex[:headers]['Content-Type']
|
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
|
10
|
+
super("server response: #{error.to_json} (status: #{ex[:status]})")
|
11
11
|
rescue JSON::ParserError
|
12
12
|
super("server response with status #{ex[:status]} and malformed JSON")
|
13
13
|
end
|
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: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Benning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,36 +38,8 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: aruba
|
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
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: faraday
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: typhoeus
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
45
|
- - "~>"
|
@@ -87,8 +59,10 @@ executables:
|
|
87
59
|
extensions: []
|
88
60
|
extra_rdoc_files: []
|
89
61
|
files:
|
62
|
+
- CHANGELOG.md
|
90
63
|
- Dockerfile
|
91
64
|
- Gemfile
|
65
|
+
- Gemfile.lock
|
92
66
|
- README.md
|
93
67
|
- Rakefile
|
94
68
|
- bin/send-circuit
|