jsonapi-consumer 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +27 -0
  3. data/.gitignore +1 -0
  4. data/Gemfile +6 -4
  5. data/README.md +9 -38
  6. data/Rakefile +17 -6
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/jsonapi-consumer.gemspec +10 -11
  10. data/lib/jsonapi/consumer/associations/base_association.rb +26 -0
  11. data/lib/jsonapi/consumer/associations/belongs_to.rb +30 -0
  12. data/lib/jsonapi/consumer/associations/has_many.rb +26 -0
  13. data/lib/jsonapi/consumer/associations/has_one.rb +19 -0
  14. data/lib/jsonapi/consumer/connection.rb +36 -0
  15. data/lib/jsonapi/consumer/error_collector.rb +91 -0
  16. data/lib/jsonapi/consumer/errors.rb +34 -76
  17. data/lib/jsonapi/consumer/formatter.rb +145 -0
  18. data/lib/jsonapi/consumer/helpers/callbacks.rb +27 -0
  19. data/lib/jsonapi/consumer/helpers/dirty.rb +71 -0
  20. data/lib/jsonapi/consumer/helpers/dynamic_attributes.rb +83 -0
  21. data/lib/jsonapi/consumer/helpers/uri.rb +9 -0
  22. data/lib/jsonapi/consumer/implementation.rb +12 -0
  23. data/lib/jsonapi/consumer/included_data.rb +49 -0
  24. data/lib/jsonapi/consumer/linking/links.rb +22 -0
  25. data/lib/jsonapi/consumer/linking/top_level_links.rb +39 -0
  26. data/lib/jsonapi/consumer/meta_data.rb +19 -0
  27. data/lib/jsonapi/consumer/middleware/json_request.rb +26 -0
  28. data/lib/jsonapi/consumer/middleware/parse_json.rb +22 -23
  29. data/lib/jsonapi/consumer/middleware/status.rb +41 -0
  30. data/lib/jsonapi/consumer/paginating/paginator.rb +89 -0
  31. data/lib/jsonapi/consumer/parsers/parser.rb +113 -0
  32. data/lib/jsonapi/consumer/query/builder.rb +212 -0
  33. data/lib/jsonapi/consumer/query/requestor.rb +67 -0
  34. data/lib/jsonapi/consumer/relationships/relations.rb +56 -0
  35. data/lib/jsonapi/consumer/relationships/top_level_relations.rb +30 -0
  36. data/lib/jsonapi/consumer/resource.rb +514 -54
  37. data/lib/jsonapi/consumer/result_set.rb +25 -0
  38. data/lib/jsonapi/consumer/schema.rb +153 -0
  39. data/lib/jsonapi/consumer/utils.rb +28 -0
  40. data/lib/jsonapi/consumer/version.rb +1 -1
  41. data/lib/jsonapi/consumer.rb +59 -34
  42. metadata +51 -111
  43. data/.rspec +0 -2
  44. data/CHANGELOG.md +0 -36
  45. data/lib/jsonapi/consumer/middleware/raise_error.rb +0 -21
  46. data/lib/jsonapi/consumer/middleware/request_headers.rb +0 -20
  47. data/lib/jsonapi/consumer/middleware/request_timeout.rb +0 -9
  48. data/lib/jsonapi/consumer/middleware.rb +0 -5
  49. data/lib/jsonapi/consumer/parser.rb +0 -75
  50. data/lib/jsonapi/consumer/query/base.rb +0 -34
  51. data/lib/jsonapi/consumer/query/create.rb +0 -9
  52. data/lib/jsonapi/consumer/query/delete.rb +0 -10
  53. data/lib/jsonapi/consumer/query/find.rb +0 -16
  54. data/lib/jsonapi/consumer/query/new.rb +0 -15
  55. data/lib/jsonapi/consumer/query/update.rb +0 -11
  56. data/lib/jsonapi/consumer/query.rb +0 -5
  57. data/lib/jsonapi/consumer/resource/association_concern.rb +0 -203
  58. data/lib/jsonapi/consumer/resource/attributes_concern.rb +0 -70
  59. data/lib/jsonapi/consumer/resource/connection_concern.rb +0 -99
  60. data/lib/jsonapi/consumer/resource/finders_concern.rb +0 -28
  61. data/lib/jsonapi/consumer/resource/object_build_concern.rb +0 -28
  62. data/lib/jsonapi/consumer/resource/serializer_concern.rb +0 -63
  63. data/spec/fixtures/.gitkeep +0 -0
  64. data/spec/fixtures/resources.rb +0 -45
  65. data/spec/fixtures/responses.rb +0 -64
  66. data/spec/jsonapi/consumer/associations_spec.rb +0 -166
  67. data/spec/jsonapi/consumer/attributes_spec.rb +0 -27
  68. data/spec/jsonapi/consumer/connection_spec.rb +0 -147
  69. data/spec/jsonapi/consumer/error_handling_spec.rb +0 -37
  70. data/spec/jsonapi/consumer/object_build_spec.rb +0 -20
  71. data/spec/jsonapi/consumer/parser_spec.rb +0 -39
  72. data/spec/jsonapi/consumer/resource_spec.rb +0 -62
  73. data/spec/jsonapi/consumer/serializer_spec.rb +0 -41
  74. data/spec/spec_helper.rb +0 -97
  75. data/spec/support/.gitkeep +0 -0
  76. data/spec/support/load_fixtures.rb +0 -4
@@ -0,0 +1,153 @@
1
+ module JSONAPI::Consumer
2
+ class Schema
3
+ module Types
4
+
5
+ class Integer
6
+ def self.cast(value, _)
7
+ value.to_i
8
+ end
9
+ end
10
+
11
+ class String
12
+ def self.cast(value, _)
13
+ value.to_s
14
+ end
15
+ end
16
+
17
+ class Float
18
+ def self.cast(value, _)
19
+ value.to_f
20
+ end
21
+ end
22
+
23
+ class Time
24
+ def self.cast(value, _)
25
+ value.is_a?(::Time) ? value : ::Time.parse(value)
26
+ end
27
+ end
28
+
29
+ class Decimal
30
+ def self.cast(value, _)
31
+ value.to_d
32
+ end
33
+ end
34
+
35
+ class Boolean
36
+ def self.cast(value, default)
37
+ case value
38
+ when "false", "0", 0, false
39
+ false
40
+ when "true", "1", 1, true
41
+ true
42
+ else
43
+ # if it's unknown, use the default value
44
+ default
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ class TypeFactory
52
+ @@types = {}
53
+ # Register a new type key or keys with appropriate classes
54
+ #
55
+ # eg:
56
+ #
57
+ # require 'money'
58
+ #
59
+ # class MyMoneyCaster
60
+ # def self.cast(value, default)
61
+ # begin
62
+ # Money.new(value, "USD")
63
+ # rescue ArgumentError
64
+ # default
65
+ # end
66
+ # end
67
+ # end
68
+ #
69
+ # JSONAPI::Consumer::Schema::Types.register money: MyMoneyCaster
70
+ #
71
+ # You can setup several at once:
72
+ #
73
+ # JSONAPI::Consumer::Schema::Types.register money: MyMoneyCaster,
74
+ # date: MyJsonDateTypeCaster
75
+ #
76
+ #
77
+ #
78
+ #
79
+ def self.register(type_hash)
80
+ @@types.merge!(type_hash)
81
+ end
82
+
83
+ def self.type_for(type)
84
+ @@types[type]
85
+ end
86
+
87
+ self.register int: Types::Integer,
88
+ integer: Types::Integer,
89
+ string: Types::String,
90
+ float: Types::Float,
91
+ time: Types::Time,
92
+ decimal: Types::Decimal,
93
+ boolean: Types::Boolean
94
+
95
+ end
96
+
97
+ Property = Struct.new(:name, :type, :default) do
98
+ def cast(value)
99
+ return nil if value.nil?
100
+ return value if type.nil?
101
+ type_caster = TypeFactory.type_for(type)
102
+ return value if type_caster.nil?
103
+ type_caster.cast(value, default)
104
+ end
105
+ end
106
+
107
+ def initialize
108
+ @properties = {}
109
+ end
110
+
111
+ # Add a property to the schema
112
+ #
113
+ # @param name [Symbol] the name of the property
114
+ # @param options [Hash] property options
115
+ # @option options [Symbol] :type The property type
116
+ # @option options [Symbol] :default The default value for the property
117
+ # @return [void]
118
+ def add(name, options)
119
+ @properties[name.to_sym] = Property.new(name.to_sym, options[:type], options[:default])
120
+ end
121
+
122
+ # How many properties are defined
123
+ #
124
+ # @return [Fixnum] the number of defined properties
125
+ def size
126
+ @properties.size
127
+ end
128
+
129
+ alias_method :length, :size
130
+
131
+ def each_property(&block)
132
+ @properties.values.each(&block)
133
+ end
134
+
135
+ alias_method :each, :each_property
136
+
137
+ # Look up a property by name
138
+ #
139
+ # @param property_name [String] the name of the property
140
+ # @return [Property, nil] the property definition for property_name or nil
141
+ def find(property_name)
142
+ @properties[property_name.to_sym]
143
+ end
144
+
145
+ alias_method :[], :find
146
+
147
+ class << self
148
+ def register(type_hash)
149
+ TypeFactory.register(type_hash)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,28 @@
1
+ module JSONAPI::Consumer
2
+ module Utils
3
+
4
+ def self.compute_type(klass, type_name)
5
+ # If the type is prefixed with a scope operator then we assume that
6
+ # the type_name is an absolute reference.
7
+ return type_name.constantize if type_name.match(/^::/)
8
+
9
+ # Build a list of candidates to search for
10
+ candidates = []
11
+ klass.name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
12
+ candidates << type_name
13
+
14
+ candidates.each do |candidate|
15
+ begin
16
+ constant = candidate.constantize
17
+ return constant if candidate == constant.to_s
18
+ rescue NameError => e
19
+ # We don't want to swallow NoMethodError < NameError errors
20
+ raise e unless e.instance_of?(NameError)
21
+ end
22
+ end
23
+
24
+ raise NameError, "uninitialized constant #{candidates.first}"
25
+ end
26
+
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module Jsonapi
2
2
  module Consumer
3
- VERSION = "0.1.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -1,41 +1,66 @@
1
1
  require "jsonapi/consumer/version"
2
2
 
3
- require 'faraday'
4
- require 'faraday_middleware'
5
- require 'active_model'
6
-
7
- require "active_support/concern"
8
- require "active_support/core_ext"
9
- require "active_support/inflector"
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "addressable/uri"
6
+ require "active_support/core_ext/string"
10
7
 
11
8
  module JSONAPI
12
9
  module Consumer
13
10
 
11
+ module Associations
12
+ autoload :BaseAssociation, 'jsonapi/consumer/associations/base_association'
13
+ autoload :BelongsTo, 'jsonapi/consumer/associations/belongs_to'
14
+ autoload :HasMany, 'jsonapi/consumer/associations/has_many'
15
+ autoload :HasOne, 'jsonapi/consumer/associations/has_one'
16
+ end
17
+
18
+ module Helpers
19
+ autoload :Callbacks, 'jsonapi/consumer/helpers/callbacks'
20
+ autoload :Dirty, 'jsonapi/consumer/helpers/dirty'
21
+ autoload :DynamicAttributes, 'jsonapi/consumer/helpers/dynamic_attributes'
22
+ autoload :URI, 'jsonapi/consumer/helpers/uri'
23
+ end
24
+
25
+ module Linking
26
+ autoload :Links, "jsonapi/consumer/linking/links"
27
+ autoload :TopLevelLinks, "jsonapi/consumer/linking/top_level_links"
28
+ end
29
+
30
+ module Relationships
31
+ autoload :Relations, "jsonapi/consumer/relationships/relations"
32
+ autoload :TopLevelRelations, "jsonapi/consumer/relationships/top_level_relations"
33
+ end
34
+
35
+ module Middleware
36
+ autoload :JsonRequest, 'jsonapi/consumer/middleware/json_request'
37
+ autoload :ParseJson, 'jsonapi/consumer/middleware/parse_json'
38
+ autoload :Status, 'jsonapi/consumer/middleware/status'
39
+ end
40
+
41
+ module Paginating
42
+ autoload :Paginator, 'jsonapi/consumer/paginating/paginator'
43
+ end
44
+
45
+ module Parsers
46
+ autoload :Parser, 'jsonapi/consumer/parsers/parser'
47
+ end
48
+
49
+ module Query
50
+ autoload :Builder, 'jsonapi/consumer/query/builder'
51
+ autoload :Requestor, 'jsonapi/consumer/query/requestor'
52
+ end
53
+
54
+ autoload :Connection, 'jsonapi/consumer/connection'
55
+ autoload :Errors, 'jsonapi/consumer/errors'
56
+ autoload :ErrorCollector, 'jsonapi/consumer/error_collector'
57
+ autoload :Formatter, 'jsonapi/consumer/formatter'
58
+ autoload :Implementation, 'jsonapi/consumer/implementation'
59
+ autoload :IncludedData, 'jsonapi/consumer/included_data'
60
+ autoload :MetaData, 'jsonapi/consumer/meta_data'
61
+ autoload :Resource, 'jsonapi/consumer/resource'
62
+ autoload :ResultSet, 'jsonapi/consumer/result_set'
63
+ autoload :Schema, 'jsonapi/consumer/schema'
64
+ autoload :Utils, 'jsonapi/consumer/utils'
14
65
  end
15
- end
16
-
17
- require "jsonapi/consumer/errors"
18
-
19
- require "jsonapi/consumer/middleware"
20
- require "jsonapi/consumer/middleware/parse_json"
21
- require "jsonapi/consumer/middleware/raise_error"
22
- require "jsonapi/consumer/middleware/request_headers"
23
- require "jsonapi/consumer/middleware/request_timeout"
24
-
25
- require "jsonapi/consumer/parser"
26
-
27
- require "jsonapi/consumer/query"
28
- require "jsonapi/consumer/query/base"
29
- require "jsonapi/consumer/query/create"
30
- require "jsonapi/consumer/query/delete"
31
- require "jsonapi/consumer/query/find"
32
- require "jsonapi/consumer/query/new"
33
- require "jsonapi/consumer/query/update"
34
-
35
- require "jsonapi/consumer/resource/association_concern"
36
- require "jsonapi/consumer/resource/attributes_concern"
37
- require "jsonapi/consumer/resource/connection_concern"
38
- require "jsonapi/consumer/resource/finders_concern"
39
- require "jsonapi/consumer/resource/object_build_concern"
40
- require "jsonapi/consumer/resource/serializer_concern"
41
- require "jsonapi/consumer/resource"
66
+ end
metadata CHANGED
@@ -1,93 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activemodel
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: activesupport
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: '3.2'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '3.2'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: faraday
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.9.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.9.0
55
- - !ruby/object:Gem::Dependency
56
- name: faraday_middleware
57
29
  requirement: !ruby/object:Gem::Requirement
58
30
  requirements:
59
31
  - - ">="
60
32
  - !ruby/object:Gem::Version
61
- version: '0'
33
+ version: '0.9'
62
34
  type: :runtime
63
35
  prerelease: false
64
36
  version_requirements: !ruby/object:Gem::Requirement
65
37
  requirements:
66
38
  - - ">="
67
39
  - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: bundler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.6'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.6'
40
+ version: '0.9'
83
41
  - !ruby/object:Gem::Dependency
84
- name: factory_girl
42
+ name: faraday_middleware
85
43
  requirement: !ruby/object:Gem::Requirement
86
44
  requirements:
87
45
  - - ">="
88
46
  - !ruby/object:Gem::Version
89
47
  version: '0'
90
- type: :development
48
+ type: :runtime
91
49
  prerelease: false
92
50
  version_requirements: !ruby/object:Gem::Requirement
93
51
  requirements:
@@ -95,35 +53,35 @@ dependencies:
95
53
  - !ruby/object:Gem::Version
96
54
  version: '0'
97
55
  - !ruby/object:Gem::Dependency
98
- name: rake
56
+ name: addressable
99
57
  requirement: !ruby/object:Gem::Requirement
100
58
  requirements:
101
59
  - - "~>"
102
60
  - !ruby/object:Gem::Version
103
- version: '10.0'
104
- type: :development
61
+ version: 2.5.2
62
+ type: :runtime
105
63
  prerelease: false
106
64
  version_requirements: !ruby/object:Gem::Requirement
107
65
  requirements:
108
66
  - - "~>"
109
67
  - !ruby/object:Gem::Version
110
- version: '10.0'
68
+ version: 2.5.2
111
69
  - !ruby/object:Gem::Dependency
112
- name: rspec
70
+ name: activemodel
113
71
  requirement: !ruby/object:Gem::Requirement
114
72
  requirements:
115
73
  - - ">="
116
74
  - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
75
+ version: '3.2'
76
+ type: :runtime
119
77
  prerelease: false
120
78
  version_requirements: !ruby/object:Gem::Requirement
121
79
  requirements:
122
80
  - - ">="
123
81
  - !ruby/object:Gem::Version
124
- version: '0'
82
+ version: '3.2'
125
83
  - !ruby/object:Gem::Dependency
126
- name: rspec-its
84
+ name: webmock
127
85
  requirement: !ruby/object:Gem::Requirement
128
86
  requirements:
129
87
  - - ">="
@@ -137,7 +95,7 @@ dependencies:
137
95
  - !ruby/object:Gem::Version
138
96
  version: '0'
139
97
  - !ruby/object:Gem::Dependency
140
- name: webmock
98
+ name: mocha
141
99
  requirement: !ruby/object:Gem::Requirement
142
100
  requirements:
143
101
  - - ">="
@@ -157,51 +115,47 @@ executables: []
157
115
  extensions: []
158
116
  extra_rdoc_files: []
159
117
  files:
118
+ - ".circleci/config.yml"
160
119
  - ".gitignore"
161
- - ".rspec"
162
- - CHANGELOG.md
163
120
  - Gemfile
164
121
  - LICENSE.txt
165
122
  - README.md
166
123
  - Rakefile
124
+ - bin/console
125
+ - bin/setup
167
126
  - jsonapi-consumer.gemspec
168
127
  - lib/jsonapi/consumer.rb
128
+ - lib/jsonapi/consumer/associations/base_association.rb
129
+ - lib/jsonapi/consumer/associations/belongs_to.rb
130
+ - lib/jsonapi/consumer/associations/has_many.rb
131
+ - lib/jsonapi/consumer/associations/has_one.rb
132
+ - lib/jsonapi/consumer/connection.rb
133
+ - lib/jsonapi/consumer/error_collector.rb
169
134
  - lib/jsonapi/consumer/errors.rb
170
- - lib/jsonapi/consumer/middleware.rb
135
+ - lib/jsonapi/consumer/formatter.rb
136
+ - lib/jsonapi/consumer/helpers/callbacks.rb
137
+ - lib/jsonapi/consumer/helpers/dirty.rb
138
+ - lib/jsonapi/consumer/helpers/dynamic_attributes.rb
139
+ - lib/jsonapi/consumer/helpers/uri.rb
140
+ - lib/jsonapi/consumer/implementation.rb
141
+ - lib/jsonapi/consumer/included_data.rb
142
+ - lib/jsonapi/consumer/linking/links.rb
143
+ - lib/jsonapi/consumer/linking/top_level_links.rb
144
+ - lib/jsonapi/consumer/meta_data.rb
145
+ - lib/jsonapi/consumer/middleware/json_request.rb
171
146
  - lib/jsonapi/consumer/middleware/parse_json.rb
172
- - lib/jsonapi/consumer/middleware/raise_error.rb
173
- - lib/jsonapi/consumer/middleware/request_headers.rb
174
- - lib/jsonapi/consumer/middleware/request_timeout.rb
175
- - lib/jsonapi/consumer/parser.rb
176
- - lib/jsonapi/consumer/query.rb
177
- - lib/jsonapi/consumer/query/base.rb
178
- - lib/jsonapi/consumer/query/create.rb
179
- - lib/jsonapi/consumer/query/delete.rb
180
- - lib/jsonapi/consumer/query/find.rb
181
- - lib/jsonapi/consumer/query/new.rb
182
- - lib/jsonapi/consumer/query/update.rb
147
+ - lib/jsonapi/consumer/middleware/status.rb
148
+ - lib/jsonapi/consumer/paginating/paginator.rb
149
+ - lib/jsonapi/consumer/parsers/parser.rb
150
+ - lib/jsonapi/consumer/query/builder.rb
151
+ - lib/jsonapi/consumer/query/requestor.rb
152
+ - lib/jsonapi/consumer/relationships/relations.rb
153
+ - lib/jsonapi/consumer/relationships/top_level_relations.rb
183
154
  - lib/jsonapi/consumer/resource.rb
184
- - lib/jsonapi/consumer/resource/association_concern.rb
185
- - lib/jsonapi/consumer/resource/attributes_concern.rb
186
- - lib/jsonapi/consumer/resource/connection_concern.rb
187
- - lib/jsonapi/consumer/resource/finders_concern.rb
188
- - lib/jsonapi/consumer/resource/object_build_concern.rb
189
- - lib/jsonapi/consumer/resource/serializer_concern.rb
155
+ - lib/jsonapi/consumer/result_set.rb
156
+ - lib/jsonapi/consumer/schema.rb
157
+ - lib/jsonapi/consumer/utils.rb
190
158
  - lib/jsonapi/consumer/version.rb
191
- - spec/fixtures/.gitkeep
192
- - spec/fixtures/resources.rb
193
- - spec/fixtures/responses.rb
194
- - spec/jsonapi/consumer/associations_spec.rb
195
- - spec/jsonapi/consumer/attributes_spec.rb
196
- - spec/jsonapi/consumer/connection_spec.rb
197
- - spec/jsonapi/consumer/error_handling_spec.rb
198
- - spec/jsonapi/consumer/object_build_spec.rb
199
- - spec/jsonapi/consumer/parser_spec.rb
200
- - spec/jsonapi/consumer/resource_spec.rb
201
- - spec/jsonapi/consumer/serializer_spec.rb
202
- - spec/spec_helper.rb
203
- - spec/support/.gitkeep
204
- - spec/support/load_fixtures.rb
205
159
  homepage: https://github.com/jsmestad/jsonapi-consumer
206
160
  licenses:
207
161
  - Apache-2.0
@@ -222,22 +176,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
176
  version: '0'
223
177
  requirements: []
224
178
  rubyforge_project:
225
- rubygems_version: 2.2.2
179
+ rubygems_version: 2.7.6
226
180
  signing_key:
227
181
  specification_version: 4
228
182
  summary: JSONAPI client framework for API consumption.
229
- test_files:
230
- - spec/fixtures/.gitkeep
231
- - spec/fixtures/resources.rb
232
- - spec/fixtures/responses.rb
233
- - spec/jsonapi/consumer/associations_spec.rb
234
- - spec/jsonapi/consumer/attributes_spec.rb
235
- - spec/jsonapi/consumer/connection_spec.rb
236
- - spec/jsonapi/consumer/error_handling_spec.rb
237
- - spec/jsonapi/consumer/object_build_spec.rb
238
- - spec/jsonapi/consumer/parser_spec.rb
239
- - spec/jsonapi/consumer/resource_spec.rb
240
- - spec/jsonapi/consumer/serializer_spec.rb
241
- - spec/spec_helper.rb
242
- - spec/support/.gitkeep
243
- - spec/support/load_fixtures.rb
183
+ test_files: []
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/CHANGELOG.md DELETED
@@ -1,36 +0,0 @@
1
-
2
- 0.1.1 / 2015-01-23
3
- ==================
4
-
5
- * Add internal helper #remove_links? for association payloads
6
- * Do not send `links: {}` if new object, and empty associations
7
-
8
- 0.1.0 / 2014-12-03
9
- ==================
10
-
11
- * `middleware` and `ssl` attributes are inheritable
12
- * Support custom faraday connection middleware with `#middleware` block
13
- * update README with usage
14
-
15
- 0.1.0.pre.3 / 2014-11-11
16
- ==================
17
-
18
- * Has One relationships use plural names in side-loading lookups.
19
-
20
- 0.1.0.pre.2 / 2014-11-11
21
- ==================
22
-
23
- * Set Accept header properly to 'application/json'
24
- * Add spec for Resource.all with params
25
-
26
- 0.1.0.pre.1 / 2014-10-19
27
- ==================
28
-
29
- * Add yarddoc to associations_concern
30
- * Add error handling and parsing of Bad Requests
31
- * Parse `has_one` and `has_many` links attribute from JSONAPI
32
- * CRUD is supported
33
- * Support create, find, all finders
34
- * Create query support
35
- * Basic serialization and association building.
36
-
@@ -1,21 +0,0 @@
1
- module JSONAPI::Consumer::Middleware
2
- class RaiseError < Faraday::Response::Middleware
3
- def on_complete(env)
4
- return if (status = env[:status]) < 400
5
- message = "#{env[:status]} #{env[:method].upcase} #{env[:url]} #{env[:body]}"
6
- raise ::JSONAPI::Consumer::Errors.class_for_error_code(status).new(message, response_values(env))
7
- end
8
-
9
- def response_values(env)
10
- {status: env[:status], headers: env[:response_headers], body: parse_body(env[:body])}
11
- end
12
-
13
- def parse_body(body)
14
- if body.nil?
15
- nil
16
- else
17
- JSON.parse(body) rescue nil
18
- end
19
- end
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- module JSONAPI::Consumer::Middleware
2
- class RequestHeaders < Faraday::Middleware
3
-
4
- def initialize(app, headers)
5
- super(app)
6
- @headers = headers
7
- end
8
-
9
- def call(env)
10
- @headers.each do |header, value|
11
- env[:request_headers][header] ||= value
12
- end
13
- @app.call(env)
14
- end
15
-
16
- end
17
- end
18
-
19
- Faraday::Request.register_middleware request_headers: JSONAPI::Consumer::Middleware::RequestHeaders
20
-
@@ -1,9 +0,0 @@
1
- module JSONAPI::Consumer::Middleware
2
- class RequestTimeout < Faraday::Middleware
3
- def call(env)
4
- @app.call(env)
5
- rescue Faraday::TimeoutError
6
- raise JSONAPI::Consumer::Errors::ServerNotResponding
7
- end
8
- end
9
- end
@@ -1,5 +0,0 @@
1
- module JSONAPI::Consumer
2
- module Middleware
3
-
4
- end
5
- end