angie-core-api 0.2.4 → 0.5.0

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: a80e53d354d041b491c1190b46a34c6cbb67aa8866f9d76502ee13832cb8615d
4
- data.tar.gz: 7ebbc228c0e9191b10aa34f2d9dcad95dc696ea6f7464bb43aae699e261beaf2
3
+ metadata.gz: 165d3139d17e5cbbe90d75bd204e4107919a8ec837ff5ffeaa945885f3a2ecc7
4
+ data.tar.gz: 1a2eb2d0eac4be055898717168d5e60f0e5131a96395dc56f02e7b987463ec6c
5
5
  SHA512:
6
- metadata.gz: b234d98303cdb71f7476c44ab22a870d8b56bed9b4113cc8d3364e94132088dc728be6497eac2b502a30ea518e30472292dfd209519cf5338c5fa5b362959723
7
- data.tar.gz: cda3471d7b3063123bc03e9134b31aee6881789d099f786108cf12ee80ced285d49543af8fd63b8fe18ca8fb87e54a5487f61f41ab8fae8c3fa93399f5253afe
6
+ metadata.gz: 83be6528c7c5a7d8367fa5dc3182ecb9348c830c7f59c69564ead71e6d005eca8852e8ab4fb2a405e500a4c326ea0b9e84dd5196f9c39324322fed843c848dc1
7
+ data.tar.gz: 6aa2b795b7aff71eade956bb5e4bf5555f2692bb12a32acc1d282178a2b5b7a49fe30898b76259a2905d3dd5992827761574c38c5029ebc5b3e026d376a60cc8
@@ -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
@@ -10,7 +12,7 @@ module AngieCoreApi
10
12
  bcc: mail.bcc,
11
13
  subject: mail.subject,
12
14
  text: mail.text_part ? mail.text_part.body&.raw_source : mail.body.raw_source,
13
- html: mail.html_part&.body&.raw_source
15
+ html: mail.html_part ? mail.html_part.body&.raw_source : mail.body.raw_source
14
16
  )
15
17
  end
16
18
  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,59 @@
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 amqp_url
55
+ @config[:url].sub(/\/\/.*@/, "//")
56
+ end
57
+ end
58
+ end
59
+ 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,40 @@
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
+ end
23
+
24
+ def self.publish(routing_key, message_id, payload)
25
+ exchange.publish(payload,
26
+ message_id: message_id,
27
+ routing_key: routing_key,
28
+ persistent: true,
29
+ content_type: "application/json",
30
+ content_encoding: "UTF-8")
31
+ end
32
+
33
+ private
34
+
35
+ def self.queue_name(routing_key)
36
+ "#{AMQPClient.instance.config[:app]}.#{routing_key}"
37
+ end
38
+ end
39
+ end
40
+ 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.4
4
+ version: 0.5.0
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-17 00:00:00.000000000 Z
11
+ date: 2021-05-03 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: []