harmony-service 0.3.7 → 0.3.8

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
  SHA1:
3
- metadata.gz: cbc119d784fec7bb9d15ea494e8416babc7a6640
4
- data.tar.gz: '049f0cf96ebf3e3697b2c85cca128e7a215c1e5c'
3
+ metadata.gz: 97593af953be5a6547c65d0dcd81626fa5c454f6
4
+ data.tar.gz: 86c5b8b56b9a9243bcf556a830b21b4222daf568
5
5
  SHA512:
6
- metadata.gz: 34324d51945b97ab2a6b2a5b98f46737db546881f7159fb6477af3a2b2ddff6e0b5e2d8cbba24c8fb595153da001c8a43b4d57d8dd34eb0a540a050e7e20ece4
7
- data.tar.gz: 71d2b58d9d42d265831268a4d96620d3662065376c316353614b3db631e41866babc2c2803d0af7ed59af93e985114d3a68aacd43e4696a3dbc06e21a514fa78
6
+ metadata.gz: 371cfce0682a1cd6e7cee8a5e4c092c2a11267de7740f020aa34e0a91271b381de5e91bc5286ea1b738aefce19ce1c2f550b635c97871d87129cf926b1308cfa
7
+ data.tar.gz: 781dc113635b85f326176738295ee4a4c72da3dc65c77ed230b406c06425f1542077918a6dbf1ab279875e4459feb03596bbdb3610380f5cbd3d1453a342b8ab
@@ -21,5 +21,8 @@ require 'harmony/service/form/get_response'
21
21
 
22
22
  require 'harmony/service/flow/ended_request'
23
23
 
24
+ require 'harmony/service/notification/request'
25
+ require 'harmony/service/notification/app_response'
26
+
24
27
  require "harmony/service/rpc_service"
25
28
 
@@ -16,11 +16,11 @@ module Harmony
16
16
  logger.debug "Request: #{message}"
17
17
  request = Oj.load(message)
18
18
  request_class = request.class
19
- response_class = request_response_mapping[request_class]
20
- raise "Unacceptable request class: #{request_class}" if response_class.nil?
19
+ response_classes = request_response_mapping[request_class]
20
+ raise "Unacceptable request class: #{request_class}" if response_classes.nil?
21
21
 
22
22
  result = new_handler.work_with_request(request)
23
- raise "Unacceptable response class: #{result.class}" unless response_class === result
23
+ raise "Unacceptable response class: #{result.class}" unless response_classes.include?(result.class)
24
24
 
25
25
  json = Oj.dump(result)
26
26
  logger.debug "Response: #{json}"
@@ -76,13 +76,14 @@ module Harmony
76
76
  private
77
77
  def request_response_mapping
78
78
  {
79
- Calculator::Request => Calculator::Response,
80
- ActionList::ListRequest => Array,
81
- ActionList::ItemRequest => ActionList::Item,
82
- ActionList::ActionRequest => Response,
83
- Chart::Request => Chart::Response,
84
- Form::GetRequest => Form::GetResponse,
85
- Flow::EndedRequest => Response
79
+ Calculator::Request => [Calculator::Response],
80
+ ActionList::ListRequest => [Array],
81
+ ActionList::ItemRequest => [ActionList::Item],
82
+ ActionList::ActionRequest => [Response],
83
+ Chart::Request => [Chart::Response],
84
+ Form::GetRequest => [Form::GetResponse],
85
+ Flow::EndedRequest => [Response],
86
+ Notification::Request => [Notification::AppResponse, Response]
86
87
  }
87
88
  end
88
89
 
@@ -1,6 +1,6 @@
1
1
  module Harmony
2
2
  module Service
3
- VERSION = "0.3.7"
3
+ VERSION = "0.3.8"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harmony-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brooke-Smith
@@ -148,7 +148,6 @@ files:
148
148
  - lib/harmony/service/response.rb
149
149
  - lib/harmony/service/rpc_service.rb
150
150
  - lib/harmony/service/version.rb
151
- - spec/harmony/rpc_service_spec.rb
152
151
  - spec/harmony/service/rpc_service_spec.rb
153
152
  - spec/spec_helper.rb
154
153
  homepage: https://github.com/HarmonyMobile/harmony-service
@@ -176,6 +175,5 @@ signing_key:
176
175
  specification_version: 4
177
176
  summary: Gem which helps you to build Harmony services
178
177
  test_files:
179
- - spec/harmony/rpc_service_spec.rb
180
178
  - spec/harmony/service/rpc_service_spec.rb
181
179
  - spec/spec_helper.rb
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Harmony::Service::RpcService do
4
-
5
- describe "#work_with_params" do
6
- let(:metadata) { instance_double("Metadata", reply_to: "harmony.trello", correlation_id: "abc123") }
7
- let(:handler) { handler = double("Object") }
8
-
9
- context "ack!" do
10
- before(:each) do
11
- expect(handler).to receive(:work_with_request).with(kind_of(request.class)) { response }
12
- allow(subject).to receive(:new_handler) { handler }
13
- allow(subject).to receive(:send_response)
14
- allow(subject).to receive(:ack!)
15
- subject.work_with_params(Oj.dump(request), {}, metadata)
16
- end
17
-
18
- context "calculation" do
19
- let(:request) { Harmony::Service::Calculator::Request.new(harmony_user_email: "matt@futureworkshops.com", inputs: {"lat" => "51.0", "lon" => "0.1"}) }
20
- let(:response) { Harmony::Service::Calculator::Response.new(outputs: {price: 50})}
21
-
22
- it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::Calculator::Response\",\"outputs\":{\":price\":50}}", "harmony.trello", "abc123") }
23
- it { expect(subject).to have_received(:ack!) }
24
- end
25
-
26
- context "action list" do
27
- context "list" do
28
- let(:request) { Harmony::Service::ActionList::ListRequest.new(harmony_user_email: "matt@futureworkshops.com", page: 0, per_page: 10) }
29
- let(:response) { [Harmony::Service::ActionList::Item.new({id: 1, title: "Carrots"})]}
30
-
31
- it { expect(subject).to have_received(:send_response).with("[{\"^o\":\"Harmony::Service::ActionList::Item\",\"id\":1,\"title\":\"Carrots\"}]", "harmony.trello", "abc123") }
32
- it { expect(subject).to have_received(:ack!) }
33
- end
34
-
35
- context "item" do
36
- let(:request) { Harmony::Service::ActionList::ItemRequest.new(harmony_user_email: "matt@futureworkshops.com", id: 1) }
37
- let(:response) { Harmony::Service::ActionList::Item.new({id: 1, title: "Carrots", subtitle: "Bag of Carrots", detail_html: "<html><body>Carrots</body></html>"})}
38
-
39
- it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::ActionList::Item\",\"id\":1,\"title\":\"Carrots\",\"subtitle\":\"Bag of Carrots\",\"detail_html\":\"<html><body>Carrots</body></html>\"}", "harmony.trello", "abc123") }
40
- it { expect(subject).to have_received(:ack!) }
41
- end
42
-
43
- context "action" do
44
- let(:request) { Harmony::Service::ActionList::ActionRequest.new(harmony_user_email: "matt@futureworkshops.com", id: 1, action: "Done") }
45
- let(:response) { nil }
46
-
47
- it { expect(subject).to have_received(:send_response).with("null", "harmony.trello", "abc123") }
48
- it { expect(subject).to have_received(:ack!) }
49
- end
50
- end
51
-
52
- context "chart" do
53
- let(:request) { Harmony::Service::Chart::Request.new(harmony_user_email: "matt@futureworkshops.com") }
54
- let(:response) { Harmony::Service::Chart::Response.new(x_values: ["Jan", "Feb", "Mar"], y_values: [10, 20, 40])}
55
- it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::Chart::Response\",\"x_values\":[\"Jan\",\"Feb\",\"Mar\"],\"y_values\":[10,20,40]}", "harmony.trello", "abc123") }
56
- it { expect(subject).to have_received(:ack!) }
57
- end
58
-
59
- context "form" do
60
- context 'get' do
61
- let(:request) { Harmony::Service::Form::GetRequest.new(harmony_user_email: "matt@futureworkshops.com", inputs: ['satisfaction_level']) }
62
- let(:response) { Harmony::Service::Form::GetResponse.new({input_values: [{'satisfaction_level': ['1','2','3']}]})}
63
- it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::Form::GetResponse\",\"input_values\":[{\":satisfaction_level\":[\"1\",\"2\",\"3\"]}],\"options\":{}}", "harmony.trello", "abc123") }
64
- it { expect(subject).to have_received(:ack!) }
65
- end
66
- end
67
-
68
- context "flow ended" do
69
- let(:request) { Harmony::Service::Flow::EndedRequest.new(harmony_user_email: "matt@futureworkshops.com", pages: [{page_id: 1}]) }
70
- let(:response) { Harmony::Service::Response.new}
71
- it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::Response\"}", "harmony.trello", "abc123") }
72
- it { expect(subject).to have_received(:ack!) }
73
- end
74
-
75
- end
76
-
77
- context "unacceptable request class" do
78
- before(:each) do
79
- allow(subject).to receive(:work_with_request).and_raise("A timeout occured")
80
- allow(subject).to receive(:send_response)
81
- allow(subject).to receive(:reject!)
82
-
83
- metadata = instance_double("Metadata", reply_to: "harmony.trello", correlation_id: "abc123")
84
- subject.work_with_params("{\"trello_board_id\": \"12345\"}", {}, metadata)
85
- end
86
-
87
- it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::ErrorResponse\",\"message\":\"An error occured.\",\"detailed_message\":\"Unacceptable request class: Hash\"}", "harmony.trello", "abc123") }
88
- it { expect(subject).to have_received(:reject!) }
89
- end
90
- end
91
-
92
-
93
- end