angie-core-api 0.2.5 → 0.5.1

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: 3f280c23183ad4da841e6900a5e2cf8f4aea56e03dea076e39cb1d6da6bf85f2
4
- data.tar.gz: 9ab9e5a42fdc73a7c1f7e8f28fa82e239f8d9e3c45682a0f147c8708fc3d44d7
3
+ metadata.gz: 5f2f5fa3154686984287f830f2844d46bf14d9bb13dcf203e83169fc136eb4ba
4
+ data.tar.gz: 4729515ac0af1678ceb9acc079dda41bef3b29552765292fb337c242436a5bc0
5
5
  SHA512:
6
- metadata.gz: 8db08c7421e1fe319b483620568e6c90e2dab26255c8c6c4f2c832e6f17eca429163f4684c5a3ef50f98249bdc0c71bdffd1399d36e7749571210080b77e4811
7
- data.tar.gz: 5be04e012ac0bda8b3d535aac32c531fd14f66906721b4cc2a2aebc741a1f3d93434db660ac644b20d331b1829e56cd1fd13f3d02cb1f64fccecd5af4dac40d9
6
+ metadata.gz: f7bb613894c91cd20083232678a79456f96608d2ac3608508b9422465256c6bb21ffe538712a4590fa8da1d5cb4c0856f4584a11e8cc527ecb977bd85c254a4f
7
+ data.tar.gz: aa9242e46beb45c12e4fa3f9da6df2693a6ba635799a8e536095e9731aa9dd605fcd5dcfe473e3720ab7d2667028b6dcda6f7e09b6bca6e7e09e3c7110d06d04
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AngieCoreApi
2
4
  autoload :Configuration, "angie-core-api/configuration"
3
- autoload :Client, "angie-core-api/client"
5
+ autoload :StompClient, "angie-core-api/client"
4
6
  autoload :Flight, "angie-core-api/flight"
5
7
  autoload :Map, "angie-core-api/map"
6
8
  autoload :Notification, "angie-core-api/notification"
9
+ autoload :TV, "angie-core-api/tv"
7
10
  autoload :Weather, "angie-core-api/weather"
8
11
  autoload :DeliveryMethod, "angie-core-api/delivery_method"
12
+ autoload :Message, "angie-core-api/message"
9
13
 
10
14
  def self.configuration
11
15
  @configuration ||= Configuration.new
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "httparty"
2
4
 
3
5
  module AngieCoreApi
@@ -1,4 +1,4 @@
1
- require "active_support"
1
+ # frozen_string_literal: true
2
2
 
3
3
  module AngieCoreApi
4
4
  class Configuration
@@ -6,5 +6,6 @@ module AngieCoreApi
6
6
 
7
7
  config_accessor(:url)
8
8
  config_accessor(:token)
9
+ config_accessor(:rabbitmq)
9
10
  end
10
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AngieCoreApi
2
4
  class DeliveryMethod
3
5
  def initialize(mail) end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AngieCoreApi
2
4
  class Flight
3
5
  def self.info(default_airport, airline, flight_number, date)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AngieCoreApi
2
4
  class Map
3
5
  def self.travel_time(origin, location, radius, unit, size, zoom, locale)
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AngieCoreApi
4
+ module Message
5
+ autoload :AMQPClient, "angie-core-api/message/amqp_client"
6
+ autoload :StompClient, "angie-core-api/message/stomp_client"
7
+ autoload :Queue, "angie-core-api/message/queue"
8
+ autoload :Topic, "angie-core-api/message/topic"
9
+ end
10
+ 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
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AngieCoreApi
4
+ module Message
5
+ class Queue
6
+ def self.classes
7
+ Dir["app/queues/*.rb"].
8
+ map { |file| File.basename(file, ".rb") }.
9
+ select { |type| type != "application_queue" }.
10
+ map(&:camelize).
11
+ map(&:constantize)
12
+ end
13
+
14
+ def self.queue
15
+ path = name.underscore.sub("_queue", "")
16
+ "/queue/#{path}"
17
+ end
18
+
19
+ def self.publish(message)
20
+ StompClient.new.async.publish(queue, message)
21
+ end
22
+
23
+ def self.subscribe
24
+ StompClient.new.async.subscribe(queue) do |message|
25
+ self.new.receive(message)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stomp"
4
+
5
+ module AngieCoreApi
6
+ module Message
7
+ class StompClient
8
+ include Concurrent::Async
9
+
10
+ def initialize
11
+ config = HashWithIndifferentAccess.new(AngieCoreApi.configuration.activemq)
12
+ @client = Stomp::Client.new(config)
13
+ end
14
+
15
+ def publish(queue, data)
16
+ @client.publish(queue, data.to_json)
17
+ @client.close
18
+ end
19
+
20
+ def subscribe(queue)
21
+ @client.subscribe(queue) { |msg| yield JSON.parse(msg.body) }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AngieCoreApi
2
4
  class Notification
3
5
  def self.email(options)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AngieCoreApi
2
4
  class Railtie < Rails::Railtie
3
5
  initializer "angie_core_api.add_delivery_method" do
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AngieCoreApi
2
4
  class Weather
3
5
  def self.info(latitude, longitude, unit, date, locale)
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angie-core-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.5.1
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-22 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actioncable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionmailer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6.1'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: httparty
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -25,33 +67,33 @@ dependencies:
25
67
  - !ruby/object:Gem::Version
26
68
  version: 0.18.1
27
69
  - !ruby/object:Gem::Dependency
28
- name: activesupport
70
+ name: stomp
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
73
  - - "~>"
32
74
  - !ruby/object:Gem::Version
33
- version: '6.0'
75
+ version: '1.4'
34
76
  type: :runtime
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
80
  - - "~>"
39
81
  - !ruby/object:Gem::Version
40
- version: '6.0'
82
+ version: '1.4'
41
83
  - !ruby/object:Gem::Dependency
42
- name: actionmailer
84
+ name: bunny
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - "~>"
46
88
  - !ruby/object:Gem::Version
47
- version: '6.0'
89
+ version: '2.17'
48
90
  type: :runtime
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: '6.0'
96
+ version: '2.17'
55
97
  description: Angie CoreAPI Ruby gem
56
98
  email:
57
99
  - rubygems@angie.ai
@@ -65,14 +107,20 @@ files:
65
107
  - lib/angie-core-api/delivery_method.rb
66
108
  - lib/angie-core-api/flight.rb
67
109
  - lib/angie-core-api/map.rb
110
+ - lib/angie-core-api/message.rb
111
+ - lib/angie-core-api/message/amqp_client.rb
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
68
115
  - lib/angie-core-api/notification.rb
69
116
  - lib/angie-core-api/railtie.rb
117
+ - lib/angie-core-api/tv.rb
70
118
  - lib/angie-core-api/weather.rb
71
119
  homepage: https://angie.ai
72
120
  licenses: []
73
121
  metadata:
74
122
  homepage_uri: https://angie.ai
75
- post_install_message:
123
+ post_install_message:
76
124
  rdoc_options: []
77
125
  require_paths:
78
126
  - lib
@@ -87,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
135
  - !ruby/object:Gem::Version
88
136
  version: '0'
89
137
  requirements: []
90
- rubygems_version: 3.0.3
91
- signing_key:
138
+ rubygems_version: 3.1.4
139
+ signing_key:
92
140
  specification_version: 4
93
141
  summary: Angie CoreAPI Ruby gem
94
142
  test_files: []