circuit_client 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/circuit_client/client.rb +45 -30
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 07c5becef6eac99b973f2e39351fc53e4d9633a9
4
- data.tar.gz: 4208a620334d4645e5e54ba0ff1d3614fa518387
2
+ SHA256:
3
+ metadata.gz: 44b59486d0af395164c4ba24986dbc36fb553aaf00b1d2621766d8227e820000
4
+ data.tar.gz: 4fb9e02e4f19d42be8e62c0e1efed8c3eff8f49c3a7f904a8444a53131c02d82
5
5
  SHA512:
6
- metadata.gz: 68b9c6b6d0a09117bdc9937528cbb2d234f0d9ec587b8ff17a0e5342c7f7a8d3d9590508407e803cd997af9453a19baedc7727aa136a8c5629e3f529463a2a9a
7
- data.tar.gz: 7a0d273864893ddb6fb698f8ff18bc069bb386b41cfe35ba682af0b5cc8bd720663f65983cdd7dbacaeea119e8042b26363d25b2067e8321666e6998b27936d0
6
+ metadata.gz: '08180e655db091020cb66e6c4a8e2f0eb609c4ae14188615a912faaf4734223803bb1c6ec1bc236cb335c1c26fe6cb31da16c995f83c9e353862ad0548f0a953'
7
+ data.tar.gz: d37e67f5acbe6096cb0c8434cdd6fe22beb947a3de2338f4d66c3f7794d2df9dfecee6b389c159363c8dc568bc4ad7858d24322495e3243367947c60f61cc0e3
@@ -7,33 +7,34 @@ require 'json'
7
7
  require 'circuit_client/error_middleware'
8
8
 
9
9
  module CircuitClient
10
+ # client for accessing circuit API
10
11
  class Client
11
12
  # Set the hostname of the circuit system
12
13
  attr_accessor :host
13
14
 
14
- # The base path of the API
15
+ # The base path of the API
15
16
  attr_accessor :base_path
16
17
 
17
- # The protocol to use 'http' or 'https'
18
+ # The protocol to use 'http' or 'https'
18
19
  attr_accessor :protocol
19
20
 
20
- # Timeout for http requests
21
+ # Timeout for http requests
21
22
  attr_accessor :timeout
22
23
 
23
- # The client_id for authentication
24
+ # The client_id for authentication
24
25
  attr_accessor :client_id
25
26
 
26
- # The client_secret for authentication
27
+ # The client_secret for authentication
27
28
  attr_accessor :client_secret
28
29
 
29
- # The authentication method to use (currently only :client_credentials supported)
30
+ # The authentication method to use (currently only :client_credentials supported)
30
31
  attr_accessor :auth_method
31
32
 
32
- # Enable tracing (outputs http requests to STDOUT)
33
- attr_accessor :trace
33
+ # Enable tracing (outputs http requests to STDOUT)
34
+ attr_accessor :trace
34
35
 
35
- # Initialize a new client
36
- #
36
+ # Initialize a new client
37
+ #
37
38
  # Examples
38
39
  #
39
40
  # CircuitClient::Client.new do |c|
@@ -52,7 +53,7 @@ module CircuitClient
52
53
  yield self
53
54
  end
54
55
 
55
- # The faraday http connection object
56
+ # The faraday http connection object
56
57
  def connection
57
58
  @connection ||= Faraday.new(url: base_uri.to_s) do |faraday|
58
59
  faraday.response :logger if @trace
@@ -61,7 +62,7 @@ module CircuitClient
61
62
  end
62
63
  end
63
64
 
64
- # The token used for authentication
65
+ # The token used for authentication
65
66
  def access_token
66
67
  return @access_token unless @access_token.nil?
67
68
  case @auth_method
@@ -72,7 +73,7 @@ module CircuitClient
72
73
  end
73
74
  end
74
75
 
75
- # Authenticate using client_credentials method
76
+ # Authenticate using client_credentials method
76
77
  def auth_client_credentials
77
78
  raise "client_id parameter required" if @client_id.nil?
78
79
  raise "client_secret parameter required" if @client_secret.nil?
@@ -86,31 +87,47 @@ module CircuitClient
86
87
  data['access_token']
87
88
  end
88
89
 
89
- # Return URI with path elements
90
+ # Return URI with path elements
90
91
  def base_uri
91
92
  URI("#{@protocol}://#{@host}")
92
93
  end
93
94
 
94
- # Returns an URI with the base_uri and the supplied path
95
+ # Returns an URI with the base_uri and the supplied path
95
96
  def build_uri(path)
96
97
  uri = base_uri
97
98
  uri.path = path
98
99
  uri.to_s
99
100
  end
100
101
 
101
- # Returns an URI and with a path relative to the base_path of the API
102
+ # Returns an URI and with a path relative to the base_path of the API
102
103
  def build_api_uri(path)
103
104
  build_uri("#{@base_path}#{path}")
104
105
  end
105
106
 
106
- # Create a new message in a existing conversation
107
- #
108
- # Examples
107
+ # Create a new message in a existing conversation
109
108
  #
110
- # client.create_message('<convId>', 'my message text...', subject: 'Todays meeting')
109
+ # Examples
110
+ #
111
+ # client.create_message(
112
+ # '<convId>',
113
+ # 'my message text...',
114
+ # subject: 'Todays meeting'
115
+ # )
116
+ #
117
+ # To send to an existing message item use :item_id parameter:
118
+ #
119
+ # client.create_message(
120
+ # '<convId>',
121
+ # 'my message text...',
122
+ # item_id: 'itemId'
123
+ # )
111
124
  #
112
125
  def create_message(conv, text, **options)
113
- call(:post, "/conversations/#{conv}/messages", {
126
+ item_id = options[:item_id]
127
+ path = "/conversations/#{conv}/messages"
128
+ path += "/#{item_id}" unless item_id.nil?
129
+ options.delete(:item_id)
130
+ call(:post, path, {
114
131
  'content' => text,
115
132
  **options,
116
133
  } )
@@ -121,7 +138,7 @@ module CircuitClient
121
138
  call(:get, "/conversations")
122
139
  end
123
140
 
124
- # Create a new group conversation
141
+ # Create a new group conversation
125
142
  def create_group_conversation(participants, topic)
126
143
  call(:post, '/conversations/group', {
127
144
  participants: participants,
@@ -129,14 +146,14 @@ module CircuitClient
129
146
  } )
130
147
  end
131
148
 
132
- # Create a new 1:1 conversation
149
+ # Create a new 1:1 conversation
133
150
  def create_direct_conversation(participant)
134
151
  call(:post, '/conversations/direct', {
135
152
  participant: participant,
136
153
  } )
137
154
  end
138
155
 
139
- # Remove participants from a conversation
156
+ # Remove participants from a conversation
140
157
  def delete_group_conversation_participants(conv, participants)
141
158
  call(:delete, "/conversations/group/#{conv}/participants", {
142
159
  participants: participants,
@@ -148,7 +165,7 @@ module CircuitClient
148
165
  delete_group_conversation_participants(conv, [current_user['userId']])
149
166
  end
150
167
 
151
- # Get the profile of the connections user
168
+ # Get the profile of the connections user
152
169
  def get_user_profile
153
170
  call(:get, "/users/profile")
154
171
  end
@@ -158,17 +175,17 @@ module CircuitClient
158
175
  @current_user ||= get_user_profile
159
176
  end
160
177
 
161
- # Get profile of a user
178
+ # Get profile of a user
162
179
  def get_users(id)
163
180
  call(:get, "/users/#{id}")
164
181
  end
165
182
 
166
- # Get presence information of a user
183
+ # Get presence information of a user
167
184
  def get_users_presence(id)
168
185
  call(:get, "/users/#{id}/presence")
169
186
  end
170
187
 
171
- private
188
+ private
172
189
 
173
190
  def call(method, path, payload = {}, headers = {})
174
191
  response = connection.send(method) do |req|
@@ -186,7 +203,5 @@ module CircuitClient
186
203
  end
187
204
  return JSON.parse(response.body) if response.success?
188
205
  end
189
-
190
206
  end
191
207
  end
192
-
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.2
4
+ version: 0.0.3
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-02-28 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.6.8
121
+ rubygems_version: 2.7.6
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Simple client for circuit REST API