reactio 1.0.0

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.
@@ -0,0 +1,23 @@
1
+ describe 'describe incident' do
2
+ include_context 'default_service_context'
3
+
4
+ subject do
5
+ service.describe_incident(123)
6
+ end
7
+
8
+ before { stub }
9
+
10
+ let(:stub) do
11
+ stub_api_request(
12
+ organization, api_key,
13
+ method: :get, path: "/api/v1/incidents/123"
14
+ ).to_return(
15
+ status: 200,
16
+ body: incident.to_json
17
+ )
18
+ end
19
+
20
+ let(:incident) { fixture('incident') }
21
+
22
+ it { is_expected.to eq(incident) }
23
+ end
@@ -0,0 +1,62 @@
1
+ describe 'handle error' do
2
+ include_context 'default_service_context'
3
+
4
+ subject do
5
+ service.notify_incident(incident_id, foo: 'bar')
6
+ end
7
+
8
+ before { stub }
9
+
10
+ let(:incident_id) { 456 }
11
+ let(:options) { { foo: 'bar' } }
12
+
13
+ let(:stub) do
14
+ stub_api_request(
15
+ organization, api_key,
16
+ method: :post, path: '/api/v1/notifications',
17
+ body: { incident_id: incident_id }.merge(options).to_json
18
+ ).to_return(
19
+ status: status,
20
+ body: error_response.to_json
21
+ )
22
+ end
23
+
24
+ context 'bad request' do
25
+ let(:status) { 400 }
26
+ let(:error_response) do
27
+ {
28
+ errors: [
29
+ { field: "notification_text", code: "missing_field" }
30
+ ],
31
+ type: "validation_error",
32
+ message: "validation error"
33
+ }
34
+ end
35
+
36
+ it { expect { subject }.to raise_error(Reactio::BadRequest, error_response.inspect) }
37
+ end
38
+
39
+ context 'authentication error' do
40
+ let(:status) { 401 }
41
+ let(:error_response) do
42
+ {
43
+ type: "authentication_error",
44
+ message: "invalid api key"
45
+ }
46
+ end
47
+
48
+ it { expect { subject }.to raise_error(Reactio::AuthenticationError, error_response.inspect) }
49
+ end
50
+
51
+ context 'server error' do
52
+ let(:status) { 500 }
53
+ let(:error_response) do
54
+ {
55
+ type: "internal_server_error",
56
+ message: "Internal Server Error"
57
+ }
58
+ end
59
+
60
+ it { expect { subject }.to raise_error(Reactio::ServerError, error_response.inspect) }
61
+ end
62
+ end
@@ -0,0 +1,76 @@
1
+ describe 'list incidents' do
2
+ include_context 'default_service_context'
3
+
4
+ subject do
5
+ service.list_incidents(options)
6
+ end
7
+
8
+ before { stub }
9
+
10
+ let(:incident_list) { fixture('incident_list') }
11
+
12
+ let(:stub) do
13
+ stub_api_request(
14
+ organization, api_key,
15
+ method: :get, path: '/api/v1/incidents',
16
+ query: expected_options
17
+ ).to_return(
18
+ status: 200,
19
+ body: incident_list.to_json
20
+ )
21
+ end
22
+
23
+ context 'without options option' do
24
+ subject { service.list_incidents }
25
+ let(:expected_options) { {} }
26
+ it { is_expected.to eq(incident_list) }
27
+ end
28
+
29
+ context 'with from option' do
30
+ let(:options) { { from: time } }
31
+ let(:expected_options) { { from: time.to_i } }
32
+ let(:time) { Time.parse('2015-01-23 12:34:56') }
33
+ it { is_expected.to eq(incident_list) }
34
+ end
35
+
36
+ context 'with to option' do
37
+ let(:options) { { to: time } }
38
+ let(:expected_options) { { to: time.to_i } }
39
+ let(:time) { Time.parse('2015-01-23 12:34:56') }
40
+ it { is_expected.to eq(incident_list) }
41
+ end
42
+
43
+ context 'with status option' do
44
+ let(:options) { { status: status } }
45
+
46
+ context 'given open as status' do
47
+ let(:status) { 'open' }
48
+ let(:expected_options) { { status: 'open' } }
49
+ it { is_expected.to eq(incident_list) }
50
+ end
51
+
52
+ context 'given pend as status' do
53
+ let(:status) { 'pend' }
54
+ let(:expected_options) { { status: 'pend' } }
55
+ it { is_expected.to eq(incident_list) }
56
+ end
57
+
58
+ context 'given close as status' do
59
+ let(:status) { 'close' }
60
+ let(:expected_options) { { status: 'close' } }
61
+ it { is_expected.to eq(incident_list) }
62
+ end
63
+ end
64
+
65
+ context 'with page option' do
66
+ let(:options) { { page: 1 } }
67
+ let(:expected_options) { { page: 1 } }
68
+ it { is_expected.to eq(incident_list) }
69
+ end
70
+
71
+ context 'with per_page option' do
72
+ let(:options) { { per_page: 100 } }
73
+ let(:expected_options) { { per_page: 100 } }
74
+ it { is_expected.to eq(incident_list) }
75
+ end
76
+ end
@@ -0,0 +1,52 @@
1
+ describe 'execute notification' do
2
+ include_context 'default_service_context'
3
+
4
+ subject do
5
+ service.notify_incident(incident_id, options)
6
+ end
7
+
8
+ let(:incident_id) { 123 }
9
+
10
+ before { stub }
11
+
12
+ let(:stub) do
13
+ stub_api_request(
14
+ organization, api_key,
15
+ method: :post, path: '/api/v1/notifications',
16
+ body: { incident_id: incident_id }.merge(expected_options).to_json
17
+ ).to_return(
18
+ status: 201,
19
+ body: notification.to_json
20
+ )
21
+ end
22
+
23
+ let(:notification) { fixture('notification') }
24
+
25
+ context 'without options' do
26
+ subject { service.notify_incident(incident_id) }
27
+ let(:expected_options) { {} }
28
+ it { is_expected.to eq(notification) }
29
+ end
30
+
31
+ context 'with notification text option' do
32
+ let(:options) { { text: text } }
33
+ let(:expected_options) { { text: text } }
34
+ let(:text) { '至急対応をお願いします。' }
35
+ it { is_expected.to eq(notification) }
36
+ end
37
+
38
+ context 'with notification call option' do
39
+ let(:options) { { call: call } }
40
+ let(:expected_options) { { call: call } }
41
+
42
+ context 'given true as call' do
43
+ let(:call) { true }
44
+ it { is_expected.to eq(notification) }
45
+ end
46
+
47
+ context 'given false as call' do
48
+ let(:call) { false }
49
+ it { is_expected.to eq(notification) }
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reactio
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hajime Sueyoshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: The official Reactio API Client for ruby.
84
+ email:
85
+ - hajime.sueyoshi@gaiax.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/reactio.rb
96
+ - lib/reactio/api_client.rb
97
+ - lib/reactio/api_endpoint.rb
98
+ - lib/reactio/errors.rb
99
+ - lib/reactio/faraday_engine.rb
100
+ - lib/reactio/service.rb
101
+ - lib/reactio/utils.rb
102
+ - lib/reactio/version.rb
103
+ - reactio.gemspec
104
+ - spec/fixtures/created_incident.yml
105
+ - spec/fixtures/incident.yml
106
+ - spec/fixtures/incident_list.yml
107
+ - spec/fixtures/notification.yml
108
+ - spec/reactio_spec.rb
109
+ - spec/service_spec.rb
110
+ - spec/spec_helper.rb
111
+ - spec/support/default_client_context.rb
112
+ - spec/support/request_stub_helper.rb
113
+ - spec/v1/create_incident_spec.rb
114
+ - spec/v1/describe_incident_spec.rb
115
+ - spec/v1/error_handling_spec.rb
116
+ - spec/v1/list_incidents_spec.rb
117
+ - spec/v1/notify_incident_spec.rb
118
+ homepage: https://reactio.jp/
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Reactio API Client
142
+ test_files:
143
+ - spec/fixtures/created_incident.yml
144
+ - spec/fixtures/incident.yml
145
+ - spec/fixtures/incident_list.yml
146
+ - spec/fixtures/notification.yml
147
+ - spec/reactio_spec.rb
148
+ - spec/service_spec.rb
149
+ - spec/spec_helper.rb
150
+ - spec/support/default_client_context.rb
151
+ - spec/support/request_stub_helper.rb
152
+ - spec/v1/create_incident_spec.rb
153
+ - spec/v1/describe_incident_spec.rb
154
+ - spec/v1/error_handling_spec.rb
155
+ - spec/v1/list_incidents_spec.rb
156
+ - spec/v1/notify_incident_spec.rb