circuit-api 0.0.13 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51388927d9356a41306ede8c608c201ef3b18f85c34eb7a25088beda20e24d36
4
- data.tar.gz: 5115068f40ff72bf72cb7cca4b52303c5c1491bebbc633e334b856658af0f091
3
+ metadata.gz: 9ce474a23b0044ab9eb65a9520538d0b8a7b436bb903c590e71b84c48a995b93
4
+ data.tar.gz: ae0bd0fd17880639a8ccc6457fc37af1d507d7ff6a7a0ec3132a2517d466380f
5
5
  SHA512:
6
- metadata.gz: 07aa006bd1e4ff648a6396b5d12e6c4059e24cb2fab966dc18d730a8f49cc9ceb3ad1463bedd604f6e0c6c3621d83affdd425e450e5ce0be70916a1d5dfb9259
7
- data.tar.gz: 35487f07c5fd30107327ad84f7c036707dca1565253857a1077743055131d9b3d9ffc5ae4d58ba333330e26d550e4b927e1f58e8a8ff39a305611c00105ec1b8
6
+ metadata.gz: 10e227014cb40e0d3cfe9bb17c6d0a153b4a3d465f778f67179259f5502abf4676efa423d6a086885f4ba8f29855fae73c6fcdf6213bc53840d2fd18d1a2b60a
7
+ data.tar.gz: fb29aa1ca7e81ce0dec95abb18f6a588e2afc069c32fc98283d811af65d85d7b77f715e79530a033184395169e659ec4eebf44ef834420b0e828142a1103dc89
@@ -14,6 +14,7 @@ require 'circuit_api/utils/object'
14
14
  require 'circuit_api/resources/base'
15
15
  require 'circuit_api/resources/conversation'
16
16
  require 'circuit_api/resources/label'
17
+ require 'circuit_api/resources/message_item'
17
18
  require 'circuit_api/resources/message'
18
19
  require 'circuit_api/resources/presence'
19
20
  require 'circuit_api/resources/rtc_session'
@@ -37,6 +37,10 @@ module CircuitApi
37
37
  CircuitApi::Resources::Message.new(self)
38
38
  end
39
39
 
40
+ def message_items
41
+ CircuitApi::Resources::MessageItem.new(self)
42
+ end
43
+
40
44
  def presence
41
45
  CircuitApi::Resources::Presence.new(self)
42
46
  end
@@ -68,6 +68,13 @@ module CircuitApi
68
68
  #binding.pry
69
69
  CircuitApi::Resource.new('foo', attributes)
70
70
  end
71
+
72
+ def handle_validation_errors(bad_request_error)
73
+ errors = bad_request_error.json_message['validationErrors']
74
+ raise unless errors
75
+
76
+ raise CircuitApi::ValidationError.new(errors, bad_request_error.uri)
77
+ end
71
78
  end
72
79
  end
73
80
  end
@@ -1,6 +1,11 @@
1
1
  module CircuitApi
2
2
  module Resources
3
3
  class Conversation < Base
4
+ DIRECT = 'DIRECT'.freeze
5
+ GROUP = 'GROUP'.freeze
6
+ COMMUNITY = 'COMMUNITY'.freeze
7
+ LARGE = 'LARGE'.freeze
8
+
4
9
  def api_resource
5
10
  'conversations'
6
11
  end
@@ -14,6 +14,9 @@ module CircuitApi
14
14
 
15
15
  result = connection(path, params).post
16
16
  response_to_object(result)
17
+
18
+ rescue CircuitApi::BadRequest => e
19
+ handle_validation_errors(e)
17
20
  end
18
21
  end
19
22
  end
@@ -0,0 +1,101 @@
1
+ module CircuitApi
2
+ module Resources
3
+ class MessageItem < Base
4
+ def api_resource
5
+ 'conversations/:conversation_id/messages/:id'
6
+ end
7
+
8
+ def find(id)
9
+ path = api_resource
10
+ .sub(':conversation_id/', '')
11
+ .sub(':id', id)
12
+
13
+ result = connection(path).get
14
+ response_to_object(result)
15
+ end
16
+
17
+ def all(conversation_id, params = {})
18
+ path = api_resource
19
+ .sub(':conversation_id', conversation_id)
20
+ .sub('messages/:id', 'items')
21
+
22
+ result = connection(path, params).get
23
+ response_to_object(result)
24
+ end
25
+
26
+ def update(conversation_id, id, params)
27
+ path = api_resource
28
+ .sub(':conversation_id', conversation_id)
29
+ .sub(':id', id)
30
+
31
+ result = connection(path, params).put
32
+ response_to_object(result)
33
+ end
34
+
35
+ def delete(conversation_id, id)
36
+ path = api_resource
37
+ .sub(':conversation_id', conversation_id)
38
+ .sub(':id', id)
39
+
40
+ result = connection(path).delete
41
+ response_to_object(result)
42
+ end
43
+
44
+ def pin(conversation_id, id)
45
+ path = api_resource
46
+ .sub(':conversation_id', conversation_id)
47
+ .sub('messages', 'pins')
48
+ .sub(':id', id)
49
+
50
+ result = connection(path).post
51
+ response_to_object(result)
52
+ end
53
+
54
+ def unpin(conversation_id, id)
55
+ path = api_resource
56
+ .sub(':conversation_id', conversation_id)
57
+ .sub('messages', 'pins')
58
+ .sub(':id', id)
59
+
60
+ result = connection(path).delete
61
+ response_to_object(result)
62
+ end
63
+
64
+ def flag(conversation_id, id, params)
65
+ path = api_resource
66
+ .sub(':conversation_id', conversation_id)
67
+ .sub(':id', id)
68
+
69
+ result = connection("#{path}/flag", params).post
70
+ response_to_object(result)
71
+ end
72
+
73
+ def unflag(conversation_id, id)
74
+ path = api_resource
75
+ .sub(':conversation_id', conversation_id)
76
+ .sub(':id', id)
77
+
78
+ result = connection("#{path}/flag").delete
79
+ response_to_object(result)
80
+ end
81
+
82
+ def like(conversation_id, id)
83
+ path = api_resource
84
+ .sub(':conversation_id', conversation_id)
85
+ .sub(':id', id)
86
+
87
+ result = connection("#{path}/like").post
88
+ response_to_object(result)
89
+ end
90
+
91
+ def unlike(conversation_id, id)
92
+ path = api_resource
93
+ .sub(':conversation_id', conversation_id)
94
+ .sub(':id', id)
95
+
96
+ result = connection("#{path}/like").delete
97
+ response_to_object(result)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -1,6 +1,17 @@
1
1
  module CircuitApi
2
2
  module Resources
3
3
  class User < Base
4
+ # Participant type
5
+ REGULAR = 'REGULAR'.freeze
6
+ MODERATOR = 'MODERATOR'.freeze
7
+ GUEST = 'GUEST'.freeze
8
+ FORMER = 'FORMER'.freeze
9
+ BOT = 'BOT'.freeze
10
+
11
+ # User stase
12
+ ACTIVE_STATE = 'ACTIVE'.freeze
13
+ DELETED_STATE = 'DELETED'.freeze
14
+
4
15
  def api_resource
5
16
  'users'
6
17
  end
@@ -5,6 +5,7 @@ module CircuitApi
5
5
  CONVERSATION_UPDATE = 'CONVERSATION.UPDATE'.freeze
6
6
  CONVERSATION_ADD_ITEM = 'CONVERSATION.ADD_ITEM'.freeze
7
7
  CONVERSATION_UPDATE_ITEM = 'CONVERSATION.UPDATE_ITEM'.freeze
8
+ USER_SUBMIT_FORM = 'USER.SUBMIT_FORM_DATA'.freeze
8
9
 
9
10
  def api_resource
10
11
  'webhooks'
@@ -1,4 +1,5 @@
1
1
  module CircuitApi
2
+ # Network Errors
2
3
  class HttpError < StandardError
3
4
  attr_reader :error_code, :error_body, :uri
4
5
 
@@ -11,10 +12,28 @@ module CircuitApi
11
12
  def message
12
13
  "HTTP #{error_code} - URI: #{uri}.\n Error: #{error_body}"
13
14
  end
15
+
16
+ def json_message
17
+ JSON.parse(error_body)
18
+ end
14
19
  end
15
20
 
16
21
  class BadRequest < HttpError; end;
17
22
  class Unauthorized < HttpError; end;
18
23
  class InternalServerError < HttpError; end;
19
24
  class ServiceUnavailable < HttpError; end;
25
+
26
+ # Data errors
27
+ class ValidationError < StandardError
28
+ attr_reader :errors, :uri
29
+
30
+ def initialize(errors, uri)
31
+ @errors = errors
32
+ @uri = uri
33
+ end
34
+
35
+ def message
36
+ "URI: #{uri}.\n Errors: #{errors}"
37
+ end
38
+ end
20
39
  end
@@ -1,3 +1,3 @@
1
1
  module CircuitApi
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.19'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuit-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Pochet
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry
42
+ name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.10'
47
+ version: 11.1.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.10'
54
+ version: 11.1.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 3.10.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 3.10.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sinatra
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.1.0
83
83
  description: Wrapper of the Circuit Rest API
84
84
  email: vincent@elqano.com
85
85
  executables: []
@@ -93,6 +93,7 @@ files:
93
93
  - lib/circuit_api/resources/conversation.rb
94
94
  - lib/circuit_api/resources/label.rb
95
95
  - lib/circuit_api/resources/message.rb
96
+ - lib/circuit_api/resources/message_item.rb
96
97
  - lib/circuit_api/resources/presence.rb
97
98
  - lib/circuit_api/resources/rtc_session.rb
98
99
  - lib/circuit_api/resources/user.rb
@@ -102,7 +103,7 @@ files:
102
103
  - lib/circuit_api/utils/errors.rb
103
104
  - lib/circuit_api/utils/object.rb
104
105
  - lib/circuit_api/version.rb
105
- homepage:
106
+ homepage: https://github.com/Elqanoteam/circuit-rest-client
106
107
  licenses:
107
108
  - MIT
108
109
  metadata: {}
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
123
124
  requirements: []
124
- rubygems_version: 3.0.1
125
+ rubygems_version: 3.0.3
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Circuit Rest API client