json_api_client 0.2.4 → 0.3.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03f3ebad69192424dfef02c6b9e285ed0b9d9b6c
|
4
|
+
data.tar.gz: c2964f6af0ef14bc87785e66608040de04f9aef3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a293d1e82116f8021b31b0f3174a11fd8ae91d5a28268c279ff6ee5958b5b88c286381f6db692cfb09aa123e06d2390db87d351aa92eda953e71f8c4df80d317
|
7
|
+
data.tar.gz: eb601756c170737bdd82cd05653661d1fa716227947a6f84bb22c77af79b231a38755c363aefdfc6e8cdd5743de7bff18cf16d05223d2c929e61ddbba96f63d5
|
@@ -3,7 +3,8 @@ module JsonApiClient
|
|
3
3
|
|
4
4
|
attr_reader :faraday
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(options = {})
|
7
|
+
site = options.fetch(:site)
|
7
8
|
@faraday = Faraday.new(site) do |builder|
|
8
9
|
builder.request :url_encoded
|
9
10
|
builder.use Middleware::JsonRequest
|
@@ -17,6 +18,7 @@ module JsonApiClient
|
|
17
18
|
# insert middleware before ParseJson - middleware executed in reverse order -
|
18
19
|
# inserted middleware will run after json parsed
|
19
20
|
def use(middleware, *args, &block)
|
21
|
+
return if faraday.builder.locked?
|
20
22
|
faraday.builder.insert_before(Middleware::ParseJson, middleware, *args, &block)
|
21
23
|
end
|
22
24
|
|
@@ -21,16 +21,6 @@ module JsonApiClient
|
|
21
21
|
save
|
22
22
|
end
|
23
23
|
|
24
|
-
def method_missing(method, *args, &block)
|
25
|
-
if match = method.to_s.match(/^(.*)=$/)
|
26
|
-
set_attribute(match[1], args.first)
|
27
|
-
elsif has_attribute?(method)
|
28
|
-
attributes[method]
|
29
|
-
else
|
30
|
-
super
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
24
|
def persisted?
|
35
25
|
attributes.has_key?(primary_key)
|
36
26
|
end
|
@@ -43,8 +33,26 @@ module JsonApiClient
|
|
43
33
|
attributes.fetch(primary_key, "").to_s
|
44
34
|
end
|
45
35
|
|
36
|
+
def respond_to?(method, include_private = false)
|
37
|
+
if (method.to_s =~ /^(.*)=$/) || has_attribute?(method)
|
38
|
+
true
|
39
|
+
else
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
46
44
|
protected
|
47
45
|
|
46
|
+
def method_missing(method, *args, &block)
|
47
|
+
if method.to_s =~ /^(.*)=$/
|
48
|
+
set_attribute($1, args.first)
|
49
|
+
elsif has_attribute?(method)
|
50
|
+
attributes[method]
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
48
56
|
def read_attribute(name)
|
49
57
|
attributes.fetch(name, nil)
|
50
58
|
end
|
@@ -59,4 +67,4 @@ module JsonApiClient
|
|
59
67
|
|
60
68
|
end
|
61
69
|
end
|
62
|
-
end
|
70
|
+
end
|
@@ -8,8 +8,9 @@ module JsonApiClient
|
|
8
8
|
extend Forwardable
|
9
9
|
def_delegators :new_scope, :where, :order, :includes, :all, :paginate, :page, :first
|
10
10
|
end
|
11
|
-
class_attribute :connection_class
|
11
|
+
class_attribute :connection_class, :connection_object, :connection_options
|
12
12
|
self.connection_class = Connection
|
13
|
+
self.connection_options = {}
|
13
14
|
end
|
14
15
|
|
15
16
|
module ClassMethods
|
@@ -17,18 +18,16 @@ module JsonApiClient
|
|
17
18
|
Scope.new(self)
|
18
19
|
end
|
19
20
|
|
20
|
-
def connection
|
21
|
-
|
22
|
-
|
23
|
-
rescue
|
24
|
-
build_connection
|
25
|
-
end
|
26
|
-
yield(@connection) if block_given?
|
27
|
-
@connection
|
21
|
+
def connection(&block)
|
22
|
+
build_connection(&block)
|
23
|
+
connection_object
|
28
24
|
end
|
29
25
|
|
30
26
|
def build_connection
|
31
|
-
|
27
|
+
return connection_object unless connection_object.nil?
|
28
|
+
self.connection_object = connection_class.new(connection_options.merge(site: site)).tap do |conn|
|
29
|
+
yield(conn) if block_given?
|
30
|
+
end
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|