shaf_client 0.7.0 → 0.7.1

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
  SHA256:
3
- metadata.gz: de51f879d8fd9a032434411bbe29df1b1dd6629c39277c1373384ae10615e2ff
4
- data.tar.gz: fa37f60def169a85f3910d6c4dd36faa3155b299f42725606682500e722c504e
3
+ metadata.gz: c4eda6aea2ca9040216f1dee7732b7123e98edfbbec2d3b53dd567f50940d145
4
+ data.tar.gz: a1d43989ce6bff97ac6801ef4fcb67f77e01933cbdf796694e6339d57606d9d0
5
5
  SHA512:
6
- metadata.gz: 6e11dd7e17aa9052606440cbb16c06e8bec99933b0d1033c803116e14c18591795eb26304277288f249c8812a3991d8a2a3bca6deedd1e0c59ea0a1a529abd85
7
- data.tar.gz: 4db2d441198e463dc8f590638d2017baab472d4d00a205b0694c6b9aef74f6952d5fb715e408f81da70959bbf9d7aeb02970ecc78a1853859dbcb595c0c43432
6
+ metadata.gz: d0ca1c6347bf9fb9d15eab004cf7cc83c5f9d571f32cb0fa65c8aaec179c03f9a6f6cd1762951d9904c2eecd537ea0d2b0d04ff347c171099541c7ef1628f9f3
7
+ data.tar.gz: 976c5ce8cd4e7868c957c7b4c74696298cb7b262ddb314a359efd28e52b6aa4c1925fe698718eed75472acf646737b12cddedaefb7bb9311026e9599fc934ef3
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -15,6 +15,7 @@ require 'shaf_client/resource'
15
15
  require 'shaf_client/shaf_form'
16
16
  require 'shaf_client/hal_form'
17
17
  require 'shaf_client/api_error'
18
+ require 'shaf_client/problem_json'
18
19
  require 'shaf_client/empty_resource'
19
20
  require 'shaf_client/unknown_resource'
20
21
  require 'shaf_client/hypertext_cache_strategy'
@@ -39,20 +39,24 @@ class ShafClient
39
39
  to_s
40
40
  end
41
41
 
42
- def attribute(key)
43
- _attribute(key) or raise Error, "No attribute for key: #{key}"
42
+ def attribute(key, &block)
43
+ block ||= proc { raise Error, "No attribute for key: #{key}" }
44
+ _attribute(key, &block)
44
45
  end
45
46
 
46
- def link(rel)
47
- _link(rel) or raise Error, "No link with rel: #{rel}"
47
+ def link(rel, &block)
48
+ block ||= proc { raise Error, "No link with rel: #{rel}" }
49
+ _link(rel, &block)
48
50
  end
49
51
 
50
- def curie(rel)
51
- _curie(rel) or raise Error, "No curie with rel: #{rel}"
52
+ def curie(rel, &block)
53
+ block ||= proc { raise Error, "No curie with rel: #{rel}" }
54
+ _curie(rel, &block)
52
55
  end
53
56
 
54
- def embedded(rel)
55
- _embedded(rel) or raise Error, "No embedded resources with rel: #{rel}"
57
+ def embedded(rel, &block)
58
+ block ||= proc { raise Error, "No embedded resources with rel: #{rel}" }
59
+ _embedded(rel, &block)
56
60
  end
57
61
 
58
62
  def rel?(rel)
@@ -75,22 +79,38 @@ class ShafClient
75
79
  @payload ||= {}
76
80
  end
77
81
 
78
- def _attribute(key)
79
- attributes[key.to_sym]
82
+ def _attribute(key, &block)
83
+ if block
84
+ attributes.fetch(key.to_sym, &block)
85
+ else
86
+ attributes[key.to_sym]
87
+ end
80
88
  end
81
89
 
82
- def _link(rel)
90
+ def _link(rel, &block)
83
91
  rewritten_rel = best_match(links.keys, rel)
84
- links[rewritten_rel]
92
+ if block
93
+ links.fetch(rewritten_rel, &block)
94
+ else
95
+ links[rewritten_rel]
96
+ end
85
97
  end
86
98
 
87
- def _curie(rel)
88
- curies[rel.to_sym]
99
+ def _curie(rel, &block)
100
+ if block
101
+ curies.fetch(rel.to_sym, &block)
102
+ else
103
+ curies[rel.to_sym]
104
+ end
89
105
  end
90
106
 
91
- def _embedded(rel)
107
+ def _embedded(rel, &block)
92
108
  rewritten_rel = best_match(embedded_resources.keys, rel)
93
- embedded_resources[rewritten_rel]
109
+ if block
110
+ embedded_resources.fetch(rewritten_rel, &block)
111
+ else
112
+ embedded_resources[rewritten_rel]
113
+ end
94
114
  end
95
115
 
96
116
  def <<(other)
@@ -2,6 +2,5 @@ class ShafClient
2
2
  module MimeTypes
3
3
  MIME_TYPE_JSON = 'application/json'
4
4
  MIME_TYPE_HAL = 'application/hal+json'
5
- DEFAULT_ADAPTER = :net_http
6
5
  end
7
6
  end
@@ -0,0 +1,38 @@
1
+ require 'shaf_client/form'
2
+ require 'shaf_client/status_codes'
3
+
4
+ class ShafClient
5
+ class ProblemJson < Resource
6
+ include StatusCodes
7
+
8
+ content_type 'application/problem+json'
9
+
10
+ def type
11
+ attribute(:type) { 'about:blank' }
12
+ end
13
+
14
+ def title
15
+ attribute(:title) do
16
+ next unless type == 'about:blank'
17
+
18
+ StatusCode[status] if (400..599).include? status.to_i
19
+ end
20
+ end
21
+
22
+ def status
23
+ attribute(:status) { http_status }
24
+ end
25
+
26
+ def detail
27
+ attribute(:detail)
28
+ end
29
+
30
+ def instance
31
+ attribute(:instance)
32
+ end
33
+
34
+ def to_h
35
+ attributes
36
+ end
37
+ end
38
+ end
@@ -89,6 +89,10 @@ class ShafClient
89
89
  delete(:delete)
90
90
  end
91
91
 
92
+ def content_type
93
+ headers['content-type']
94
+ end
95
+
92
96
  protected
93
97
 
94
98
  def <<(other)
@@ -0,0 +1,70 @@
1
+ class ShafClient
2
+ module StatusCodes
3
+ StatusCode = {
4
+ 100 => 'Continue',
5
+ 101 => 'Switching Protocols',
6
+ 102 => 'Processing',
7
+ 103 => 'Early Hints',
8
+ 200 => 'OK',
9
+ 201 => 'Created',
10
+ 202 => 'Accepted',
11
+ 203 => 'Non-Authoritative Information',
12
+ 204 => 'No Content',
13
+ 205 => 'Reset Content',
14
+ 206 => 'Partial Content',
15
+ 207 => 'Multi-Status',
16
+ 208 => 'Already Reported',
17
+ 226 => 'IM Used',
18
+ 300 => 'Multiple Choices',
19
+ 301 => 'Moved Permanently',
20
+ 302 => 'Found',
21
+ 303 => 'See Other',
22
+ 304 => 'Not Modified',
23
+ 305 => 'Use Proxy',
24
+ 306 => '(Unused)',
25
+ 307 => 'Temporary Redirect',
26
+ 308 => 'Permanent Redirect',
27
+ 400 => 'Bad Request',
28
+ 401 => 'Unauthorized',
29
+ 402 => 'Payment Required',
30
+ 403 => 'Forbidden',
31
+ 404 => 'Not Found',
32
+ 405 => 'Method Not Allowed',
33
+ 406 => 'Not Acceptable',
34
+ 407 => 'Proxy Authentication Required',
35
+ 408 => 'Request Timeout',
36
+ 409 => 'Conflict',
37
+ 410 => 'Gone',
38
+ 411 => 'Length Required',
39
+ 412 => 'Precondition Failed',
40
+ 413 => 'Payload Too Large',
41
+ 414 => 'URI Too Long',
42
+ 415 => 'Unsupported Media Type',
43
+ 416 => 'Range Not Satisfiable',
44
+ 417 => 'Expectation Failed',
45
+ 421 => 'Misdirected Request',
46
+ 422 => 'Unprocessable Entity',
47
+ 423 => 'Locked',
48
+ 424 => 'Failed Dependency',
49
+ 425 => 'Too Early',
50
+ 426 => 'Upgrade Required',
51
+ 428 => 'Precondition Required',
52
+ 429 => 'Too Many Requests',
53
+ 431 => 'Request Header Fields Too Large',
54
+ 451 => 'Unavailable For Legal Reasons',
55
+ 500 => 'Internal Server Error',
56
+ 501 => 'Not Implemented',
57
+ 502 => 'Bad Gateway',
58
+ 503 => 'Service Unavailable',
59
+ 504 => 'Gateway Timeout',
60
+ 505 => 'HTTP Version Not Supported',
61
+ 506 => 'Variant Also Negotiates',
62
+ 507 => 'Insufficient Storage',
63
+ 508 => 'Loop Detected',
64
+ 510 => 'Not Extended',
65
+ 511 => 'Network Authentication Required',
66
+ }
67
+ StatusCode.default = 'Unassigned'
68
+ StatusCode.freeze
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  class ShafClient
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shaf_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  ZMhjYR7sRczGJx+GxGU2EaR0bjRsPVlC4ywtFxoOfRG3WaJcpWGEoAoMJX6Z0bRv
31
31
  M40=
32
32
  -----END CERTIFICATE-----
33
- date: 2019-11-01 00:00:00.000000000 Z
33
+ date: 2020-05-16 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: faraday
@@ -38,14 +38,14 @@ dependencies:
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0.15'
41
+ version: '1.0'
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0.15'
48
+ version: '1.0'
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: faraday-http-cache
51
51
  requirement: !ruby/object:Gem::Requirement
@@ -66,14 +66,14 @@ dependencies:
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '12.0'
69
+ version: '13.0'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '12.0'
76
+ version: '13.0'
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: minitest
79
79
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  version: '5'
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
- version: '5.10'
86
+ version: '5.14'
87
87
  type: :development
88
88
  prerelease: false
89
89
  version_requirements: !ruby/object:Gem::Requirement
@@ -93,7 +93,7 @@ dependencies:
93
93
  version: '5'
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '5.10'
96
+ version: '5.14'
97
97
  description: A HAL client customized for Shaf APIs
98
98
  email: sammy.henningsson@gmail.com
99
99
  executables: []
@@ -114,9 +114,11 @@ files:
114
114
  - lib/shaf_client/link.rb
115
115
  - lib/shaf_client/middleware/redirect.rb
116
116
  - lib/shaf_client/mime_types.rb
117
+ - lib/shaf_client/problem_json.rb
117
118
  - lib/shaf_client/resource.rb
118
119
  - lib/shaf_client/resource_mapper.rb
119
120
  - lib/shaf_client/shaf_form.rb
121
+ - lib/shaf_client/status_codes.rb
120
122
  - lib/shaf_client/unknown_resource.rb
121
123
  - lib/shaf_client/version.rb
122
124
  homepage: https://github.com/sammyhenningsson/shaf_client
@@ -138,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  - !ruby/object:Gem::Version
139
141
  version: '0'
140
142
  requirements: []
141
- rubygems_version: 3.0.6
143
+ rubygems_version: 3.0.3
142
144
  signing_key:
143
145
  specification_version: 4
144
146
  summary: HAL client for Shaf
metadata.gz.sig CHANGED
Binary file