angie-core-api 0.3.1 → 0.5.2

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: 0a907b04190f30ca644d2940b3e1e3e308b62443eb1f9e86fbc96ba0325d26d5
4
- data.tar.gz: dc6f7fca4ceb86aaec2019647e285b2ff5c3851598c7d5a61feff7ece43e5da6
3
+ metadata.gz: d185df7acc9ca64734639270b514f271b7fe022387427e4e8916bfb65f01e659
4
+ data.tar.gz: d201e4255fdb6b170a3cbdb18844b5b9936deeccfa41f1f1d2298731e879e22e
5
5
  SHA512:
6
- metadata.gz: 57e9e5688d548bdb9db6867e93a7684a61e73c572738818612957ce7486f39bab27d0276ba1ff326dcb302971f3cb38a16b422c87d7efb1223587293c2e8e986
7
- data.tar.gz: 4e680e8d5981156568b94587cdcc66d68b2d38276b1f7363341cc925625c808602c724d2e6abc264416191112746dfb16862a4f559229896ebfc8235e6a76836
6
+ metadata.gz: 0b5322ead6f5f95b595de2d99f5147e096e115dc0a2bcc800ae028bec8830072873a102dae243f67ad40252751482d88af84a288cc17411a0ae0e92053fbea04
7
+ data.tar.gz: 9a9d0109021b99ba85c73a3354cc9177a92a3219f8acfa340fe9b8452b8537fe50201fe8fe040102c558e86269cb7cb21c874a05f61446b91b0b153a4281152a
@@ -6,6 +6,6 @@ module AngieCoreApi
6
6
 
7
7
  config_accessor(:url)
8
8
  config_accessor(:token)
9
- config_accessor(:activemq)
9
+ config_accessor(:rabbitmq)
10
10
  end
11
11
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bunny"
4
+
5
+ module AngieCoreApi
6
+ module Message
7
+ class AMQPClient
8
+ include Singleton
9
+
10
+ attr :config, :connection, :channel
11
+
12
+ def self.instance
13
+ @@instance ||= new
14
+ end
15
+
16
+ def initialize
17
+ @rabbitmq_config = AngieCoreApi.configuration.rabbitmq
18
+ @config = HashWithIndifferentAccess.new(@rabbitmq_config)
19
+
20
+ @connection = Bunny.new(config[:url])
21
+ @connection.start
22
+
23
+ @channel = @connection.create_channel
24
+
25
+ puts "Connected to #{amqp_url}"
26
+ rescue Bunny::TCPConnectionFailed => e
27
+ puts "Connection to #{amqp_url} failed: #{e.message}"
28
+ end
29
+
30
+ def self.classes
31
+ Dir["app/topics/*.rb"].
32
+ map { |file| File.basename(file, ".rb") }.
33
+ select { |type| type != "application_topic" }.
34
+ map(&:camelize).
35
+ map(&:constantize)
36
+ end
37
+
38
+ def self.connect
39
+ AMQPClient.instance
40
+
41
+ classes.each { |k| k.new }
42
+ end
43
+
44
+ def self.disconnect!
45
+ amqp_url = AMQPClient.instance.amqp_url
46
+
47
+ AMQPClient.instance.channel.close
48
+ AMQPClient.instance.connection.close
49
+ @@instance = nil
50
+
51
+ puts "Disconnected from #{amqp_url}"
52
+ end
53
+
54
+ def self.reconnect!
55
+ disconnect!
56
+ connect
57
+ end
58
+
59
+ def amqp_url
60
+ @config[:url].sub(/\/\/.*@/, "//")
61
+ end
62
+ end
63
+ end
64
+ end
@@ -17,11 +17,11 @@ module AngieCoreApi
17
17
  end
18
18
 
19
19
  def self.publish(message)
20
- Client.new.async.publish(queue, message)
20
+ StompClient.new.async.publish(queue, message)
21
21
  end
22
22
 
23
23
  def self.subscribe
24
- Client.new.async.subscribe(queue) do |message|
24
+ StompClient.new.async.subscribe(queue) do |message|
25
25
  self.new.receive(message)
26
26
  end
27
27
  end
@@ -4,7 +4,7 @@ require "stomp"
4
4
 
5
5
  module AngieCoreApi
6
6
  module Message
7
- class Client
7
+ class StompClient
8
8
  include Concurrent::Async
9
9
 
10
10
  def initialize
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AngieCoreApi
4
+ module Message
5
+ class Topic
6
+ def self.topic_name
7
+ @topic_name ||= name.underscore.dasherize
8
+ end
9
+
10
+ def self.exchange
11
+ @exchange ||= AMQPClient.instance.channel.topic(topic_name, durable: true, auto_delete: true)
12
+ end
13
+
14
+ def self.subscribe(routing_key, options = { manual_ack: false })
15
+ queue = AMQPClient.instance.channel.queue(queue_name(routing_key), durable: true)
16
+ queue.bind(exchange, routing_key: routing_key)
17
+
18
+ queue.subscribe(options.merge(block: false)) do |delivery_info, properties, payload|
19
+ yield delivery_info, properties, payload
20
+ AMQPClient.instance.channel.acknowledge(delivery_info.delivery_tag) if options[:manual_ack]
21
+ end
22
+ rescue Interrupt => _
23
+ AMQPClient.reconnect!
24
+ end
25
+
26
+ def self.publish(routing_key, message_id, payload)
27
+ exchange.publish(payload,
28
+ message_id: message_id,
29
+ routing_key: routing_key,
30
+ persistent: true,
31
+ content_type: "application/json",
32
+ content_encoding: "UTF-8")
33
+ end
34
+
35
+ private
36
+
37
+ def self.queue_name(routing_key)
38
+ "#{AMQPClient.instance.config[:app]}.#{routing_key}"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,7 +2,9 @@
2
2
 
3
3
  module AngieCoreApi
4
4
  module Message
5
- autoload :Client, "angie-core-api/message/client"
5
+ autoload :AMQPClient, "angie-core-api/message/amqp_client"
6
+ autoload :StompClient, "angie-core-api/message/stomp_client"
6
7
  autoload :Queue, "angie-core-api/message/queue"
8
+ autoload :Topic, "angie-core-api/message/topic"
7
9
  end
8
10
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AngieCoreApi
4
+ class TV
5
+ def initialize(provider)
6
+ @provider = provider
7
+ end
8
+
9
+ def command(command)
10
+ Client.data(:post, "/tv", { provider: @provider, command: command})
11
+ end
12
+ end
13
+ end
@@ -2,10 +2,11 @@
2
2
 
3
3
  module AngieCoreApi
4
4
  autoload :Configuration, "angie-core-api/configuration"
5
- autoload :Client, "angie-core-api/client"
5
+ autoload :StompClient, "angie-core-api/client"
6
6
  autoload :Flight, "angie-core-api/flight"
7
7
  autoload :Map, "angie-core-api/map"
8
8
  autoload :Notification, "angie-core-api/notification"
9
+ autoload :TV, "angie-core-api/tv"
9
10
  autoload :Weather, "angie-core-api/weather"
10
11
  autoload :DeliveryMethod, "angie-core-api/delivery_method"
11
12
  autoload :Message, "angie-core-api/message"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angie-core-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angie Hospitality
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-30 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '6.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: '6.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionmailer
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.0'
33
+ version: '6.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '6.0'
40
+ version: '6.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '6.0'
47
+ version: '6.1'
48
48
  type: :runtime
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: '6.0'
54
+ version: '6.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: httparty
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.18.1
61
+ version: 0.20.0
62
62
  type: :runtime
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.18.1
68
+ version: 0.20.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: stomp
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bunny
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.17'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.17'
83
97
  description: Angie CoreAPI Ruby gem
84
98
  email:
85
99
  - rubygems@angie.ai
@@ -94,16 +108,19 @@ files:
94
108
  - lib/angie-core-api/flight.rb
95
109
  - lib/angie-core-api/map.rb
96
110
  - lib/angie-core-api/message.rb
97
- - lib/angie-core-api/message/client.rb
111
+ - lib/angie-core-api/message/amqp_client.rb
98
112
  - lib/angie-core-api/message/queue.rb
113
+ - lib/angie-core-api/message/stomp_client.rb
114
+ - lib/angie-core-api/message/topic.rb
99
115
  - lib/angie-core-api/notification.rb
100
116
  - lib/angie-core-api/railtie.rb
117
+ - lib/angie-core-api/tv.rb
101
118
  - lib/angie-core-api/weather.rb
102
119
  homepage: https://angie.ai
103
120
  licenses: []
104
121
  metadata:
105
122
  homepage_uri: https://angie.ai
106
- post_install_message:
123
+ post_install_message:
107
124
  rdoc_options: []
108
125
  require_paths:
109
126
  - lib
@@ -118,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
135
  - !ruby/object:Gem::Version
119
136
  version: '0'
120
137
  requirements: []
121
- rubygems_version: 3.0.3
122
- signing_key:
138
+ rubygems_version: 3.1.4
139
+ signing_key:
123
140
  specification_version: 4
124
141
  summary: Angie CoreAPI Ruby gem
125
142
  test_files: []