zenaton 0.2.2 → 0.2.3

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
  SHA256:
3
- metadata.gz: 7939421fd535c9d50c3bc52a475ee7c747d817c535efb6c4f9f73e067ad43c64
4
- data.tar.gz: d339d9dd2b93d09d35e65150b0adb02c8034095d68e60530eccc216d0bb9f24e
3
+ metadata.gz: a6a9c77b434d1e5d39b2360c9d5580653820c9a6ed7d0e4cbecc8adc7e1f6dea
4
+ data.tar.gz: 4c1ac27216af901b760dd663007f79e6b57b56787fbc2cb6cbc7166eb0173abe
5
5
  SHA512:
6
- metadata.gz: a95ef6370c230b7abc53c04238d0655f653555b08cc51135c13015cc8c5717d2a59faf01cee4f35781bf2ecb7b53baf9312530c4f05a133ec2f29169debd3a25
7
- data.tar.gz: 784fec1e1808ecc5d6444580c278cf6538365b34a2865423b3b9a144d2b27bdbc602f2c5af6f769f19d0a71b0a9881f4a19afaaed04640f15fbec77e20578835
6
+ metadata.gz: aa0e97fa56d7ddf29855763660213f9fb40eda55af32b91984161fcb8d1b8ee3e2c427b18af86b4c2f47902a52f0777125975eaefe4feb87752882526d42432a
7
+ data.tar.gz: 7e68f8714d40d9c8fdf52c222dd449c6950e98bf71ab709b0272c1816e871a6a1172537363a72d21d8db0b93d184d63738c476ae9de99c32ba3e49c7552d5872
data/CHANGELOG.md ADDED
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.3] - 2018-08-13
10
+ ### Added
11
+ - Introduce this changelog file.
12
+
13
+ ### Removed
14
+ - Dependency on httparty
15
+
16
+ ## [0.2.2] - 2018-08-10
17
+ ### Fixed
18
+ - [Serialization]: Distinct objects, even if equal to one another, now map to
19
+ distinct entries in the data store.
20
+
21
+ ## [0.2.1] - 2018-08-10
22
+ ### Added
23
+ - Serializer now handles the same objects as Ruby's built-in JSON library.
24
+ - Instructions on how to use the gem in a Ruby on Rails application.
25
+
26
+ ### Changed
27
+ - Fixed typos and broken links in the readme
28
+
29
+ ## [0.2.0] - 2018-08-08
30
+ ### Added
31
+ - New serialization format for array and hashes. Currently running workflows
32
+ should still be able to deserialize data in the old format.
33
+
34
+ ### Fixed
35
+ - Arrays and hashes with circular structures no longer cause infinite loops when
36
+ serializing.
37
+
38
+ ## [0.1.1] - 2018-08-03
39
+ ### Added
40
+ - Run test suite against all currently supported ruby versions
41
+ - Readme has a rubygems badge showing the current released version.
42
+
43
+ ### Fixed
44
+ - Serialization should now be working on Ruby 2.3.
45
+
46
+ ## 0.1.0 - 2018-08-03
47
+ ### Added
48
+ - Initial release.
49
+
50
+ [Unreleased]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.3...HEAD
51
+ [0.2.3]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.2...v0.2.3
52
+ [0.2.2]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.1...v0.2.2
53
+ [0.2.1]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.0...v0.2.1
54
+ [0.2.0]: https://github.com/zenaton/zenaton-ruby/compare/v0.1.1...v0.2.0
55
+ [0.1.1]: https://github.com/zenaton/zenaton-ruby/compare/v0.1.0...v0.1.1
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zenaton (0.2.2)
4
+ zenaton (0.2.3)
5
5
  activesupport
6
- httparty
7
6
  tzinfo-data
8
7
 
9
8
  GEM
@@ -24,15 +23,12 @@ GEM
24
23
  diff-lcs (1.3)
25
24
  docile (1.3.1)
26
25
  hashdiff (0.3.7)
27
- httparty (0.16.2)
28
- multi_xml (>= 0.5.2)
29
26
  i18n (1.1.0)
30
27
  concurrent-ruby (~> 1.0)
31
28
  jaro_winkler (1.5.1)
32
29
  json (2.1.0)
33
30
  method_source (0.9.0)
34
31
  minitest (5.11.3)
35
- multi_xml (0.6.0)
36
32
  parallel (1.12.1)
37
33
  parser (2.5.1.2)
38
34
  ast (~> 2.4.0)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'httparty'
3
+ require 'net/http'
4
4
  require 'zenaton/exceptions'
5
5
 
6
6
  module Zenaton
@@ -11,12 +11,26 @@ module Zenaton
11
11
  # - sets appropriate headers for each request type
12
12
  # - translates exceptions into Zenaton specific ones
13
13
  class Http
14
+ # Net::HTTP errors translated into a Zenaton::ConnectionError
15
+ ALL_NET_HTTP_ERRORS = [
16
+ Timeout::Error,
17
+ Errno::EINVAL,
18
+ Errno::ECONNRESET,
19
+ EOFError,
20
+ Net::HTTPBadResponse,
21
+ Net::HTTPHeaderSyntaxError,
22
+ Net::ProtocolError
23
+ ].freeze
24
+
14
25
  # Makes a GET request and sets the correct headers
15
26
  #
16
27
  # @param url [String] the url for the request
17
28
  # @return [Hash] the parsed json response
18
29
  def get(url)
19
- request(:get, url, default_options)
30
+ parsed_url = parse_url(url)
31
+ request = Net::HTTP::Get.new(parsed_url[:uri])
32
+ set_body_and_headers(request, default_options)
33
+ make_request(request, parsed_url)
20
34
  end
21
35
 
22
36
  # Makes a POST request with some data and sets the correct headers
@@ -25,7 +39,10 @@ module Zenaton
25
39
  # @param body [Hash] the payload to send with the request
26
40
  # @return [Hash] the parsed json response
27
41
  def post(url, body)
28
- request(:post, url, post_options(body))
42
+ parsed_url = parse_url(url)
43
+ request = Net::HTTP::Post.new(parsed_url[:uri])
44
+ set_body_and_headers(request, post_options(body))
45
+ make_request(request, parsed_url)
29
46
  end
30
47
 
31
48
  # Makes a PUT request with some data and sets the correct headers
@@ -34,25 +51,46 @@ module Zenaton
34
51
  # @param body [Hash] the payload to send with the request
35
52
  # @return [Hash] the parsed json response
36
53
  def put(url, body)
37
- request(:put, url, put_options(body))
54
+ parsed_url = parse_url(url)
55
+ request = Net::HTTP::Put.new(parsed_url[:uri])
56
+ set_body_and_headers(request, put_options(body))
57
+ make_request(request, parsed_url)
38
58
  end
39
59
 
40
60
  private
41
61
 
42
- def request(verb, url, options)
43
- make_request(verb, url, options)
44
- rescue SocketError, HTTParty::Error => error
45
- raise Zenaton::ConnectionError, error
62
+ def parse_url(url)
63
+ uri = URI.parse(url)
64
+ { uri: uri, use_ssl: uri.scheme == 'https' }
65
+ end
66
+
67
+ def set_body_and_headers(request, options)
68
+ options[:headers].each do |key, value|
69
+ request[key] = value
70
+ end
71
+ request.body = options[:body].to_json if options[:body]
72
+ end
73
+
74
+ def make_request(request, parsed_url)
75
+ res = get_response(request, parsed_url)
76
+ raise Zenaton::InternalError, format_error(res) if errors?(res)
77
+ JSON.parse(res.body)
78
+ rescue *ALL_NET_HTTP_ERRORS
79
+ raise Zenaton::ConnectionError
46
80
  end
47
81
 
48
- def make_request(verb, url, options)
49
- response = HTTParty.send(verb, url, options)
50
- raise Zenaton::InternalError, format_error(response) if errors? response
51
- JSON.parse(response.body)
82
+ def get_response(request, parsed_url)
83
+ Net::HTTP.start(
84
+ parsed_url[:uri].hostname,
85
+ parsed_url[:uri].port,
86
+ use_ssl: parsed_url[:use_ssl]
87
+ ) do |http|
88
+ http.request(request)
89
+ end
52
90
  end
53
91
 
54
92
  def errors?(response)
55
- response.code >= 400
93
+ response.code.to_i >= 400
56
94
  end
57
95
 
58
96
  def format_error(response)
@@ -67,7 +105,7 @@ module Zenaton
67
105
 
68
106
  def post_options(body)
69
107
  {
70
- body: body.to_json,
108
+ body: body,
71
109
  headers: {
72
110
  'Accept' => 'application/json',
73
111
  'Content-Type' => 'application/json'
@@ -26,6 +26,7 @@ module Zenaton
26
26
  defined?(::BigDecimal) ? ::BigDecimal : nil
27
27
  ].compact.freeze
28
28
 
29
+ # Handle blank object instantiation differently for these classes
29
30
  NUMERIC_INITIALIATION = [
30
31
  ::Rational,
31
32
  ::Complex,
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Zenaton
4
4
  # This gem's current version
5
- VERSION = '0.2.2'
5
+ VERSION = '0.2.3'
6
6
  end
data/zenaton.gemspec CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_runtime_dependency 'activesupport'
26
- spec.add_runtime_dependency 'httparty'
27
26
  spec.add_runtime_dependency 'tzinfo-data'
28
27
 
29
28
  spec.add_development_dependency 'bundler', '~> 1.16'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zenaton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-10 00:00:00.000000000 Z
11
+ date: 2018-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: httparty
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: tzinfo-data
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -204,6 +190,7 @@ files:
204
190
  - ".rspec"
205
191
  - ".rubocop.yml"
206
192
  - ".yardopts"
193
+ - CHANGELOG.md
207
194
  - CODE_OF_CONDUCT.md
208
195
  - Gemfile
209
196
  - Gemfile.lock