json-api-client 0.0.2
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/json-api-client.gemspec +31 -0
- data/lib/json_api_client.rb +8 -0
- data/lib/json_api_client/consumer.rb +35 -0
- data/lib/json_api_client/error.rb +49 -0
- data/lib/json_api_client/mapper.rb +92 -0
- data/lib/json_api_client/resource.rb +30 -0
- data/lib/json_api_client/version.rb +3 -0
- data/spec/json_api_client/consumer_spec.rb +69 -0
- data/spec/json_api_client/mapper_spec.rb +112 -0
- data/spec/json_api_client/resource_spec.rb +31 -0
- data/spec/spec_helper.rb +23 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7af31af9bdd82d1f44c25c01448ea3c6ced7c771
|
4
|
+
data.tar.gz: b401b8c2aae3412d2db4c19e3405bb0ecbe8b051
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2070691e0a2e74414ed834e02e0f977d2e9384d67400702005beaf7d7d222a049c8cf64b50c8e4a7fec18e6b0218d91dcf4efae4886975f364c0dc368ec7ce8
|
7
|
+
data.tar.gz: 0132dfb25f4b27fad1248b056e00dcdea592d4034888de12cfc9966130455388db3c4453483c006570b28409c0458cb22f74a59dbb84c682e78de89a0caef5c9
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 John Bohn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Json::Api::Client
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'json-api-client'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install json-api-client
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/json-api-client/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'json_api_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "json-api-client"
|
8
|
+
spec.version = JsonApiClient::VERSION
|
9
|
+
spec.authors = ["John Bohn"]
|
10
|
+
spec.email = ["jjbohn@gmail.com"]
|
11
|
+
spec.summary = %q{A client for working with json api spec based apis}
|
12
|
+
spec.description = %q{A client for working with json api spec based apis}
|
13
|
+
spec.homepage = "https://www.github.com/jjbohn/json-api-spec"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "guard"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
26
|
+
|
27
|
+
spec.add_dependency "activesupport"
|
28
|
+
spec.add_dependency "faraday"
|
29
|
+
spec.add_dependency "faraday_middleware"
|
30
|
+
spec.add_dependency "hashie"
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
|
4
|
+
module JsonApiClient
|
5
|
+
class Consumer
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def get(url, params = {})
|
11
|
+
connection.get(url, params) do |request|
|
12
|
+
request.headers["Content-Type"] = "application/vnd.api+json"
|
13
|
+
end
|
14
|
+
rescue Faraday::Error => e
|
15
|
+
raise "JsonApiClient::#{e.class.name.demodulize}".constantize.new(e)
|
16
|
+
end
|
17
|
+
|
18
|
+
def connection
|
19
|
+
@connection ||= Faraday.new(url: config(:base_url)).tap do |connection|
|
20
|
+
connection.authorization :Token, config(:token)
|
21
|
+
connection.use Faraday::Response::RaiseError
|
22
|
+
connection.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def config(key)
|
29
|
+
env_var = "#{@name}_#{key}".upcase
|
30
|
+
ENV.fetch(env_var)
|
31
|
+
rescue KeyError
|
32
|
+
raise KeyError.new("Environment variable #{env_var} was requested, but is not set")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module JsonApiClient
|
2
|
+
class Error < StandardError; end
|
3
|
+
class MissingDependency < Error; end
|
4
|
+
|
5
|
+
class ClientError < Error
|
6
|
+
def initialize(ex)
|
7
|
+
@wrapped_exception = nil
|
8
|
+
|
9
|
+
if ex.respond_to?(:backtrace)
|
10
|
+
super(ex.message)
|
11
|
+
@wrapped_exception = ex
|
12
|
+
elsif ex.respond_to?(:each_key)
|
13
|
+
super("the server responded with status #{ex[:status]}")
|
14
|
+
else
|
15
|
+
super(ex.to_s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def backtrace
|
20
|
+
if @wrapped_exception
|
21
|
+
@wrapped_exception.backtrace
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
%(#<#{self.class}>)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class ConnectionFailed < ClientError; end
|
33
|
+
class ResourceNotFound < ClientError; end
|
34
|
+
class ParsingError < ClientError; end
|
35
|
+
|
36
|
+
class TimeoutError < ClientError
|
37
|
+
def initialize(ex = nil)
|
38
|
+
super(ex || "timeout")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class SSLError < ClientError
|
43
|
+
end
|
44
|
+
|
45
|
+
[:MissingDependency, :ClientError, :ConnectionFailed, :ResourceNotFound,
|
46
|
+
:ParsingError, :TimeoutError, :SSLError].each do |const|
|
47
|
+
Error.const_set(const, JsonApiClient.const_get(const))
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "hashie/mash"
|
2
|
+
require "active_support/inflector"
|
3
|
+
|
4
|
+
module JsonApiClient
|
5
|
+
class Mapper
|
6
|
+
attr_reader :primary_resource, :primary_resource_methods
|
7
|
+
|
8
|
+
def initialize(primary_resource, primary_resource_methods = nil)
|
9
|
+
@classes = {}
|
10
|
+
@class_ids = {} # Keeps track of current class ids
|
11
|
+
@primary_resource = primary_resource
|
12
|
+
@primary_resource_methods = primary_resource_methods
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(data, resource_type = primary_resource)
|
16
|
+
data.fetch(resource_type).map do |resource|
|
17
|
+
except_links = resource.reject { |k, _| k == "links" }
|
18
|
+
|
19
|
+
apply_linked_resources(resource, data, except_links)
|
20
|
+
|
21
|
+
build_resource(resource_type, except_links, &primary_resource_methods)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_resource(resource_type, hash, &primary_resource_methods)
|
28
|
+
Hashie::Mash.new(hash).tap do |mash|
|
29
|
+
mash.instance_exec(&primary_resource_methods) if primary_resource_methods
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def apply_linked_resources(resource, data, hash)
|
34
|
+
return {} unless data["linked"]
|
35
|
+
|
36
|
+
link_type_map = build_link_type_map(data)
|
37
|
+
|
38
|
+
resource["links"].map do |association, id|
|
39
|
+
type = link_type_map[association]
|
40
|
+
|
41
|
+
if linked_resource = get_linked_resources(data, type, id)
|
42
|
+
hash[association.to_sym] = linked_resource
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_linked_resources(data, type, id_or_ids)
|
48
|
+
map = build_linked_resources_map(data)
|
49
|
+
|
50
|
+
multiple = id_or_ids.is_a?(Array)
|
51
|
+
|
52
|
+
if multiple
|
53
|
+
id_or_ids.map{ |id| send(__method__, data, type, id) }
|
54
|
+
else
|
55
|
+
return unless resource = map[type] && map[type][id_or_ids]
|
56
|
+
|
57
|
+
value = call({ type => [resource].flatten}, type)
|
58
|
+
|
59
|
+
multiple ? value : value.first
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Builds a map to enable getting references by type and id
|
64
|
+
#
|
65
|
+
# eg.
|
66
|
+
# {
|
67
|
+
# "users" => {
|
68
|
+
# "1" => { "id" => "1", "name" => "John" },
|
69
|
+
# "5" => { "id" => "5", "name" => "Walter" },
|
70
|
+
# }
|
71
|
+
# }
|
72
|
+
def build_linked_resources_map(data)
|
73
|
+
data["linked"].each_with_object({}) do |(type, resources), obj|
|
74
|
+
obj[type] ||= {}
|
75
|
+
resources.each do |linked_resource|
|
76
|
+
obj[type][linked_resource["id"]] = linked_resource
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Builds a map to translate references to types
|
82
|
+
#
|
83
|
+
# eg.
|
84
|
+
# { "author" => "users", "comments" => "comments" }
|
85
|
+
def build_link_type_map(data)
|
86
|
+
data["links"].each_with_object({}) do |(key, value), obj|
|
87
|
+
association = key.split(".").last
|
88
|
+
obj[association] = value["type"].pluralize
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module JsonApiClient
|
2
|
+
module Resource
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def api_client
|
9
|
+
@api_client ||= Consumer.new(@resource_config_prefix)
|
10
|
+
end
|
11
|
+
|
12
|
+
def mapper
|
13
|
+
@mapper ||= Mapper.new(resource, @resource_methods)
|
14
|
+
end
|
15
|
+
|
16
|
+
def resource(resource = nil)
|
17
|
+
@resource = String(resource) unless resource.nil?
|
18
|
+
@resource
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource_config_prefix(resource_config_prefix)
|
22
|
+
@resource_config_prefix = String(resource_config_prefix)
|
23
|
+
end
|
24
|
+
|
25
|
+
def resource_methods(&block)
|
26
|
+
@resource_methods = block
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe JsonApiClient::Consumer do
|
4
|
+
subject(:consumer){ described_class.new("resource_api") }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
stub_const("ENV", {
|
8
|
+
"RESOURCE_API_BASE_URL" => "https://example.com/api",
|
9
|
+
"RESOURCE_API_TOKEN" => "token",
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#connection" do
|
14
|
+
it "builds a Faraday connection with an authorization header" do
|
15
|
+
connection = consumer.connection
|
16
|
+
|
17
|
+
expect(connection.headers["Authorization"]).to eql("Token token")
|
18
|
+
expect(connection.builder.handlers).to include(FaradayMiddleware::ParseJson)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "memoizes the connection response" do
|
22
|
+
expect(consumer.connection).to equal(consumer.connection)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#get" do
|
27
|
+
it "it call a GET request on the connection" do
|
28
|
+
connection = Faraday.new do |builder|
|
29
|
+
builder.adapter :test do |stub|
|
30
|
+
stub.get("/foo"){ [200, { "Accept" => "application/vnd.api+json" }, "bar"] }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
allow(consumer).to receive(:connection).and_return(connection)
|
35
|
+
expect(consumer.get("foo").body).to eql("bar")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "forwards params" do
|
39
|
+
response = double(body: "response")
|
40
|
+
|
41
|
+
expect(consumer.connection).to receive(:get).with("http://google.com", foo: "bar").and_return(response)
|
42
|
+
expect(consumer.get("http://google.com", foo: "bar").body).to eql("response")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "merges params" do
|
46
|
+
response = double(body: "response")
|
47
|
+
|
48
|
+
expect(consumer.connection).to receive(:get).with("http://google.com?test=param", foo: "bar").and_return(response)
|
49
|
+
expect(consumer.get("http://google.com?test=param", foo: "bar").body).to eql("response")
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when there is a Faraday::Error" do
|
53
|
+
it "raises it's own error" do
|
54
|
+
allow(consumer.connection).to receive(:get).and_raise(Faraday::Error)
|
55
|
+
|
56
|
+
expect{ consumer.get("/foo") }.to raise_error(JsonApiClient::Error)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when there is a Faraday::Error::ConnectionError" do
|
61
|
+
it "raises it's own error" do
|
62
|
+
original_error = double
|
63
|
+
allow(consumer.connection).to receive(:get).and_raise(Faraday::Error::ConnectionFailed.new(double))
|
64
|
+
|
65
|
+
expect{ consumer.get("/foo") }.to raise_error(JsonApiClient::Error::ConnectionFailed)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe JsonApiClient::Mapper do
|
4
|
+
let(:data) do
|
5
|
+
{
|
6
|
+
"resources" => [
|
7
|
+
{ "property" => "foo" },
|
8
|
+
{ "property" => "bar" },
|
9
|
+
],
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#call" do
|
14
|
+
it "generates a new resource and maps the values" do
|
15
|
+
mapper = described_class.new("resources")
|
16
|
+
resources = mapper.call(data)
|
17
|
+
|
18
|
+
expect(resources.length).to eql(2)
|
19
|
+
expect(resources.first.property).to eql("foo")
|
20
|
+
expect(resources.last.property).to eql("bar")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "if extra resource methods are passed" do
|
24
|
+
it "makes those methods available" do
|
25
|
+
methods = Proc.new{ def custom_method; "biz" end }
|
26
|
+
mapper = described_class.new("resources", methods)
|
27
|
+
|
28
|
+
resources = mapper.call(data)
|
29
|
+
expect(resources.first.custom_method).to eql("biz")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can overwrite existing properties" do
|
33
|
+
methods = Proc.new{ def property; "biz" end }
|
34
|
+
mapper = described_class.new("resources", methods)
|
35
|
+
|
36
|
+
resources = mapper.call(data)
|
37
|
+
expect(resources.first.property).to eql("biz")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with a compound object" do
|
43
|
+
subject(:mapper){ described_class.new("posts") }
|
44
|
+
|
45
|
+
context "with singular linked resource" do
|
46
|
+
let(:data) do
|
47
|
+
{
|
48
|
+
"links" => {
|
49
|
+
"posts.author" => {
|
50
|
+
"href" => "http://example.com/users/{posts.author}",
|
51
|
+
"type" => "user",
|
52
|
+
},
|
53
|
+
"posts.comments" => {
|
54
|
+
"href" => "http://example.com/comments/{posts.comments}",
|
55
|
+
"type" => "comments",
|
56
|
+
}
|
57
|
+
},
|
58
|
+
"posts" => [{
|
59
|
+
"id" => "1",
|
60
|
+
"links" => {
|
61
|
+
"author" => "1",
|
62
|
+
"comments" => ["1", "2"],
|
63
|
+
},
|
64
|
+
"id" => "3",
|
65
|
+
"links" => {
|
66
|
+
"author" => "1",
|
67
|
+
"comments" => ["1", "2"],
|
68
|
+
},
|
69
|
+
}, {
|
70
|
+
"id" => "2",
|
71
|
+
"extra" => "3",
|
72
|
+
"links" => {
|
73
|
+
"author" => "1",
|
74
|
+
"comments" => ["3"],
|
75
|
+
},
|
76
|
+
}],
|
77
|
+
"linked" => {
|
78
|
+
"users" => [{
|
79
|
+
"id" => "1",
|
80
|
+
"name" => "John",
|
81
|
+
}],
|
82
|
+
"comments" => [{
|
83
|
+
"id" => "1",
|
84
|
+
"body" => "foo",
|
85
|
+
}, {
|
86
|
+
"id" => "2",
|
87
|
+
"body" => "bar",
|
88
|
+
}, {
|
89
|
+
"id" => "3",
|
90
|
+
"body" => "baz",
|
91
|
+
}],
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
it "maps the linked resources" do
|
97
|
+
posts = mapper.call(data)
|
98
|
+
expect(posts[0].author).to_not be_nil
|
99
|
+
expect(posts[0].author.id).to eql("1")
|
100
|
+
expect(posts[0].author.name).to eql("John")
|
101
|
+
expect(posts[1].author).to eql(posts[0].author)
|
102
|
+
|
103
|
+
expect(posts[0].comments[0].id).to eql("1")
|
104
|
+
expect(posts[0].comments[0].body).to eql("foo")
|
105
|
+
expect(posts[0].comments[1].id).to eql("2")
|
106
|
+
expect(posts[0].comments[1].body).to eql("bar")
|
107
|
+
expect(posts[1].comments[0].id).to eql("3")
|
108
|
+
expect(posts[1].comments[0].body).to eql("baz")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe JsonApiClient::Resource do
|
4
|
+
subject(:expected_proc){}
|
5
|
+
subject(:resource) do
|
6
|
+
Class.new do
|
7
|
+
include (JsonApiClient::Resource)
|
8
|
+
resource :foo
|
9
|
+
resource_config_prefix :foo_api
|
10
|
+
resource_methods do
|
11
|
+
def custom_method; end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates a mapper" do
|
17
|
+
mapper = resource.mapper
|
18
|
+
|
19
|
+
expect(mapper).to be_kind_of(JsonApiClient::Mapper)
|
20
|
+
expect(resource.mapper).to equal(mapper)
|
21
|
+
expect(mapper.primary_resource).to eql("foo")
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates a consumer" do
|
26
|
+
consumer = resource.api_client
|
27
|
+
|
28
|
+
expect(consumer).to be_kind_of(JsonApiClient::Consumer)
|
29
|
+
expect(resource.api_client).to equal(consumer)
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require_relative "../lib/json_api_client"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.filter_run :none
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
|
8
|
+
if config.files_to_run.one?
|
9
|
+
config.default_formatter = 'doc'
|
10
|
+
end
|
11
|
+
|
12
|
+
config.order = :random
|
13
|
+
Kernel.srand config.seed
|
14
|
+
|
15
|
+
config.expect_with :rspec do |expectations|
|
16
|
+
expectations.syntax = :expect
|
17
|
+
end
|
18
|
+
|
19
|
+
config.mock_with :rspec do |mocks|
|
20
|
+
mocks.syntax = :expect
|
21
|
+
mocks.verify_partial_doubles = true
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json-api-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Bohn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
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: guard-rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: faraday_middleware
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: hashie
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: A client for working with json api spec based apis
|
140
|
+
email:
|
141
|
+
- jjbohn@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- Gemfile
|
148
|
+
- Guardfile
|
149
|
+
- LICENSE.txt
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- json-api-client.gemspec
|
153
|
+
- lib/json_api_client.rb
|
154
|
+
- lib/json_api_client/consumer.rb
|
155
|
+
- lib/json_api_client/error.rb
|
156
|
+
- lib/json_api_client/mapper.rb
|
157
|
+
- lib/json_api_client/resource.rb
|
158
|
+
- lib/json_api_client/version.rb
|
159
|
+
- spec/json_api_client/consumer_spec.rb
|
160
|
+
- spec/json_api_client/mapper_spec.rb
|
161
|
+
- spec/json_api_client/resource_spec.rb
|
162
|
+
- spec/spec_helper.rb
|
163
|
+
homepage: https://www.github.com/jjbohn/json-api-spec
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.2.2
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: A client for working with json api spec based apis
|
187
|
+
test_files:
|
188
|
+
- spec/json_api_client/consumer_spec.rb
|
189
|
+
- spec/json_api_client/mapper_spec.rb
|
190
|
+
- spec/json_api_client/resource_spec.rb
|
191
|
+
- spec/spec_helper.rb
|
192
|
+
has_rdoc:
|