norad_beacon 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: 493261db07c8a9508e4e9acf6a08bbe18a4d4ba2
4
- data.tar.gz: b1e539d86334dd97fb3c353cced013c692b9edf8
3
+ metadata.gz: 99ae90cc58a883071e41492b8446da7d1130a6e0
4
+ data.tar.gz: 8ec70cfcde36e46f8529ef566f41e60d51983402
5
5
  SHA512:
6
- metadata.gz: 67eb0d6a8cf25d5855810a596a9d290c3b5824e62be0d679d768e4b87170a99f7467ff5e1483471c148d7a92e5428b13ab3beb47b5508ee6834a9109d98035d3
7
- data.tar.gz: 90761a3330b5adf854c1a2f269849cbdb43cf37b360a57da7143a47eda9a9fdbb64b2b137162bd52da412c6b25f25441f4484c4bdd6a264d2d3c9d6fd43984e8
6
+ metadata.gz: 47e67ee1bc409641a34b17818c982e605a28b77f258895e4e4de5350c2771b6246a9dcc80ad5c3c88c8fe2c5dc0ea71e774b11fff0f0538f5056a456296e5b8d
7
+ data.tar.gz: a209abe48d4e7114b02dad759413cf520f456a7b769b14b610652d69a769da7069dabe7fa856562fd2c258b1f7f149b3529bb58dfd1d9af5d21d540d4e34fc74
@@ -26,14 +26,35 @@ module NoradBeacon
26
26
  private
27
27
 
28
28
  def http_req(http_payload, verb)
29
- auth_header = { 'NORAD-SIGNATURE' => http_payload.compute_signature }
30
- address = @norad_root + http_payload.url
31
- send(
32
- verb,
33
- address,
29
+ httpparty_response = send(verb, @norad_root + http_payload.url, http_req_options(http_payload))
30
+ error_msg = unsuccessful_http_response_msg(httpparty_response)
31
+ puts error_msg if error_msg
32
+ httpparty_response
33
+ end
34
+
35
+ def unsuccessful_http_response_msg(httpparty_response)
36
+ code = httpparty_response.response.code
37
+ msg = httpparty_response.response.message
38
+ heading = '[Beacon] Non-200 response received from API:'
39
+
40
+ return nil unless display_http_error?(code, msg)
41
+ return "#{heading} #{code}" if msg.nil? && code
42
+ return "#{heading} #{msg.strip}" if code.nil? && msg
43
+ "#{heading} #{msg.strip}. (#{code})"
44
+ end
45
+
46
+ def display_http_error?(code, msg)
47
+ code.to_s != '200' && (code || msg)
48
+ end
49
+
50
+ def http_req_options(http_payload)
51
+ {
34
52
  body: http_payload.payload,
35
- headers: { 'Content-Type' => 'application/json' }.merge(auth_header)
36
- )
53
+ headers: {
54
+ 'Content-Type' => 'application/json',
55
+ 'NORAD-SIGNATURE' => http_payload.compute_signature
56
+ }
57
+ }
37
58
  end
38
59
  end
39
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoradBeacon
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norad_beacon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hitchcock
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-10-18 00:00:00.000000000 Z
13
+ date: 2018-01-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty