real_savvy 0.0.7 → 0.0.8

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
  SHA1:
3
- metadata.gz: 83c3eb21fb475cd2006eeaeff541e57edba481c6
4
- data.tar.gz: 3e9c22f823cb9e87dc86677df7d6c33215b95db3
3
+ metadata.gz: 652be299d2ea9f3028126a7e3f0d8be72ba69735
4
+ data.tar.gz: 9308a23ee4e072d315562f2ad6e470212907276d
5
5
  SHA512:
6
- metadata.gz: 6d417e599280f1bcea965a7da684ae7c1f55952d88592f52098140d02d9c97f4521fa6b76c08b10f737b06057dd51c178dc6298b1cf0661b8ee30f4cbde14b5d
7
- data.tar.gz: 792908183863481ff23f39fce1707c55ce92d8f16bb3a77f17816105d98ef9abaf5b67af55352761eefe7a65cb4f5a14c4982d1d9975c52f29e498948662c435
6
+ metadata.gz: 0f9033d41e6e25da94b3a5fd2643077367760278e2a9c2b827a01b89013f81f9b8716ecf0878048ed0f73b23b3d59c60bf354ffbf3bfe20ae2b72fd7b4c77ca3
7
+ data.tar.gz: 05f024c4368bd03e42f478ba94fcc51afbce7f2ccf71eebb34135bb684f9a699cdcd986d13e4c3ed2f05054154fe7b6e52740027dcebf126b4ae0d9f71eaac41
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- real_savvy (0.0.6)
4
+ real_savvy (0.0.7)
5
5
  faraday (>= 0.8.0)
6
6
  faraday_middleware (>= 0.8.0)
7
7
  jwt (>= 1.0.0)
@@ -5,16 +5,6 @@ class RealSavvy::Document
5
5
 
6
6
  attr_reader :document
7
7
 
8
- TYPE_TO_RESOURCE = {
9
- 'properties' => RealSavvy::Resource::Property,
10
- 'listings' => RealSavvy::Resource::Property,
11
- 'collections' => RealSavvy::Resource::Collection,
12
- 'saved_searches' => RealSavvy::Resource::SavedSearch,
13
- 'users' => RealSavvy::Resource::User,
14
- }.tap do |lookup|
15
- lookup.default = RealSavvy::Resource::Base
16
- end.freeze
17
-
18
8
  def initialize(document, status: nil)
19
9
  @document = document
20
10
  @status = status
@@ -27,7 +17,7 @@ class RealSavvy::Document
27
17
  alias results data
28
18
 
29
19
  def result
30
- data[0]
20
+ data
31
21
  end
32
22
 
33
23
  def included
@@ -55,6 +45,10 @@ class RealSavvy::Document
55
45
  end
56
46
 
57
47
  def self.process_resources(resources, document=nil)
58
- ::RealSavvy.safe_wrap(resources).map { |object| TYPE_TO_RESOURCE[object['type']].new(object, document) }
48
+ if resources.is_a?(Array)
49
+ resources.map { |object| RealSavvy::Resource.new(object, document) }
50
+ elsif resources
51
+ RealSavvy::Resource.new(resources, document)
52
+ end
59
53
  end
60
54
  end
@@ -4,7 +4,7 @@ module RealSavvy
4
4
  # In order of access level
5
5
  SCOPE_VERBS = %w{public read write admin}.freeze
6
6
 
7
- attr_reader :scopes, :user, :site, :token, :header
7
+ attr_reader :scopes, :user, :site, :token, :header, :claims
8
8
 
9
9
  def initialize(token)
10
10
  @token = token
@@ -98,20 +98,24 @@ module RealSavvy
98
98
  Base64.urlsafe_encode64(share_token_json, padding: false)
99
99
  end
100
100
 
101
+ def short_token
102
+ @token.split('.')[1]
103
+ end
104
+
101
105
  private
102
106
 
103
- attr_reader :claims, :audience, :subject
107
+ attr_reader :audience, :subject
104
108
 
105
109
  def retrieve_claims
106
110
  raise NotImplementedError, "subclass did not define #retrieve_claims"
107
111
  end
108
112
 
109
113
  def retrieve_audience
110
- @audience = ::RealSavvy::JWT::Config.retrieve_audience(claims) if claims
114
+ @audience = ::RealSavvy::JWT::Config.retrieve_audience(self) if claims && claims['aud']
111
115
  end
112
116
 
113
117
  def retrieve_subject
114
- @subject = ::RealSavvy::JWT::Config.retrieve_subject(claims) if claims
118
+ @subject = ::RealSavvy::JWT::Config.retrieve_subject(self) if claims && claims['sub']
115
119
  end
116
120
 
117
121
  def retrieve_site
@@ -2,10 +2,6 @@ module RealSavvy
2
2
  module JWT
3
3
  class ShareToken < AbstractToken
4
4
 
5
- def short_token
6
- @token.split('.')[1]
7
- end
8
-
9
5
  private
10
6
 
11
7
  def retrieve_claims
@@ -26,7 +26,7 @@ module RealSavvy
26
26
  end
27
27
 
28
28
  def validate_token
29
- ::RealSavvy::JWT::Config.validate_token(token)
29
+ ::RealSavvy::JWT::Config.validate_token(self)
30
30
  end
31
31
  end
32
32
  end
@@ -1,6 +1,83 @@
1
- module RealSavvy::Resource
1
+ require 'set'
2
+ require 'real_savvy/attributes'
3
+ require 'real_savvy/links'
2
4
 
3
- end
5
+ class RealSavvy::Resource
6
+ attr_reader :json, :document
7
+
8
+ def initialize(json, document)
9
+ @json = json
10
+ @document = document
11
+ end
12
+
13
+ def hash
14
+ {id: id, type: type}.to_json.hash
15
+ end
16
+
17
+ def id
18
+ json['id']
19
+ end
20
+
21
+ def type
22
+ json['type']
23
+ end
24
+
25
+ def attributes
26
+ @attributes ||= RealSavvy::Attributes.new(json['attributes'] || {})
27
+ end
28
+
29
+ def links
30
+ @links ||= RealSavvy::Links.new(json['links'] || {})
31
+ end
32
+
33
+ def meta
34
+ @meta ||= RealSavvy::Meta.new(json['meta'] || {})
35
+ end
36
+
37
+ def relationships
38
+ self
39
+ end
4
40
 
5
- require 'real_savvy/resource/base'
6
- Dir[File.dirname(__FILE__) + '/resource/*.rb'].each {|file| require file }
41
+ def inspect
42
+ json.inspect
43
+ end
44
+
45
+ private
46
+
47
+ def objects_lookup
48
+ document&.objects_lookup || {}
49
+ end
50
+
51
+ def loaded_relationships
52
+ @loaded_relationships ||= {}
53
+ end
54
+
55
+ def has_relationship(relationship)
56
+ possible_relation_ship = json['relationships']&.[](relationship.to_s)
57
+ possible_relation_ship && possible_relation_ship.length > 0
58
+ end
59
+
60
+ def build_relationship(relationship)
61
+ relationship_raw = json['relationships']&.[](relationship.to_s)&.[]('data')
62
+ relationship_processed = ::RealSavvy::Document.process_resources(relationship_raw)
63
+ end
64
+
65
+ def load_relationship_with_lookup(relationship)
66
+ loaded_relationships[relationship] ||= begin
67
+ relationship_object = build_relationship(relationship)
68
+ if relationship_object.is_a?(Array)
69
+ relationship_object.map { |resource| objects_lookup[resource.hash] || resource }
70
+ else
71
+ objects_lookup[relationship_object.hash] || relationship_object
72
+ end
73
+ end
74
+ end
75
+
76
+ def method_missing(m, *args, &block)
77
+ if has_relationship(m)
78
+ load_relationship_with_lookup(m)
79
+ else
80
+ super
81
+ end
82
+ end
83
+ end
@@ -1,3 +1,3 @@
1
1
  module RealSavvy
2
- VERSION = [0,0,7]
2
+ VERSION = [0,0,8]
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real_savvy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Rauh
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-03-26 00:00:00.000000000 Z
13
+ date: 2018-03-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -138,7 +138,6 @@ files:
138
138
  - README.md
139
139
  - bin/console
140
140
  - bin/setup
141
- - client.rb
142
141
  - lib/real_savvy.rb
143
142
  - lib/real_savvy/adapter.rb
144
143
  - lib/real_savvy/adapter/agent.rb
@@ -178,11 +177,6 @@ files:
178
177
  - lib/real_savvy/links.rb
179
178
  - lib/real_savvy/meta.rb
180
179
  - lib/real_savvy/resource.rb
181
- - lib/real_savvy/resource/base.rb
182
- - lib/real_savvy/resource/collection.rb
183
- - lib/real_savvy/resource/property.rb
184
- - lib/real_savvy/resource/saved_search.rb
185
- - lib/real_savvy/resource/user.rb
186
180
  - lib/real_savvy/version.rb
187
181
  - real_savvy.gemspec
188
182
  homepage: http://rubygems.org/gems/realsavvy
data/client.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'real_savvy/connection'
2
- require 'real_savvy/concern'
3
- require 'real_savvy/adapter'
4
-
5
- Dir[File.dirname(__FILE__) + '/adapaters/*.rb'].each {|file| require file }
6
-
7
- class RealSavvy::Client
8
- def initialize(token:, logger: nil)
9
- @token = token
10
- @logger = logger
11
- end
12
-
13
- def connection
14
- @connection ||= RealSavvy::Connection.new(client: self)
15
- end
16
-
17
- def logger
18
- @logger
19
- end
20
-
21
- def logging?
22
- !!@logging
23
- end
24
-
25
- def token
26
- @token
27
- end
28
-
29
- def properties
30
- resource_adapaters[:properties] ||= RealSavvy::Adapter::Property.new(connection: connection)
31
- end
32
-
33
- private
34
-
35
- def resource_adapaters
36
- @resource_adapaters ||= {}
37
- end
38
- end
@@ -1,95 +0,0 @@
1
- require 'set'
2
- require 'real_savvy/attributes'
3
- require 'real_savvy/links'
4
-
5
- class RealSavvy::Resource::Base
6
- attr_reader :json, :document
7
-
8
- def initialize(json, document)
9
- @json = json
10
- @document = document
11
- end
12
-
13
- def hash
14
- {id: id, type: type}.to_json.hash
15
- end
16
-
17
- def id
18
- json['id']
19
- end
20
-
21
- def type
22
- json['type']
23
- end
24
-
25
- def attributes
26
- @attributes ||= RealSavvy::Attributes.new(json['attributes'] || {})
27
- end
28
-
29
- def links
30
- @links ||= RealSavvy::Links.new(json['links'] || {})
31
- end
32
-
33
- def meta
34
- @meta ||= RealSavvy::Meta.new(json['meta'] || {})
35
- end
36
-
37
- def relationships
38
- self
39
- end
40
-
41
- def inspect
42
- json.inspect
43
- end
44
-
45
- def self.relationships
46
- @relationships ||= {}
47
- end
48
-
49
- def self.has_one relationship
50
- relationships[relationship.to_s] ||= {}
51
- relationships[relationship.to_s].merge!(single: true)
52
- end
53
-
54
- def self.belongs_to relationship
55
- has_one relationship
56
- end
57
-
58
- # Do nothing default behavior
59
- def self.has_many relationship
60
-
61
- end
62
-
63
- private
64
-
65
- def objects_lookup
66
- document&.objects_lookup || {}
67
- end
68
-
69
- def loaded_relationships
70
- @loaded_relationships ||= {}
71
- end
72
-
73
- def has_relationship(relationship)
74
- possible_relation_ship = json['relationships']&.[](relationship.to_s)
75
- possible_relation_ship && possible_relation_ship.length > 0
76
- end
77
-
78
- def build_relationship(relationship)
79
- relationship_raw = json['relationships']&.[](relationship.to_s)&.[]('data')
80
- relationship_processed = ::RealSavvy::Document.process_resources(relationship_raw)
81
- end
82
-
83
- def load_relationship_with_lookup(relationship)
84
- loaded_relationships[relationship] ||= build_relationship(relationship).map { |resource| objects_lookup[resource.hash] || resource }
85
- self.class.relationships[relationship.to_s]&.[](:single) ? loaded_relationships[relationship].first : loaded_relationships[relationship]
86
- end
87
-
88
- def method_missing(m, *args, &block)
89
- if has_relationship(m)
90
- load_relationship_with_lookup(m)
91
- else
92
- super
93
- end
94
- end
95
- end
@@ -1,4 +0,0 @@
1
- class RealSavvy::Resource::Collection < RealSavvy::Resource::Base
2
- belongs_to :user
3
- belongs_to :site
4
- end
@@ -1,3 +0,0 @@
1
- class RealSavvy::Resource::Property < RealSavvy::Resource::Base
2
-
3
- end
@@ -1,4 +0,0 @@
1
- class RealSavvy::Resource::SavedSearch < RealSavvy::Resource::Base
2
- belongs_to :user
3
- belongs_to :site
4
- end
@@ -1,3 +0,0 @@
1
- class RealSavvy::Resource::User < RealSavvy::Resource::Base
2
-
3
- end