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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8ede2c67d6007b81a374d34013c55ecb6031aca0aabd1cbd15685882dbc10a7
4
- data.tar.gz: c750950b29ed485c4c662ac2593b07ac005271b42103d640c2cb71a0fd72900f
3
+ metadata.gz: 21c82b46e11989d8d28d5f9ca959539eaf86417891312711c21aec8667f1dedb
4
+ data.tar.gz: ece2b2b67d64439021dbf0d8dd82e8593fab954cbde8782b973e40c8a5bc2963
5
5
  SHA512:
6
- metadata.gz: f6dea096242a5d412dbe09773b2e31135bbd98e31d375475eb7b4f337d2cebe0c242dae5a7bfd401bee00ec969d6383e636ed0ebb10957e00e6916516a3a7543
7
- data.tar.gz: cd95a588cd1f2a65e0a22838f12183e2e281bf3fb0a8e080c6d8095d8e4d2654ecd0d50d46dca0c3a0d2bb4ebea534c6c91b93f5866d4e2bd940a2e285ba316e
6
+ metadata.gz: 475b935dbd2d708664d3099ee15d8e0cbf411b30e6f289989f88dd22ea6309dc81d3b6cb4adba9fc049f3c66a7a0fca7f27d5becc83e6f9e92e092d4fed6476e
7
+ data.tar.gz: 90c7c822a5338db5eb240de788c66035bc7d07115887ba8d6f3aef3b08b5acfb9922d0df0d8df361366b8f83e84e066ac2975223e951cca20485f207731ca1b6
@@ -0,0 +1,13 @@
1
+ # CircuitClient Changelog
2
+
3
+ ## v1.0.0
4
+
5
+ Changes:
6
+
7
+ * Upgrades to faraday v1.0
8
+ * No longer depend on typhoeus as faraday adapter
9
+
10
+ ## v0.0.4
11
+
12
+ ...
13
+
@@ -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 |faraday|
70
- faraday.response :logger if @trace
71
- faraday.use CircuitClient::ErrorMiddleware
72
- faraday.adapter :typhoeus
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 "client_id parameter required" if @client_id.nil?
90
- raise "client_secret parameter required" if @client_secret.nil?
91
- response = connection.post(build_uri('/oauth/token'), {
92
- client_id: @client_id,
93
- client_secret: @client_secret,
94
- grant_type: 'client_credentials',
95
- scope: @auth_scope,
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(:post, path, {
142
- 'content' => text,
143
- **options,
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, "/conversations")
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(:post, '/conversations/group', {
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(:post, '/conversations/direct', {
163
- participant: participant,
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(:delete, "/conversations/group/#{conv}/participants", {
170
- participants: participants,
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, "/users/profile")
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::Middleware
5
- ClientErrorStatuses = 400...600
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 404
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
- def response_values(env)
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::Error::ClientError
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['errorDescription'] || error} (status: #{ex[:status]})")
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
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: 2018-05-30 00:00:00.000000000 Z
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