harmony-service 0.3.5 → 0.3.7

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: b1290880d874335b7a3c88a5cb76e6bacb39a2f0
4
- data.tar.gz: 5fe08632a8dba9fb790bd0a99f7eb4c742670a42
3
+ metadata.gz: cbc119d784fec7bb9d15ea494e8416babc7a6640
4
+ data.tar.gz: '049f0cf96ebf3e3697b2c85cca128e7a215c1e5c'
5
5
  SHA512:
6
- metadata.gz: 7066e6df2bef3a7c644f15b80316ff37299afec97df9d945c7b692fdc2c7d30e30211486be1daa18992735d6b5475dbdcf5f86d403e4b37e0fbd9bd65d005f90
7
- data.tar.gz: e8680ed78c6eaec8e51bbea63da89524cd6d53a437aaccd915680dc075b09964567b28a6db0333d978ad2d5e39b17ba3da17451672ce2ebce5530ff57f7d7a2e
6
+ metadata.gz: 34324d51945b97ab2a6b2a5b98f46737db546881f7159fb6477af3a2b2ddff6e0b5e2d8cbba24c8fb595153da001c8a43b4d57d8dd34eb0a540a050e7e20ece4
7
+ data.tar.gz: 71d2b58d9d42d265831268a4d96620d3662065376c316353614b3db631e41866babc2c2803d0af7ed59af93e985114d3a68aacd43e4696a3dbc06e21a514fa78
@@ -0,0 +1,3 @@
1
+ class Harmony::Service::Notification::AppResponse < Harmony::Service::Response
2
+ attr_accessor :text
3
+ end
@@ -0,0 +1,3 @@
1
+ class Harmony::Service::Notification::Request < Harmony::Service::Request
2
+
3
+ end
@@ -1,6 +1,6 @@
1
1
  module Harmony
2
2
  module Service
3
- VERSION = "0.3.5"
3
+ VERSION = "0.3.7"
4
4
  end
5
5
  end
6
6
 
@@ -24,3 +24,7 @@ end
24
24
  module Harmony::Service::Flow
25
25
 
26
26
  end
27
+
28
+ module Harmony::Service::Notification
29
+
30
+ end
@@ -0,0 +1,100 @@
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) { Harmony::Service::Response.new }
46
+
47
+ it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::Response\"}", "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
+ context "app notification" do
76
+ let(:request) { Harmony::Service::Notification::Request.new }
77
+ let(:response) { Harmony::Service::Notification::AppResponse.new(text: 'Check out the new data')}
78
+ it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::Notification::AppResponse\",\"text\":\"Check out the new data\"}", "harmony.trello", "abc123") }
79
+ it { expect(subject).to have_received(:ack!) }
80
+ end
81
+
82
+ end
83
+
84
+ context "unacceptable request class" do
85
+ before(:each) do
86
+ allow(subject).to receive(:work_with_request).and_raise("A timeout occured")
87
+ allow(subject).to receive(:send_response)
88
+ allow(subject).to receive(:reject!)
89
+
90
+ metadata = instance_double("Metadata", reply_to: "harmony.trello", correlation_id: "abc123")
91
+ subject.work_with_params("{\"trello_board_id\": \"12345\"}", {}, metadata)
92
+ end
93
+
94
+ it { expect(subject).to have_received(:send_response).with("{\"^o\":\"Harmony::Service::ErrorResponse\",\"message\":\"An error occurred.\",\"detailed_message\":\"Unacceptable request class: Hash\"}", "harmony.trello", "abc123") }
95
+ it { expect(subject).to have_received(:reject!) }
96
+ end
97
+ end
98
+
99
+
100
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harmony-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brooke-Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-05 00:00:00.000000000 Z
11
+ date: 2017-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sneakers
@@ -142,11 +142,14 @@ files:
142
142
  - lib/harmony/service/form/get_request.rb
143
143
  - lib/harmony/service/form/get_response.rb
144
144
  - lib/harmony/service/message.rb
145
+ - lib/harmony/service/notification/app_response.rb
146
+ - lib/harmony/service/notification/request.rb
145
147
  - lib/harmony/service/request.rb
146
148
  - lib/harmony/service/response.rb
147
149
  - lib/harmony/service/rpc_service.rb
148
150
  - lib/harmony/service/version.rb
149
151
  - spec/harmony/rpc_service_spec.rb
152
+ - spec/harmony/service/rpc_service_spec.rb
150
153
  - spec/spec_helper.rb
151
154
  homepage: https://github.com/HarmonyMobile/harmony-service
152
155
  licenses:
@@ -174,4 +177,5 @@ specification_version: 4
174
177
  summary: Gem which helps you to build Harmony services
175
178
  test_files:
176
179
  - spec/harmony/rpc_service_spec.rb
180
+ - spec/harmony/service/rpc_service_spec.rb
177
181
  - spec/spec_helper.rb