dayman 0.1.1 → 0.1.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/dayman.rb +1 -0
- data/lib/dayman/class_finder.rb +40 -0
- data/lib/dayman/parsers/base.rb +3 -1
- data/lib/dayman/request.rb +1 -1
- data/lib/dayman/resource.rb +1 -3
- data/lib/dayman/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ce784719c149e5065f26e2c034afc68c5d3ab47
|
4
|
+
data.tar.gz: a7df9151bf2342d4cf01f6f21295d4483ea4716f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 957b6870a12abff57610411fed4fa0ebbdf22fe0c2f2c3483f9107f6e35720fd9e51c45e90260a72dcf4c86b556c532bd4683129386416bdd335c4bcd3a0a3a3
|
7
|
+
data.tar.gz: 5d842310cbe3ae554c0891485f1387c30338d441380ddc7522623b33c195d9f675b85eb46e1a8cd8b1b1508ff3b259455b1d2c853094ec0aa11900d705159015
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|

|
4
4
|
|
5
|
-
Yet another JSON API client, heavily inspired by
|
5
|
+
Yet another [JSON API](http://jsonapi.org) client, heavily inspired by
|
6
6
|
[json_api_client](https://github.com/chingor13/json_api_client) and
|
7
7
|
[ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html).
|
8
8
|
|
@@ -29,7 +29,7 @@ Or install it yourself as:
|
|
29
29
|
```ruby
|
30
30
|
module CoolPetsApi
|
31
31
|
class Base < Dayman::Resource
|
32
|
-
|
32
|
+
API_BASE_URL = "http://coolpets.com"
|
33
33
|
end
|
34
34
|
|
35
35
|
class CoolDog < Base
|
data/lib/dayman.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Finds class according to the resource's context:
|
3
|
+
#
|
4
|
+
# module Foo
|
5
|
+
# class TestResource
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# module Bar
|
9
|
+
# class TestResource
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Using Dayman to fetch a Foo::Bar::TestResource
|
15
|
+
# containing a { type: 'test_resources' } object
|
16
|
+
# ClassFinder will look for the first TestResource
|
17
|
+
# class starting from Foo::Bar::TestResource's nesting.
|
18
|
+
# If Foo::Bar::TestResource did not exist, it would find
|
19
|
+
# Foo::TestResource instead.
|
20
|
+
#
|
21
|
+
class ClassFinder
|
22
|
+
MODULE_SEPARATOR = '::'
|
23
|
+
|
24
|
+
def initialize(resource:, type:)
|
25
|
+
@resource = resource
|
26
|
+
@type = type
|
27
|
+
@klass = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def find
|
31
|
+
namespaces = @resource.name.split(MODULE_SEPARATOR)
|
32
|
+
|
33
|
+
while @klass.blank? && namespaces.present?
|
34
|
+
namespaces.pop
|
35
|
+
@klass = (namespaces + [@type.classify]).join(MODULE_SEPARATOR).safe_constantize
|
36
|
+
end
|
37
|
+
|
38
|
+
@klass
|
39
|
+
end
|
40
|
+
end
|
data/lib/dayman/parsers/base.rb
CHANGED
@@ -20,7 +20,7 @@ module Dayman
|
|
20
20
|
def resource_class_for(item)
|
21
21
|
return if item.nil?
|
22
22
|
|
23
|
-
item[:type].
|
23
|
+
ClassFinder.new(resource: @resource, type: item[:type]).find
|
24
24
|
end
|
25
25
|
|
26
26
|
def response_item_to_object(item)
|
@@ -56,6 +56,8 @@ module Dayman
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def find_included_item(relationship_item)
|
59
|
+
return if parsed_response[:included].blank?
|
60
|
+
|
59
61
|
parsed_response[:included].find do |e|
|
60
62
|
e.slice(:id, :type) == relationship_item[:data].slice(:id, :type)
|
61
63
|
end
|
data/lib/dayman/request.rb
CHANGED
data/lib/dayman/resource.rb
CHANGED
@@ -6,8 +6,6 @@ module Dayman
|
|
6
6
|
class << self
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
-
attr_accessor :site
|
10
|
-
|
11
9
|
def_delegators :request,
|
12
10
|
:all,
|
13
11
|
:fields,
|
@@ -19,7 +17,7 @@ module Dayman
|
|
19
17
|
:where
|
20
18
|
|
21
19
|
def path
|
22
|
-
name.underscore.pluralize
|
20
|
+
name.demodulize.underscore.pluralize
|
23
21
|
end
|
24
22
|
|
25
23
|
def has_one(relationship_name)
|
data/lib/dayman/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dayman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Bongart
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- circle.yml
|
173
173
|
- dayman.gemspec
|
174
174
|
- lib/dayman.rb
|
175
|
+
- lib/dayman/class_finder.rb
|
175
176
|
- lib/dayman/parsers/base.rb
|
176
177
|
- lib/dayman/parsers/collection_parser.rb
|
177
178
|
- lib/dayman/parsers/member_parser.rb
|